Game Loop

Started by
1 comment, last by GameDev.net 24 years, 3 months ago
Well you don't want to poll for every single message windows sends. You only poll for the ones that intrest you. Like WM_Create, WM_Paint, and WM_Destroy. And you ignore the rest of the messages.

Now onto the game loop question. The best way to implement a SET FRAME rate in your main game loop is to use a high resolution timer (there are articles on this in the articles section on game dev). You could also use Sleep(30), or grab the monitors refreshrate & use that as your limiting factor but those two will never run at the same speed on diffrent systems.

The methodology wouldn't change much if you were running on a diffrent platform. You'd just have to deal with diffrent messages. The high resolution timer function would be basicly the same. I'm not giving you any code here, but if you just create a main game loop and only deal with the above menchoned messages and add in a hi-res timer you'll be fine.

Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
Advertisement
I want to know the best way to design the general game loop. This probably differs from platform to platform, so I am confining my question to the "Windows" platform (insert flame here).

As I understand it, if you are going to take over windows to run your game, you need to have some mechanism in place to deal with Windows Messages. Obviously you can't ignore them, because operations such as polling the CD Rom or hard drive are dependant on Windows. The problem is, everytime you move the mouse you also get a window's message (right???) so dealing with messages in a timely manner will prevent them from being stored in cache and bottlenecking.

My question (oh yes I do have one) is how do you set up your game loop so that you can handle Windows messages in a timely manner and also render graphics at a set framerate??

Would this methodology change if you wanted you game to run one a different platform??

I look forward to your thoughts.
-Thanx

if you create a directinput device to handle the mouse the mouse messages don't get sent. my message loop is designed like so that the engine would render frames whenever there was no message. it uses PeekMessage to avoid blocking. when there is a message, it just processes it and continues on. messages don't take up much time because there aren't that many in the first place if you just create a fullscreen window. the only ones i handle are WM_ACTIVEATEAPP, WM_MOVE, WM_PAINT, WM_SETCURSOR, WM_CLOSE, and WM_DESTROY

------------------
http://members.xoom.com/mutex0


This topic is closed to new replies.

Advertisement