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/Makefile.am6
-rw-r--r--src/core/applicationinterface.cc25
-rw-r--r--src/core/applicationinterface.h6
-rw-r--r--src/core/commandbuffer.cc56
-rw-r--r--src/core/commandbuffer.h33
-rw-r--r--src/core/core.h7
-rw-r--r--src/core/func.cc32
-rw-r--r--src/core/func.h30
-rw-r--r--src/core/gameinterface.cc16
-rw-r--r--src/core/gameinterface.h10
10 files changed, 208 insertions, 13 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index a70652e..27477dc 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -1,11 +1,13 @@
METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
-libcore_la_SOURCES = applicationinterface.cc gameinterface.cc
+libcore_la_SOURCES = applicationinterface.cc commandbuffer.cc func.cc \
+ gameinterface.cc
libcore_la_LDFLAGS = -avoid-version -no-undefined
libcore_la_LIBADD = $(top_builddir)/src/math/libmath.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
+noinst_HEADERS = applicationinterface.h commandbuffer.h core.h func.h \
+ gameinterface.h
diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc
index 209a4f5..9a2cce2 100644
--- a/src/core/applicationinterface.cc
+++ b/src/core/applicationinterface.cc
@@ -14,6 +14,17 @@
namespace core {
+// --------------- function repository ------------------------------
+extern "C" void func_print(std::stringstream &args) {
+ char text[MAXCMDSIZE];
+ if(args.getline(text, MAXCMDSIZE))
+ con_print << args << std::endl;
+}
+
+extern "C" void func_help(std::stringstream &args) {
+ con_print << "This is the help function" << std::endl;
+}
+
// --------------- signal_handler -----------------------------------
extern "C" void signal_handler(int signum)
{
@@ -71,10 +82,14 @@ void ApplicationInterface::init()
con_debug << "Initializing core..." << std::endl;
+ // register our functions
+ func::add("print", func_print);
+ func::add("help", func_help);
+
if (game())
game()->init();
else
- con_warn << "No game module found!" << std::endl;
+ con_warn << "No game module loaded!" << std::endl;
}
@@ -85,7 +100,7 @@ void ApplicationInterface::shutdown()
if (game())
game()->shutdown();
else
- con_warn << "No game module found!" << std::endl;
+ con_warn << "No game module loaded!" << std::endl;
filesystem::shutdown();
}
@@ -97,8 +112,12 @@ void ApplicationInterface::quit(int status)
void ApplicationInterface::frame(float seconds)
{
- if (game())
+ if (game()) {
game()->frame(seconds);
+ }
+
+ // execute commands in the buffer
+ commandbuffer::execute();
}
}
diff --git a/src/core/applicationinterface.h b/src/core/applicationinterface.h
index 6093427..ef02d8f 100644
--- a/src/core/applicationinterface.h
+++ b/src/core/applicationinterface.h
@@ -24,15 +24,15 @@ public:
/// shutdown the application
virtual void shutdown();
- /// quit the application
- virtual void quit(int status);
-
/// run a core frame
virtual void frame(float seconds);
/// a pointer to the current console instance
static ApplicationInterface *instance();
+ /// quit the application
+ virtual void quit(int status);
+
private:
/// console singleton
static ApplicationInterface *applicationinterface_instance;
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
new file mode 100644
index 0000000..23e8a8d
--- /dev/null
+++ b/src/core/commandbuffer.cc
@@ -0,0 +1,56 @@
+/*
+ core/commandbuffer.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/commandbuffer.h"
+#include "sys/sys.h"
+
+// C++ headers
+#include <string>
+#include <sstream>
+
+namespace core {
+
+std::stringstream cmd(std::stringstream::in | std::stringstream::out);
+
+namespace commandbuffer {
+
+void exec(const char *text) {
+ std::stringstream cmdstream(text);
+ std::string cmdname;
+
+ cmdstream >> cmdname;
+
+ func::Func f = func::find(cmdname);
+
+ if (f) {
+ f(cmdstream);
+ return;
+ }
+
+ con_print << "unknown command '" << cmdname << "'" << std::endl;
+}
+
+void execute() {
+ if (core::cmd.eof())
+ return;
+
+ char line[MAXCMDSIZE];
+ while(core::cmd.getline(line, MAXCMDSIZE-1)) {
+ exec(line);
+ }
+
+ cmd.clear();
+}
+
+void clear() {
+ char line[MAXCMDSIZE];
+ while(core::cmd.getline(line, MAXCMDSIZE-1));
+}
+
+}
+
+}
+
diff --git a/src/core/commandbuffer.h b/src/core/commandbuffer.h
new file mode 100644
index 0000000..c18acd0
--- /dev/null
+++ b/src/core/commandbuffer.h
@@ -0,0 +1,33 @@
+/*
+ core/commandbuffer.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_COMMANDBUFFER_H__
+#define __INCLUDED_COMMANDBUFFER_H__
+
+// project headers
+#include "core/core.h"
+
+// C++ headers
+#include <sstream>
+
+namespace core {
+
+/// global buffer to hold the command stream
+extern std::stringstream cmd;
+
+namespace commandbuffer {
+
+/// execute the commands in the buffer
+void execute();
+
+/// flush the command buffer
+void clear();
+
+}
+
+}
+
+#endif // COMMANDBUFFER
diff --git a/src/core/core.h b/src/core/core.h
index 745fd86..64eadb1 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -10,15 +10,20 @@
#include "core/gameinterface.h"
#include "core/applicationinterface.h"
+#define MAXCMDSIZE 1024
+
/// core contains the basic functionality of the engine
namespace core
{
+ /// pointer to the current GameInterface
inline GameInterface *game() { return GameInterface::instance(); }
+ /// pointer to the current ApplicationInterface
inline ApplicationInterface *application() { return ApplicationInterface::instance(); }
-
};
+#include "core/commandbuffer.h"
+#include "core/func.h"
#endif // __INCLUDED_CORE_H__
diff --git a/src/core/func.cc b/src/core/func.cc
new file mode 100644
index 0000000..6ffc20e
--- /dev/null
+++ b/src/core/func.cc
@@ -0,0 +1,32 @@
+/*
+ core/func.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/func.h"
+#include <map>
+
+namespace core {
+
+namespace func {
+
+ std::map<std::string, Func> functionmap;
+
+ void add(const char * functionname, Func functionptr)
+ {
+ functionmap[std::string(functionname)] = functionptr;
+ }
+
+ void remove(std:: string functionname)
+ {
+ functionmap.erase(std::string(functionname));
+ }
+
+ Func find(std::string functionname)
+ {
+ return functionmap[functionname];
+ }
+}
+
+}
diff --git a/src/core/func.h b/src/core/func.h
new file mode 100644
index 0000000..9d9f352
--- /dev/null
+++ b/src/core/func.h
@@ -0,0 +1,30 @@
+/*
+ core/core.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_FUNC_H__
+#define __INCLUDED_CORE_FUNC_H__
+
+#include <sstream>
+
+namespace core {
+
+/// engine functions registry
+namespace func {
+ typedef void (* Func)(std::stringstream &args);
+
+ /// register a function pointer
+ void add(const char *functionname, Func functionptr);
+
+ /// unregister a function pointer
+ void remove(std:: string functionname);
+
+ /// find a fuction
+ Func find(std::string functionname);
+}
+
+}
+
+#endif // __INCLUDED_CORE_FUNC_H__
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 964da2d..d9d8f0c 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -1,5 +1,5 @@
/*
- core/game.cc
+ core/gameinterface.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
@@ -21,6 +21,7 @@ GameInterface::GameInterface()
exit(2);
}
gameinterface_instance = this;
+ game_ready = false;
}
GameInterface::~GameInterface()
@@ -33,5 +34,18 @@ GameInterface *GameInterface::instance()
return gameinterface_instance;
}
+void GameInterface::init()
+{
+ game_ready = true;
+}
+
+void GameInterface::shutdown()
+{
+ game_ready = false;
}
+bool GameInterface::ready()
+{
+ return game_ready;
+}
+}
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index 3bd887c..622aaf5 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -1,5 +1,5 @@
/*
- core/game.h
+ core/gameinterface.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
@@ -21,10 +21,10 @@ public:
virtual ~GameInterface();
/// initialize the game
- virtual void init() = 0;
+ virtual void init();
/// shutdown the game
- virtual void shutdown() = 0;
+ virtual void shutdown();
/// run one frame of the game
/** @param sec time since the previous frame, in seconds
@@ -34,9 +34,13 @@ public:
/// a pointer to the current game instance
static GameInterface * instance();
+ /// state of the game
+ bool ready();
+
private:
/// game singleton
static GameInterface *gameinterface_instance;
+ bool game_ready;
};
}