diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-02 13:23:00 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-02 13:23:00 +0000 |
commit | cdc5a69a108654ff378839e8cf93669de31ff9c5 (patch) | |
tree | 10bdc47d0d51485f49387bee3aeae7037c47df6e /src | |
parent | 1765b93250ac3b89947c3da7f0c7266a910367c9 (diff) |
removed libcommon
modularized client and server
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 13 | ||||
-rw-r--r-- | src/client/Makefile.am | 22 | ||||
-rw-r--r-- | src/client/console.h | 4 | ||||
-rw-r--r-- | src/client/main.cc | 14 | ||||
-rw-r--r-- | src/client/video.cc | 2 | ||||
-rw-r--r-- | src/client/view.cc | 4 | ||||
-rw-r--r-- | src/core/Makefile.am | 5 | ||||
-rw-r--r-- | src/core/applicationinterface.cc | 28 | ||||
-rw-r--r-- | src/core/applicationinterface.h | 3 | ||||
-rw-r--r-- | src/filesystem/Makefile.am | 3 | ||||
-rw-r--r-- | src/filesystem/file.cc | 2 | ||||
-rw-r--r-- | src/filesystem/filesystem.cc | 2 | ||||
-rw-r--r-- | src/filesystem/path.cc | 18 | ||||
-rw-r--r-- | src/game/Makefile.am | 6 | ||||
-rw-r--r-- | src/game/game.cc | 2 | ||||
-rw-r--r-- | src/game/game.h | 2 | ||||
-rw-r--r-- | src/gl/Makefile.am | 1 | ||||
-rw-r--r-- | src/gl/gllib.cc | 2 | ||||
-rw-r--r-- | src/server/Makefile.am | 13 | ||||
-rw-r--r-- | src/server/application.cc | 14 | ||||
-rw-r--r-- | src/server/application.h | 3 | ||||
-rw-r--r-- | src/server/console.h | 4 | ||||
-rw-r--r-- | src/server/main.cc | 14 | ||||
-rw-r--r-- | src/server/server.cc | 2 | ||||
-rw-r--r-- | src/server/server.h | 2 | ||||
-rw-r--r-- | src/sys/Makefile.am | 4 | ||||
-rw-r--r-- | src/sys/consoleinterface.cc | 35 | ||||
-rw-r--r-- | src/sys/consoleinterface.h | 59 | ||||
-rw-r--r-- | src/sys/sys.cc | 19 | ||||
-rw-r--r-- | src/sys/sys.h | 10 |
30 files changed, 205 insertions, 107 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ad350fc..cd06cd7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,17 @@ # set the include path found by configure AM_CPPFLAGS = $(DEBUG_CFLAGS) $(WARN_CFLAGS) $(all_includes) +INCLUDES = -I$(top_srcdir)/src +SUBDIRS = math sys filesystem core game server gl client -SUBDIRS = math common sys filesystem core game server gl client +noinst_HEADERS = config.h +bin_PROGRAMS = osiriond osirion +# dedicated server +osiriond_SOURCES = osiriond.cc +osiriond_LDADD = $(top_builddir)/src/server/libserver.la +# client +osirion_SOURCES = osirion.cc +osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) +osirion_LDADD = $(top_builddir)/src/client/libclient.la +osirion_LDFLAGS = $(LIBSDL_LIBS) $(GL_LIBS) diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 9807963..f1a3f9d 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -1,17 +1,13 @@ - METASOURCES = AUTO -bin_PROGRAMS = osirion - -osirion_LDADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la \ - $(top_builddir)/src/gl/libgl.la -osirion_SOURCES = application.cc camera.cc client.cc console.cc hud.cc input.cc main.cc \ - shipdrawer.cc stardrawer.cc video.cc view.cc - INCLUDES = -I$(top_srcdir)/src -osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) -osirion_LDFLAGS = $(LIBSDL_LIBS) $(GL_LIBS) +libclient_la_SOURCES = application.cc camera.cc client.cc console.cc hud.cc input.cc \ + shipdrawer.cc stardrawer.cc video.cc view.cc +libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) +libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) +noinst_LTLIBRARIES = libclient.la noinst_HEADERS = application.h camera.h client.h console.h input.h shipdrawer.h stardrawer.h \ - video.h view.h + video.h view.h +libclient_la_LIBADD = $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la \ + $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la $(top_builddir)/src/gl/libgl.la diff --git a/src/client/console.h b/src/client/console.h index 8e8ab02..1a36d00 100644 --- a/src/client/console.h +++ b/src/client/console.h @@ -7,12 +7,12 @@ #ifndef __INCLUDED_CLIENT_CONSOLE_H__ #define __INCLUDED_CLIENT_CONSOLE_H__ -#include "common/consoleinterface.h" +#include "sys/consoleinterface.h" namespace client { /// client console implementation -class Console : public common::ConsoleInterface { +class Console : public sys::ConsoleInterface { public: /// stream to send normal messages too virtual std::ostream & messagestream(); diff --git a/src/client/main.cc b/src/client/main.cc deleted file mode 100644 index 6955042..0000000 --- a/src/client/main.cc +++ /dev/null @@ -1,14 +0,0 @@ -/* client/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 -*/ - -#include "client/client.h" - -int main( int argc, char *argv[] ) -{ - client::application.init(); - client::application.run(); - client::application.shutdown(); -} - diff --git a/src/client/video.cc b/src/client/video.cc index 9a542f3..ca0401f 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -6,7 +6,7 @@ #include "client/client.h" #include "gl/gllib.h" -#include "common/common.h" +#include "sys/sys.h" #include <SDL/SDL.h> diff --git a/src/client/view.cc b/src/client/view.cc index 63a6942..30dd6d6 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -9,7 +9,7 @@ #include "client/stardrawer.h" #include "game/game.h" #include "gl/gllib.h" -#include "common/common.h" +#include "sys/sys.h" #include "math/mathlib.h" #include <SDL/SDL.h> @@ -17,8 +17,6 @@ namespace client { -using namespace common; - ShipDrawer *shipdrawer = 0; StarDrawer *stardrawer = 0; diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 8046b79..a70652e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -2,10 +2,9 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src libcore_la_SOURCES = applicationinterface.cc gameinterface.cc -libcore_la_LDFLAGS = -avoid-version +libcore_la_LDFLAGS = -avoid-version -no-undefined libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/filesystem/libfilesystem.la + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la noinst_LTLIBRARIES = libcore.la noinst_HEADERS = applicationinterface.h core.h gameinterface.h diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc index ba22d8c..209a4f5 100644 --- a/src/core/applicationinterface.cc +++ b/src/core/applicationinterface.cc @@ -7,17 +7,14 @@ #include "core/core.h" #include "filesystem/filesystem.h" #include "sys/sys.h" -#include "common/common.h" #include <iostream> - -#include <stdlib.h> - #include <errno.h> #include <signal.h> namespace core { +// --------------- signal_handler ----------------------------------- extern "C" void signal_handler(int signum) { switch(signum){ @@ -25,24 +22,30 @@ extern "C" void signal_handler(int signum) case SIGINT: case SIGQUIT: case SIGTERM: - con_warn << "received signal " << signum << ", shutting down..." << std::endl; - if (ApplicationInterface::instance()); + if (ApplicationInterface::instance()) { + con_warn << "received signal " << signum << ", shutting down..." << std::endl; ApplicationInterface::instance()->shutdown(); - exit(1); + ApplicationInterface::instance()->quit(0); + } else { + std::cerr << "received signal " << signum << ", no application found, terminated..." << std::endl; + sys::quit(1); + } break; default: - con_warn << "received signal " << signum << ", terminated..." << std::endl; - exit(1); + std::cerr << "received signal " << signum << ", terminated..." << std::endl; + sys::quit(1); break; } } +// --------------- ApplicationInterface ----------------------------- + ApplicationInterface *ApplicationInterface::applicationinterface_instance = 0; ApplicationInterface::ApplicationInterface() { if (applicationinterface_instance) { std::cerr << "multiple singleton instances: core::ApplicationInterface" << std::endl; - exit(2); + sys::quit(2); } applicationinterface_instance = this; @@ -87,6 +90,11 @@ void ApplicationInterface::shutdown() filesystem::shutdown(); } +void ApplicationInterface::quit(int status) +{ + sys::quit(status); +} + void ApplicationInterface::frame(float seconds) { if (game()) diff --git a/src/core/applicationinterface.h b/src/core/applicationinterface.h index 19eaee6..6093427 100644 --- a/src/core/applicationinterface.h +++ b/src/core/applicationinterface.h @@ -24,6 +24,9 @@ public: /// shutdown the application virtual void shutdown(); + /// quit the application + virtual void quit(int status); + /// run a core frame virtual void frame(float seconds); diff --git a/src/filesystem/Makefile.am b/src/filesystem/Makefile.am index 2eb094f..a490cd3 100644 --- a/src/filesystem/Makefile.am +++ b/src/filesystem/Makefile.am @@ -2,8 +2,7 @@ METASOURCES = AUTO libfilesystem_la_SOURCES = file.cc filesystem.cc inifile.cc path.cc libfilesystem_la_LDFLAGS = -avoid-version -no-undefined -libfilesystem_la_LIBADD = $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/common/libcommon.la +libfilesystem_la_LIBADD = $(top_builddir)/src/sys/libsys.la noinst_LTLIBRARIES = libfilesystem.la noinst_HEADERS = file.h filesystem.h inifile.h path.h diff --git a/src/filesystem/file.cc b/src/filesystem/file.cc index 4e68bbd..cd6ae1b 100644 --- a/src/filesystem/file.cc +++ b/src/filesystem/file.cc @@ -5,7 +5,7 @@ */ // project headers -#include "common/common.h" +#include "sys/sys.h" #include "filesystem/filesystem.h" namespace filesystem { diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index 5ae4da7..b720198 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -6,7 +6,7 @@ // project headers #include "filesystem/filesystem.h" -#include "common/common.h" +#include "sys/sys.h" std::string filesystem::datadir = ""; std::string filesystem::homedir = ""; diff --git a/src/filesystem/path.cc b/src/filesystem/path.cc index ac780c4..c090791 100644 --- a/src/filesystem/path.cc +++ b/src/filesystem/path.cc @@ -6,13 +6,7 @@ // project headers #include "filesystem/path.h" -#include "common/common.h" - -#ifdef _WIN32 -#include <dlfcn.h> -#else -#include <sys/stat.h> -#endif +#include "sys/sys.h" namespace filesystem { @@ -21,14 +15,10 @@ void Path::create(std::string path) { if (tmp[tmp.size()-1] == '/') tmp = tmp.substr(0, tmp.size() - 1); -#ifdef _WIN32 - mkdir(tmp.c_str()); -#else - if (!mkdir(tmp.c_str(), 0777)) - con_warn << "Could not create directory " << tmp << std::endl; + if (!sys::mkdir(tmp.c_str())) + con_warn << "could not create directory " << tmp << std::endl; else - con_debug << "Path created " << tmp << std::endl; -#endif + con_debug << "directory created " << tmp << std::endl; } bool Path::exists(std::string path) { diff --git a/src/game/Makefile.am b/src/game/Makefile.am index 1ed5015..f86c814 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -1,11 +1,7 @@ INCLUDES = -I$(top_srcdir)/src METASOURCES = AUTO -libgame_la_LDFLAGS = -avoid-version --no-undefined -libgame_la_LIBADD = $(top_builddir)/src/math/libmath.la \ - $(top_builddir)/src/common/libcommon.la \ - $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/core/libcore.la +libgame_la_LDFLAGS = -avoid-version libgame_la_SOURCES = game.cc sector.cc ship.cc shipspecs.cc star.cc noinst_LTLIBRARIES = libgame.la diff --git a/src/game/game.cc b/src/game/game.cc index b2b0822..7f2ad17 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -10,7 +10,7 @@ #include "game/ship.h" #include "game/star.h" #include "filesystem/filesystem.h" -#include "common/common.h" +#include "sys/sys.h" // C++ headers #include <vector> diff --git a/src/game/game.h b/src/game/game.h index 5a0afc7..6f77bcf 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -11,7 +11,7 @@ #include "game/ship.h" #include "game/star.h" #include "core/core.h" -#include "common/common.h" +#include "sys/sys.h" /// the game-specific engine /** The main game functions. The console should be initialized before calling these. diff --git a/src/gl/Makefile.am b/src/gl/Makefile.am index 7c1445e..7ddb67b 100644 --- a/src/gl/Makefile.am +++ b/src/gl/Makefile.am @@ -8,3 +8,4 @@ libgl_la_CXXFLAGS = @GL_CFLAGS@ noinst_LTLIBRARIES = libgl.la noinst_HEADERS = box.h gllib.h sphere.h +libgl_la_LIBADD = $(top_builddir)/src/math/libmath.la diff --git a/src/gl/gllib.cc b/src/gl/gllib.cc index e57ab5d..3d3e26c 100644 --- a/src/gl/gllib.cc +++ b/src/gl/gllib.cc @@ -6,7 +6,7 @@ // project includes #include "gl/gllib.h" -#include "common/common.h" +#include "sys/sys.h" // system includes #include "GL/gl.h" diff --git a/src/server/Makefile.am b/src/server/Makefile.am index 729fabf..6875dbf 100644 --- a/src/server/Makefile.am +++ b/src/server/Makefile.am @@ -1,10 +1,9 @@ METASOURCES = AUTO -bin_PROGRAMS = osiriond -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/sys/libsys.la \ - $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la +libserver_la_SOURCES = application.cc console.cc server.cc timer.cc noinst_HEADERS = application.h console.h server.h timer.h - +noinst_LTLIBRARIES = libserver.la INCLUDES = -I$(top_srcdir)/src - +libserver_la_LDFLAGS = -avoid-version -no-undefined +libserver_la_LIBADD = $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la \ + $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la diff --git a/src/server/application.cc b/src/server/application.cc index b6cd91f..0d3fe4b 100644 --- a/src/server/application.cc +++ b/src/server/application.cc @@ -14,6 +14,10 @@ namespace server { void Application::init() { + // FIXME core should be able to load game.so + // force initialization of the game object + server::game = new game::Game(); + // initialize core core::ApplicationInterface::init(); @@ -44,7 +48,15 @@ void Application::shutdown() core::ApplicationInterface::shutdown(); - exit(0); + quit(0); +} + +void Application::quit(int status) +{ + // FIXME core should be able to unload game.so + delete server::game; + + core::ApplicationInterface::quit(status); } } diff --git a/src/server/application.h b/src/server/application.h index c12a608..b081726 100644 --- a/src/server/application.h +++ b/src/server/application.h @@ -22,6 +22,9 @@ public: /// shutdown the server Application virtual void shutdown(); + + /// quit the server Application + virtual void quit(int status); }; } diff --git a/src/server/console.h b/src/server/console.h index 188d2b6..34166be 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/consoleinterface.h" +#include "sys/consoleinterface.h" namespace server { /// server console implementation -class Console : public common::ConsoleInterface { +class Console : public sys::ConsoleInterface { public: /// stream to send normal messages too virtual std::ostream & messagestream(); diff --git a/src/server/main.cc b/src/server/main.cc deleted file mode 100644 index 052c68d..0000000 --- a/src/server/main.cc +++ /dev/null @@ -1,14 +0,0 @@ -/* - 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 -*/ - -#include "server/server.h" - -int main( int argc, char *argv[] ) -{ - server::application.init(); - server::application.run(); - server::application.shutdown(); -} diff --git a/src/server/server.cc b/src/server/server.cc index ad8960e..fc37aa6 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -14,7 +14,7 @@ namespace server { Application application; Console console; -game::Game Game; +game::Game *game; } diff --git a/src/server/server.h b/src/server/server.h index 14d1d4b..7871c5f 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -21,7 +21,7 @@ extern Application application; extern Console console; /// global Game instance -extern game::Game game; +extern game::Game *game; } // namespace server diff --git a/src/sys/Makefile.am b/src/sys/Makefile.am index 44f69c4..be1c636 100644 --- a/src/sys/Makefile.am +++ b/src/sys/Makefile.am @@ -2,5 +2,5 @@ INCLUDES = -I$(top_srcdir)/src METASOURCES = AUTO libsys_la_LDFLAGS = -avoid-version -no-undefined noinst_LTLIBRARIES = libsys.la -libsys_la_SOURCES = sys.cc -noinst_HEADERS = sys.h +libsys_la_SOURCES = consoleinterface.cc sys.cc +noinst_HEADERS = consoleinterface.h sys.h diff --git a/src/sys/consoleinterface.cc b/src/sys/consoleinterface.cc new file mode 100644 index 0000000..45df367 --- /dev/null +++ b/src/sys/consoleinterface.cc @@ -0,0 +1,35 @@ +/* + sys/consoleinterface.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "sys/consoleinterface.h" + +#include <iostream> + +#include <stdlib.h> + +namespace sys { + +ConsoleInterface *ConsoleInterface::consoleinterface_instance = 0; + +ConsoleInterface::ConsoleInterface() { + if (consoleinterface_instance) { + std::cerr << "multiple singleton instances: sys::ConsoleInterface" << std::endl; + sys::quit(2); + } + consoleinterface_instance = this; +} + +ConsoleInterface::~ConsoleInterface() +{ + consoleinterface_instance = 0; +} + +ConsoleInterface *ConsoleInterface::instance() +{ + return consoleinterface_instance; +} + +} // namespace sys diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h new file mode 100644 index 0000000..e0228ae --- /dev/null +++ b/src/sys/consoleinterface.h @@ -0,0 +1,59 @@ +/* + sys/consoleinterface.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2. +*/ + +#ifndef __INCLUDED_SYS_CONSOLEINTERFACE_H__ +#define __INCLUDED_SYS_CONSOLEINTERFACE_H__ + +// project headers +#include "sys/sys.h" + +// C++ headers +#include <iostream> + +/// global define to send a message to the system console +#define con_print sys::ConsoleInterface::instance()->messagestream() +/// global define to send a warning message to the system console +#define con_warn sys::ConsoleInterface::instance()->warningstream() + +#ifdef HAVE_DEBUG_MESSAGES +/// global define to send a debug message to the system console +#define con_debug sys::ConsoleInterface::instance()->debugstream() +#else +#define con_debug if (0) *(std::ostream*)(0) +#endif + +namespace sys { + +/// interface for the client and server Console classes +class ConsoleInterface { +public: + /// default constructor + ConsoleInterface(); + + /// default destructor + virtual ~ConsoleInterface(); + + /// stream to send normal messages too + virtual std::ostream & messagestream() = 0; + + /// stream to send warning messages too + virtual std::ostream & warningstream() = 0; + + /// stream to send debug messages too + virtual std::ostream & debugstream() = 0; + + /// a pointer to the current console instance + static ConsoleInterface *instance(); + +private: + /// console singleton + static ConsoleInterface *consoleinterface_instance; +}; + +} // namespace sys + +#endif // __INCLUDED_SYS_CONSOLEINTERFACE_H__ + diff --git a/src/sys/sys.cc b/src/sys/sys.cc index 97da23e..dc342bd 100644 --- a/src/sys/sys.cc +++ b/src/sys/sys.cc @@ -8,15 +8,20 @@ #include "sys/sys.h" // system headers -#include <signal.h> +#ifdef _WIN32 + +#include <dlfcn.h> + +#else +#include <signal.h> #include <sys/stat.h> #include <sys/types.h> +#endif +#include <stdlib.h> -namespace sys { - -bool mkdir(const char *path) +bool sys::mkdir(const char *path) { #ifdef _WIN32 ::mkdir(path); @@ -27,7 +32,7 @@ bool mkdir(const char *path) #endif } -void signal(int signum, signalfunc handler) +void sys::signal(int signum, signalfunc handler) { #ifndef _WIN32 struct sigaction sa; @@ -35,8 +40,10 @@ void signal(int signum, signalfunc handler) sa.sa_handler = handler; sa.sa_flags = 0; - sigaction(signum, &sa, 0); + ::sigaction(signum, &sa, 0); #endif } +void sys::quit(int status) { + exit(status); } diff --git a/src/sys/sys.h b/src/sys/sys.h index 0d05b67..86642e5 100644 --- a/src/sys/sys.h +++ b/src/sys/sys.h @@ -7,13 +7,23 @@ #ifndef __INCLUDED_SYS_H__ #define __INCLUDED_SYS_H__ +#include "config.h" + /// contains operating system dependent functions namespace sys { typedef void (* signalfunc)(int signum); + /// create a directory bool mkdir(const char *path); + /// intercept OS signals void signal(int signum, signalfunc handler); + /// quit + /** @param status return value + */ + void quit(int status); } +#include "sys/consoleinterface.h" + #endif // __INCLUDED_SYS_H__ |