Moved the gettime functions to gettime.cpp and gettime.h
This commit is contained in:
parent
f6c1abcc43
commit
80036808f1
@ -204,6 +204,8 @@ set(common_SRCS
|
||||
sha1.cpp
|
||||
base64.cpp
|
||||
ban.cpp
|
||||
gettime.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
# This gives us the icon
|
||||
@ -257,13 +259,11 @@ set(minetest_SRCS
|
||||
filecache.cpp
|
||||
tile.cpp
|
||||
game.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
# Server sources
|
||||
set(minetestserver_SRCS
|
||||
${common_SRCS}
|
||||
main.cpp
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
67
src/gettime.cpp
Normal file
67
src/gettime.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
BlockPlanet
|
||||
Copyright (C) 2012 MiJyn, Joel Leclerc <mijyn@mail.com>
|
||||
Licensed under GPLv3
|
||||
|
||||
|
||||
Based on:
|
||||
Minetest-c55
|
||||
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "porting.h"
|
||||
#include "gettime.h"
|
||||
|
||||
|
||||
/*
|
||||
gettime.h implementation
|
||||
*/
|
||||
|
||||
#ifdef SERVER
|
||||
|
||||
u32 getTimeMs()
|
||||
{
|
||||
/* Use imprecise system calls directly (from porting.h) */
|
||||
return porting::getTimeMs();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// A precise irrlicht one
|
||||
u32 IrrlichtTimeGetter::getTime()
|
||||
{
|
||||
if(m_device == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return m_device->getTimer()->getRealTime();
|
||||
}
|
||||
|
||||
// Not so precise one which works without irrlicht
|
||||
u32 SimpleTimeGetter::getTime()
|
||||
{
|
||||
return porting::getTimeMs();
|
||||
}
|
||||
|
||||
u32 getTimeMs()
|
||||
{
|
||||
if(g_timegetter == NULL)
|
||||
return 0;
|
||||
return g_timegetter->getTime();
|
||||
}
|
||||
|
||||
#endif
|
@ -51,5 +51,44 @@ inline std::string getTimestamp()
|
||||
return cs;
|
||||
}
|
||||
|
||||
#ifdef SERVER
|
||||
|
||||
u32 getTimeMs();
|
||||
|
||||
#else
|
||||
|
||||
// A small helper class
|
||||
class TimeGetter
|
||||
{
|
||||
public:
|
||||
virtual u32 getTime() = 0;
|
||||
};
|
||||
|
||||
// A precise irrlicht one
|
||||
class IrrlichtTimeGetter: public TimeGetter
|
||||
{
|
||||
public:
|
||||
IrrlichtTimeGetter(IrrlichtDevice *device):
|
||||
m_device(device)
|
||||
{}
|
||||
u32 getTime();
|
||||
private:
|
||||
IrrlichtDevice *m_device;
|
||||
};
|
||||
// Not so precise one which works without irrlicht
|
||||
class SimpleTimeGetter: public TimeGetter
|
||||
{
|
||||
public:
|
||||
u32 getTime();
|
||||
};
|
||||
|
||||
// A pointer to a global instance of the time getter
|
||||
// TODO: why?
|
||||
TimeGetter *g_timegetter = NULL;
|
||||
|
||||
u32 getTimeMs();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
60
src/main.cpp
60
src/main.cpp
@ -119,66 +119,6 @@ bool noMenuActive()
|
||||
MainGameCallback *g_gamecallback = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
gettime.h implementation
|
||||
*/
|
||||
|
||||
#ifdef SERVER
|
||||
|
||||
u32 getTimeMs()
|
||||
{
|
||||
/* Use imprecise system calls directly (from porting.h) */
|
||||
return porting::getTimeMs();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// A small helper class
|
||||
class TimeGetter
|
||||
{
|
||||
public:
|
||||
virtual u32 getTime() = 0;
|
||||
};
|
||||
|
||||
// A precise irrlicht one
|
||||
class IrrlichtTimeGetter: public TimeGetter
|
||||
{
|
||||
public:
|
||||
IrrlichtTimeGetter(IrrlichtDevice *device):
|
||||
m_device(device)
|
||||
{}
|
||||
u32 getTime()
|
||||
{
|
||||
if(m_device == NULL)
|
||||
return 0;
|
||||
return m_device->getTimer()->getRealTime();
|
||||
}
|
||||
private:
|
||||
IrrlichtDevice *m_device;
|
||||
};
|
||||
// Not so precise one which works without irrlicht
|
||||
class SimpleTimeGetter: public TimeGetter
|
||||
{
|
||||
public:
|
||||
u32 getTime()
|
||||
{
|
||||
return porting::getTimeMs();
|
||||
}
|
||||
};
|
||||
|
||||
// A pointer to a global instance of the time getter
|
||||
// TODO: why?
|
||||
TimeGetter *g_timegetter = NULL;
|
||||
|
||||
u32 getTimeMs()
|
||||
{
|
||||
if(g_timegetter == NULL)
|
||||
return 0;
|
||||
return g_timegetter->getTime();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class StderrLogOutput: public ILogOutput
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user