   seems to have been fixed.. -  FPS limiter acting very odd
  Oddly enough, this problem seems to have sorted itself out on its own.. I must have made a parenthesis error or something.----------------------------------------------------------------Hello.  I'm currently working on an RTS in java.  I thought my FPS counter and limiter were working properly, but they aren't.  Just recently, I added another thing that is based on framerate, and found that my actual FPS was double what was shown.  I thought, no big deal, I'll just double the FPS when I calculate it, and it should fix the problem...  But now my actual FPS is half of what it should be!Here's a bit of code to show you what I mean.Here is what I use to calculate my FPSif(FPSCount%10==0){long ThisTime=System.currentTimeMillis();FPS=(int)(1.0f/((float)(ThisTime-LastTime)/10000.0f));  //I change the 1.0f to a 2.0f and it forths my FPS after limiting.debug=""+FPS;LastTime=ThisTime;}FPSCount++;g.drawString(debug,50,50);And here is my limiter.if(counter%10==0 && (FPS<27 || FPS>33)){SleepTime+=(FPS-30)/4;}Every frame, I sleep for the amount of time suggested by SleepTime.  The displayed FPS ends up stabalizing between 27 and 33, like I expected, but the actual FPS is different.I have no clue what is causing this..  Help would be appreciated.edit-----------sqrt(2) instead of 1 or 2 also does not work.  It causes the shown FPS to be lower than the actual FPS.[Edited by - Adams555 on June 19, 2006 2:37:00 PM]
  If you want me to be completely honest, I don't understand why your code is so complicated. Here is my FPS counter and limiter:Assumed it is called once per frame. Deltatime is the time between each frame#define ONE_SECOND 1000void FpsCounter::Update(void){    // Get the deltatime and add to TimeElapsedInMs    _TimeElapsedInMs += _SdlTimer.GetDeltatime();    // Increment FrameCount    ++_FrameCount;    // Check if 1 second (1000 ms) has passed    if(_TimeElapsedInMs >= ONE_SECOND)    {   // If so, CurrentFps is equal to the FrameCount   _CurrentFps = _FrameCount;   // Reset all the counters taking into account of previous overflow   _FrameCount = 0;   _TimeElapsedInMs -= ONE_SECOND;    }}// Limit the framerate// Update the timer and store the time taken to render the frame_FrameDelay = 1000/60;unsigned int Deltatime = _Timer->GetDeltatime();// Sleep for the remaining time needed to limit the FPS only if Deltatime is less then the FrameDelayif(Deltatime < _FrameDelay)   _Timer->Delay(_FrameDelay - Deltatime);;  i wouldn't advice using sleep , cause the time consumed by sleep changes according to the amount of proceses currently running. so basicly the more applications in need of CPU time-- the more time sleep will take. here is what i use// if there is a limit calculate the Time needed for each frameif (Sync_rate!=0) TIME_Space = tickpersecond/Sync_rate;// holds the current timeUINT64 x_TIME;//get the current time ,in ticks.if( !QueryPerformanceCounter((LARGE_INTEGER *)&x_TIME) )x_TIME = (UINT64)GetTickCount();// if Time_Space has already passed since the last frameif (((x_TIME) >= (Next_Time+ TIME_Space))&&Sync_rate!=0){//the next time.//Next_Time = x_TIME;if( !QueryPerformanceCounter((LARGE_INTEGER *)&Next_Time) )Next_Time = (UINT64)GetTickCount();// Renderthis->Render(MyXWnd);}// if there is no limit , just render.if (Sync_rate==0)this->Render(MyXWnd);// the current timefloat Cur_time;//get the current time in secondsCur_time = GetPTime();// if one second has passedif ((Cur_time-time) >=1.0f){//fill the var with the fpsStringCchPrintf(fps,40,"%s%f","FPS is ",frames/(Cur_time-time));// reset the framesframes = 0;// reset the timetime= GetPTime();}