Panda3D
Loading...
Searching...
No Matches
time_accumulator.h
1#ifndef __TIME_ACCUMULATOR_H__
2#define __TIME_ACCUMULATOR_H__
3// Think of this as a stopwatch that can be restarted.
5{
6public:
9
10 void Start();
11 void Stop();
12 void Reset();
13 void Set(const Time_Span & in);
14
15 Time_Span Report();
16private:
17
18 Time_Span _total_time; // the collected time from previous start/stops
19 Time_Clock *_accum_start; // the time of day the clock started
20};
21
22// you can set the internal accumilator to a value..
23inline void Time_Accumulator::Set(const Time_Span & in)
24{
25 _total_time = in;
26 // this seems to make the most since .. if you are running the clock right
27 // know... assume the timespane you are passing in is inclusive.. but keep
28 // clock running.. May need to rethink this...
29 if(_accum_start != nullptr)
30 {
31 Stop();
32 Start();
33 }
34}
35/**
36 *
37 */
38inline Time_Accumulator::Time_Accumulator() : _total_time(0,0,0,0,0), _accum_start(nullptr)
39{
40}
41/**
42 *
43 */
44inline Time_Accumulator::~Time_Accumulator()
45{
46 if(_accum_start != nullptr)
47 delete _accum_start;
48}
49/**
50 *
51 */
52inline void Time_Accumulator::Start()
53{
54 if(_accum_start == nullptr)
55 _accum_start = new Time_Clock();
56}
57/**
58 *
59 */
60inline void Time_Accumulator::Stop()
61{
62 if(_accum_start != nullptr)
63 {
64 Time_Span work1(Time_Clock::GetCurrentTime() - *_accum_start);
65 _total_time += work1;
66 delete _accum_start;
67 _accum_start = nullptr;
68 }
69}
70/**
71 *
72 */
73void Time_Accumulator::Reset()
74{
75 if(_accum_start != nullptr)
76 {
77 delete _accum_start;
78 _accum_start = nullptr;
79 }
80 _total_time.Set(0,0,0,0,0);
81}
82/**
83 *
84 */
85inline Time_Span Time_Accumulator::Report()
86{
87 Time_Span answer(_total_time);
88 if(_accum_start != nullptr)
89 {
90 Time_Span ww(Time_Clock::GetCurrentTime() - *_accum_start);
91 answer += ww;
92 }
93 return answer;
94}
95
96#endif //__TIME_ACCUMULATOR_H__
This class is to provide a consistant interface and storage to clock time
Definition time_clock.h:14
static Time_Clock GetCurrentTime()
The Default no param constructor.
Definition time_clock.h:128