Game Development Reference
In-Depth Information
m_pScene->VOnRestore();
return true;
}
The only task here is to hook up the keyboard and mouse handlers and then restore
the scene to make sure all the resources are loaded and ready to draw when the first
frame is rendered. If you don
t do that here, you might see a black window in the
game view area before the editor is fully initialized.
As you learned in Chapter 21, A Game of Teapot Wars, the Scene class registers
delegates to listen for events, such as when a new actor is created. Actors like AI
spawn points or trigger zones are invisible in the game but should most certainly be
visible in the editor. Render components are a great example of how some compo-
nents may be
'
and get stripped out when the game files are built. In
this simple editor, there are no editor only components, but that would be a great
extension to the component system.
editor only
Functions to Access the Game Engine
While it is possible to instantiate objects in C++ and pass their pointers to C#, doing
so requires a lot of preparation work, and it makes this sample editor a lot more com-
plicated. Instead of creating an instance of the editor application layer and passing
that pointer to the C# editor app, I
ll use C-style functions that will access the global
instance of the application layer and communicate data between the two with simple
data structures like XML. This not only simplifies the code and my explanation of it,
but it also makes the editor extensible without modifying much, if any, C# code.
These C++ functions are all going to be exported and exposed in a DLL that the C#
application will load and call into. These free functions fall into a few general catego-
ries of
'
functionality: the editor framework, accessing actor data, and modifying
'
actors. I
ll start with the editor framework.
Editor Framework Functions
One of the functions that definitely needs to be exposed is the entry point to the
application, which you read about back in Chapter 5. It is very similar to the original
GameCode4() function, but it has a different beginning and ending.
int EditorMain(int *instancePtrAddress,
int *hPrevInstancePtrAddress,
int *hWndPtrAddress,
int nCmdShow,
int screenWidth, int screenHeight)
{
// C# passes HINSTANCE and HWND values to C++ DLL as (int *)
 
 
Search WWH ::




Custom Search