Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualHodgman

Posted 29 August 2012 - 11:14 AM

As I said, I would put some code down. Here you go:

...
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.

I'd suggest using constructors/destructors and not using the singleton anti-pattern:
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
	T_Engine engine;
	T_Window window( hInstance, nCmdShow );
	T_System system( engine, window );

	StarBattle starBattle(engine, window, system);

	// Run the Message loop
	MSG msg = {};
	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/engine.GetFramerate();
				starBattle.GameUpdate();
				starBattle.GameRender();
			}
			else
			{
				Sleep(1);
			}
		}
	}

	return TRUE;
}

Should release in the reverse order of allocation

This is good advice, and N.B. this happens automatically in the above re-write, when not over-engineering things Posted Image

#2Hodgman

Posted 29 August 2012 - 11:12 AM

As I said, I would put some code down. Here you go:

...
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.

I'd suggest using constructors/destructors and not using the singleton anti-pattern:
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
	T_Engine engine;
	T_Window window( hInstance, nCmdShow );
	T_System system( engine, window );

	StarBattle starBattle(engine, window, system);

	// Run the Message loop
	MSG msg = {};
	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/engine.GetFramerate();
				starBattle.GameUpdate();
				starBattle.GameRender();
			}
			else
			{
				Sleep(1);
			}
		}
	}

	return TRUE;
}

#1Hodgman

Posted 29 August 2012 - 11:11 AM

As I said, I would put some code down. Here you go:

...
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.

I'd suggest using constructors/destructors and not using the singleton anti-pattern:
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
T_Engine engine;
T_Window window( hInstance, nCmdShow );
T_System system( engine, window );
StarBattle starBattle(engine, window, system);
// Run the Message loop
MSG msg = {};
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/engine.GetFramerate();
    starBattle.GameUpdate();
    starBattle.GameRender();
   }
   else
   {
    Sleep(1);
   }
  }
}
return TRUE;
}

PARTNERS