From 6c8446cddb37df732fc9e5fc21f98e31968ce634 Mon Sep 17 00:00:00 2001
From: Stijn Buys <ingar@osirion.org>
Date: Fri, 1 Feb 2008 19:34:47 +0000
Subject: interface cleanup

---
 src/server/Makefile.am    |  4 ++--
 src/server/application.cc | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 src/server/application.h  | 29 +++++++++++++++++++++++++++
 src/server/console.h      |  6 +++---
 src/server/main.cc        |  8 +++-----
 src/server/server.cc      | 48 ++++++---------------------------------------
 src/server/server.h       | 23 ++++++++++++++--------
 7 files changed, 108 insertions(+), 60 deletions(-)
 create mode 100644 src/server/application.cc
 create mode 100644 src/server/application.h

(limited to 'src/server')

diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index f842c05..c8695ca 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -1,12 +1,12 @@
 METASOURCES = AUTO
 bin_PROGRAMS = osiriond
-osiriond_SOURCES = console.cc main.cc server.cc timer.cc
+osiriond_SOURCES = application.cc console.cc main.cc server.cc timer.cc
 osiriond_LDADD = $(top_builddir)/src/math/libmath.la \
 		$(top_builddir)/src/common/libcommon.la \
 		$(top_builddir)/src/filesystem/libfilesystem.la \
 		$(top_builddir)/src/core/libcore.la \
 		$(top_builddir)/src/game/libgame.la
-noinst_HEADERS = console.h server.h timer.h
+noinst_HEADERS = application.h console.h server.h timer.h
 
 INCLUDES = -I$(top_srcdir)/src
 
diff --git a/src/server/application.cc b/src/server/application.cc
new file mode 100644
index 0000000..b6cd91f
--- /dev/null
+++ b/src/server/application.cc
@@ -0,0 +1,50 @@
+/*
+   server/application.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 
+*/
+
+// project headers
+#include "server/server.h"
+#include "server/application.h"
+#include "server/timer.h"
+#include "core/core.h"
+
+namespace server {
+
+void Application::init()
+{
+	// initialize core
+	core::ApplicationInterface::init();
+
+	con_debug << "Initializing server..." << std::endl;
+}
+
+void Application::run()
+{
+	const float server_framerate =  1.0f / 20.0f;
+	server::Timer timer;
+
+	timer.mark();
+
+	while(true) {
+		float elapsed = timer.elapsed();
+
+		frame(elapsed);
+
+		timer.sleep(server_framerate - elapsed);
+		timer.mark();
+	}
+	
+}
+
+void Application::shutdown() 
+{
+	con_debug << "Shutting down server..." << std::endl;
+	
+	core::ApplicationInterface::shutdown();
+	
+	exit(0);
+}
+
+}
diff --git a/src/server/application.h b/src/server/application.h
new file mode 100644
index 0000000..c12a608
--- /dev/null
+++ b/src/server/application.h
@@ -0,0 +1,29 @@
+/*
+   server/application.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_SERVER_APPLICATION_H__
+#define __INCLUDED_SERVER_APPLICATION_H__
+
+#include "core/applicationinterface.h"
+
+namespace server {
+
+/// server Application implementation
+class Application : public core::ApplicationInterface {
+public:
+	/// initialize the server Application
+	virtual void init();
+
+	/// run the server Application
+	virtual void run();
+
+	/// shutdown the server Application
+	virtual void shutdown();
+};
+
+}
+#endif // __INCLUDED_SERVER_APPLICATION_H__
+
diff --git a/src/server/console.h b/src/server/console.h
index 45563a4..188d2b6 100644
--- a/src/server/console.h
+++ b/src/server/console.h
@@ -7,12 +7,12 @@
 #ifndef __INCLUDED_SERVER_CONSOLE_H__
 #define __INCLUDED_SERVER_CONSOLE_H__
 
-#include "common/console.h"
+#include "common/consoleinterface.h"
 
 namespace server {
 
-/// the server console
-class Console : public common::Console {
+/// server console implementation
+class Console : public common::ConsoleInterface {
 public:
 	/// stream to send normal messages too
 	virtual std::ostream & messagestream();
diff --git a/src/server/main.cc b/src/server/main.cc
index 56b29a8..052c68d 100644
--- a/src/server/main.cc
+++ b/src/server/main.cc
@@ -8,9 +8,7 @@
 
 int main( int argc, char *argv[] )
 {
-	server::init();
-
-	server::run();
-
-	server::shutdown();
+	server::application.init();
+	server::application.run();
+	server::application.shutdown();
 }
diff --git a/src/server/server.cc b/src/server/server.cc
index 69c58b2..ad8960e 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -5,52 +5,16 @@
 */
 
 // project headers
-#include "server/server.h"
+
+#include "server/application.h"
+#include "server/console.h"
 #include "game/game.h"
-#include "core/core.h"
-#include "common/common.h"
 
 namespace server {
 
-// private instance of the server console object
-Console console_instance;
-// private instance of the game object
-game::Game game_instance;
-
-void init()
-{
-	// initialize core
-	core::init();
-
-	con_debug << "Initializing server..." << std::endl;
-}
-
-void run()
-{
-
-	const float server_framerate =  1.0f / 20.0f;
-	server::Timer timer;
+Application application;
+Console console;
+game::Game Game;
 
-	timer.mark();
-
-	while(true) {
-		float elapsed = timer.elapsed();
-
-		core::frame(elapsed);
-
-		timer.sleep(server_framerate - elapsed);
-		timer.mark();
-	}
-	
 }
 
-void shutdown() 
-{
-	con_debug << "Shutting down server..." << std::endl;
-	
-	core::shutdown();
-	
-	exit(0);
-}
-
-}
diff --git a/src/server/server.h b/src/server/server.h
index 1f839a5..14d1d4b 100644
--- a/src/server/server.h
+++ b/src/server/server.h
@@ -7,16 +7,23 @@
 #ifndef __INCLUDED_SERVER_H__
 #define __INCLUDED_SERVER_H__
 
-#include "server/timer.h"
+#include "server/application.h"
 #include "server/console.h"
+#include "game/game.h"
 
+/// contains classes and functions to run a dedicated server
 namespace server {
-	/// initialize the server
-	void init();
-	/// run the server
-	void run();
-	/// shutdown the server
-	void shutdown();
-}
+	
+/// global server application instance
+extern Application application;
+	
+/// global server console instance
+extern Console console;
+	
+/// global Game instance
+extern game::Game game;
+
+} // namespace server
 
 #endif // __INCLUDED_SERVER_H__
+
-- 
cgit v1.2.3