#include "Main.h"
const int GraphicsDeviceType = GD_D3D9;
const UINT WindowWidth = 720;
const UINT WindowHeight = 640;
const bool VSync = true;
const String FontName = "Verdana";
void App::Init(HINSTANCE hInstance, int nCmdShow)
{
_state.graphics = NULL;
const String &windowName = "BaseCode";
#ifdef USE_D3D9
if(GraphicsDeviceType == GD_D3D9)
{
_state.graphics = new D3D9GraphicsDevice;
}
#endif
else
{
Assert(NULL, "Invalid graphics device type");
}
Assert(_state.graphics != NULL, "Failed to allocate graphics device");
g_WndProcContext = &_state.input;
_state.window.InitAll(hInstance, nCmdShow, false, WindowWidth, WindowHeight, windowName);
_controller = new Controller;
_controller->Init(_state);
GraphicsDeviceParameters parameters;
parameters.WaitForVSync = VSync;
parameters.MainFontName = FontName;
_state.graphics->Init(parameters, _state.window);
_state.timer.Start(60.0f);
_state.timer.Pause();
_controller->Init3D();
}
void App::RenderFrame()
{
_state.input.Frame();
Vec2i curDimensions = _state.window.Dimensions();
if(curDimensions != _state.dimensions)
{
_state.dimensions = curDimensions;
_state.graphics->ReSize(_state.window, *_controller);
_controller->ReSize();
return;
}
bool active = _state.graphics->StartRender();
if(active)
{
_state.timer.Frame();
_controller->Frame();
}
else
{
_state.timer.Pause();
}
_state.graphics->FinishRender(_state.window, *_controller);
}
void App::MessageLoop(HINSTANCE hInstance, int nCmdShow)
{
MSG msg;
BOOL bGotMsg;
PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );
while( WM_QUIT != msg.message ) {
bGotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ); if( bGotMsg ) {
TranslateMessage( &msg ); DispatchMessage( &msg );
}
else
{
RenderFrame();
}
}
}
void App::FreeMemory()
{
_controller->FreeMemory();
_state.graphics->FreeMemory();
_state.window.FreeMemory();
}