27 Sep 11, 01:34AM
[SELECT ALL] Code:
void limitfps(int &millis, int curmillis)
683 {
684 if(!maxfps) return;
685 static int fpserror = 0;
686 int delay = 1000/maxfps - (millis-curmillis);
687 if(delay < 0) fpserror = 0;
688 else
689 {
690 fpserror += 1000%maxfps;
691 if(fpserror >= maxfps)
692 {
693 ++delay;
694 fpserror -= maxfps;
695 }
696 if(delay > 0)
697 {
698 SDL_Delay(delay);
699 millis += delay;
700 }
701 }
...
1222 for(;;)
1223 {
1224 static int frames = 0;
1225 static float fps = 10.0f;
1226 int millis = SDL_GetTicks() - clockrealbase;
1227 if(clockfix) millis = int(millis*(double(clockerror)/1000000));
1228 millis += clockvirtbase;
1229 if(millis<totalmillis) millis = totalmillis;
1230 limitfps(millis, totalmillis);
1231 int elapsed = millis-totalmillis;
1232 if(multiplayer(false)) curtime = elapsed;
1233 else
1234 {
1235 static int timeerr = 0;
1236 int scaledtime = elapsed*gamespeed + timeerr;
1237 curtime = scaledtime/100;
1238 timeerr = scaledtime%100;
1239 if(nextmillis && watchingdemo)
1240 {
1241 curtime += nextmillis;
1242 nextmillis = 0;
1243 }
1244 if(paused) curtime = 0;
1245 }
1246 lastmillis += curtime;
1247 totalmillis = millis;
1248
1249 checkinput();
1250
1251 if(lastmillis) updateworld(curtime, lastmillis);
1252
1253 if(needsautoscreenshot) showscores(true);
1254
1255 serverslice(0);
1256
1257 if(elapsed) fps = (1000.0f/elapsed+fps*10)/11; // avoid DIV-by-0
1258 frames++;
1259
1260 audiomgr.updateaudio();
1261
1262 computeraytable(camera1->o.x, camera1->o.y, dynfov());
1263 if(frames>3 && !minimized)
1264 {
1265 gl_drawframe(screen->w, screen->h, fps<lowfps ? fps/lowfps : (fps>highfps ? fps/highfps : 1.0f), fps);
1266 if(frames>4) SDL_GL_SwapBuffers();
1267 }
1268
1269 if(needsautoscreenshot) makeautoscreenshot();
1270
1271 #ifdef _DEBUG
1272 if(millis>lastflush+60000) { fflush(stdout); lastflush = millis; }
1273 #endif
1274 if (direct_connect)
1275 {
1276 direct_connect = false;
1277 connectserv(servername, serverport, password);
1278 }
1279 }
This was taken from main.cpp. Essentially, all that having a high framerate means is that there is very little delay each time it goes through a certain point in the main method. I'm not incredibly familiar with c++ so I can't really explain this that well but this is basically like having some sort of script wait a second before it continues. The actual framerate for the video is most likely around 60 despite it saying 1000 since most monitors refresh at a rate of around 60 hertz. This is also the reason why there are certain bugs when playing with very low framerates since the system clock does not stop (remember in 1.0.2 how smg would shoot at a lower rate with low fps?). For things like physics, I have not looked at the code, but I'm pretty sure it's based off of the system clock since you can't walk through walls at 1 fps.