Adding Spectre/System/Stopwatch
This commit is contained in:
parent
919aa7740a
commit
f62373dcbc
3 changed files with 54 additions and 1 deletions
|
|
@ -34,7 +34,8 @@ local system_module = Module("source/System", {
|
||||||
"MessageQueue.cpp",
|
"MessageQueue.cpp",
|
||||||
"Event.cpp",
|
"Event.cpp",
|
||||||
"EventListener.cpp",
|
"EventListener.cpp",
|
||||||
"Log.cpp"
|
"Log.cpp",
|
||||||
|
"Stopwatch.cpp"
|
||||||
})
|
})
|
||||||
|
|
||||||
local platform_common_module = Module("source/Platform", {
|
local platform_common_module = Module("source/Platform", {
|
||||||
|
|
|
||||||
27
include/Spectre/System/Stopwatch.h
Normal file
27
include/Spectre/System/Stopwatch.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
#ifndef SPECTRE_SYSTEM_STOPWATCH_H
|
||||||
|
#define SPECTRE_SYSTEM_STOPWATCH_H
|
||||||
|
|
||||||
|
#include <Spectre/Math/Time.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
class Stopwatch {
|
||||||
|
public :
|
||||||
|
Stopwatch();
|
||||||
|
|
||||||
|
// Restart the watch. also returns the elapsed time before
|
||||||
|
// the watch was restarted.
|
||||||
|
Time restart();
|
||||||
|
|
||||||
|
// Get the elapsed time since the watch was restarted.
|
||||||
|
Time elapsed() const;
|
||||||
|
|
||||||
|
private :
|
||||||
|
|
||||||
|
Time m_start;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
|
|
||||||
|
#endif /* SPECTRE_SYSTEM_STOPWATCH_H */
|
||||||
25
source/System/Stopwatch.cpp
Normal file
25
source/System/Stopwatch.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
#include <Spectre/System/Stopwatch.h>
|
||||||
|
#include <Spectre/System/System.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
|
Stopwatch::Stopwatch()
|
||||||
|
{
|
||||||
|
m_start = Time::milliseconds(system::getMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
Time Stopwatch::restart()
|
||||||
|
{
|
||||||
|
Time now = Time::milliseconds(system::getMilliseconds());
|
||||||
|
Time elapsed = now - m_start;
|
||||||
|
m_start = now;
|
||||||
|
return elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
Time Stopwatch::elapsed() const
|
||||||
|
{
|
||||||
|
return Time::milliseconds(system::getMilliseconds()) - m_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace sp
|
||||||
Loading…
Add table
Add a link
Reference in a new issue