Archived

This topic is now archived and is closed to further replies.

Program flow?

This topic is 5108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hia guys! Ok, I''m about to start a "real" 3d engine now... What I''m wondering is how I should manage my "flow" of the engine? This time I would like to do it in somewhat professional way. So far I have managed ok with something like this:
CBaseApplication {
virtual init();
virtual loop();
virtual extendedloop();
virtual draw();
virtual shutdown();
.
.
.
}
 
then when I wanted to make the init sceene or the in game flow or the menue in game, I just derived from this base. Then I used an object like: CBaseApplication *application; CGameMenue *mainMenue = new CGameMenue(); ... application = mainMenue; ... application->loop(); ... But I feel that this is somewhat newbee level of managing the program flow ? Now recently I have been thinking of somekind of StateManager, that keeps track of all available states... for eg. My mainMenue state or even the Init state of the whole application... ? This manager would keep track of all the in game "states" and what state they are in, eg. if the mainMenue stat is in the Init state or in the Loop state or whatever ? Does this sound like a better idea? How do u manage the "flow" in you applications? Please give me some nice ideas, I want it to look "elegant" and effective, but most of all so that it is dynamic and easy to add new states by just adding a new source file. (the latter gave me the idea of a global Singleton StateManager...) thx! c ya all!

Share this post


Link to post
Share on other sites
You don''t tell much what kind of game you are thinking about and how you will interact different features.

If you think of a modern 3dgame, then I a simple solution as this will be enough:

bool update( ... )
{
if( menu.enabled() )
menu.update(...);
else
game.update(...);
}

bool render(...)
{
game.render(...);
if( menu.enabled() )
menu.render(...);
}


In most games, I don''t really see why a statemanager should be needed. But you can of course make one. You can have a pointer to a CBaseapplicaiton inside your managerclass

CBaseApp* pMenu = new CMenu();
CBaseApp* pGame = new CGame();


main()
{
statemgr.setstate(MAINENGINE);
while(1)
{
statemgr.update();
}
}

Statemgr::setstate(int state)
{
m_state = state;
switch(state)
{
case MENU: m_subset = pMenu;
}
}

Statemgr::update()
{
if( m_action == INIT )
{
m_subset.init();
m_action = RUN;
}

if ( m_action == DEINIT )
{
m_subset.cleanup();
m_action = NULL;
}

if ( m_action == RUN )
{
m_subset.update();
m_subset.draw();
}

}

----------------------------------------------
Petter Nordlander

"There are only 10 kinds of people in the world. They who understand binary and those who do not"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
daerid ... just fuck off...

Well, actually I just wanted to hear from you guys how you have your applications built upp. I just wanted some ideas on how a good application should be built

And I want my application to "look" good, heh - where my idea about a statemanager came in. "the more complicated the better" hehe...

So feel free to post any method you use...

thx to the other two guys!

Share this post


Link to post
Share on other sites
daerid ... just fuck off...

Well, actually I just wanted to hear from you guys how you have your applications built upp. I just wanted some ideas on how a good application should be built

And I want my application to "look" good, heh - where my idea about a statemanager came in. "the more complicated the better" hehe...

So feel free to post any method you use...

thx to the other two guys!

that eniginuity looks promising
(now that's exactly what I was looking for! hella great! thx !)

[edited by - bilsa on December 17, 2003 12:09:09 PM]

[edited by - bilsa on December 17, 2003 12:48:19 PM]

Share this post


Link to post
Share on other sites