From 669e18be678b4970116ceff8605e4afd85995e24 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Tue, 2 Oct 2012 07:17:28 +0000 Subject: [PATCH] Renamed getFloatTimeSincEpoch into getRealTime (since this time does not need nor is based on a fixed epoch). Changed getTimeSinceEpoch back to the previous implementation which returns time in seconds since 1.1.1970 - this is important to compare addon download time. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11657 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/modes/cutscene_world.cpp | 55 ++++++++++++++++++++---------------- src/utils/time.hpp | 43 ++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index 186b9fa82..4f409d9d8 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -93,7 +93,8 @@ void CutsceneWorld::init() if (!StringUtils::fromString(frameStr, frame)) { - fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", condition.c_str()); + fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", + condition.c_str()); continue; } @@ -112,7 +113,8 @@ void CutsceneWorld::init() if (!StringUtils::fromString(frameStr, frame)) { - fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", condition.c_str()); + fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", + condition.c_str()); continue; } @@ -126,7 +128,8 @@ void CutsceneWorld::init() if (!StringUtils::fromString(frameStr, frame)) { - fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", condition.c_str()); + fprintf(stderr, "[CutsceneWorld] Invalid condition '%s'\n", + condition.c_str()); continue; } @@ -139,7 +142,8 @@ void CutsceneWorld::init() if (dynamic_cast(curr) != NULL) { m_duration = std::max(m_duration, - (double)dynamic_cast(curr)->getAnimationDuration()); + (double)dynamic_cast(curr) + ->getAnimationDuration()); } } @@ -201,7 +205,7 @@ void CutsceneWorld::update(float dt) curr->reset(); } m_time = 0.01f; - m_time_at_second_reset = Time::getFloatTimeSinceEpoch(); + m_time_at_second_reset = Time::getRealTime(); m_second_reset = true; } else if (m_second_reset) @@ -216,7 +220,7 @@ void CutsceneWorld::update(float dt) } //m_time_at_second_reset = m_time; - m_time_at_second_reset = Time::getFloatTimeSinceEpoch(); + m_time_at_second_reset = Time::getRealTime(); m_time = 0.01f; } else @@ -224,35 +228,37 @@ void CutsceneWorld::update(float dt) // this way of calculating time and dt is more in line with what // irrlicht does andprovides better synchronisation double prev_time = m_time; - double now = Time::getFloatTimeSinceEpoch(); + double now = Time::getRealTime(); m_time = now - m_time_at_second_reset; dt = (float)(m_time - prev_time); } - + float fade; if (m_time < 2.0f) { - dynamic_cast(m_race_gui)->setFadeLevel(1.0f - (float)m_time / 2.0f); + fade = 1.0f - (float)m_time / 2.0f; } else if (m_time > m_duration - 2.0f) { - dynamic_cast(m_race_gui)->setFadeLevel((float)(m_time - (m_duration - 2.0f)) / 2.0f); + fade = (float)(m_time - (m_duration - 2.0f)) / 2.0f; } else { - dynamic_cast(m_race_gui)->setFadeLevel(0.0f); + fade = 0.0f; } + dynamic_cast(m_race_gui)->setFadeLevel(fade); // We assume 25 FPS. Irrlicht starts at frame 0. - float currFrame = (float)(m_time*25.0f - 1.0f); + float curr_frame = (float)(m_time*25.0f - 1.0f); - //printf("Estimated current frame : %f\n", currFrame); + //printf("Estimated current frame : %f\n", curr_frame); const std::vector& subtitles = m_track->getSubtitles(); bool foundSubtitle = false; for (unsigned int n = 0; n < subtitles.size(); n++) { - if (currFrame >= subtitles[n].getFrom() && currFrame < subtitles[n].getTo()) + if (curr_frame >= subtitles[n].getFrom() && + curr_frame < subtitles[n].getTo()) { dynamic_cast(m_race_gui)->setSubtitle(subtitles[n].getText()); foundSubtitle = true; @@ -284,15 +290,17 @@ void CutsceneWorld::update(float dt) m_camera->setRotation(rot2.toIrrVector()); sfx_manager->positionListener(m_camera->getAbsolutePosition(), - m_camera->getTarget() - m_camera->getAbsolutePosition()); + m_camera->getTarget() - + m_camera->getAbsolutePosition()); break; - //printf("Camera %f %f %f\n", curr->getNode()->getPosition().X, curr->getNode()->getPosition().Y, curr->getNode()->getPosition().Z); + //printf("Camera %f %f %f\n", curr->getNode()->getPosition().X, + // curr->getNode()->getPosition().Y, + // curr->getNode()->getPosition().Z); } } - - for (std::map >::iterator it = m_sounds_to_trigger.begin(); - it != m_sounds_to_trigger.end(); ) + std::map >::iterator it; + for (it = m_sounds_to_trigger.begin(); it != m_sounds_to_trigger.end(); ) { if (m_time >= it->first) { @@ -308,9 +316,9 @@ void CutsceneWorld::update(float dt) it++; } } - - for (std::map >::iterator it = m_particles_to_trigger.begin(); - it != m_particles_to_trigger.end(); ) + + for (it = m_particles_to_trigger.begin(); + it != m_particles_to_trigger.end(); ) { if (m_time >= it->first) { @@ -327,8 +335,7 @@ void CutsceneWorld::update(float dt) } } - for (std::map >::iterator it = m_sounds_to_stop.begin(); - it != m_sounds_to_stop.end(); ) + for (it = m_sounds_to_stop.begin(); it != m_sounds_to_stop.end(); ) { if (m_time >= it->first) { diff --git a/src/utils/time.hpp b/src/utils/time.hpp index 843c56933..e5f1b18bb 100644 --- a/src/utils/time.hpp +++ b/src/utils/time.hpp @@ -46,16 +46,43 @@ public: return s; } // toString // ------------------------------------------------------------------------ - /** In integer seconds */ + /** Returns the number of seconds since 1.1.1970. This function is used + * to compare access times of files, e.g. news, addons data etc. + */ static TimeType getTimeSinceEpoch() { - return (TimeType)(irr_driver->getDevice()->getTimer() - ->getRealTime()/1000.0); +#ifdef WIN32 + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + __int64 t = ft.dwHighDateTime; + t <<= 32; + t /= 10; + // The Unix epoch starts on Jan 1 1970. Need to subtract + // the difference in seconds from Jan 1 1601. +# if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) +# define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +# else +# define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +# endif + t -= DELTA_EPOCH_IN_MICROSECS; + + t |= ft.dwLowDateTime; + // Convert to seconds since epoch + t /= 1000000UL; + return t; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec; +#endif }; // getTimeSinceEpoch // ------------------------------------------------------------------------ - /** In floating point seconds */ - static double getFloatTimeSinceEpoch(long startAt=0) + /** Returns a time based on an arbitrary 'epoch' (e.g. could be start + * time of the application, 1.1.1970, ...). + * The value is a double precision floating point value in seconds. + */ + static double getRealTime(long startAt=0) { return irr_driver->getDevice()->getTimer()->getRealTime()/1000.0; }; // getTimeSinceEpoch @@ -67,14 +94,12 @@ public: ScopeProfiler(const char* name) { printf("%s {\n", name); - // 1325966438 is an arbitrary time that is in the past but much after 1970 - // to get smaller numbers in order to not lose the precision of float - m_time = (float)getFloatTimeSinceEpoch(1325966438); + m_time = (float)getRealTime(); } ~ScopeProfiler() { - float f2 = (float)getFloatTimeSinceEpoch(1325966438); + float f2 = (float)getRealTime(); printf("} // took %f s\n", (f2 - m_time)); } };