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
This commit is contained in:
hikerstk 2012-10-02 07:17:28 +00:00
parent eb82e6caff
commit 669e18be67
2 changed files with 65 additions and 33 deletions

View File

@ -93,7 +93,8 @@ void CutsceneWorld::init()
if (!StringUtils::fromString(frameStr, frame)) 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; continue;
} }
@ -112,7 +113,8 @@ void CutsceneWorld::init()
if (!StringUtils::fromString(frameStr, frame)) 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; continue;
} }
@ -126,7 +128,8 @@ void CutsceneWorld::init()
if (!StringUtils::fromString(frameStr, frame)) 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; continue;
} }
@ -139,7 +142,8 @@ void CutsceneWorld::init()
if (dynamic_cast<AnimationBase*>(curr) != NULL) if (dynamic_cast<AnimationBase*>(curr) != NULL)
{ {
m_duration = std::max(m_duration, m_duration = std::max(m_duration,
(double)dynamic_cast<AnimationBase*>(curr)->getAnimationDuration()); (double)dynamic_cast<AnimationBase*>(curr)
->getAnimationDuration());
} }
} }
@ -201,7 +205,7 @@ void CutsceneWorld::update(float dt)
curr->reset(); curr->reset();
} }
m_time = 0.01f; m_time = 0.01f;
m_time_at_second_reset = Time::getFloatTimeSinceEpoch(); m_time_at_second_reset = Time::getRealTime();
m_second_reset = true; m_second_reset = true;
} }
else if (m_second_reset) 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 = m_time;
m_time_at_second_reset = Time::getFloatTimeSinceEpoch(); m_time_at_second_reset = Time::getRealTime();
m_time = 0.01f; m_time = 0.01f;
} }
else else
@ -224,35 +228,37 @@ void CutsceneWorld::update(float dt)
// this way of calculating time and dt is more in line with what // this way of calculating time and dt is more in line with what
// irrlicht does andprovides better synchronisation // irrlicht does andprovides better synchronisation
double prev_time = m_time; double prev_time = m_time;
double now = Time::getFloatTimeSinceEpoch(); double now = Time::getRealTime();
m_time = now - m_time_at_second_reset; m_time = now - m_time_at_second_reset;
dt = (float)(m_time - prev_time); dt = (float)(m_time - prev_time);
} }
float fade;
if (m_time < 2.0f) if (m_time < 2.0f)
{ {
dynamic_cast<CutsceneGUI*>(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) else if (m_time > m_duration - 2.0f)
{ {
dynamic_cast<CutsceneGUI*>(m_race_gui)->setFadeLevel((float)(m_time - (m_duration - 2.0f)) / 2.0f); fade = (float)(m_time - (m_duration - 2.0f)) / 2.0f;
} }
else else
{ {
dynamic_cast<CutsceneGUI*>(m_race_gui)->setFadeLevel(0.0f); fade = 0.0f;
} }
dynamic_cast<CutsceneGUI*>(m_race_gui)->setFadeLevel(fade);
// We assume 25 FPS. Irrlicht starts at frame 0. // 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<Subtitle>& subtitles = m_track->getSubtitles(); const std::vector<Subtitle>& subtitles = m_track->getSubtitles();
bool foundSubtitle = false; bool foundSubtitle = false;
for (unsigned int n = 0; n < subtitles.size(); n++) 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<CutsceneGUI*>(m_race_gui)->setSubtitle(subtitles[n].getText()); dynamic_cast<CutsceneGUI*>(m_race_gui)->setSubtitle(subtitles[n].getText());
foundSubtitle = true; foundSubtitle = true;
@ -284,15 +290,17 @@ void CutsceneWorld::update(float dt)
m_camera->setRotation(rot2.toIrrVector()); m_camera->setRotation(rot2.toIrrVector());
sfx_manager->positionListener(m_camera->getAbsolutePosition(), sfx_manager->positionListener(m_camera->getAbsolutePosition(),
m_camera->getTarget() - m_camera->getAbsolutePosition()); m_camera->getTarget() -
m_camera->getAbsolutePosition());
break; 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);
} }
} }
std::map<float, std::vector<TrackObject*> >::iterator it;
for (std::map<float, std::vector<TrackObject*> >::iterator it = m_sounds_to_trigger.begin(); for (it = m_sounds_to_trigger.begin(); it != m_sounds_to_trigger.end(); )
it != m_sounds_to_trigger.end(); )
{ {
if (m_time >= it->first) if (m_time >= it->first)
{ {
@ -308,9 +316,9 @@ void CutsceneWorld::update(float dt)
it++; it++;
} }
} }
for (std::map<float, std::vector<TrackObject*> >::iterator it = m_particles_to_trigger.begin(); for (it = m_particles_to_trigger.begin();
it != m_particles_to_trigger.end(); ) it != m_particles_to_trigger.end(); )
{ {
if (m_time >= it->first) if (m_time >= it->first)
{ {
@ -327,8 +335,7 @@ void CutsceneWorld::update(float dt)
} }
} }
for (std::map<float, std::vector<TrackObject*> >::iterator it = m_sounds_to_stop.begin(); for (it = m_sounds_to_stop.begin(); it != m_sounds_to_stop.end(); )
it != m_sounds_to_stop.end(); )
{ {
if (m_time >= it->first) if (m_time >= it->first)
{ {

View File

@ -46,16 +46,43 @@ public:
return s; return s;
} // toString } // 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() static TimeType getTimeSinceEpoch()
{ {
return (TimeType)(irr_driver->getDevice()->getTimer() #ifdef WIN32
->getRealTime()/1000.0); 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 }; // getTimeSinceEpoch
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** In floating point seconds */ /** Returns a time based on an arbitrary 'epoch' (e.g. could be start
static double getFloatTimeSinceEpoch(long startAt=0) * 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; return irr_driver->getDevice()->getTimer()->getRealTime()/1000.0;
}; // getTimeSinceEpoch }; // getTimeSinceEpoch
@ -67,14 +94,12 @@ public:
ScopeProfiler(const char* name) ScopeProfiler(const char* name)
{ {
printf("%s {\n", name); printf("%s {\n", name);
// 1325966438 is an arbitrary time that is in the past but much after 1970 m_time = (float)getRealTime();
// to get smaller numbers in order to not lose the precision of float
m_time = (float)getFloatTimeSinceEpoch(1325966438);
} }
~ScopeProfiler() ~ScopeProfiler()
{ {
float f2 = (float)getFloatTimeSinceEpoch(1325966438); float f2 = (float)getRealTime();
printf("} // took %f s\n", (f2 - m_time)); printf("} // took %f s\n", (f2 - m_time));
} }
}; };