2020-01-03 20:05:16 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
2023-06-25 21:15:14 +02:00
|
|
|
#pragma once
|
2020-01-03 20:05:16 +01:00
|
|
|
|
|
|
|
#include "ITimer.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
//! Device independent implementation of the timer
|
|
|
|
class CTimer : public ITimer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2023-09-01 12:22:27 +02:00
|
|
|
CTimer()
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
2023-09-01 12:22:27 +02:00
|
|
|
os::Timer::initTimer();
|
2020-01-03 20:05:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns current real time in milliseconds of the system.
|
|
|
|
/** This value does not start with 0 when the application starts.
|
|
|
|
For example in one implementation the value returned could be the
|
|
|
|
amount of milliseconds which have elapsed since the system was started. */
|
2022-10-09 20:57:28 +02:00
|
|
|
u32 getRealTime() const override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
return os::Timer::getRealTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns current virtual time in milliseconds.
|
|
|
|
/** This value starts with 0 and can be manipulated using setTime(), stopTimer(),
|
|
|
|
startTimer(), etc. This value depends on the set speed of the timer if the timer
|
|
|
|
is stopped, etc. If you need the system time, use getRealTime() */
|
2022-10-09 20:57:28 +02:00
|
|
|
u32 getTime() const override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
return os::Timer::getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! sets current virtual time
|
2022-10-09 20:57:28 +02:00
|
|
|
void setTime(u32 time) override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
os::Timer::setTime(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Stops the game timer.
|
|
|
|
/** The timer is reference counted, which means everything which calls
|
|
|
|
stopTimer() will also have to call startTimer(), otherwise the timer may not start/stop
|
|
|
|
corretly again. */
|
2022-10-09 20:57:28 +02:00
|
|
|
void stop() override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
os::Timer::stopTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Starts the game timer.
|
|
|
|
/** The timer is reference counted, which means everything which calls
|
|
|
|
stopTimer() will also have to call startTimer(), otherwise the timer may not start/stop
|
|
|
|
corretly again. */
|
2022-10-09 20:57:28 +02:00
|
|
|
void start() override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
os::Timer::startTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Sets the speed of the timer
|
|
|
|
/** The speed is the factor with which the time is running faster or slower then the
|
|
|
|
real system time. */
|
2022-10-09 20:57:28 +02:00
|
|
|
void setSpeed(f32 speed = 1.0f) override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
os::Timer::setSpeed(speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns current speed of the timer
|
|
|
|
/** The speed is the factor with which the time is running faster or slower then the
|
|
|
|
real system time. */
|
2022-10-09 20:57:28 +02:00
|
|
|
f32 getSpeed() const override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
return os::Timer::getSpeed();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Returns if game timer is currently stopped
|
2022-10-09 20:57:28 +02:00
|
|
|
bool isStopped() const override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
bool ret = os::Timer::isStopped();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Advances the virtual time
|
|
|
|
/** Makes the virtual timer update the time value based on the real time. This is
|
|
|
|
called automatically when calling IrrlichtDevice::run(), but you can call it manually
|
|
|
|
if you don't use this method. */
|
2022-10-09 20:57:28 +02:00
|
|
|
void tick() override
|
2020-01-03 20:05:16 +01:00
|
|
|
{
|
|
|
|
os::Timer::tick();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
|