int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
// Avoid Warnings
UNREFERENCED_PARAMETER( hPrevInstance );
UNREFERENCED_PARAMETER( lpCmdLine );
// Create Engine Objects
T_Engine::CreateInstance();
T_Window::CreateInstance();
T_System::CreateInstance();
// Return FALSE if an instance is corrupt
if( T_ENGINE->HasInstance() == false ) return FALSE;
if( T_WINDOW->HasInstance() == false ) return FALSE;
if( T_SYSTEM->HasInstance() == false ) return FALSE;
// Create The Game Object
StarBattle* pStarBattle = new StarBattle();
// Receive Properties from Game Object
pStarBattle->InitializeProperties();
// Initialize Engine Objects with Properties
T_WINDOW->Initialize( hInstance, nCmdShow );
// Startup the Game
pStarBattle->GameStart();
// Run the Message loop
MSG msg = {0};
int iTickCount = 0, iTickTrigger = 0;
while( msg.message != WM_QUIT )
{
if( PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
iTickCount = GetTickCount();
if( iTickCount > iTickTrigger )
{
iTickTrigger = iTickCount + 1000/T_ENGINE->GetFramerate();
// Update Game
pStarBattle->GameUpdate();
// Render Game
pStarBattle->GameRender();
}
else
{
Sleep(1);
}
}
}
// End the Game
pStarBattle->GameEnd();
// Deallocate all Engine Objects
T_Engine::ReleaseInstance();
T_Window::ReleaseInstance();
T_System::ReleaseInstance();
return TRUE;
}
So this is a basic code of my WinMain.
Creating Engine objects using Singleton design.
Asking the Game class for the properties and initialize engine with it.