necron Posted September 26, 2006 Report Share Posted September 26, 2006 (edited) 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 secondand 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) ... regardsNecron Edited September 26, 2006 by necron Link to comment Share on other sites More sharing options...
red knight Posted September 26, 2006 Report Share Posted September 26, 2006 There are several side issues when you apply framelocking. One and probably the most serious one is when your frame loop is already taking near 70 FPS. The sleep will cause the process to move from the ready state to a sleep state waiting for an OS interruption. Something that in normal operation isnt problematic at all.. however when you are near the framerate you will end up hurting for a few frames (in the worst case - theoretically- can be 2 per frame step if you are VSynched, something that you cannot know before hand ). Now the complexity and the problems caused by not having the 100% of the time "doing nothing" can have other side issues... for instance if you have enough unconstrained time, your physics engine can at the end execute with smaller steps adding extra robustness to the physics and gameplay, improving playability in the general case ... maybe that is not applicable to Xenocide, but it is a consecuence that you must be aware of... The reality is that there is not a non functional requirement to keep the CPU use on the lower bound for Xenocide, so until it is so, the unnecesary complexity that it adds is not worth even the effort. I really appreciate the involvement in bringing the issue forward, but this special one will be defered until needed. See you soon in the forums GreetingsRed Knight Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now