OpenXcom  1.0
Open-source clone of the original X-Com
Timer.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <SDL.h>
21 #include "State.h"
22 #include "Surface.h"
23 
24 namespace OpenXcom
25 {
26 
27 typedef void (State::* StateHandler)();
28 typedef void (Surface::* SurfaceHandler)();
29 
35 class Timer
36 {
37 public:
38  static int maxFrameSkip;
39  static Uint32 gameSlowSpeed;
40 
41 private:
42  Uint32 _start;
43  Uint32 _frameSkipStart;
44  int _interval;
45  bool _running;
46  bool _frameSkipping;
47  StateHandler _state;
48  SurfaceHandler _surface;
49 public:
51  Timer(Uint32 interval, bool frameSkipping = false);
53  ~Timer();
55  void start();
57  void stop();
59  Uint32 getTime() const;
61  bool isRunning() const;
63  void think(State* state, Surface* surface);
65  void setInterval(Uint32 interval);
67  void onTimer(StateHandler handler);
69  void onTimer(SurfaceHandler handler);
71  void setFrameSkipping(bool skip);
72 };
73 
74 }
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Timer used to run code in fixed intervals.
Definition: Timer.h:35
~Timer()
Cleans up the timer.
Definition: Timer.cpp:59
void setFrameSkipping(bool skip)
Turns frame skipping on or off.
Definition: Timer.cpp:171
void start()
Starts the timer.
Definition: Timer.cpp:66
void stop()
Stops the timer.
Definition: Timer.cpp:75
void think(State *state, Surface *surface)
Advances the timer.
Definition: Timer.cpp:109
void setInterval(Uint32 interval)
Sets the timer&#39;s interval.
Definition: Timer.cpp:144
Timer(Uint32 interval, bool frameSkipping=false)
Creates a stopped timer.
Definition: Timer.cpp:51
void onTimer(StateHandler handler)
Hooks a state action handler to the timer interval.
Definition: Timer.cpp:153
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
bool isRunning() const
Gets if the timer&#39;s running.
Definition: Timer.cpp:98
Definition: BaseInfoState.cpp:40
Uint32 getTime() const
Gets the current time interval.
Definition: Timer.cpp:85