Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Makefile.am7
-rw-r--r--src/server/main.cc40
-rw-r--r--src/server/timer.cc37
-rw-r--r--src/server/timer.h40
4 files changed, 124 insertions, 0 deletions
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
new file mode 100644
index 0000000..20dffcd
--- /dev/null
+++ b/src/server/Makefile.am
@@ -0,0 +1,7 @@
+INCLUDES = -I$(top_srcdir)/src
+METASOURCES = AUTO
+bin_PROGRAMS = osiriond
+osiriond_SOURCES = main.cc timer.cc timer.h
+noinst_HEADERS = timer.h
+osiriond_LDADD = $(top_builddir)/src/game/libgame.la \
+ $(top_builddir)/src/common/libcommon.la
diff --git a/src/server/main.cc b/src/server/main.cc
new file mode 100644
index 0000000..3ce5197
--- /dev/null
+++ b/src/server/main.cc
@@ -0,0 +1,40 @@
+/* server/main.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
+*/
+
+// C++ headers
+#include <iostream>
+
+// project headers
+#include "osirion.h"
+
+#include "game/game.h"
+#include "timer.h"
+
+void quit(int status)
+{
+ exit(status);
+}
+
+int main( int argc, char *argv[] )
+{
+ const float server_framerate = 1.0f / 20.0f;
+ std::cout << "The Osirion project " << OSIRION_VERSION << std::endl;
+ Timer timer;
+
+ // initialize game
+ game::init();
+ timer.mark();
+
+ while(game::initialized) {
+ float elapsed = timer.elapsed();
+ game::update(elapsed);
+ timer.sleep(server_framerate - elapsed);
+ timer.mark();
+ }
+ // shutdown
+ game::shutdown();
+
+ quit(0);
+}
diff --git a/src/server/timer.cc b/src/server/timer.cc
new file mode 100644
index 0000000..c8e6975
--- /dev/null
+++ b/src/server/timer.cc
@@ -0,0 +1,37 @@
+/* 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 <unistd.h>
+
+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()
+{ timeval tick;
+
+ gettimeofday(&tick, &timer_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);
+}
+
+void Timer::sleep(float seconds)
+{
+ usleep((useconds_t) seconds*1000000.0f);
+}
diff --git a/src/server/timer.h b/src/server/timer.h
new file mode 100644
index 0000000..63957ee
--- /dev/null
+++ b/src/server/timer.h
@@ -0,0 +1,40 @@
+#ifndef __INCLUDED_TIMER_H__
+#define __INCLUDED_TIMER_H__
+
+#include <sys/time.h>
+
+
+/// a timer measures that 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 now as a reference
+ * that must be timed.
+ */
+ void mark();
+
+ /*! return the time elapsed since the last mark
+ * @see mark()
+ */
+ float elapsed();
+
+ /// suspend calling process for a number of seconds
+ void sleep(float seconds);
+
+private:
+ float timer_elapsed;
+ struct timezone timer_tz;
+ struct timeval timer_tick;
+}; // class Timer
+
+
+#endif // __INCLUDED_TIMER_H__