PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

restart my program

Hello.
How can I restart my program?
(I want to change orientation in PocketFrog, but it can't do it on-the-fly)
Evc 4.0.
thanks.
How do you start your game loop? Is it something like this:
Code:
// WinMain - Application Entry Point
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, int )
{
_Module.Init( 0, hInstance );
pMyGame = new MyGame();
pMyGame->Run();
return 0;
}
If so, you could wrap the two "pMyGame..." lines in a loop, checking for an orientation change with a global variable... Like this:
Code:
bool bOrientationChange;

// WinMain - Application Entry Point
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPTSTR, int )
{
_Module.Init( 0, hInstance );
bOrientationChange = true;
while(bOrientationChange)
{
bOrientationChange = false;
pMyGame = new MyGame();
pMyGame->Run();
}
return 0;
}
That way, if you change bOrientationChange to true somewhere in your game, and then call Shutdown(), it should restart. Of course, you'll need to set an orientation variable somewhere too so it knows which orientation to use. You can also use a variable for whether or not to play the game's splash screen, to keep the user from having to wait any longer than necessary.

-John
Presto, thanks!
I have also added SetForegroundWindow(m_hWnd); in GameInit() to set my window foreground.
John, if you do this don't you need to delete the pMyGame?

Does this cause the GameEnd() to trigger and another GameInit()?
Good call, fast_rx. Definitely want to delete pMyGame after the Run() line. I haven't tried switching the orientation like this myself, so I'm not sure if anything quirky happens behind the scenes, but it seems straight-forward enough.

:)

BTW, whatever happened to that top-down tank combat game you were developing?
The tank game is pretty much finished - although I was considering trying to get the orientation to switch with your code... I don't think I will bother. Currently, you just have to exit and restart for an orientation change to occur.

After I build up a couple of dozen more levels, it (Assaultaire) will be released through Clickgamer. I'm hoping that will be in a couple of weeks.
Any chance you could post a screenshot or two? There seems to be a lack of cool games at the moment. :-)
It's a pretty fun game, might I add, although the editor gives me nightmares :P

I'll stop dragging this thread off topic now.