From fa589fafa7f094bc1bf07642b55f3d824814adba Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 15 Aug 2008 16:07:58 +0000 Subject: moved Timer to core:: --- src/core/Makefile.am | 5 +++-- src/core/timer.cc | 41 +++++++++++++++++++++++++++++++++++++++++ src/core/timer.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/server/Makefile.am | 4 ++-- src/server/server.cc | 4 ++-- src/server/timer.cc | 41 ----------------------------------------- src/server/timer.h | 39 --------------------------------------- 7 files changed, 93 insertions(+), 86 deletions(-) create mode 100644 src/core/timer.cc create mode 100644 src/core/timer.h delete mode 100644 src/server/timer.cc delete mode 100644 src/server/timer.h (limited to 'src') diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 3badbd9..802234e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -3,7 +3,8 @@ INCLUDES = -I$(top_srcdir)/src libcore_la_SOURCES = application.cc clientstate.cc commandbuffer.cc core.cc \ cvar.cc entity.cc func.cc gameconnection.cc gameinterface.cc gameserver.cc \ - module.cc netclient.cc netconnection.cc netserver.cc player.cc stats.cc zone.cc + module.cc netclient.cc netconnection.cc netserver.cc player.cc stats.cc timer.cc \ + zone.cc libcore_la_LDFLAGS = -avoid-version -no-undefined libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \ $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la \ @@ -12,5 +13,5 @@ libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \ noinst_LTLIBRARIES = libcore.la noinst_HEADERS = application.h clientstate.h commandbuffer.h core.h cvar.h \ entity.h func.h gameconnection.h gameinterface.h gameserver.h module.h net.h \ - netclient.h netconnection.h netserver.h player.h range.h stats.h + netclient.h netconnection.h netserver.h player.h range.h stats.h timer.h diff --git a/src/core/timer.cc b/src/core/timer.cc new file mode 100644 index 0000000..e5a808e --- /dev/null +++ b/src/core/timer.cc @@ -0,0 +1,41 @@ +/* + core/timer.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "core/timer.h" + +#include +#include + +namespace core { + +Timer::Timer() +{ + gettimeofday(&this->timer_tick, &this->timer_tz); + this->timer_elapsed = 0; +} + +Timer::~Timer() +{ +} + +void Timer::mark() +{ + gettimeofday(&timer_tick, &timer_tz); +} + +float Timer::elapsed() +{ + struct timeval tick; + struct timezone tick_tz; + + gettimeofday(&tick, &tick_tz); + + // calculate elapsed time in 10^-6 seconds + long delta = (tick.tv_sec - timer_tick.tv_sec) * 1000000 + (tick.tv_usec - timer_tick.tv_usec); + return( (float) delta / 1000000.0f); +} + +} diff --git a/src/core/timer.h b/src/core/timer.h new file mode 100644 index 0000000..9e172bf --- /dev/null +++ b/src/core/timer.h @@ -0,0 +1,45 @@ +/* + core/timer.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CORE_TIMER_H__ +#define __INCLUDED_CORE_TIMER_H__ + +#include + +namespace core { + +/// a timer measures intervals in seconds +/*! A timer class measures the time elapsed +* between the last two calls to its mark() function. +*/ +class Timer { +public: + /// Constructor + Timer(); + /// Destructor + ~Timer(); + + /// mark the current time as zero + /*! Reset the timer, all subsequent calls too elapsed() will + * use the current timestamp as reference + */ + void mark(); + + /*! return the time elapsed since the last mark + * @see mark() + */ + float elapsed(); + +private: + float timer_elapsed; + struct timezone timer_tz; + struct timeval timer_tick; +}; // class Timer + +} // namespace core + +#endif // __INCLUDED_CORE_TIMER_H__ + diff --git a/src/server/Makefile.am b/src/server/Makefile.am index ed43cd7..bc2f741 100644 --- a/src/server/Makefile.am +++ b/src/server/Makefile.am @@ -1,6 +1,6 @@ METASOURCES = AUTO -libserver_la_SOURCES = console.cc server.cc timer.cc -noinst_HEADERS = console.h server.h timer.h +libserver_la_SOURCES = console.cc server.cc +noinst_HEADERS = console.h server.h noinst_LTLIBRARIES = libserver.la INCLUDES = -I$(top_srcdir)/src libserver_la_LDFLAGS = -avoid-version -no-undefined diff --git a/src/server/server.cc b/src/server/server.cc index fce2181..27cf6bd 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -9,9 +9,9 @@ #include "core/core.h" #include "core/stats.h" +#include "core/timer.h" #include "server/console.h" #include "server/server.h" -#include "server/timer.h" namespace server { @@ -77,7 +77,7 @@ void Server::run() if (core::Cvar::sv_framerate->value()) server_framerate = 1.0f / core::Cvar::sv_framerate->value(); - server::Timer timer; + core::Timer timer; float elapsed = 0; while(connected()) { diff --git a/src/server/timer.cc b/src/server/timer.cc deleted file mode 100644 index 56075c7..0000000 --- a/src/server/timer.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* - server/timer.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#include "timer.h" - -#include -#include - -namespace server { - -Timer::Timer() -{ - gettimeofday(&this->timer_tick, &this->timer_tz); - this->timer_elapsed = 0; -} - -Timer::~Timer() -{ -} - -void Timer::mark() -{ - gettimeofday(&timer_tick, &timer_tz); -} - -float Timer::elapsed() -{ - struct timeval tick; - struct timezone tick_tz; - - gettimeofday(&tick, &tick_tz); - - // calculate elapsed time in 10^-6 seconds - long delta = (tick.tv_sec - timer_tick.tv_sec) * 1000000 + (tick.tv_usec - timer_tick.tv_usec); - return( (float) delta / 1000000.0f); -} - -} diff --git a/src/server/timer.h b/src/server/timer.h deleted file mode 100644 index 496d698..0000000 --- a/src/server/timer.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __INCLUDED_TIMER_H__ -#define __INCLUDED_TIMER_H__ - -#include - -namespace server { - -/// a timer measures intervals in seconds -/*! A timer class measures the time elapsed -* between the last two calls to its mark() function. -*/ -class Timer { -public: - /// Constructor - Timer(); - /// Destructor - ~Timer(); - - /// mark the current time as zero - /*! Reset the timer, all subsequent calls too elapsed() will - * use the current timestamp as reference - */ - void mark(); - - /*! return the time elapsed since the last mark - * @see mark() - */ - float elapsed(); - -private: - float timer_elapsed; - struct timezone timer_tz; - struct timeval timer_tick; -}; // class Timer - -} // namespace server - -#endif // __INCLUDED_TIMER_H__ - -- cgit v1.2.3