Mana
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <cstdint>
25
29static constexpr unsigned MILLISECONDS_IN_A_TICK = 10;
30
31namespace Time
32{
33
39
43unsigned deltaTimeMs();
44
48float deltaTime();
49
53void beginFrame();
54
55} // namespace Time
56
61class Timer
62{
63public:
64 Timer() = default;
65
69 void set(uint32_t ms = 0)
71
75 void reset()
76 { mTimeout = 0; }
77
81 bool isSet() const
82 { return mTimeout != 0; }
83
88 bool passed() const
89 { return elapsed() >= 0; }
90
95 { mTimeout += ms; }
96
104 int32_t elapsed() const;
105
106private:
108};
Simple timer that can be used to check if a certain amount of time has passed.
Definition time.h:62
bool passed() const
Returns whether the timer has passed.
Definition time.h:88
int32_t elapsed() const
Returns the number of milliseconds elapsed since the set time, or a negative value if the timer hasn'...
Definition time.cpp:65
uint32_t mTimeout
Definition time.h:107
Timer()=default
void reset()
Reset the timer.
Definition time.h:75
bool isSet() const
Returns whether the timer has been set.
Definition time.h:81
void extend(uint32_t ms)
Extend the timer by the given number of milliseconds.
Definition time.h:94
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
Definition time.h:69
Definition time.cpp:29
unsigned deltaTimeMs()
The time in milliseconds since the last frame, but never more than 1000.
Definition time.cpp:39
float deltaTime()
The time in seconds since the last frame, but never more than 1.
Definition time.cpp:44
void beginFrame()
Called at the start of each frame, updates the above variables.
Definition time.cpp:54
uint32_t absoluteTimeMs()
The time in milliseconds since the program started (wraps around after ~49 days).
Definition time.cpp:34
unsigned int uint32_t
Definition sha256.cpp:82