Jump to content
XCOMUFO & Xenocide

necron

Forum Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by necron

  1. Hi guys, some of you know me from irc ... I am a guy who is interested in project xenocide and I plan to join as a recruit in the programming department. As there is some discussion going on in the workshop / acitve:programming forum where I cant post, I asked reist, if I should open a new topic where non-members/non-recruits can join the discussion too ... so here it is I once started a discussion about "frameratelocking" and now I will try to clarify what was my point about that. Here is an example about what I was talking about (quick and dirty, as we all love it) ... sorry about the weird spacing: #define FPS_MAX 70 long timeSinceLastFrame=0; int sleepTime=0; // time to sleep if pc is too fast // begin main loop while (this->getCurrentState() != SHUTDOWN) { this->mApplicationTimer->reset(); // timer = 0 this->mInputHandler->capture(); // get some input // run the message pump #if defined (WIN32) { MSG msg; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) this->requestStateChange(SHUTDOWN); else { TranslateMessage(&msg); DispatchMessage(&msg); } // else } // while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) } // if defined #endif this->mOgre->renderOneFrame(); timeSinceLastFrame = this->mApplicationTimer->getMilliseconds(); sleepTime = (1/(float)FPS_MAX*1000) - timeSinceLastFrame; if ( sleepTime > 0) // sleep, if pc was too fast Sleep ( sleepTime ); // this was for windows only -> is there a linux-command for this? } // while (this->getCurrentState() != SHUTDOWN) In this example the game won't do more than 70 loops per second. To prevent having 70 loops at maximum speed and then a long sleep, I calculate the time one loop should need. At the end of the loop, I check if the loop was too fast and sleep the rest of the time ... so we would have: loop,sleep 70 times per second and not 70 loops and one long sleep per second. I hope this clarifies it a little bit ... if not, just ask As far as I remember I learned this from the Ogre forums ... perhaps we can look there too ... I noticed, that there seem to be many different opinions by all the projectmembers from irc on this subject. so perhaps we just discuss it here ... perhaps its a bad idea to do such a "fpslock" ... I am eager to learn The "fpslock" or "maxlock" is only intended to make the game not using 100% cpu power. In the near future I will post some code from a book (I am running out of time now) about logic frame rates and only rendering the frame out when time is left to do so (on slow machines for example) ... Some people use a mix of these two ways in their main loop (the max-lock(as shown above) and the min-lock) ... regards Necron
×
×
  • Create New...