PocketMatrix forums

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

Struggling with game loop

Hi,

I've always wondered what's the best way to make a tight game loop for PocketPC games.

eg:
I have a WinMain like so:
Code:

WinMain()
{
while (game.Running())
{
game.Process();
}
}


Where the game.Process clears the screen, checks input, does all game related things, and returns.

However, making it all OOP based, I have a GFX baseclass, with a GDI and GAPI class that you can swap out and pick whichever one you want.

I create the Window in the GAPI.Create() function, and have the WndProc in the GAPI.cpp file to handle input etc, with it having a pointer to the main game object, so in the WndProc on LBUTTON_DOWN I do game->GetInput()->AddMouse(x,y, button) kind of thing.

Is this correct? How do make sure that nothing starves ? All I want is a game loop that is as tight as it can be, but still gets mouse and key input.

This seems like a silly question, but it's just a concept I can't seem to get, how to most people do their loops and window message handling?

And if I'm speaking nonsense, just say, and I'll try explain it again.

Thanks in advance.
You should look at how PocketFrog works. But I'll summarize:

The GameLoop() function is called as often as possible.

There are event functions for: StylusDown(x,y), StylusMove(x,y), StylusUp(x,y), ButtonDown(button), ButtonUp(button).

There are of course initialization and shutdown functions, and it's all wrapped nicely in a Game class. That's pretty much it... There's not any nasty overhead.

Depending on the complexity of your app, you may want to develop a separate class to handle individual screens, and then just branch to the active screen from the GameLoop... In which case you could also give your screen class its own set of input event functions.

After having written games both ways (having TONS of stuff in GameLoop and having almost nothing in GameLoop), I much prefer dividing out the game functionality.

Hope this helps,
-John
I'd second that recommendation; take a look at PocketFrogs source code. You could also take a look at GapiDraws CGapiApplication class.
Hey Presto! (ba boom dish!)

Thanks for the suggestions, I will take a look at PocketFrog today.