Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-08-15 16:07:58 +0000
committerStijn Buys <ingar@osirion.org>2008-08-15 16:07:58 +0000
commitfa589fafa7f094bc1bf07642b55f3d824814adba (patch)
treedc1b96685c4d92cd838551ee14ce02a7f81eb5bf /src/core
parentb780874cf4ab23cf9e48aa23da2394169da24887 (diff)
moved Timer to core::
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Makefile.am5
-rw-r--r--src/core/timer.cc41
-rw-r--r--src/core/timer.h45
3 files changed, 89 insertions, 2 deletions
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 <unistd.h>
+#include <iostream>
+
+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 <sys/time.h>
+
+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__
+