Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/applicationinterface.cc15
-rw-r--r--src/core/commandbuffer.cc2
-rw-r--r--src/core/func.cc27
-rw-r--r--src/core/func.h16
-rw-r--r--src/core/gameinterface.cc13
-rw-r--r--src/core/gameinterface.h13
6 files changed, 52 insertions, 34 deletions
diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc
index 9a2cce2..d195881 100644
--- a/src/core/applicationinterface.cc
+++ b/src/core/applicationinterface.cc
@@ -25,6 +25,11 @@ extern "C" void func_help(std::stringstream &args) {
con_print << "This is the help function" << std::endl;
}
+extern "C" void func_quit(std::stringstream &args) {
+ ApplicationInterface::instance()->shutdown();
+ ApplicationInterface::instance()->quit(0);
+}
+
// --------------- signal_handler -----------------------------------
extern "C" void signal_handler(int signum)
{
@@ -80,11 +85,13 @@ void ApplicationInterface::init()
{
filesystem::init();
- con_debug << "Initializing core..." << std::endl;
+ con_print << "Initializing core..." << std::endl;
+ con_debug << "Debug messages enabled" << std::endl;
// register our functions
- func::add("print", func_print);
- func::add("help", func_help);
+ func_register("print", func_print);
+ func_register("help", func_help);
+ func_register("quit", func_quit);
if (game())
game()->init();
@@ -95,7 +102,7 @@ void ApplicationInterface::init()
void ApplicationInterface::shutdown()
{
- con_debug << "Shutting down core..." << std::endl;
+ con_print << "Shutting down core..." << std::endl;
if (game())
game()->shutdown();
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 23e8a8d..fbeba7b 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -23,7 +23,7 @@ void exec(const char *text) {
cmdstream >> cmdname;
- func::Func f = func::find(cmdname);
+ Func f = func_find(cmdname);
if (f) {
f(cmdstream);
diff --git a/src/core/func.cc b/src/core/func.cc
index 6ffc20e..c4f14db 100644
--- a/src/core/func.cc
+++ b/src/core/func.cc
@@ -9,24 +9,21 @@
namespace core {
-namespace func {
+std::map<std::string, Func> functionmap;
- std::map<std::string, Func> functionmap;
-
- void add(const char * functionname, Func functionptr)
- {
- functionmap[std::string(functionname)] = functionptr;
- }
+void func_register(const char * functionname, Func functionptr)
+{
+ functionmap[std::string(functionname)] = functionptr;
+}
- void remove(std:: string functionname)
- {
- functionmap.erase(std::string(functionname));
- }
+void func_unregister(std:: string functionname)
+{
+ functionmap.erase(std::string(functionname));
+}
- Func find(std::string functionname)
- {
- return functionmap[functionname];
- }
+Func func_find(std::string functionname)
+{
+ return functionmap[functionname];
}
}
diff --git a/src/core/func.h b/src/core/func.h
index 9d9f352..901490e 100644
--- a/src/core/func.h
+++ b/src/core/func.h
@@ -10,21 +10,19 @@
#include <sstream>
namespace core {
-
-/// engine functions registry
-namespace func {
+ /// function pointer type
typedef void (* Func)(std::stringstream &args);
/// register a function pointer
- void add(const char *functionname, Func functionptr);
+ void func_register(const char *functionname, Func functionptr);
/// unregister a function pointer
- void remove(std:: string functionname);
-
- /// find a fuction
- Func find(std::string functionname);
-}
+ void func_unregister(std:: string functionname);
+ /// find a fuction pointer
+ /** Returns 0 if the function pointer could not be found
+ */
+ Func func_find(std::string functionname);
}
#endif // __INCLUDED_CORE_FUNC_H__
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index d9d8f0c..ac5209b 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -44,8 +44,19 @@ void GameInterface::shutdown()
game_ready = false;
}
-bool GameInterface::ready()
+bool GameInterface::ready() const
{
return game_ready;
}
+
+float GameInterface::time() const
+{
+ return current_time;
+}
+
+void GameInterface::frame (float seconds)
+{
+ current_time += seconds;
+}
+
}
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index 622aaf5..1986939 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -29,18 +29,23 @@ public:
/// run one frame of the game
/** @param sec time since the previous frame, in seconds
*/
- virtual void frame (float sec) = 0;
+ virtual void frame (float seconds);
/// a pointer to the current game instance
static GameInterface * instance();
- /// state of the game
- bool ready();
+ /// return true if the game is ready and running
+ bool ready() const;
+
+ /// return the current game time, in seconds
+ float time() const;
private:
- /// game singleton
static GameInterface *gameinterface_instance;
+
bool game_ready;
+
+ float current_time;
};
}