Fix #2051 by keeping a copy of the timer in the SktTimer class.
This commit is contained in:
parent
80de98f40a
commit
17039141e4
@ -1085,6 +1085,7 @@ void initRest()
|
|||||||
stk_config->load(file_manager->getAsset("stk_config.xml"));
|
stk_config->load(file_manager->getAsset("stk_config.xml"));
|
||||||
|
|
||||||
irr_driver = new IrrDriver();
|
irr_driver = new IrrDriver();
|
||||||
|
StkTime::init(); // grabs the timer object from the irrlicht device
|
||||||
|
|
||||||
// Now create the actual non-null device in the irrlicht driver
|
// Now create the actual non-null device in the irrlicht driver
|
||||||
irr_driver->initDevice();
|
irr_driver->initDevice();
|
||||||
|
@ -22,13 +22,31 @@
|
|||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
irr::ITimer *StkTime::m_timer = NULL;
|
||||||
|
|
||||||
|
/** Init function for the timer. It grabs a copy of the timer of the
|
||||||
|
* current irrlicht device (which is the NULL device). This way the
|
||||||
|
* irrlicht time routine can be used even if no device exists. This
|
||||||
|
* situation can happen when the window resolution is changed - if the
|
||||||
|
* sfx manager (in a separate thread) would access the timer while the
|
||||||
|
* device does not exist, stk crashes.
|
||||||
|
*/
|
||||||
|
void StkTime::init()
|
||||||
|
{
|
||||||
|
assert(!m_timer);
|
||||||
|
m_timer = irr_driver->getDevice()->getTimer();
|
||||||
|
m_timer->grab();
|
||||||
|
} // init
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
/** Returns a time based on an arbitrary 'epoch' (e.g. could be start
|
/** Returns a time based on an arbitrary 'epoch' (e.g. could be start
|
||||||
* time of the application, 1.1.1970, ...).
|
* time of the application, 1.1.1970, ...).
|
||||||
* The value is a double precision floating point value in seconds.
|
* The value is a double precision floating point value in seconds.
|
||||||
*/
|
*/
|
||||||
double StkTime::getRealTime(long startAt)
|
double StkTime::getRealTime(long startAt)
|
||||||
{
|
{
|
||||||
return irr_driver->getRealTime()/1000.0;
|
assert(m_timer);
|
||||||
|
return m_timer->getRealTime()/1000.0;
|
||||||
} // getTimeSinceEpoch
|
} // getTimeSinceEpoch
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
#ifndef HEADER_TIME_HPP
|
#ifndef HEADER_TIME_HPP
|
||||||
#define HEADER_TIME_HPP
|
#define HEADER_TIME_HPP
|
||||||
|
|
||||||
|
#include "ITimer.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -36,9 +39,16 @@
|
|||||||
|
|
||||||
class StkTime
|
class StkTime
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
/** This objects keeps a copy of irrlicht's null-device timer. This is
|
||||||
|
* important otherwise we can't get the time when resolution is switched
|
||||||
|
* (and the sfx threads needs real time at that time). */
|
||||||
|
static irr::ITimer *m_timer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef time_t TimeType;
|
typedef time_t TimeType;
|
||||||
|
|
||||||
|
static void init();
|
||||||
static void getDate(int *day=NULL, int *month=NULL, int *year=NULL);
|
static void getDate(int *day=NULL, int *month=NULL, int *year=NULL);
|
||||||
|
|
||||||
/** Converts the time in this object to a human readable string. */
|
/** Converts the time in this object to a human readable string. */
|
||||||
|
Loading…
Reference in New Issue
Block a user