Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Clock.cpp
1
2/*
3Copyright (C) 2012,2019,2025 Rodrigo Jose Hernandez Cordoba
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16*/
17
18#include "aeongames/Clock.hpp"
19
20namespace AeonGames
21{
22 Clock::Clock() : mTime{}, mScale{1.0}, mPaused{}
23 {
24 }
25
26 Clock::Clock ( double starttime ) :
27 mTime {static_cast<uint64_t> ( starttime * 1e+9 ) },
28 mScale { 1.0 },
29 mPaused {}
30 {
31 }
32
33 uint64_t Clock::GetTime() const
34 {
35 return mTime;
36 }
37
38 double Clock::GetDelta ( const Clock& clock )
39 {
40 return ( mTime - clock.mTime ) * 1e-9f;
41 }
42
43 double Clock::GetDelta ( const uint64_t& start_time )
44 {
45 return ( mTime - start_time ) * 1e-9f;
46 }
47
48 void Clock::Update ( double seconds )
49 {
50 if ( !mPaused )
51 {
52 mTime += static_cast<uint64_t> ( seconds * mScale * 1e+9f );
53 }
54 }
55
56 void Clock::Pause ( bool pause )
57 {
58 mPaused = pause;
59 }
60
62 {
63 return mPaused;
64 }
65
66 void Clock::SetTimeScale ( double timescale )
67 {
68 mScale = timescale;
69 }
70
72 {
73 return mScale;
74 }
75
77 {
78 if ( mPaused )
79 {
80 mTime += static_cast<uint64_t> ( ( 1.0 / 30.0 ) * mScale * 1e+9 );
81 }
82 }
83}
Header file for the Clock class.
DLL uint64_t GetTime() const
Definition Clock.cpp:33
DLL bool IsPaused()
Definition Clock.cpp:61
DLL void SetTimeScale(double timescale)
Definition Clock.cpp:66
DLL void Update(double seconds)
Definition Clock.cpp:48
DLL void Pause(bool pause=true)
Definition Clock.cpp:56
DLL void SingleStep()
Single step the clock when paused.
Definition Clock.cpp:76
DLL double GetTimeScale()
Definition Clock.cpp:71
DLL Clock()
Construct a clock with local time 0.
Definition Clock.cpp:22
DLL double GetDelta(const Clock &clock)
Definition Clock.cpp:38
<- This is here just for the literals
Definition AABB.hpp:31