Game Development Reference
In-Depth Information
DXUTMainLoop() here, the C# editor wouldn
'
tgetanycontroluntil DXUTMainLoop()
returned.
If the C# editor application
s main loop is going to be responsible for handling mes-
sages, the editor needs to expose a few other functions as C free functions.
'
void WndProc(int *hWndPtrAddress, int msg, int wParam, int lParam)
{
HWND hWnd = (HWND)hWndPtrAddress;
DXUTStaticWndProc( hWnd, msg, WPARAM(wParam), LPARAM(lParam) );
}
void RenderFrame()
{
DXUTRender3DEnvironment();
}
int Shutdown()
{
DXUTShutdown();
return g_pApp->GetExitCode();
}
RenderFrame() exposes the rendering call, DXUTRender3DEnvironment() ,to
the C# application so it can render a frame if the editor isn
t handling any other mes-
sages. WndProc() exposes the C++ side message handling function so that the editor
can forward any appropriate messages to be handled by the editor game engine, such
as user input to move the camera position around. Finally, Shutdown() shuts down
the DirectX device and exits the editor.
The next method opens an existing level file, but before you see that, you need to
know a little more about how to pass strings between C# and C++, since they store
strings differently. One method is to use a type common to both, the BSTR type,
which is also used by COM. BSTR strings are converted easily to std::wstring
objects, which the game engine can convert to a std::string with ws2s .
'
std::string ws2s(const std::wstring& s)
{
int slength = (int)s.length() + 1;
int len = WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0)-1;
std::string r(len,
);
WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, &r[0], len, 0, 0);
return r;
'
\0
'
}
Search WWH ::




Custom Search