Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/application.cc17
-rw-r--r--src/client/application.h3
-rw-r--r--src/client/camera.cc9
-rw-r--r--src/client/console.cc77
-rw-r--r--src/client/console.h23
-rw-r--r--src/client/input.cc19
-rw-r--r--src/client/video.cc28
-rw-r--r--src/client/view.cc98
-rw-r--r--src/client/view.h3
-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
-rw-r--r--src/game/game.cc28
-rw-r--r--src/game/game.h29
-rw-r--r--src/osirion.cc14
-rw-r--r--src/osiriond.cc14
-rw-r--r--src/server/application.cc1
-rw-r--r--src/server/console.cc4
-rw-r--r--src/server/console.h3
-rw-r--r--src/sys/consoleinterface.h5
27 files changed, 472 insertions, 124 deletions
diff --git a/src/client/application.cc b/src/client/application.cc
index 03dda2f..d3e7f4e 100644
--- a/src/client/application.cc
+++ b/src/client/application.cc
@@ -20,7 +20,7 @@ namespace client {
void Application::quit(int status)
{
SDL_Quit();
- exit(status);
+ core::ApplicationInterface::quit(status);
}
void Application::init()
@@ -28,7 +28,7 @@ void Application::init()
// initialize core
core::ApplicationInterface::init();
- con_debug << "Initializing client..." << std::endl;
+ con_debug << "Initializing client..." << std::endl;
// Initialize the video subsystem
video.init();
@@ -56,7 +56,7 @@ void Application::run()
float elapsed = (float) ( current - chrono) / 1000.0f;
chrono = current;
- frame(elapsed);
+ core::ApplicationInterface::frame(elapsed);
// update the video chronometers and draw
video.draw(elapsed);
@@ -70,15 +70,18 @@ void Application::run()
void Application::shutdown()
{
con_debug << "Shutting down client..." << std::endl;
-
- input.shutdown();
+ console.flush();
+ input.shutdown();
+ console.flush();
+
video.shutdown();
+ console.flush();
core::ApplicationInterface::shutdown();
+ console.flush();
- quit(0);
-
+ quit(0);
}
}
diff --git a/src/client/application.h b/src/client/application.h
index 571e5af..40da1da 100644
--- a/src/client/application.h
+++ b/src/client/application.h
@@ -23,9 +23,8 @@ public:
/// shutdown the client Application
virtual void shutdown();
-protected:
/// quit the client Application
- void quit(int result);
+ virtual void quit(int status);
};
}
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 5355a26..a7c3349 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -4,8 +4,7 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "client/camera.h"
-#include "game/game.h"
+#include "client/client.h"
#include "math/mathlib.h"
using math::degrees360f;
@@ -40,7 +39,7 @@ Camera::~Camera()
void Camera::draw(float elapsed)
{
if (mode == Track) {
- yaw_target = game::ship.yaw();
+ yaw_target = game.ship.yaw();
}
// adjust yaw
@@ -107,7 +106,7 @@ void Camera::nextmode() {
case Overview:
// switch camera to Track mode
mode = Track;
- yaw_target = game::ship.yaw();
+ yaw_target = game.ship.yaw();
yaw_current = yaw_target;
pitch_target = pitch_track;
pitch_current = pitch_target;
@@ -116,7 +115,7 @@ void Camera::nextmode() {
case Track:
// switch camera to Free mode
mode = Free;
- yaw_target = game::ship.yaw();
+ yaw_target = game.ship.yaw();
yaw_current = yaw_target;
pitch_target = pitch_track;
pitch_current = pitch_target;
diff --git a/src/client/console.cc b/src/client/console.cc
index 6a3dfaa..50093f9 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -4,24 +4,93 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "client/client.h"
#include "client/console.h"
+#include "core/core.h"
+#include "render/render.h"
+
+#include <iostream>
namespace client {
+Console::Console() {
+ visible = false;
+}
+
std::ostream & Console::messagestream()
{
- return (std::cout << ". ");
+ return (buffer << ". ");
}
std::ostream & Console::warningstream()
{
- return (std::cout << "! ");
+ return (buffer << "* ");
+}
+
+std::ostream & Console::errorstream()
+{
+ return (buffer << "! ");
}
std::ostream & Console::debugstream()
{
- return (std::cout << "? ");
+ return (buffer << "? ");
}
-} // namespace client
+void Console::draw()
+{
+ using namespace render;
+
+ flush();
+
+ float height;
+ if (core::game()) {
+ if (!core::game()->ready())
+ height = 0.6f;
+ else if (visible)
+ height = 0.6f;
+ else
+ return;
+ } else
+ height = 1.0f;
+
+ // console background rectangle
+ gl::enable(GL_BLEND);
+ gl::begin(gl::Quads);
+ gl::color(1, 1, 1, .1);
+ gl::vertex(-0.5f*video.ratio , 0.5, -1.0f);
+ gl::vertex(0.5f*video.ratio ,0.5, -1.0f);
+ gl::vertex(0.5f*video.ratio , 0.5-height, -1.0f);
+ gl::vertex(-0.5f*video.ratio , 0.5-height, -1.0f);
+ gl::end();
+ gl::disable(GL_BLEND);
+}
+
+void Console::flush()
+{
+ char line[MAXCMDSIZE];
+ while(this->buffer.getline(line, MAXCMDSIZE-1)) {
+
+ while (text.size() >= 32765 - MAXCMDSIZE) {
+ size_t i = 0;
+ while (i+1 < text.size() && text[i] != '\n')
+ i++;
+ text.erase(0, i+1);
+ }
+
+ text.append(line);
+ text.append("\n");
+
+ std::cout << line << std::endl;
+ }
+
+ buffer.clear();
+}
+
+void Console::toggle()
+{
+ visible = !visible;
+}
+
+} // namespace client
diff --git a/src/client/console.h b/src/client/console.h
index 1a36d00..ee3b85e 100644
--- a/src/client/console.h
+++ b/src/client/console.h
@@ -8,21 +8,44 @@
#define __INCLUDED_CLIENT_CONSOLE_H__
#include "sys/consoleinterface.h"
+#include <sstream>
namespace client {
/// client console implementation
class Console : public sys::ConsoleInterface {
public:
+ Console();
+
/// stream to send normal messages too
virtual std::ostream & messagestream();
/// stream to send warning messages too
virtual std::ostream & warningstream();
+ /// stream to send error messages too
+ virtual std::ostream & errorstream();
+
/// stream to send debug messages too
virtual std::ostream & debugstream();
+
+ /// flush buffer
+ void flush();
+
+ /// draw the console
+ void draw();
+
+ /// toggle the console on or off
+ void toggle();
+
+ bool visible;
+
+protected:
+ /// console text buffer
+ std::stringstream buffer;
+ /// console text data
+ std::string text;
};
}
diff --git a/src/client/input.cc b/src/client/input.cc
index 3e37a19..d30a97e 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -5,8 +5,7 @@
*/
//project headers
-#include "client.h"
-#include "game/game.h"
+#include "client/client.h"
namespace client {
@@ -33,6 +32,10 @@ http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_
void Input::handle_keyreleased(SDL_keysym* keysym)
{
switch( keysym->sym ) {
+ case '`':
+ case '~':
+ console.toggle();
+ break;
case SDLK_SPACE:
camera.nextmode();
break;
@@ -46,7 +49,7 @@ void Input::handle_keypressed(SDL_keysym* keysym)
{
switch( keysym->sym ) {
case SDLK_ESCAPE:
- application.shutdown();
+ client::application.shutdown();
break;
case SDLK_LEFT:
camera.rotate_left();
@@ -61,16 +64,16 @@ void Input::handle_keypressed(SDL_keysym* keysym)
camera.rotate_down();
break;
case SDLK_KP_PLUS:
- game::ship.set_thrust(game::ship.thrust() + 0.08f);
+ game.ship.set_thrust(game.ship.thrust() + 0.08f);
break;
case SDLK_KP_MINUS:
- game::ship.set_thrust(game::ship.thrust() - 0.1f);
+ game.ship.set_thrust(game.ship.thrust() - 0.1f);
break;
case SDLK_KP4:
- game::ship.set_yaw(game::ship.yaw() + 10);
+ game.ship.set_yaw(game.ship.yaw() + 10);
break;
case SDLK_KP6:
- game::ship.set_yaw(game::ship.yaw() - 10);
+ game.ship.set_yaw(game.ship.yaw() - 10);
break;
default:
break;
@@ -91,7 +94,7 @@ void Input::process()
handle_keyreleased( &event.key.keysym );
break;
case SDL_QUIT:
- application.shutdown();
+ client::application.shutdown();
break;
}
diff --git a/src/client/video.cc b/src/client/video.cc
index 5772961..4018834 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -30,20 +30,7 @@ void Video::reset()
{
ratio = (float) width / (float) height;
- // Our shading model--Gouraud (smooth).
- gl::shademodel(GL_SMOOTH);
- // Culling
- gl::cullface( GL_BACK );
- gl::frontface(GL_CCW );
- gl::enable( GL_CULL_FACE );
-
- // Depth buffer writing
- gl::depthmask(GL_TRUE);
- gl::enable(GL_DEPTH_TEST);
-
- // Alpha blending
- gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Set the clear color
gl::clearcolor( 0, 0, 0, 0 );
@@ -64,18 +51,18 @@ void Video::init()
int flags = 0;
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
- con_warn << "SDL_Init() failed: " << SDL_GetError() << std::endl;
+ std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl;
return;
}
const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo();
if( !sdl_videoinfo) {
- con_warn << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
+ std::cerr << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
return;
}
- width = 800;
- height = 600;
+ width = 1024;
+ height = 768;
bpp = sdl_videoinfo->vfmt->BitsPerPixel;
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
@@ -88,7 +75,7 @@ void Video::init()
flags = SDL_OPENGL | SDL_FULLSCREEN;
if(!SDL_SetVideoMode(width, height, bpp, flags )) {
- con_warn << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl;
+ std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl;
return;
}
@@ -103,7 +90,10 @@ void Video::init()
void Video::draw(float elapsed)
{
- view.draw(elapsed);
+ if (core::game() && core::game()->ready())
+ view.draw(elapsed);
+
+ SDL_GL_SwapBuffers();
}
void Video::shutdown()
diff --git a/src/client/view.cc b/src/client/view.cc
index 8754549..8881ac2 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -22,14 +22,14 @@ namespace client
ShipDrawer *shipdrawer = 0;
StarDrawer *stardrawer = 0;
-game::Ship *target =0; // the view's target
+game::Ship *target = 0; // the view's target
void View::init() {
// draw scene
if (!shipdrawer) {
- stardrawer = new StarDrawer(&game::star);
- shipdrawer = new ShipDrawer(&game::ship);
- target = &game::ship;
+ stardrawer = new StarDrawer(&game.star);
+ shipdrawer = new ShipDrawer(&game.ship);
+ target = &game.ship;
}
}
@@ -43,28 +43,47 @@ void View::shutdown()
}
void View::reset() {
- // Change to the projection matrix and set our viewing volume.
- gl::matrixmode( GL_PROJECTION );
- gl::loadidentity();
+ // Our shading model--Gouraud (smooth).
+ gl::shademodel(GL_SMOOTH);
+
+ // Culling
+ gl::cullface( GL_BACK );
+ gl::frontface(GL_CCW );
+}
+
+
+void View::draw_world(float elapsed)
+{
+
+ gl::enable( GL_CULL_FACE );
+
+ // Depth buffer writing
+ gl::depthmask(GL_TRUE);
+ gl::enable(GL_DEPTH_TEST);
+
+ // draw the world
+ gl::push();
+
+ gl::translate(game.ship.location - target->location);
+ gl::scale(0.2f, 0.2f, 0.2f);
+ shipdrawer->draw(elapsed);
+ gl::pop();
+
+ gl::push();
+ gl::translate(game.star.location - target->location);
+ stardrawer->draw(elapsed);
+ gl::pop();
+
+ gl::disable( GL_CULL_FACE );
- //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 );
- const float frustumsize=0.5f;
- gl::frustum( -frustumsize * video.ratio, frustumsize * video.ratio, -frustumsize, frustumsize, 1.0f, 1024.0f);
- /*
- map world coordinates to GL coordinates
-
- The world coordinates are identical to GL coordinates,
- but the default viewing pitch (0 degrees)
- is the positive X-axis
- */
- gl::rotate(90.0f, 0, 1.0, 0);
}
void View::draw_background(float elapsed)
{
using namespace gl;
-// // // enable Alpha blending
+ // enable Alpha blending
+ gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl::enable(GL_BLEND);
// galactic axis
@@ -109,23 +128,7 @@ void View::draw_background(float elapsed)
end();
gl::disable(GL_BLEND);
-}
-
-void View::draw_world(float elapsed)
-{
- // draw the world
- gl::push();
-
- gl::translate(game::ship.location - target->location);
- gl::scale(0.2f, 0.2f, 0.2f);
- shipdrawer->draw(elapsed);
- gl::pop();
-
- gl::push();
- gl::translate(game::star.location - target->location);
- stardrawer->draw(elapsed);
- gl::pop();
-
+ gl::disable(GL_DEPTH_TEST);
}
void View::draw(float elapsed)
@@ -133,10 +136,20 @@ void View::draw(float elapsed)
// Clear the color and depth buffers.
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- // We don't want to modify the projection matrix.
- gl::matrixmode( GL_MODELVIEW );
+ // Change to the projection matrix and set our viewing volume.
+ gl::matrixmode( GL_PROJECTION );
gl::loadidentity();
+ //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 );
+ const float frustumsize = 0.5f;
+ gl::frustum( -frustumsize * video.ratio, frustumsize * video.ratio, -frustumsize, frustumsize, 1.0f, 1024.0f);
+
+
+ gl::matrixmode( GL_MODELVIEW );
+
+ gl::loadidentity();
+ gl::rotate(90.0f, 0, 1.0, 0);
+
// Camera transformation
camera.draw(elapsed);
@@ -146,7 +159,14 @@ void View::draw(float elapsed)
// draw the semi-static background
draw_background(elapsed);
- SDL_GL_SwapBuffers();
+ // draw the console
+ //gl::matrixmode( GL_PROJECTION );
+ //gl::loadidentity();
+
+ gl::matrixmode( GL_MODELVIEW );
+ gl::loadidentity();
+
+ console.draw();
}
} // namespace view
diff --git a/src/client/view.h b/src/client/view.h
index fa62d98..e0a613f 100644
--- a/src/client/view.h
+++ b/src/client/view.h
@@ -24,6 +24,9 @@ public:
/// reset the projection matrix
void reset();
+ float width;
+ float height;
+
protected:
/// draw the world
void draw_world(float elapsed);
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;
};
}
diff --git a/src/game/game.cc b/src/game/game.cc
index 7f2ad17..2945657 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -18,23 +18,11 @@
namespace game
{
-Ship ship;
-Star star;
-bool initialized = false;
-
-std::string name; // name of the game
-std::string label; // label of the game
-std::string author; // author of the game
-
-// sectors in space
-std::vector<Sector*> sectors;
-
void Game::init()
{
using math::Vector3f;
using filesystem::IniFile;
- con_print << "Project::OSiRiON " << VERSION << std::endl;
con_debug << "Debug messages enabled" << std::endl;
// read game.ini
@@ -61,7 +49,8 @@ void Game::init()
}
f.close();
- con_print << "game.ini loaded " << name << " [" << label << "] by " << author << std::endl;
+ con_print << name << std::endl;
+ con_print << "by " << author << std::endl;
// read world.ini
std::string tmp;
@@ -108,14 +97,16 @@ void Game::init()
star.location = Vector3f(256.0f, 0.0f, 256.0f);
ship.location = Vector3f(0,0,0);
- // all done, ready to run
- initialized = true;
+ // signal the gameinterface the game is ready
+ core::GameInterface::init();
+
+ // test functions
+ core::cmd << "help" << std::endl;
+ core::cmd << "test" << std::endl;
}
void Game::shutdown()
{
- initialized = false;
-
// delete every sector object in the sectors vector
for (unsigned int n =0; n< sectors.size(); n++) {
delete sectors[n];
@@ -123,6 +114,9 @@ void Game::shutdown()
}
// clear the sectors vector
sectors.clear();
+
+ // signal the gameinterface the game has shutdown
+ core::GameInterface::shutdown();
}
void Game::frame(float elapsed)
diff --git a/src/game/game.h b/src/game/game.h
index 6f77bcf..bd9cebb 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -10,31 +10,40 @@
// project headers
#include "game/ship.h"
#include "game/star.h"
+#include "game/sector.h"
#include "core/core.h"
#include "sys/sys.h"
+// C++ headers
+#include <vector>
+#include <string>
+
/// the game-specific engine
-/** The main game functions. The console should be initialized before calling these.
+/** The main game functions.
*/
namespace game
{
-/// the only ship in the game
-extern Ship ship;
-
-/// the only star in the game
-extern Star star;
-
class Game : public core::GameInterface {
public:
/// initialize the game
void init();
-
/// shutdown the game
void shutdown();
-
- /// update the game state
+ /// execute one game grame
void frame(float sec);
+
+ /// sectors in space
+ std::vector<Sector*> sectors;
+ /// the only ship in the game
+ Ship ship;
+ /// the only star in the game
+ Star star;
+
+private:
+ std::string name;
+ std::string label;
+ std::string author;
};
}
diff --git a/src/osirion.cc b/src/osirion.cc
new file mode 100644
index 0000000..6955042
--- /dev/null
+++ b/src/osirion.cc
@@ -0,0 +1,14 @@
+/* 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/osiriond.cc b/src/osiriond.cc
new file mode 100644
index 0000000..052c68d
--- /dev/null
+++ b/src/osiriond.cc
@@ -0,0 +1,14 @@
+/*
+ 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/application.cc b/src/server/application.cc
index 0d3fe4b..ee5f32f 100644
--- a/src/server/application.cc
+++ b/src/server/application.cc
@@ -9,6 +9,7 @@
#include "server/application.h"
#include "server/timer.h"
#include "core/core.h"
+#include "game/game.h"
namespace server {
diff --git a/src/server/console.cc b/src/server/console.cc
index 3df0e09..a2e8503 100644
--- a/src/server/console.cc
+++ b/src/server/console.cc
@@ -18,6 +18,10 @@ std::ostream & Console::warningstream()
{
return std::cerr;
}
+std::ostream & Console::errorstream()
+{
+ return std::cerr;
+}
std::ostream & Console::debugstream()
{
diff --git a/src/server/console.h b/src/server/console.h
index 34166be..a5f45c3 100644
--- a/src/server/console.h
+++ b/src/server/console.h
@@ -20,6 +20,9 @@ public:
/// stream to send warning messages too
virtual std::ostream & warningstream();
+ /// stream to send warning messages too
+ virtual std::ostream & errorstream();
+
/// stream to send debug messages too
virtual std::ostream & debugstream();
diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h
index e0228ae..6540d95 100644
--- a/src/sys/consoleinterface.h
+++ b/src/sys/consoleinterface.h
@@ -17,6 +17,8 @@
#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()
+/// global define to send an error message to the system console
+#define con_error sys::ConsoleInterface::instance()->errorstream()
#ifdef HAVE_DEBUG_MESSAGES
/// global define to send a debug message to the system console
@@ -42,6 +44,9 @@ public:
/// stream to send warning messages too
virtual std::ostream & warningstream() = 0;
+ /// stream to send error messages too
+ virtual std::ostream & errorstream() = 0;
+
/// stream to send debug messages too
virtual std::ostream & debugstream() = 0;