Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/Makefile.am8
-rw-r--r--src/client/camera.cc22
-rw-r--r--src/client/camera.h15
-rw-r--r--src/client/client.cc4
-rw-r--r--src/client/console.cc13
-rw-r--r--src/client/draw.cc (renamed from src/client/shipdrawer.cc)69
-rw-r--r--src/client/draw.h21
-rw-r--r--src/client/input.cc42
-rw-r--r--src/client/shipdrawer.h32
-rw-r--r--src/client/stardrawer.cc30
-rw-r--r--src/client/stardrawer.h30
-rw-r--r--src/client/view.cc45
-rw-r--r--src/core/Makefile.am6
-rw-r--r--src/core/application.cc31
-rw-r--r--src/core/application.h2
-rw-r--r--src/core/clientstate.cc26
-rw-r--r--src/core/clientstate.h29
-rw-r--r--src/core/core.h1
-rw-r--r--src/core/entity.cc56
-rw-r--r--src/core/entity.h53
-rw-r--r--src/game/Makefile.am3
-rw-r--r--src/game/game.cc8
-rw-r--r--src/game/game.h5
-rw-r--r--src/game/shared.h18
-rw-r--r--src/game/ship.cc3
-rw-r--r--src/game/ship.h6
-rw-r--r--src/game/star.cc11
-rw-r--r--src/game/star.h4
-rw-r--r--src/server/server.cc4
29 files changed, 368 insertions, 229 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 1550238..74dc743 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -1,13 +1,13 @@
METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
-libclient_la_SOURCES = camera.cc client.cc console.cc hud.cc input.cc \
- keyboard.cc shipdrawer.cc stardrawer.cc video.cc view.cc
+libclient_la_SOURCES = camera.cc client.cc console.cc draw.cc hud.cc input.cc \
+ keyboard.cc video.cc view.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
noinst_LTLIBRARIES = libclient.la
-noinst_HEADERS = camera.h client.h console.h input.h keyboard.h shipdrawer.h \
- stardrawer.h video.h view.h
+noinst_HEADERS = camera.h client.h console.h draw.h input.h keyboard.h video.h \
+ view.h
libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \
$(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \
$(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la
diff --git a/src/client/camera.cc b/src/client/camera.cc
index c1ceaa9..45cd65a 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -22,8 +22,9 @@ namespace camera
// public variables
-// camera target
+// gameworld coordinates of the camera target
math::Vector3f target;
+
// target yaw, angle in XZ plane, positive is looking left
float yaw_target;
// target pitch, angle in XZ plane, positive is looking left
@@ -71,7 +72,7 @@ void draw(float elapsed)
{
// TODO camera needs to get this from selected core entity
if (mode == Track) {
- yaw_target = game.ship.yaw();
+ yaw_target = game.ship->yaw();
}
// adjust yaw
@@ -87,37 +88,40 @@ void draw(float elapsed)
gl::translate(1.0f+distance, -distance/2, 0.0f);
gl::rotate(-pitch_current, 0, 0, 1.0f);
gl::rotate(-yaw_current, 0, 1.0f, 0);
+ gl::translate(-1*target);
break;
case Track:
gl::translate(1.0f+distance, -distance , 0.0f);
gl::rotate(-pitch_current, 0, 0, 1.0f);
gl::rotate(-yaw_current, 0, 1.0f, 0);
+ gl::translate(-1*target);
break;
case Overview:
gl::translate(-distance/2, -distance, 0.0f);
gl::rotate(-pitch_current, 0, 0, 1.0f);
gl::rotate(-yaw_current, 0, 1.0f, 0);
+ gl::translate(-1*target);
break;
default:
break;
}
}
-void rotate_right()
+void key_right()
{
if (mode == Free || mode == Overview) {
yaw_target = degrees360f( yaw_target + offset_inc);
}
}
-void rotate_left()
+void key_left()
{
if (mode == Free || mode == Overview) {
yaw_target = degrees360f( yaw_target - offset_inc);
}
}
-void rotate_up()
+void key_up()
{
if (mode == Free) {
pitch_target = pitch_target - offset_inc;
@@ -125,7 +129,7 @@ void rotate_up()
}
}
-void rotate_down()
+void key_down()
{
if (mode == Free) {
pitch_target = pitch_target + offset_inc;
@@ -133,12 +137,12 @@ void rotate_down()
}
}
-void nextmode() {
+void next_mode() {
switch(mode) {
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;
@@ -147,7 +151,7 @@ void 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/camera.h b/src/client/camera.h
index b1245c8..93b44d1 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -7,6 +7,8 @@
#ifndef __INCLUDED_CLIENT_CAMERA_H__
#define __INCLUDED_CLIENT_CAMERA_H__
+#include "math/mathlib.h"
+
namespace client {
/// camera functions
@@ -25,19 +27,22 @@ namespace camera
void draw(float elapsed);
/// rotate the camera left
- void rotate_left();
+ void key_left();
/// rotate the camera right
- void rotate_right();
+ void key_right();
/// rotate the camera up
- void rotate_up();
+ void key_up();
/// rotate the camera down
- void rotate_down();
+ void key_down();
/// switch to next camera mode
- void nextmode();
+ void next_mode();
+
+ /// gameworld coordinates of the camera target
+ extern math::Vector3f target;
} // namespace camera
diff --git a/src/client/client.cc b/src/client/client.cc
index 8970dea..faf9ac3 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -46,7 +46,7 @@ Client app;
//--- engine functions --------------------------------------------
-extern "C" void func_r_restart(std::stringstream &args)
+void func_r_restart(std::stringstream &args)
{
video::shutdown();
console::flush();
@@ -83,7 +83,9 @@ void Client::quit(int status)
void Client::init()
{
con_print << "Initializing client..." << std::endl;
+
// initialize core
+ core::localstate.name = "Client";
core::Application::init();
// initialize SDL, but do not initialize any subsystems
diff --git a/src/client/console.cc b/src/client/console.cc
index 01f90da..1c2ab1e 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -58,9 +58,13 @@ size_t console_scroll = 0;
//--- engine functions --------------------------------------------
-extern "C" void func_con_toggle(std::stringstream &args)
+void func_con_toggle(std::stringstream &args)
{
- console_visible = !console_visible;
+ int i;
+ if (args >> i) {
+ if (i) console_visible = true; else console_visible = false;
+ } else
+ console_visible = !console_visible;
}
//--- public ------------------------------------------------------
@@ -215,6 +219,7 @@ void keypressed(const SDL_keysym &keysym)
}
core::cmd << (*history_pos) << std::endl;
+ (*history.rbegin()) = (*history_pos);
history.push_back("");
history_pos = history.rbegin();
@@ -242,7 +247,7 @@ void keypressed(const SDL_keysym &keysym)
input_pos = 0;
break;
case SDLK_KP1:
- case SDLK_END:
+ case SDLK_END:
input_pos = (*history_pos).size();
break;
case SDLK_KP4:
@@ -256,7 +261,7 @@ void keypressed(const SDL_keysym &keysym)
input_pos++;
break;
case SDLK_BACKSPACE:
- if ((*history_pos).size() && input_pos) {
+ if ((*history.rbegin()).size() && input_pos) {
(*history_pos).erase(input_pos-1, 1);
input_pos--;
}
diff --git a/src/client/shipdrawer.cc b/src/client/draw.cc
index 074dbd8..f907267 100644
--- a/src/client/shipdrawer.cc
+++ b/src/client/draw.cc
@@ -1,45 +1,44 @@
/*
- shipdrawer.cc
+ draw.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/shipdrawer.h"
+// projet headers
#include "render/render.h"
+#include "render/sphere.h"
#include "render/box.h"
+#include "client/client.h"
+#include "client/draw.h"
-#include <iostream>
-
-namespace client {
-
-using namespace render;
-
-using math::Vector3f;
-using math::Color;
-
-Vector3f v0(1.0f, -1.0f, -1.0f);
-Vector3f v1(1.0f, 1.0f, -1.0f);
-Vector3f v2(1.0f, 1.0f, 1.0f);
-Vector3f v3(1.0f, -1.0f, 1.0f);
+namespace client
+{
-Vector3f v4(-1.0f, -1.0f, -1.0f);
-Vector3f v5(-1.0f, 1.0f, -1.0f);
-Vector3f v6(-1.0f, 1.0f, 1.0f);
-Vector3f v7(-1.0f, -1.0f, 1.0f);
+render::Sphere sphere(math::Vector3f(0,0,0),1);
-ShipDrawer::ShipDrawer(game::Ship *s)
+void draw_star(game::Star *star, float elapsed)
{
- angle = 0;
- ship = s;
+ render::gl::color(star->color);
+ sphere.radius = star->radius;
+ sphere.draw();
}
-ShipDrawer::~ShipDrawer()
-{
-}
+math::Vector3f v0(1.0f, -1.0f, -1.0f);
+math::Vector3f v1(1.0f, 1.0f, -1.0f);
+math::Vector3f v2(1.0f, 1.0f, 1.0f);
+math::Vector3f v3(1.0f, -1.0f, 1.0f);
+
+math::Vector3f v4(-1.0f, -1.0f, -1.0f);
+math::Vector3f v5(-1.0f, 1.0f, -1.0f);
+math::Vector3f v6(-1.0f, 1.0f, 1.0f);
+math::Vector3f v7(-1.0f, -1.0f, 1.0f);
+float angle = 0;
-void ShipDrawer::draw(float elapsed)
+void draw_ship(game::Ship *ship, float elapsed)
{
- gl::push();
+ using math::Vector3f;
+ using math::Color;
+ using namespace render;
gl::rotate(ship->yaw(), 0.0f, 1.0f, 0.0f );
@@ -106,7 +105,23 @@ void ShipDrawer::draw(float elapsed)
gl::vertex(v7);
gl::vertex(v4);
gl::end();
+}
+
+void draw_world(float elapsed)
+{
+ using namespace render;
+ // draw the ship
+ gl::push();
+ gl::translate(game.ship->location);
+ gl::scale(0.2f, 0.2f, 0.2f);
+ draw_ship(game.ship, elapsed);
+ gl::pop();
+
+ // draw the star
+ gl::push();
+ gl::translate(game.star->location);
+ draw_star(game.star, elapsed);
gl::pop();
}
diff --git a/src/client/draw.h b/src/client/draw.h
new file mode 100644
index 0000000..d019216
--- /dev/null
+++ b/src/client/draw.h
@@ -0,0 +1,21 @@
+/*
+ draw.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 "game/game.h"
+
+namespace client
+{
+
+/// draw a star
+void draw_star(game::Star *star, float elapsed);
+
+/// draw a ship
+void draw_ship(game::Ship *ship, float elapsed);
+
+/// draw the world
+void draw_world(float elapsed);
+
+}
diff --git a/src/client/input.cc b/src/client/input.cc
index ccfd998..d3b2900 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -30,40 +30,49 @@ void shutdown()
con_print << "Shutting down input..." << std::endl;
}
-// handle pressed keys for the game world
-void keypressed(const SDL_keysym &keysym)
+// handle key release for the game world
+void keyreleased(const SDL_keysym &keysym)
{
switch( keysym.sym) {
case SDLK_SPACE:
- camera::nextmode();
+ camera::next_mode();
+ break;
+ default:
break;
+ }
+}
+
+// handle key press events for the game world
+void keypressed(const SDL_keysym &keysym)
+{
+ switch( keysym.sym) {
case SDLK_LEFT:
- camera::rotate_left();
+ camera::key_left();
break;
case SDLK_RIGHT:
- camera::rotate_right();
+ camera::key_right();
break;
case SDLK_UP:
- camera::rotate_up();
+ camera::key_up();
break;
case SDLK_DOWN:
- camera::rotate_down();
+ camera::key_down();
break;
case SDLK_KP_PLUS:
// TODO set core entity params
- game.ship.set_thrust(game.ship.thrust() + 0.08f);
+ game.ship->set_thrust(game.ship->thrust() + 0.08f);
break;
case SDLK_KP_MINUS:
// TODO set core entity params
- game.ship.set_thrust(game.ship.thrust() - 0.1f);
+ game.ship->set_thrust(game.ship->thrust() - 0.1f);
break;
case SDLK_KP4:
// TODO set core entity params
- game.ship.set_yaw(game.ship.yaw() + 10);
+ game.ship->set_yaw(game.ship->yaw() + 10);
break;
case SDLK_KP6:
// TODO set core entity params
- game.ship.set_yaw(game.ship.yaw() - 10);
+ game.ship->set_yaw(game.ship->yaw() - 10);
break;
default:
break;
@@ -78,10 +87,11 @@ void frame(float seconds)
while( SDL_PollEvent( &event ) ) {
switch( event.type ) {
+ case SDL_KEYUP:
+ if (!console::visible() && core::connected())
+ keyreleased(event.key.keysym );
+ break;
case SDL_KEYDOWN:
- /*if (event.key.keysym.sym == SDLK_ESCAPE) {
- client::application.shutdown();
- } else */
if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') {
console::toggle();
} else if (console::visible()) {
@@ -92,10 +102,6 @@ void frame(float seconds)
keypressed(event.key.keysym );
}
break;
-
- case SDL_KEYUP:
- break;
-
case SDL_QUIT:
core::application()->shutdown();
break;
diff --git a/src/client/shipdrawer.h b/src/client/shipdrawer.h
deleted file mode 100644
index 3ad7208..0000000
--- a/src/client/shipdrawer.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- shipdrawer.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_SHIPDRAWER_H__
-#define __INCLUDED_SHIPDRAWER_H__
-
-// project headers
-#include "game/ship.h"
-
-namespace client {
-
-class ShipDrawer
-{
-public:
- ShipDrawer(game::Ship *s);
- ~ShipDrawer();
-
- /// update the model state
- void draw(float elapsed);
-
-private:
- game::Ship *ship;
- float angle;
-};
-
-} // namespace client
-
-#endif // __INCLUDED_SHIPDRAWER_H__
-
diff --git a/src/client/stardrawer.cc b/src/client/stardrawer.cc
deleted file mode 100644
index 534c1e6..0000000
--- a/src/client/stardrawer.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-/* stardrawer.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
-*/
-
-// projet headers
-#include "client/stardrawer.h"
-#include "render/render.h"
-
-namespace client {
-
-using namespace render;
-
-StarDrawer::StarDrawer(game::Star *s) {
- star = s;
- sphere.radius = s->radius;
-
-}
-StarDrawer::~StarDrawer() {
- star = 0;
-}
-
-void StarDrawer::draw(float elapsed)
-{
- gl::color(star->color);
- sphere.draw();
-}
-
-} // namespace client
-
diff --git a/src/client/stardrawer.h b/src/client/stardrawer.h
deleted file mode 100644
index dbfd91a..0000000
--- a/src/client/stardrawer.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* stardrawer.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_STARDRAWER_H__
-#define __INCLUDED_STARDRAWER_H__
-
-#include "render/sphere.h"
-#include "game/star.h"
-
-namespace client {
-
-/// Class to draw stars
-class StarDrawer
-{
-public:
- StarDrawer(game::Star *s);
- ~StarDrawer();
-
- void draw(float elapsed);
-
-private:
- game::Star *star;
- render::Sphere sphere;
-};
-
-} // namespace client
-
-#endif // __INCLUDED_STARDRAWER_H__
diff --git a/src/client/view.cc b/src/client/view.cc
index 07e7cff..4627d26 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -7,9 +7,8 @@
#include "client/client.h"
#include "client/camera.h"
#include "client/console.h"
-#include "client/shipdrawer.h"
-#include "client/stardrawer.h"
#include "client/video.h"
+#include "client/draw.h"
#include "render/render.h"
#include "game/game.h"
#include "sys/sys.h"
@@ -26,31 +25,16 @@ namespace client
namespace view
{
-ShipDrawer *shipdrawer = 0;
-StarDrawer *stardrawer = 0;
-game::Ship *target = 0; // the view's target
-
float fps = 0;
void init()
{
- if (!shipdrawer) {
- stardrawer = new StarDrawer(&game.star);
- shipdrawer = new ShipDrawer(&game.ship);
- target = &game.ship;
- }
-
camera::init();
}
void shutdown()
{
camera::shutdown();
-
- delete stardrawer;
- stardrawer = 0;
- delete shipdrawer;
- shipdrawer = 0;
}
void reset()
@@ -77,26 +61,6 @@ void reset()
gl::disable(GL_CULL_FACE);
}
-
-void draw_world(float elapsed)
-{
- using namespace render;
-
- // 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();
-
-}
-
void draw_background(float elapsed)
{
using namespace render::gl;
@@ -115,12 +79,14 @@ void draw_background(float elapsed)
vertex(0,-1, 0);
end();
+ translate(camera::target);
+
int gridsize = 32;
float s = 1.0f / gridsize;
float y = -4.0f;
- float dx = target->location.x - floorf(target->location.x);
- float dz = target->location.z - floorf(target->location.z);
+ float dx = camera::target.x - floorf(camera::target.x);
+ float dz = camera::target.z - floorf(camera::target.z);
color(0,0, 1.0f);
begin(Lines);
@@ -233,6 +199,7 @@ void frame(float seconds)
gl::loadidentity();
gl::rotate(90.0f, 0, 1.0, 0);
+ camera::target = game.ship->location;
camera::draw(seconds); // draw the current camera transformation
gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 75a2f6c..1d330ef 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -1,13 +1,13 @@
METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
-libcore_la_SOURCES = application.cc commandbuffer.cc cvar.cc func.cc \
- gameinterface.cc
+libcore_la_SOURCES = application.cc clientstate.cc commandbuffer.cc cvar.cc \
+ entity.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 = application.h commandbuffer.h core.h cvar.h func.h \
+noinst_HEADERS = application.h commandbuffer.h core.h cvar.h entity.h func.h \
gameinterface.h
diff --git a/src/core/application.cc b/src/core/application.cc
index e444b14..5979fc7 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -4,9 +4,11 @@
the terms of the GNU General Public License version 2
*/
-#include "core/core.h"
-#include "filesystem/filesystem.h"
#include "sys/sys.h"
+#include "filesystem/filesystem.h"
+#include "core/entity.h"
+#include "core/application.h"
+#include "core/core.h"
#include <iostream>
#include <errno.h>
@@ -16,7 +18,7 @@ namespace core
{
// --------------- engine functions ------------------------------
-extern "C" void func_print(std::stringstream &args)
+void func_print(std::stringstream &args)
{
char text[MAXCMDSIZE];
if (args.getline(text, MAXCMDSIZE)) {
@@ -27,12 +29,12 @@ extern "C" void func_print(std::stringstream &args)
}
}
-extern "C" void func_help(std::stringstream &args)
+void func_help(std::stringstream &args)
{
con_print << "This is the help function" << std::endl;
}
-extern "C" void func_quit(std::stringstream &args)
+void func_quit(std::stringstream &args)
{
if (Application::instance()) {
Application::instance()->shutdown();
@@ -40,28 +42,32 @@ extern "C" void func_quit(std::stringstream &args)
}
}
-extern "C" void func_connect(std::stringstream &args)
+void func_connect(std::stringstream &args)
{
if (Application::instance())
Application::instance()->connect();
}
-extern "C" void func_disconnect(std::stringstream &args)
+void func_disconnect(std::stringstream &args)
{
if (Application::instance())
Application::instance()->disconnect();
}
-extern "C" void func_list_func(std::stringstream &args)
+void func_list_func(std::stringstream &args)
{
func::list();
}
-extern "C" void func_list_var(std::stringstream &args)
+void func_list_var(std::stringstream &args)
{
cvar::list();
}
+void func_list_ent(std::stringstream &args)
+{
+ entity::list();
+}
// --------------- signal_handler -----------------------------------
extern "C" void signal_handler(int signum)
@@ -133,6 +139,7 @@ void Application::init()
func::add("list_var", func_list_var);
func::add("list_func", func_list_func);
+ func::add("list_ent", func_list_ent);
if (game())
game()->connected = false;
@@ -166,8 +173,10 @@ void Application::connect()
if (game()->connected) {
con_warn << "Connected. Disconnect first." << std::endl;
}
-
+
+ entity::clear();
game()->current_time = 0;
+
if (game()->connected = game()->init()) {
con_print << "Connected." << std::endl;
} else {
@@ -192,6 +201,8 @@ void Application::disconnect()
game()->connected = false;
game()->current_time = 0;
+ entity::clear();
+
con_print << "Disconnected." << std::endl;
}
diff --git a/src/core/application.h b/src/core/application.h
index 985c823..34e0a97 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -33,7 +33,7 @@ public:
/// quit the application
virtual void quit(int status);
- /// connect to the game module
+ /// load the game module
void connect();
/// disconnect from the game module
diff --git a/src/core/clientstate.cc b/src/core/clientstate.cc
new file mode 100644
index 0000000..19daab9
--- /dev/null
+++ b/src/core/clientstate.cc
@@ -0,0 +1,26 @@
+/*
+ core/clientstate.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/clientstate.h"
+
+namespace core
+{
+
+ClientState::ClientState()
+{
+ dirty = false;
+ id = 0;
+ name.clear();
+}
+
+ClientState::~ClientState()
+{
+}
+
+ClientState localstate;
+
+}
+
diff --git a/src/core/clientstate.h b/src/core/clientstate.h
new file mode 100644
index 0000000..ef912ed
--- /dev/null
+++ b/src/core/clientstate.h
@@ -0,0 +1,29 @@
+/*
+ core/clientstate.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_CLIENTSTATE_H__
+#define __INCLUDED_CORE_CLIENTSTATE_H__
+
+#include <string>
+
+namespace core
+{
+
+class ClientState {
+public:
+ ClientState();
+ ~ClientState();
+
+ std::string name;
+ unsigned int id;
+ bool dirty;
+};
+
+extern ClientState localstate;
+
+}
+
+#endif // __INCLUDED_CORE_CLIENTSTATE_H__
diff --git a/src/core/core.h b/src/core/core.h
index 688d4c9..6a2d855 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -7,6 +7,7 @@
#ifndef __INCLUDED_CORE_H__
#define __INCLUDED_CORE_H__
+#include "core/clientstate.h"
#include "core/gameinterface.h"
#include "core/application.h"
diff --git a/src/core/entity.cc b/src/core/entity.cc
new file mode 100644
index 0000000..c8736da
--- /dev/null
+++ b/src/core/entity.cc
@@ -0,0 +1,56 @@
+/*
+ core/entity.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2.
+*/
+
+#include "sys/sys.h"
+#include "core/entity.h"
+#include <iomanip>
+
+namespace core
+{
+
+Entity::Entity(unsigned int entity_type, unsigned int entity_flags)
+{
+ flags = entity_flags;
+ type = entity_type;
+ core::entity::add(this);
+}
+
+Entity::~Entity()
+{
+}
+
+namespace entity
+{
+
+std::vector<Entity*> registry;
+
+void add(Entity *ent)
+{
+ ent->id = (unsigned int) registry.size();
+ registry.push_back(ent);
+}
+
+void clear()
+{
+ std::vector<Entity *>::iterator it;
+ for (it=registry.begin(); it != registry.end(); it++) {
+ delete (*it);
+ (*it) = 0;
+ }
+ registry.clear();
+}
+
+void list()
+{
+ std::vector<Entity *>::iterator it;
+ for (it=registry.begin(); it != registry.end(); it++) {
+ con_print << " id " << std::setw(3) << (*it)->id << " type " << std::setw(2) << (*it)->type << std::endl;
+ }
+ con_print << registry.size() << " registered entities" << std::endl;
+}
+}
+
+}
diff --git a/src/core/entity.h b/src/core/entity.h
new file mode 100644
index 0000000..ef9168b
--- /dev/null
+++ b/src/core/entity.h
@@ -0,0 +1,53 @@
+/*
+ core/entity.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_ENTITY_H__
+#define __INCLUDED_CORE_ENTITY_H__
+
+#include "math/mathlib.h"
+#include <vector>
+
+namespace core
+{
+
+/// The base world entity. All gameworld entities must derive from this class.
+class Entity {
+public:
+ /// create a new entity and add it to the registry
+ Entity(unsigned int entity_type, unsigned int entity_flags=0);
+ virtual ~Entity();
+
+ /// core id of the entity
+ unsigned int id;
+
+ /// location of the entity
+ math::Vector3f location;
+
+ /// flags
+ unsigned int flags;
+
+ /// type
+ unsigned int type;
+};
+
+namespace entity {
+
+ /// the entity registry
+ extern std::vector<Entity*> registry;
+
+ /// add an entity to the registry
+ void add(Entity *ent);
+
+ /// clear the entity registry
+ void clear();
+
+ /// list the entity registry
+ void list();
+}
+
+}
+
+#endif // __INCLUDED_CORE_ENTITY_H__
diff --git a/src/game/Makefile.am b/src/game/Makefile.am
index f86c814..584981a 100644
--- a/src/game/Makefile.am
+++ b/src/game/Makefile.am
@@ -5,4 +5,5 @@ libgame_la_LDFLAGS = -avoid-version
libgame_la_SOURCES = game.cc sector.cc ship.cc shipspecs.cc star.cc
noinst_LTLIBRARIES = libgame.la
-noinst_HEADERS = game.h player.h sector.h ship.h shipspecs.h star.h world.h
+noinst_HEADERS = game.h player.h sector.h shared.h ship.h shipspecs.h star.h \
+ world.h
diff --git a/src/game/game.cc b/src/game/game.cc
index f9c7aa4..f8b8596 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -97,8 +97,10 @@ bool Game::init()
con_print << " " << sectors[n]->label << " " << sectors[n]->name << std::endl;
*/
- star.location = Vector3f(256.0f, 0.0f, 256.0f);
- ship.location = Vector3f(0,0,0);
+ ship = new Ship();
+ star = new Star();
+ star->location = Vector3f(256.0f, 0.0f, 256.0f);
+ ship->location = Vector3f(0,0,0);
return true;
}
@@ -117,7 +119,7 @@ void Game::shutdown()
void Game::frame(float seconds)
{
- ship.update(seconds);
+ ship->update(seconds);
}
}; // namespace game
diff --git a/src/game/game.h b/src/game/game.h
index f9c6667..bceb62d 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -35,10 +35,11 @@ public:
/// sectors in space
std::vector<Sector*> sectors;
+
/// the only ship in the game
- Ship ship;
+ Ship *ship;
/// the only star in the game
- Star star;
+ Star *star;
private:
std::string name;
diff --git a/src/game/shared.h b/src/game/shared.h
new file mode 100644
index 0000000..5c04309
--- /dev/null
+++ b/src/game/shared.h
@@ -0,0 +1,18 @@
+/*
+ game/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_GAME_SHARED_H__
+#define __INCLUDED_GAME_SHARED_H__
+
+namespace game
+{
+ // entity type constants
+ const unsigned int ship_enttype = 1;
+ const unsigned int star_enttype = 2;
+
+}
+
+#endif
diff --git a/src/game/ship.cc b/src/game/ship.cc
index fc18375..9252f1d 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -5,6 +5,7 @@
*/
// project headers
+#include "game/shared.h"
#include "game/ship.h"
#include "math/mathlib.h"
@@ -16,7 +17,7 @@ using math::degrees180f;
namespace game {
-Ship::Ship()
+Ship::Ship() : core::Entity(ship_enttype)
{
speed = 0;
yaw_current = 0;
diff --git a/src/game/ship.h b/src/game/ship.h
index d420f67..f83c41e 100644
--- a/src/game/ship.h
+++ b/src/game/ship.h
@@ -8,11 +8,12 @@
#define __INCLUDED_GAME_SHIP_H__
// project headers
+#include "core/entity.h"
#include "math/vector3f.h"
namespace game {
-class Ship
+class Ship : public core::Entity
{
public:
Ship();
@@ -21,8 +22,6 @@ public:
/// update the ship state
void update(float elapsed);
- /// location of the ship in space
- math::Vector3f location;
/// speed vector in units/second
float speed;
@@ -44,6 +43,7 @@ public:
/// yaw turn speed
float yaw_speed;
+ static const unsigned int type_id=1;
private:
/// current yaw, angle in XZ plane, 0-360
float yaw_current;
diff --git a/src/game/star.cc b/src/game/star.cc
index 924bb96..a8b5e87 100644
--- a/src/game/star.cc
+++ b/src/game/star.cc
@@ -1,11 +1,16 @@
+/*
+ game/star.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2.
+*/
+#include "game/shared.h"
+#include "game/star.h"
-#include "star.h"
namespace game {
-Star::Star() :
- location(0,0,0),
+Star::Star() : core::Entity(star_enttype),
color(1,1,1,1)
{
radius = 48;
diff --git a/src/game/star.h b/src/game/star.h
index 70ce2aa..7a087d0 100644
--- a/src/game/star.h
+++ b/src/game/star.h
@@ -8,6 +8,7 @@
#define __INCLUDED_GAME_STAR_H__
// project headers
+#include "core/entity.h"
#include "math/mathlib.h"
// C++ headers
@@ -16,12 +17,11 @@
namespace game {
/// a star, that shines so bright
-class Star {
+class Star : public core::Entity {
public:
Star();
~Star();
- math::Vector3f location;
math::Color color;
float radius;
diff --git a/src/server/server.cc b/src/server/server.cc
index 78309bc..1c298e8 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -4,10 +4,11 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "core/core.h"
+#include "core/clientstate.h"
#include "server/console.h"
#include "server/server.h"
#include "server/timer.h"
-#include "core/core.h"
#include "game/game.h"
namespace server {
@@ -58,6 +59,7 @@ void Server::init()
con_print << "Initializing server..." << std::endl;
+ core::localstate.name = "Console";
core::Application::init();
console::init();