diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 4 | ||||
-rw-r--r-- | src/core/applicationinterface.cc | 68 | ||||
-rw-r--r-- | src/core/applicationinterface.h | 42 | ||||
-rw-r--r-- | src/core/core.cc | 50 | ||||
-rw-r--r-- | src/core/core.h | 14 | ||||
-rw-r--r-- | src/core/gameinterface.cc | 37 | ||||
-rw-r--r-- | src/core/gameinterface.h | 44 |
7 files changed, 199 insertions, 60 deletions
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__ |