OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Timer.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_TIMER_H
20 #define OPENXCOM_TIMER_H
21 
22 #include <SDL.h>
23 #include "State.h"
24 #include "Surface.h"
25 
26 namespace OpenXcom
27 {
28 
29 typedef void (State::* StateHandler)();
30 typedef void (Surface::* SurfaceHandler)();
31 
37 class Timer
38 {
39 public:
40  static int maxFrameSkip;
41  static Uint32 gameSlowSpeed;
42 
43 private:
44  Uint32 _start;
45  Uint32 _frameSkipStart;
46  int _interval;
47  bool _running;
48  bool _frameSkipping;
49  StateHandler _state;
50  SurfaceHandler _surface;
51 public:
53  Timer(Uint32 interval, bool frameSkipping = false);
55  ~Timer();
57  void start();
59  void stop();
61  Uint32 getTime() const;
63  bool isRunning() const;
65  void think(State* state, Surface* surface);
67  void setInterval(Uint32 interval);
69  void onTimer(StateHandler handler);
71  void onTimer(SurfaceHandler handler);
73  void setFrameSkipping(bool skip);
74 };
75 
76 }
77 
78 #endif
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:37
~Timer()
Cleans up the timer.
Definition: Timer.cpp:60
void setFrameSkipping(bool skip)
Turns frame skipping on or off.
Definition: Timer.cpp:172
void start()
Starts the timer.
Definition: Timer.cpp:67
void stop()
Stops the timer.
Definition: Timer.cpp:76
void think(State *state, Surface *surface)
Advances the timer.
Definition: Timer.cpp:110
Uint32 getTime() const
Gets the current time interval.
Definition: Timer.cpp:86
void setInterval(Uint32 interval)
Sets the timer's interval.
Definition: Timer.cpp:145
Timer(Uint32 interval, bool frameSkipping=false)
Creates a stopped timer.
Definition: Timer.cpp:52
void onTimer(StateHandler handler)
Hooks a state action handler to the timer interval.
Definition: Timer.cpp:154
bool isRunning() const
Gets if the timer's running.
Definition: Timer.cpp:99
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39