30 #include "util/base/exception.h"
31 #include "util/time/timemanager.h"
33 #include "timeprovider.h"
39 m_time_static = m_time_scaled = master ? master->
getGameTime() : TimeManager::instance()->getTime();
42 TimeProvider::~TimeProvider() {}
45 if (multiplier < 0.0) {
46 throw NotSupported(
"Negative time multiplier are not supported");
48 m_time_static = getPreciseGameTime();
49 m_time_scaled = m_master ? m_master->getPreciseGameTime() :
static_cast<float>(TimeManager::instance()->getTime());
50 m_multiplier = multiplier;
66 return static_cast<unsigned int>(getPreciseGameTime());
69 double TimeProvider::getPreciseGameTime()
const {
70 return m_time_static + m_multiplier * ((m_master ? m_master->getPreciseGameTime() :
static_cast<float>(TimeManager::instance()->getTime())) - m_time_scaled);
73 unsigned int scaleTime(
float multiplier,
unsigned int ticks) {
74 return static_cast<unsigned int>(
static_cast<float>(ticks) * multiplier);