SFML community forums
General => Feature requests => Topic started by: silverweed on September 23, 2015, 07:32:54 pm
-
There have been already a couple (http://en.sfml-dev.org/forums/index.php?topic=11989.0) of discussions (http://en.sfml-dev.org/forums/index.php?topic=4356.msg28520#msg28520) on this, but none has a definitive answer, so I'm proposing this again.
I think the sf::Clock class would greatly benefit from a pause() and resume() method, since more often than not games can be paused and resumed as well, and this usually needs some internal timers to be paused when the game pauses and resumed later.
Of course, one can use a third party implementation - and it's pretty trivial to implement this by oneself - but having a standard API would be a better option.
Adding these two method would not break compatibility, but if sf::Clock is not to be changed, a new class could be added with the same interface as sf::Clock plus these methods.
(If API change is problematic, this may be considered for SFML 3)
-
Those "discussions" come up with a couple of solutions - both being to use a separate code for the pausable clock.
I'm not sure that this is required in SFML as "it's pretty trivial to implement this by oneself" and would go along with other stuff that you use all the time but isn't a part of SFML.
more often than not games can be paused and resumed as well, and this usually needs some internal timers to be paused when the game pauses and resumed later.
Pausing the game means pausing the game logic but not necessarily time, as menus (for example) may require animations.
Since you'll probably end up creating and reusing timestep code anyway, why not add your pausable clock (if you still need it) to be included with your timestep code?
It would be odd for me to not mention my small timing library, Kairos (https://github.com/Hapaxia/Kairos/wiki), which - amongst other things - provides pausable clocks (including one which can have its speed altered - including backwards!), and also timestep simplification.
-
You can also use thor::StopWatch (http://www.bromeon.ch/libraries/thor/v2.0/doc/classthor_1_1_stop_watch.html). There's some other stuff in Thor that you might find interesting, too ;)
-
You can also use thor::StopWatch (http://www.bromeon.ch/libraries/thor/v2.0/doc/classthor_1_1_stop_watch.html). There's some other stuff in Thor that you might find interesting, too ;)
I'm going to have a look and probably use it for my next project - since I'm almost done with the game logic for the game I'm currently doing, and since it's my first SFML project at all, I prefer not adding more libraries to it right now ;)
@Hapax: thanks for pointing that out; for now I'm using sftools::Chronometer (https://github.com/mantognini/sftools) with a couple of changes to adapt to the sf::Clock interface, but I'll take a look at your library too for the future.
-
There's also this
https://github.com/anthnich/sfml-pauseableclock