Advertisement

Strange DS <---> FPS bug (?)

Started by March 05, 2000 06:04 AM
9 comments, last by kieren_j 24 years, 7 months ago
Hi, Im not sure if anybody else has experienced something like this, but there appears to be a framerate that makes DirectSound unstable and jittery. I''ve been using GetTickCount() to do a basic framerate limiter.... * If I turn off the limit the game runs fine (no sound faults). * If I turn the limit up quite high the game runs fine (no sound faults). * If I set the limiter to about 30 (i.e. wait for 30 ticks to happen from the start to the end of each frame) then I get sound faults. Why is this? Does anybody else have this problem? thx
anybody?
Advertisement
How is the code for the framerate set?
1) Do you call a function that gets the framerate and the function just waits and returns once the time reaches a certain value?
2) Or do you have it set up so the function always returns a value and just doesn''t render the scene if the time hasn''t reached a certain number?

If 1, waiting for a certain time value might explain why. It might limit your FPS, but at the same time, the code to access sound won''t be executed until that same time is reached, resulting in chopping. But if the framerate is turned higher, the time will decrease, and thus the sound will sound smoother.
If 2, I would need to see your code to help.
That''s strange, i also use a limiter with GetTickCount() and the sound works just fine with or without the limiter.
Have you tried the DX SDK?
The problem seems to be that the game freezes when you wait, like you do a finitive loop with Sleep() or something. In Visual Basic, I would throw in a DoEvents() in the loop waiting for the time to pass, but I don''t know about C/C++. How do you do your waiting exacly?

One question though, why do all people limit the framerate? This is no good, and generally, I don''t think people using your software would like their framerate to be constantly, imagine buying a GeForce DDR and notice that Q3 is limited to 30fps. If you need to control the speed of things, limit the updates of the objects based on how fast the renderloop is instead. That would solve your problem too.

============================
Daniel Netz, Sentinel Design

"I'm not stupid, I'm from Sweden" - Unknown
============================Daniel Netz, Sentinel Design"I'm not stupid, I'm from Sweden" - Unknown
Framerates are - Locked - so to speak so that a game may run at the same FR on all pc''s much like pacman on a 486 could become super pacman on a PIII with Voodoo technology
Advertisement
I know that, but controlling the animation updates of the seperate objects instead of the whole scene is a better approach, if possible since if you do a strategy game with 100+ animated objects on screen at the same time, you might wanna do like you say.

============================
Daniel Netz, Sentinel Design
"I'm not stupid, I'm from Sweden" - Unknown
============================Daniel Netz, Sentinel Design"I'm not stupid, I'm from Sweden" - Unknown
The code I use is:
(example)

DWORD tme;while (running){    tme = GetTickCount();    frame();    windowsmessages();    while (GetTickCount() - tme < 30) {};} 


(where I alter the "30")
kieren_j, as I thought, you have a loop that does nothing, therefore, the sound code will only execute only every 1/30th of a second. Try the following (remember to change to correct code):
DWORD lastTickCount =  0;DWORD thisTickCount = 0;float delay = 1.0f/numberOfFrames*1000;bool isValidFrame(void){     thisTickCount = GetTickCount();     if ( (thisTickCount - lastTickCount) > delay){          lastTickCount = thisTickCount;          return true;     }     return false;}while (running){     if( isValidFrame() )          renderGraphics();     allOtherFunctions();}

This should work something like what I think you are asking for.
This is strange...
I tried your code, and I even tried checking for windows messages in the loop (rather than just idle loop), but if anything, this makes it a lot worse!

This topic is closed to new replies.

Advertisement