Re: Timers based on fps?

2021-02-17 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: Timers based on fps?

If the question is how do I get time based off framerate then @2 has answered it.  you just sum the time between frames and don't bother advancing it when the game is paused.If the question is how do I efficiently schedule millions of callbacks to run at specific times without bogging down the game, then the answer is either a priority queue or a timer wheel.  I'd go priority queue mostly because there's either a built-in package or a library for any programming language you care to name.  Make the time the priority and just keep grabbing the lowest until the lowest isn't going to run.  Timer wheels are technically more scalable but you don't care about pushing this far enough that you need one unless you're something like an operating system, and overall there's not a lot of packages for them even in something like Rust where you'd expect there to be a lot.However, as usual: wait until a simple "here's my list of timers and a for loop" approach is too slow before doing anything.  Complicated can be faster but isn't going to be for small numbers of timers and complicated always has the chance of introducing a lot more bugs than simple.

URL: https://forum.audiogames.net/post/616323/#p616323




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Timers based on fps?

2021-02-16 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Timers based on fps?

That can depend on a number of things, for example if VSync is enabled tent the frame rate is typically locked to the refresh rate of the monitor, typically 60 fps. But the rate that a computer can refresh a scene can be several times greater than that, like upwards of 240 fps or more, or less depending on the process load.Generally speaking, its more efficient to have a single update loop timer, and use that to set the rate of the rest of the program. For example:import pyglet

class Prototype(pyglet.window.Window):
def __init__(self):
super(Prototype, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()

self.counter = 0

pyglet.clock.schedule_interval(self.update, .01)


def update(self,dt):
self.counter += dt

if self.counter >= 0.13 and self.counter <= 0.15:
print('0.2 seconds have passed')
self.draw()

elif self.counter >= 1.0:
print('a second has passed')
self.counter = 0


def draw(self):
self.clear()

if __name__ == '__main__':
window = Prototype()
pyglet.app.run()In this case, you can use the dt time value to set the refresh rate, decide when code is run, etc. without having to bother with many different timers. Just create a new variable that adds up from the main dt value.

URL: https://forum.audiogames.net/post/616237/#p616237




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Timers based on fps?

2021-02-16 Thread AudioGames . net Forum — Developers room : BoundTo via Audiogames-reflector


  


Timers based on fps?

What would be an efficient way to create timers that update accordding to the frame rate? It makes sense that timers that update from system time wouldn't be that helful, so one would have to resort to implimenting their own timers that respect how quickly the game updates. Any thoughts? I'm assuming you have to be careful how you do this since timers would likely be used in many different places across a project.

URL: https://forum.audiogames.net/post/616225/#p616225




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector