diff options
29 files changed, 540 insertions, 315 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am index f8542e2..e191f5f 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -8,12 +8,12 @@ osirion_LDADD = $(top_builddir)/src/math/libmath.la \ $(top_builddir)/src/core/libcore.la \ $(top_builddir)/src/game/libgame.la \ $(top_builddir)/src/gl/libgl.la -osirion_SOURCES = camera.cc client.cc console.cc hud.cc input.cc main.cc \ +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) -noinst_HEADERS = camera.h client.h console.h input.h shipdrawer.h stardrawer.h \ +noinst_HEADERS = application.h camera.h client.h console.h input.h shipdrawer.h stardrawer.h \ video.h view.h diff --git a/src/client/application.cc b/src/client/application.cc new file mode 100644 index 0000000..03dda2f --- /dev/null +++ b/src/client/application.cc @@ -0,0 +1,84 @@ +/* + client/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 "client/client.h" +#include "client/application.h" +#include "core/core.h" + +// SDL headers +#include <SDL/SDL.h> + +// C++ headers +#include <cmath> + +namespace client { + +void Application::quit(int status) +{ + SDL_Quit(); + exit(status); +} + +void Application::init() +{ + // initialize core + core::ApplicationInterface::init(); + + con_debug << "Initializing client..." << std::endl; + + // Initialize the video subsystem + video.init(); + if (!video.initialized) { + quit(1); + } + + // initialize input + input.init(); +} + +void Application::run() +{ + Uint32 chrono = SDL_GetTicks(); + + while(true) { + Uint32 current = SDL_GetTicks(); + + // overflow protection ~49 days + if (current < chrono) { + chrono = current; + } + + // update the game chronometers + float elapsed = (float) ( current - chrono) / 1000.0f; + chrono = current; + + frame(elapsed); + + // update the video chronometers and draw + video.draw(elapsed); + + // process input + input.process(); + } + +} + +void Application::shutdown() +{ + con_debug << "Shutting down client..." << std::endl; + + input.shutdown(); + + video.shutdown(); + + core::ApplicationInterface::shutdown(); + + quit(0); + +} + +} diff --git a/src/client/application.h b/src/client/application.h new file mode 100644 index 0000000..571e5af --- /dev/null +++ b/src/client/application.h @@ -0,0 +1,33 @@ +/* + client/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_CLIENT_APPLICATION_H__ +#define __INCLUDED_CLIENT_APPLICATION_H__ + +#include "core/applicationinterface.h" + +namespace client { + +/// client Application implementation +class Application : public core::ApplicationInterface { +public: + /// initialize the client Application + virtual void init(); + + /// run the client Application + virtual void run(); + + /// shutdown the client Application + virtual void shutdown(); + +protected: + /// quit the client Application + void quit(int result); +}; + +} +#endif // __INCLUDED_CLIENT_APPLICATION_H__ + diff --git a/src/client/client.cc b/src/client/client.cc index 7a718a3..e78f73d 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -4,91 +4,25 @@ the terms and conditions of the GNU General Public License version 2 */ -// project headers -#include "client/client.h" -#include "game/game.h" -#include "core/core.h" -#include "common/common.h" - -// SDL headers -#include <SDL/SDL.h> +#include "client/application.h" +#include "client/camera.h" +#include "client/console.h" +#include "client/input.h" +#include "client/video.h" +#include "client/view.h" -// C++ headers -#include <cmath> +#include "game/game.h" namespace client { // public instances -Camera camera; -View view; -Video video; -Input input; - -// private instance of the client console object -Console console_instance; -// private instance of the game object -game::Game game_instance; - -void quit(int status) -{ - SDL_Quit(); - exit(status); -} - -void init() -{ - // core initializes all the modules - core::init(); - - con_debug << "Initializing client..." << std::endl; - - // Initialize the video subsystem - video.init(); - if (!video.initialized) { - quit(1); - } - - // initialize input - input.init(); -} - -void run() -{ - Uint32 chrono = SDL_GetTicks(); - - while(true) { - Uint32 current = SDL_GetTicks(); - - // overflow protection ~49 days - if (current < chrono) { - chrono = current; - } - - // update the game chronometers - float elapsed = (float) ( current - chrono) / 1000.0f; - chrono = current; - - core::frame(elapsed); - - // update the video chronometers and draw - video.draw(elapsed); - - // process input - input.process(); - } -} - -void shutdown() -{ - con_debug << "Shutting down client..." << std::endl; - - input.shutdown(); - - video.shutdown(); - - core::shutdown(); - - quit(0); -} +Application application; +Camera camera; +View view; +Video video; +Input input; +Console console; +game::Game game; } // namespace client + diff --git a/src/client/client.h b/src/client/client.h index a25643c..af3e53b 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -7,32 +7,45 @@ #ifndef __INCLUDED_CLIENT_H__ #define __INCLUDED_CLIENT_H__ -#include "client/console.h" +// project headers +#include "client/application.h" #include "client/camera.h" -#include "client/view.h" +#include "client/console.h" #include "client/input.h" #include "client/video.h" +#include "client/view.h" + +#include "core/core.h" +#include "game/game.h" /// client-side functions to render and control the gameworld /** The client namespace contains the necessary functions to * accept input, send it to the game and renders the result */ namespace client { - /// initialize the client - extern void init(); - /// run the client - extern void run(); - /// shutdown the client - extern void shutdown(); - - /// global Video object - extern Video video; - /// global Input object - extern Input input; - /// global View object - extern View view; - /// global Camera object - extern Camera camera; -} + +/// global Application instance; +extern Application application; + +/// global Video instance +extern Video video; + +/// global Input instance +extern Input input; + +/// global View instance +extern View view; + +/// global Camera instance +extern Camera camera; + +/// global server Console instance +extern Console console; + +/// global Game instance +extern game::Game game; + +} // namespace client #endif // __INCLUDED_CLIENT_H__ + diff --git a/src/client/console.h b/src/client/console.h index 21d5df9..8e8ab02 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/console.h" +#include "common/consoleinterface.h" namespace client { -/// Interface for a console object that writes messages on the screen -class Console : public common::Console { +/// client console implementation +class Console : public common::ConsoleInterface { public: /// stream to send normal messages too virtual std::ostream & messagestream(); diff --git a/src/client/input.cc b/src/client/input.cc index b18339e..5f38d35 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -12,6 +12,8 @@ namespace client { void Input::init() { + con_debug << "Initializing input..." << std::endl; + //condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY << std::endl; //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL); @@ -19,6 +21,7 @@ void Input::init() void Input::shutdown() { + con_debug << "Shutting down input..." << std::endl; } /* @@ -43,7 +46,7 @@ void Input::handle_keypressed(SDL_keysym* keysym) { switch( keysym->sym ) { case SDLK_ESCAPE: - client::shutdown(); + client::application.shutdown(); break; case SDLK_LEFT: camera.rotate_left(); @@ -88,7 +91,7 @@ void Input::process() handle_keyreleased( &event.key.keysym ); break; case SDL_QUIT: - client::shutdown(); + client::application.shutdown(); break; } diff --git a/src/client/main.cc b/src/client/main.cc index 7c5f7b7..6955042 100644 --- a/src/client/main.cc +++ b/src/client/main.cc @@ -7,9 +7,8 @@ int main( int argc, char *argv[] ) { - client::init(); - - client::run(); - - client::shutdown(); + client::application.init(); + client::application.run(); + client::application.shutdown(); } + diff --git a/src/common/Makefile.am b/src/common/Makefile.am index dd5c5d1..a3f50a6 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -1,6 +1,6 @@ METASOURCES = AUTO -libcommon_la_SOURCES = common.cc console.cc +libcommon_la_SOURCES = consoleinterface.cc libcommon_la_LDFLAGS = -avoid-version -no-undefined noinst_LTLIBRARIES = libcommon.la -noinst_HEADERS = common.h console.h +noinst_HEADERS = common.h consoleinterface.h INCLUDES = -I$(top_srcdir)/src diff --git a/src/common/common.cc b/src/common/common.cc deleted file mode 100644 index cb968c0..0000000 --- a/src/common/common.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* - common/common.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "common/common.h" - -namespace common { - -void init() { - con_debug << "Initializing common..." << std::endl; -} - -void shutdown() { - con_debug << "Shutting down common..." << std::endl; -} - -} - diff --git a/src/common/common.h b/src/common/common.h index 1be6827..61aa47c 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -9,18 +9,11 @@ #include "config.h" -/// common functions and components that are used by the other subsytems -namespace common { +/// common functions and components that can be use by any subsytem +namespace common {} - /// initialize common components - void init(); +#include "common/consoleinterface.h" - /// shutdown common components - void shutdown(); - -} - -#include "common/console.h" #endif // __INCLUDED_COMMON_H__ diff --git a/src/common/console.cc b/src/common/console.cc deleted file mode 100644 index a7d0dd7..0000000 --- a/src/common/console.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - common/console.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "common/console.h" - -#include <iostream> - -#include <stdlib.h> - -namespace common { - -Console *Console::console_instance = 0; - -Console::Console() { - if (console_instance) { - std::cerr << "duplicate common::Console::console_instance" << std::endl; - exit(2); - } - console_instance = this; -} - -Console::~Console() -{ - console_instance = 0; -} - -Console *Console::instance() -{ - return console_instance; -} - -} // namespace common - diff --git a/src/common/consoleinterface.cc b/src/common/consoleinterface.cc new file mode 100644 index 0000000..eb532c6 --- /dev/null +++ b/src/common/consoleinterface.cc @@ -0,0 +1,36 @@ +/* + common/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 "common/consoleinterface.h" + +#include <iostream> + +#include <stdlib.h> + +namespace common { + +ConsoleInterface *ConsoleInterface::consoleinterface_instance = 0; + +ConsoleInterface::ConsoleInterface() { + if (consoleinterface_instance) { + std::cerr << "multiple singleton instances: common::ConsoleInterface" << std::endl; + exit(2); + } + consoleinterface_instance = this; +} + +ConsoleInterface::~ConsoleInterface() +{ + consoleinterface_instance = 0; +} + +ConsoleInterface *ConsoleInterface::instance() +{ + return consoleinterface_instance; +} + +} // namespace common + diff --git a/src/common/console.h b/src/common/consoleinterface.h index 0706f11..ec77e1d 100644 --- a/src/common/console.h +++ b/src/common/consoleinterface.h @@ -1,11 +1,11 @@ /* - common/console.h + common/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_COMMON_CONSOLE_H__ -#define __INCLUDED_COMMON_CONSOLE_H__ +#ifndef __INCLUDED_COMMON_CONSOLEINTERFACE_H__ +#define __INCLUDED_COMMON_CONSOLEINTERFACE_H__ // project headers #include "common/common.h" @@ -14,27 +14,27 @@ #include <iostream> /// global define to send a message to the system console -#define con_print common::Console::instance()->messagestream() +#define con_print common::ConsoleInterface::instance()->messagestream() /// global define to send a warning message to the system console -#define con_warn common::Console::instance()->warningstream() +#define con_warn common::ConsoleInterface::instance()->warningstream() #ifdef HAVE_DEBUG_MESSAGES /// global define to send a debug message to the system console -#define con_debug common::Console::instance()->debugstream() +#define con_debug common::ConsoleInterface::instance()->debugstream() #else #define con_debug if (0) *(std::ostream*)(0) #endif namespace common { -/// interface for a console object that writes messages on the screen -class Console { +/// common interface for the client and server Console classes +class ConsoleInterface { public: /// default constructor - Console(); + ConsoleInterface(); /// default destructor - virtual ~Console(); + virtual ~ConsoleInterface(); /// stream to send normal messages too virtual std::ostream & messagestream() = 0; @@ -46,15 +46,14 @@ public: virtual std::ostream & debugstream() = 0; /// a pointer to the current console instance - static Console *instance(); + static ConsoleInterface *instance(); private: /// console singleton - static Console *console_instance; -} -; // class Console + static ConsoleInterface *consoleinterface_instance; +}; } // namespace common -#endif // __INCLUDED_COMMON_CONSOLE_H__ +#endif // __INCLUDED_COMMON_CONSOLEINTERFACE_H__ diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 1f1cc2e..b062f9e 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -1,12 +1,12 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src -libcore_la_SOURCES = core.cc game.cc +libcore_la_SOURCES = applicationinterface.cc gameinterface.cc libcore_la_LDFLAGS = -avoid-version libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \ $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/filesystem/libfilesystem.la noinst_LTLIBRARIES = libcore.la -noinst_HEADERS = core.h game.h +noinst_HEADERS = applicationinterface.h core.h gameinterface.h diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc new file mode 100644 index 0000000..9ef5c16 --- /dev/null +++ b/src/core/applicationinterface.cc @@ -0,0 +1,68 @@ +/* + core/applicationinterface.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "core/core.h" +#include "filesystem/filesystem.h" +#include "common/common.h" + +#include <iostream> + +#include <stdlib.h> + +namespace core { + +ApplicationInterface *ApplicationInterface::applicationinterface_instance = 0; + +ApplicationInterface::ApplicationInterface() { + if (applicationinterface_instance) { + std::cerr << "multiple singleton instances: core::ApplicationInterface" << std::endl; + exit(2); + } + applicationinterface_instance = this; +} + +ApplicationInterface::~ApplicationInterface() +{ + applicationinterface_instance = 0; +} + +ApplicationInterface *ApplicationInterface::instance() +{ + return applicationinterface_instance; +} + +void ApplicationInterface::init() +{ + filesystem::init(); + + con_debug << "Initializing core..." << std::endl; + + if (game()) + game()->init(); + else + con_warn << "No game module found!" << std::endl; + +} + +void ApplicationInterface::shutdown() +{ + con_debug << "Shutting down core..." << std::endl; + + if (game()) + game()->shutdown(); + else + con_warn << "No game module found!" << std::endl; + + filesystem::shutdown(); +} + +void ApplicationInterface::frame(float seconds) +{ + if (game()) + game()->frame(seconds); +} + +} diff --git a/src/core/applicationinterface.h b/src/core/applicationinterface.h new file mode 100644 index 0000000..19eaee6 --- /dev/null +++ b/src/core/applicationinterface.h @@ -0,0 +1,42 @@ +/* + core/applicationinterface.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_CORE_APPLICATIONINTERFACE_H__ +#define __INCLUDED_CORE_APPLICATIONINTERFACE_H__ + +namespace core { + +/// core interface for the client and server Application classes +class ApplicationInterface { +public: + /// default constructor + ApplicationInterface(); + + /// default destructor + virtual ~ApplicationInterface(); + + /// initialize the application + virtual void init(); + + /// shutdown the application + virtual void shutdown(); + + /// run a core frame + virtual void frame(float seconds); + + /// a pointer to the current console instance + static ApplicationInterface *instance(); + +private: + /// console singleton + static ApplicationInterface *applicationinterface_instance; +}; + + +} // namespace core + +#endif // __INCLUDED_CORE_APPLICATIONINTERFACE_H__ + diff --git a/src/core/core.cc b/src/core/core.cc deleted file mode 100644 index 0a4ed60..0000000 --- a/src/core/core.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - core/core.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -// project headers -#include "common/common.h" -#include "filesystem/filesystem.h" -#include "core/core.h" - -namespace core -{ - -void init() -{ - con_debug << "Initializing core..." << std::endl; - - common::init(); - - filesystem::init(); - - if (::core::Game::instance()) - ::core::Game::instance()->init(); - else - con_warn << "No game module found!" << std::endl; - -} - -void shutdown() -{ - con_debug << "Shutting down core..." << std::endl; - - if (::core::Game::instance()) - ::core::Game::instance()->shutdown(); - else - con_warn << "No game module found!" << std::endl; - - filesystem::shutdown(); - - common::shutdown(); -} - -void frame(float sec) -{ - if (::core::Game::instance()) - ::core::Game::instance()->frame(sec); -} - -} //namespace core diff --git a/src/core/core.h b/src/core/core.h index 09c7209..745fd86 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -7,20 +7,18 @@ #ifndef __INCLUDED_CORE_H__ #define __INCLUDED_CORE_H__ +#include "core/gameinterface.h" +#include "core/applicationinterface.h" + /// core contains the basic functionality of the engine namespace core { - /// initialize the core - void init(); - - /// shutdown the core - void shutdown(); + inline GameInterface *game() { return GameInterface::instance(); } - /// run one frame - void frame(float sec); + inline ApplicationInterface *application() { return ApplicationInterface::instance(); } + }; -#include "core/game.h" #endif // __INCLUDED_CORE_H__ diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc new file mode 100644 index 0000000..964da2d --- /dev/null +++ b/src/core/gameinterface.cc @@ -0,0 +1,37 @@ +/* + core/game.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "core/gameinterface.h" + +#include <iostream> + +#include <stdlib.h> + +namespace core { + +GameInterface *GameInterface::gameinterface_instance = 0; + +GameInterface::GameInterface() +{ + if (gameinterface_instance) { + std::cerr << "multiple singleton instances: core::GameInterface" << std::endl; + exit(2); + } + gameinterface_instance = this; +} + +GameInterface::~GameInterface() +{ + gameinterface_instance = 0; +} + +GameInterface *GameInterface::instance() +{ + return gameinterface_instance; +} + +} + diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h new file mode 100644 index 0000000..3bd887c --- /dev/null +++ b/src/core/gameinterface.h @@ -0,0 +1,44 @@ +/* + core/game.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_CORE_GAMEINTERFACE_H__ +#define __INCLUDED_CORE_GAMEINTERFACE_H__ + +namespace core +{ + +/// abstract interface from the core to the game-specific code +/** The real game class has to derive from this class + */ +class GameInterface { +public: + /// create a new game singleton + GameInterface(); + /// destroy the game singleton + virtual ~GameInterface(); + + /// initialize the game + virtual void init() = 0; + + /// shutdown the game + virtual void shutdown() = 0; + + /// run one frame of the game + /** @param sec time since the previous frame, in seconds + */ + virtual void frame (float sec) = 0; + + /// a pointer to the current game instance + static GameInterface * instance(); + +private: + /// game singleton + static GameInterface *gameinterface_instance; +}; + +} + +#endif // __INCLUDED_CORE_GAMEINTERFACE_H__ diff --git a/src/game/game.h b/src/game/game.h index ee9e286..5a0afc7 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -25,7 +25,7 @@ extern Ship ship; /// the only star in the game extern Star star; -class Game : public core::Game { +class Game : public core::GameInterface { public: /// initialize the game void init(); 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__ + |