Ok, so let’s say I have unchecked the Use Frame Rate button to let the speed of the bge go wild. But I want to make sure the frame-rate doesn’t go over 60. V-Sync works, but then if someone uses a display higher than 60hz then the game will run faster. I’m doing this to work-around a bug.
You can use sleep functions to force the processes wait based on the estimated time that takes for the game to execute each logic step. So for example if the game takes an average of 6ms each frame it would be 1000/6 = 166Hz, so to get 60Hz = 16ms you need to wait 10ms.
That would work perfectly, could I use the newly added time related functions in 2.77 to achieve this like bge.logic.setUseExternalClock?
Ah nvm i got it! So simple, just used
import time
time.sleep(0.016) which is about 60fps, needs some tuning. Thank you for the help! also set it to pulse.
actually this doesn’t quite get the job done, it still adds onto the render-time so even if one thing is using 1ms it won’t be 60.
Well first of you should calculate the average time (or last time), not hardcode it. Also this solution shouldn’t really be used outside tests, the sleep functions differ on precision across different OS, so you need to enforce some level of precision there. In any case the proper way to do this kind of things is from inside the BGE.
Is there a way within the bge to cap the framerate which is consistent across all OS, If this solution isn’t?
I do not understand your request. You do not want to use the build-in processing, but fiddle with tricks to get the same effect?
Well yes, there’s an issue I’m having with the game engine when the framerate goes below the one set in the physics tab. I have animation, when that animation gets to a certain frame a sound will play. When the framerate is under the fps set in the physics tab, there is a chance this sound will not be played when that animation gets to that frame.
This sounds as your way of detecting the event is the problem. What setup do you have?
Alright, can’t get a screens hot now but here’s my setup, always-and-action the object plays the action when the game starts. Within the action actuator, I have set a int variable named “shot” to keep track of the frame the animation is on. I have a property sensor on the same object, if shot = 900 then it will play a sound. At lower framerates the sound never plays.
Ok so I have a video of the problem now,
The first time I start the scene, it runs normally because the framerate is normal, it goes onto the next scene (static screen). When I decrease the framerate by adding on a filter and some AA, notice how it never changes scenes and the camera action doesn’t play. Only happens when the framerate is below 60.