Kiwano Engine v1.3.x
Ticker.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/utils/Timer.h>
23
24namespace kiwano
25{
26
29class KGE_API Ticker : public ObjectBase
30{
31public:
36 Ticker(Duration interval, int tick_count = -1);
37
38 Ticker();
39
43 virtual bool Tick();
44
49 virtual bool Tick(Duration dt);
50
53 Duration GetDeltaTime();
54
57 bool IsPausing() const;
58
61 void Pause();
62
65 void Resume();
66
69 int GetTickedCount() const;
70
73 int GetTotalTickCount() const;
74
77 void SetTotalTickCount(int count);
78
81 Duration GetInterval() const;
82
85 void SetInterval(Duration interval);
86
89 Duration GetErrorTime() const;
90
93 RefPtr<Timer> GetTimer();
94
97 void SetTimer(RefPtr<Timer> timer);
98
101 void Reset();
102
103private:
104 bool is_paused_;
105 int ticked_count_;
106 int total_tick_count_;
107 Duration interval_;
108 Duration elapsed_time_;
109 Duration delta_time_;
110 Duration error_time_;
111 RefPtr<Timer> timer_;
112};
113
114inline bool Ticker::IsPausing() const
115{
116 return is_paused_;
117}
118
119inline int Ticker::GetTickedCount() const
120{
121 return ticked_count_;
122}
123
125{
126 return total_tick_count_;
127}
128
129inline void Ticker::SetTotalTickCount(int count)
130{
131 total_tick_count_ = count;
132}
133
135{
136 return interval_;
137}
138
139inline void Ticker::SetInterval(Duration interval)
140{
141 interval_ = interval;
142}
143
145{
146 return error_time_;
147}
148
149} // namespace kiwano
基础对象
Definition: ObjectBase.h:138
引用计数智能指针
Definition: RefBasePtr.hpp:35
报时器
Definition: Ticker.h:30
int GetTickedCount() const
获取报时器报时次数
Definition: Ticker.h:119
Duration GetInterval() const
获取报时间隔
Definition: Ticker.h:134
void SetInterval(Duration interval)
设置报时间隔
Definition: Ticker.h:139
int GetTotalTickCount() const
获取报时器总报时次数
Definition: Ticker.h:124
void SetTotalTickCount(int count)
设置报时器总报时次数
Definition: Ticker.h:129
bool IsPausing() const
获取暂停状态
Definition: Ticker.h:114
Duration GetErrorTime() const
获取时间误差
Definition: Ticker.h:144
时间段
Definition: Duration.h:48