Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Pausable clock...?  (Read 4571 times)

0 Members and 1 Guest are viewing this topic.

silverweed

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Pausable clock...?
« on: September 23, 2015, 07:32:54 pm »
There have been already a couple of discussions 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)
« Last Edit: September 23, 2015, 07:38:31 pm by silverweed »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Pausable clock...?
« Reply #1 on: September 23, 2015, 08:54:01 pm »
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, which - amongst other things - provides pausable clocks (including one which can have its speed altered - including backwards!), and also timestep simplification.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Pausable clock...?
« Reply #2 on: September 24, 2015, 09:07:29 am »
You can also use thor::StopWatch. There's some other stuff in Thor that you might find interesting, too ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

silverweed

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: Pausable clock...?
« Reply #3 on: September 24, 2015, 09:34:49 am »
You can also use thor::StopWatch. 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 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.

Sub

  • Full Member
  • ***
  • Posts: 159
    • View Profile
Re: Pausable clock...?
« Reply #4 on: October 04, 2015, 03:36:22 am »