What's your WinMain look like?

Started by
21 comments, last by Fahrenheit451 18 years, 1 month ago
I'm just starting out in game programming, and I'm thinking about how I want to architect my game. I would like the majority of the generic game stuff to be reusable. I am not concerned right now with OS or graphics API independence, but I may be in the future. I was thinking about how the WinMain routine would call the game routines, and thought maybe you all would have some suggestions. My idea is similar to this (pseudocode): WinMain() { Game g = new Game; g.InitalizeGraphics(); g.CreateWindow(); TerrainManager t = new TerrainManager; t.LoadLevel(0); ModelManager m = new ModelManager; UnitManager u = new UnitManager(m); u.LoadUnits(0); ... while(!done) { ProcessWindowsMessages(); UpdateGameData(); RenderScene(); } DestroyAll(); } What do you think? What kind of generic layout do you guys use?
Advertisement
You should probably check for a previous instance of your game.
WinMain(){    Game *g = new Game();    g->Run();    delete g;}

Quote:Original post by Dave Hunt


I agree. The responsiblity of WinMain is to be an entry point for the linker. It should delegate all other responsibilities to other functions.

Quote:Original post by Dave Hunt
WinMain(){    Game *g = new Game();    g->Run();    delete g;}


Mines the same,
Here's the main from my current project (SDL)
int main( int argc, char** argv ){	try	{		Ultra1::App app;		app.Run( );	}	catch( Sim::Exception exc )	{		exc.WriteError( );	}	catch( ... )	{		Sim::Exception exc( "Unknown", "A built in exception occured" );		exc.WriteError( );	}	return 0;}
Quote:Original post by ToohrVyk
Quote:Original post by Dave Hunt


I agree. The responsiblity of WinMain is to be an entry point for the linker. It should delegate all other responsibilities to other functions.


Why?
-----------------------------Language: C++API: Win32, DirectXCompiler: VC++ 2003
Quote:Original post by simon10k
Quote:Original post by ToohrVyk
Quote:Original post by Dave Hunt


I agree. The responsiblity of WinMain is to be an entry point for the linker. It should delegate all other responsibilities to other functions.


Why?


1. WinMain is merely an entry point for an application.
2. More importantly, no function should do more than one thing.
Quote:Original post by Dave
1. WinMain is merely an entry point for an application.
2. More importantly, no function should do more than one thing.


Could you refer me to some documentation that states this?

-----------------------------Language: C++API: Win32, DirectXCompiler: VC++ 2003
Quote:Original post by simon10k
Could you refer me to some documentation that states this?


Common sense. Separation of responsibilities increases modularity, and modularity decreases the amount of work necessary when you have to change something. And decreasing the amount of work necessary to achieve something is inherently a Good ThingTM.

Typically, when a function F does A and B, you are bound to end up with a situation where you need a function G that does A but not B (solved by responsibility separation).

This topic is closed to new replies.

Advertisement