Jump to content
  • Advertisement

Archived

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

Nullio

MFC Game Loop

This topic is 6589 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

I''m reading "Tricks of the windows game programming gurus" By Andre LaMothe (very sweet book, a must read) and all of the examples are done is precedure style programming. I''m a OOPer myself and am wondering how to convert 2 things from precedure programming -> Object Programming. 1) The main game loop. I''ve been putting my game loop in the ::OnIdle method, is this the best way? 2) Creating a frameless window, I set up the code and flags perfectly but when I start DirectDraw and go full screen there is a border around the screen. here''s the code I''m using: //---Variables--- CString WndClass; //---Window Int Code--- WndClass= AfxRegisterWndClass(CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW, LoadCursor(NULL, IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), LoadIcon(NULL, IDI_APPLICATION)); CreateEx(NULL,WndClass, "Direct Draw Test",WS_POPUP | WS_VISIBLE, 0,0, 640,480, NULL, NULL, NULL); //---Thats All /* Thanks to anyone who can help P.S. If anyone loves game programming please find me on icq (please be a nice person who doesn''t mind being asked questions)

Share this post


Link to post
Share on other sites
Advertisement
quote:

1) The main game loop. I''ve been putting my game loop in the ::OnIdle method, is this the best way?


NOOOOO!!! Fel will back me up on this. You almost never want to override the default behavior of OnIdle in an MFC app.

As for what the best method is, it''s hard to say. Maybe OnTimer if it''s not critical (doubtful). Maybe in a separate thread? The problem is that a "game loop" is usually a procedural concept; when you move from that to a message-based program, like windows, it might not be appropriate.

Re: 2nd question, I''m not used to changing the flags (only write business apps), but I believe WS_POPUP includes a border; you might want to find that #define and pick only the flags you want.

Share this post


Link to post
Share on other sites
First off I''m going to beg you: please please PLEASE do NOT use OnIdle. Ever. Because if you do, in about a week you''re going to be back here complaining that you added some AI and all the sudden your game loop isn''t processing because OnIdle is never guaranteed to be called. Set up a windows timer and loop when you get a WM_TIMER message *if* you''re doing something that requires animation. If you''re doing something simple, like say a board game, then you just need to process mouse and keyboard input events. If you''re trying to do background stuff like AI, throw it in a worker thread.

As for getting rid of your frame: you can get rid of your frame and make your window basically any shape your heart desires (I have a pretty darn cool rhino-head-shaped one, personally) if you use CRgn. Rather than go into an in-depth explanation I''ll send you here. It''s Spiffy(TM).

-fel

Share this post


Link to post
Share on other sites
WM_TIMER is [a really bad] way to render, it''s worse than locking the frame rate...

If you do use OnIdle, as soon as you click on the one of the menu items or move the window, it stops & stalls. You can use a seperate UI thread and override its OnIdle to run the game loop.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster


I have had moderate success overriding CWinApp::Run to include calls to my rendering code, for what its worth.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!