JNR
laTimer.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 #ifndef M_TIMER_H
30 #define M_TIMER_H
31 
33 
34 
35 //
36 // FILE: laTimer.h
37 //
38 // This class facilitates per-frame timing (delta, fps, etc)
39 //
40 // Copyright (C) 2007-2013 Atanas Laskov, <latanas@gmail.com>
41 //
42 
43 class laTimer
44 {
45  static double _dTimeMultiplier;
46  M_BOOL _bFirstFrame;
47 
48  LARGE_INTEGER fr;
49  LARGE_INTEGER f_start;
50  DWORD _dwTickCount;
51 
52  double _dFPS;
53  double _dSPF;
54 
55  M_BOOL _bStatisticsOn;
56  laTimeTrig _ttSampleFPS;
57  double _dFPS_Sampled, _dFPS_Avg, _dFPS_Min, _dFPS_Max;
58  double _nsamples;
59 
60 public:
61  laTimer(void);
62  ~laTimer(void);
63 
64  void frameStart();
65  void frameEnd();
66  void frameForce(double fps);
67 
68  inline double fps() const{return _dFPS; };
69  inline double delta() const{ return _dSPF; };
70 
71  inline double fps_sampled() const{ return _dFPS_Sampled; }
72  inline double fps_avg() const{ return _dFPS_Avg; }
73  inline double fps_min() const{ return _dFPS_Min; }
74  inline double fps_max() const{ return _dFPS_Max; }
75 
76  void statistics_log();
77  inline void statistics_enable(M_BOOL bon = M_TRUE) { _bStatisticsOn = bon; };
78 };
80 #endif //#ifndef M_TIMER_H
Time-triggered events.
Definition: laTimeTrig.h:41