What is better OnIdle or CTimer ????

When you are creating a game , you want to run it fast and steady , so that's why i want to show 30 frames per second, not 1 .

I use MFC , and i have this problem ,when i use CTimer,i set the interval to 1 , to run the game as fast as possible ,but that's not enough ,on fast computer that would be ok,but for exemple 200 Mhz , it would run slowly (for me).

Recently i 've discovered MFC function OnIdle ( this function is called when there arent any messages sent to application), it's far more better than CTimer ,but i has bugs too.When there arent any messages , i call my Draw function , and do other stuff. But that 's not a good programming , i think ...

So any advice would be appreciated.

P.S.
When i call OnIdle ,
i use GetTickCount to calculate how much time has passed..

Comments

  • : When you are creating a game , you want to run it fast and steady , so that's why i want to show 30 frames per second, not 1 .
    :
    : I use MFC , and i have this problem ,when i use CTimer,i set the interval to 1 , to run the game as fast as possible ,but that's not enough ,on fast computer that would be ok,but for exemple 200 Mhz , it would run slowly (for me).
    :
    : Recently i 've discovered MFC function OnIdle ( this function is called when there arent any messages sent to application), it's far more better than CTimer ,but i has bugs too.When there arent any messages , i call my Draw function , and do other stuff. But that 's not a good programming , i think ...
    :
    : So any advice would be appreciated.
    :
    : P.S.
    : When i call OnIdle ,
    : i use GetTickCount to calculate how much time has passed..
    :

    I surely think OnIdle is good compared to CTimer. Actually i programmed in Win32 not MFC where i wrote all my game code in the messageloop.
    like below:
    WinMain(.............)
    {
    // perform initilizations, create window etc....
    ..
    ..
    while(1)
    {
    PeekMessage(&msg,hwnd,0,0,PM_REMOVE))
    if(msg.message == WM_QUIT)
    break;

    Main_Game_Func();
    }
    return 0;
    }

    It is not the entire code but something like this.
    The idea is to use most of the CPU for our gaming purpose rather then processing messages. So i think CTimer is not suggested. Also i think CTimer has lower priority then other messages so the game may not run smoothly.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion