mirror of https://github.com/stella-emu/stella.git
The getTicks() method is updated to work similar to gettimeofday, for
systems where gettimeofday doesn't exist. Basically, the functionality for OSystem::getTicks() has changed to always output an increasing value each time it's called, even between program runs (needed for timestamps for continuous snapshots, but also for similar things in the future). It does this by refering to some set time in the past, which is currently the UNIX epoch. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2056 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
9b6ed83d7e
commit
99e7f6c5d0
|
@ -22,8 +22,8 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
#include <time.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -95,6 +95,9 @@ OSystem::OSystem()
|
||||||
myFont(NULL),
|
myFont(NULL),
|
||||||
myConsoleFont(NULL)
|
myConsoleFont(NULL)
|
||||||
{
|
{
|
||||||
|
// Calculate startup time
|
||||||
|
myMillisAtStart = (uInt32)(time(NULL) * 1000);
|
||||||
|
|
||||||
// Get built-in features
|
// Get built-in features
|
||||||
#ifdef DISPLAY_OPENGL
|
#ifdef DISPLAY_OPENGL
|
||||||
myFeatures += "OpenGL ";
|
myFeatures += "OpenGL ";
|
||||||
|
@ -918,12 +921,17 @@ void OSystem::stateChanged(EventHandler::State state)
|
||||||
uInt64 OSystem::getTicks() const
|
uInt64 OSystem::getTicks() const
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
|
// Gettimeofday natively refers to the UNIX epoch (a set time in the past)
|
||||||
timeval now;
|
timeval now;
|
||||||
gettimeofday(&now, 0);
|
gettimeofday(&now, 0);
|
||||||
|
|
||||||
return uInt64(now.tv_sec) * 1000000 + now.tv_usec;
|
return uInt64(now.tv_sec) * 1000000 + now.tv_usec;
|
||||||
#else
|
#else
|
||||||
return uInt64(SDL_GetTicks()) * 1000;
|
// We use SDL_GetTicks, but add in the time when the application was
|
||||||
|
// initialized. This is necessary, since SDL_GetTicks only measures how
|
||||||
|
// long SDL has been running, which can be the same between multiple runs
|
||||||
|
// of the application.
|
||||||
|
return uInt64(SDL_GetTicks() + myMillisAtStart) * 1000;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -377,20 +377,21 @@ class OSystem
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// The following methods are system-specific and must be implemented
|
// The following methods are system-specific and can be overrided in
|
||||||
// in derived classes.
|
// derived classes. Otherwise, the base methods will be used.
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
/**
|
/**
|
||||||
This method returns number of ticks in microseconds.
|
This method returns number of ticks in microseconds since some
|
||||||
|
pre-defined time in the past. *NOTE*: it is necessary that this
|
||||||
|
pre-defined time exists between runs of the application, and must
|
||||||
|
be (relatively) unique. For example, the time since the system
|
||||||
|
started running is not a good choice, since it can be duplicated.
|
||||||
|
The current implementation uses time since the UNIX epoch.
|
||||||
|
|
||||||
@return Current time in microseconds.
|
@return Current time in microseconds.
|
||||||
*/
|
*/
|
||||||
virtual uInt64 getTicks() const;
|
virtual uInt64 getTicks() const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
// The following methods are system-specific and can be overrided in
|
|
||||||
// derived classes. Otherwise, the base methods will be used.
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
/**
|
/**
|
||||||
This method runs the main loop. Since different platforms
|
This method runs the main loop. Since different platforms
|
||||||
may use different timing methods and/or algorithms, this method can
|
may use different timing methods and/or algorithms, this method can
|
||||||
|
@ -503,6 +504,9 @@ class OSystem
|
||||||
// Time per frame for a video update, based on the current framerate
|
// Time per frame for a video update, based on the current framerate
|
||||||
uInt32 myTimePerFrame;
|
uInt32 myTimePerFrame;
|
||||||
|
|
||||||
|
// The time (in milliseconds) from the UNIX epoch when the application starts
|
||||||
|
uInt32 myMillisAtStart;
|
||||||
|
|
||||||
// Indicates whether to stop the main loop
|
// Indicates whether to stop the main loop
|
||||||
bool myQuitLoop;
|
bool myQuitLoop;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue