Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ROADMAP2
-rw-r--r--osirion.kdevelop2
-rw-r--r--osirion.kdevelop.pcsbin302061 -> 323648 bytes
-rw-r--r--osirion.kdevses37
-rw-r--r--src/Makefile.am8
-rw-r--r--src/client/Makefile.am6
-rw-r--r--src/client/camera.cc46
-rw-r--r--src/client/client.cc2
-rw-r--r--src/client/client.h5
-rw-r--r--src/client/draw.cc32
-rw-r--r--src/client/draw.h2
-rw-r--r--src/client/input.cc149
-rw-r--r--src/client/input.h6
-rw-r--r--src/client/view.cc4
-rw-r--r--src/core/Makefile.am4
-rw-r--r--src/core/application.cc18
-rw-r--r--src/core/core.h30
-rw-r--r--src/core/entity.cc30
-rw-r--r--src/core/entity.h91
-rw-r--r--src/core/gameinterface.cc8
-rw-r--r--src/core/gameinterface.h3
-rw-r--r--src/core/player.cc6
-rw-r--r--src/core/player.h13
-rw-r--r--src/game/game.cc50
-rw-r--r--src/game/game.h6
-rw-r--r--src/game/ship.cc55
-rw-r--r--src/game/ship.h31
-rw-r--r--src/math/functions.h2
-rw-r--r--src/osirion.cc10
-rw-r--r--src/osiriond.cc9
-rw-r--r--src/server/Makefile.am5
-rw-r--r--src/server/server.cc4
-rw-r--r--src/server/server.h5
33 files changed, 401 insertions, 280 deletions
diff --git a/ROADMAP b/ROADMAP
index 97a884f..6a3deb8 100644
--- a/ROADMAP
+++ b/ROADMAP
@@ -6,7 +6,9 @@ filesystem::
core::
Cvar (ok)
+ must be possible to mark a Cvar cvar::Game
Func (ok)
+ must be possible to mark a Func func::Game
CommandBuffer (ok)
Entity
seperate client:: and game::
diff --git a/osirion.kdevelop b/osirion.kdevelop
index 58a8bfc..d40c050 100644
--- a/osirion.kdevelop
+++ b/osirion.kdevelop
@@ -21,7 +21,7 @@
</general>
<kdevautoproject>
<general>
- <activetarget>src/client/libclient.la</activetarget>
+ <activetarget>src/core/libcore.la</activetarget>
<useconfiguration>debug</useconfiguration>
</general>
<run>
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs
index 7285ff5..5ce4adb 100644
--- a/osirion.kdevelop.pcs
+++ b/osirion.kdevelop.pcs
Binary files differ
diff --git a/osirion.kdevses b/osirion.kdevses
index c801edd..01b9244 100644
--- a/osirion.kdevses
+++ b/osirion.kdevses
@@ -1,31 +1,34 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE KDevPrjSession>
<KDevPrjSession>
- <DocsAndViews NumberOfDocuments="8" >
- <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/render.cc" >
- <View0 Encoding="" line="22" Type="Source" />
+ <DocsAndViews NumberOfDocuments="9" >
+ <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/draw.cc" >
+ <View0 Encoding="" Type="Source" />
</Doc0>
- <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/tga.h" >
- <View0 Encoding="" line="0" Type="Source" />
+ <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/entity.cc" >
+ <View0 Encoding="" Type="Source" />
</Doc1>
- <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/tga.cc" >
- <View0 Encoding="" line="76" Type="Source" />
+ <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/camera.cc" >
+ <View0 Encoding="" Type="Source" />
</Doc2>
- <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/commandbuffer.cc" >
- <View0 Encoding="" line="76" Type="Source" />
+ <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/view.cc" >
+ <View0 Encoding="" Type="Source" />
</Doc3>
- <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/console.cc" >
- <View0 Encoding="" line="201" Type="Source" />
+ <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/gameinterface.h" >
+ <View0 Encoding="" Type="Source" />
</Doc4>
- <Doc5 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/cvar.h" >
- <View0 Encoding="" line="10" Type="Source" />
+ <Doc5 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/game/game.cc" >
+ <View0 Encoding="" Type="Source" />
</Doc5>
- <Doc6 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/func.h" >
- <View0 Encoding="" line="12" Type="Source" />
+ <Doc6 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/game/game.h" >
+ <View0 Encoding="" Type="Source" />
</Doc6>
- <Doc7 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/commandbuffer.h" >
- <View0 Encoding="" line="29" Type="Source" />
+ <Doc7 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/game/ship.cc" >
+ <View0 Encoding="" Type="Source" />
</Doc7>
+ <Doc8 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/entity.h" >
+ <View0 Encoding="" line="84" Type="Source" />
+ </Doc8>
</DocsAndViews>
<pluginList>
<kdevdebugger>
diff --git a/src/Makefile.am b/src/Makefile.am
index fbadbd7..4fc1732 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,17 +1,19 @@
# set the include path found by configure
AM_CPPFLAGS = $(DEBUG_CFLAGS) $(WARN_CFLAGS) $(all_includes)
INCLUDES = -I$(top_srcdir)/src
-SUBDIRS = math sys filesystem core game server render client
+SUBDIRS = math sys filesystem core server render game client
noinst_HEADERS = config.h
bin_PROGRAMS = osiriond osirion
# dedicated server
osiriond_SOURCES = osiriond.cc
-osiriond_LDADD = $(top_builddir)/src/server/libserver.la
+osiriond_LDADD = $(top_builddir)/src/game/libgame.la \
+ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/server/libserver.la
# client
osirion_SOURCES = osirion.cc
osirion_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS) $(GLUT_CFLAGS)
-osirion_LDADD = $(top_builddir)/src/client/libclient.la
+osirion_LDADD = $(top_builddir)/src/game/libgame.la \
+ $(top_builddir)/src/core/libcore.la $(top_builddir)/src/client/libclient.la
osirion_LDFLAGS = $(GL_LIBS) $(LIBSDL_LIBS)
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 74dc743..bd4aaf1 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -8,6 +8,6 @@ libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
noinst_LTLIBRARIES = libclient.la
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
+libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la \
+ $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la \
+ $(top_builddir)/src/render/librender.la $(top_builddir)/src/sys/libsys.la
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 2def781..85929cc 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -4,10 +4,11 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "math/mathlib.h"
+#include "core/player.h"
#include "client/client.h"
#include "client/camera.h"
#include "render/render.h"
-#include "math/mathlib.h"
using math::degrees360f;
using math::degrees180f;
@@ -78,18 +79,32 @@ void shutdown()
void draw(float elapsed)
{
- // TODO camera needs to get this from selected core entity
+ if (!core::localplayer.controled) {
+ // switch the camera to Overview of the player is not controling anything
+ if (mode != Overview) {
+ mode = Overview;
+ target = math::Vector3f(0,0,0);
+ x_offset = 0;
+ z_offset = 0;
+ distance = 20.0f;
+ }
+ } else {
+ camera::target = core::localplayer.controled->location;
+ }
+
if (mode == Track) {
- yaw_target = game.ship->yaw();
+ yaw_target = core::localplayer.controled->direction;
}
- // adjust yaw
- float d = degrees180f(yaw_current - yaw_target);
- yaw_current = degrees360f( yaw_current - d * elapsed) ;
+ if ((mode == Free) || (mode == Track)) {
+ // adjust yaw
+ float d = degrees180f(yaw_current - yaw_target);
+ yaw_current = degrees360f( yaw_current - d * elapsed) ;
- // adjust pitch target
- d = degrees180f(pitch_current - pitch_target);
- pitch_current = degrees360f( pitch_current - d *elapsed);
+ // adjust pitch target
+ d = degrees180f(pitch_current - pitch_target);
+ pitch_current = degrees360f( pitch_current - d *elapsed);
+ }
switch (mode) {
case Free:
@@ -154,11 +169,20 @@ void key_down()
}
void next_mode() {
+
+ if (!core::localplayer.controled) {
+ mode = Overview;
+ target = math::Vector3f(0,0,0);
+ x_offset = 0;
+ z_offset = 0;
+ distance = 20.0f;
+ }
+
switch(mode) {
case Overview:
// switch camera to Track mode
mode = Track;
- yaw_target = game.ship->yaw();
+ yaw_target = core::localplayer.controled->direction;
yaw_current = yaw_target;
pitch_target = pitch_track;
pitch_current = pitch_target;
@@ -167,7 +191,7 @@ void next_mode() {
case Track:
// switch camera to Free mode
mode = Free;
- yaw_target = game.ship->yaw();
+ yaw_target = core::localplayer.controled->direction;
yaw_current = yaw_target;
pitch_target = pitch_track;
pitch_current = pitch_target;
diff --git a/src/client/client.cc b/src/client/client.cc
index 5243d28..6ae6ba8 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -12,7 +12,6 @@
#include "client/input.h"
#include "client/view.h"
#include "core/core.h"
-#include "game/game.h"
// SDL headers
#include <SDL/SDL.h>
@@ -58,7 +57,6 @@ void func_r_restart(std::stringstream &args)
}
//--- public ------------------------------------------------------
-game::Game game;
void main(int count, char **arguments)
{
diff --git a/src/client/client.h b/src/client/client.h
index 7c0b74d..ee2e7af 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -7,17 +7,12 @@
#ifndef __INCLUDED_CLIENT_H__
#define __INCLUDED_CLIENT_H__
-#include "game/game.h"
-
/// client part of the engine
namespace client {
/// the client main loop
void main(int count, char **arguments);
-/// global client Game instance
-extern game::Game game;
-
} // namespace client
#endif // __INCLUDED_CLIENT_H__
diff --git a/src/client/draw.cc b/src/client/draw.cc
index 8d83ba8..021cf3a 100644
--- a/src/client/draw.cc
+++ b/src/client/draw.cc
@@ -1,10 +1,10 @@
/*
- draw.cc
+ client/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
*/
-// projet headers
+#include "core/player.h"
#include "render/render.h"
#include "render/sphere.h"
#include "render/box.h"
@@ -89,13 +89,16 @@ math::Vector3f v6(-1.0f, 1.0f, 1.0f);
math::Vector3f v7(-1.0f, -1.0f, 1.0f);
float angle = 0;
-void draw_ship(game::Ship *ship, float elapsed)
+void draw_ship(core::EntityControlable *entity)
{
using math::Vector3f;
using math::Color;
using namespace render;
- gl::rotate(ship->yaw(), 0.0f, 1.0f, 0.0f );
+ gl::push();
+ gl::translate(entity->location);
+ gl::scale(0.2f, 0.2f, 0.2f);
+ gl::rotate(entity->direction, 0.0f, 1.0f, 0.0f );
Vector3f tl(0.25, 0.125, 0.125);
Vector3f br(-0.25, -0.125, -0.125);
@@ -124,14 +127,14 @@ void draw_ship(game::Ship *ship, float elapsed)
cockpit.bottomcolor = engine1.bottomcolor;
cockpit.draw();
- if(ship->thrust() > 0 ) {
+ if(entity->target_thrust > 0 ) {
gl::color(1.0f,0 ,0 );
gl::begin(gl::Lines);
gl::vertex(-0.5f, 0, 0.185);
- gl::vertex(-0.5f-0.25f*ship->thrust(), 0, 0.185);
+ gl::vertex(-0.5f-0.25f*entity->target_thrust, 0, 0.185);
gl::vertex(-0.5f, 0, -0.185f);
- gl::vertex(-0.5f-0.25f*ship->thrust(), 0, -0.185f);
+ gl::vertex(-0.5f-0.25f*entity->target_thrust, 0, -0.185f);
gl::end();
}
@@ -156,6 +159,8 @@ void draw_ship(game::Ship *ship, float elapsed)
gl::vertex(v7);
gl::vertex(v4);
gl::end();
+
+ gl::pop();
}
void draw_spacegrid()
@@ -192,10 +197,10 @@ void draw_spacegrid()
end();
}
-void draw_world(float elapsed)
+void draw_world(float seconds)
{
// used for animations
- angle += 180.0f * elapsed;
+ angle += 180.0f * seconds;
if( angle > 360.0f ) {
angle -= 360.0f;
}
@@ -208,18 +213,13 @@ void draw_world(float elapsed)
case core::entity::Default:
draw_entity_default((*it));
break;
+ case core::entity::Controlable:
+ draw_ship(static_cast<core::EntityControlable *>(*it));
default:
break;
}
}
- // 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 background grid
draw_spacegrid();
}
diff --git a/src/client/draw.h b/src/client/draw.h
index a0e65eb..b6b7b31 100644
--- a/src/client/draw.h
+++ b/src/client/draw.h
@@ -4,8 +4,6 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "game/game.h"
-
namespace client
{
diff --git a/src/client/input.cc b/src/client/input.cc
index d3b2900..17c52bb 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -1,10 +1,10 @@
/*
client/input.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
+ 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 "core/core.h"
#include "client/client.h"
#include "client/input.h"
#include "client/console.h"
@@ -13,12 +13,15 @@
#include "SDL/SDL.h"
-namespace client
+namespace client
{
-namespace input
+namespace input
{
+// local offset to make turns
+float turn_offset;
+
void init()
{
con_print << "Initializing input..." << std::endl;
@@ -33,82 +36,90 @@ void shutdown()
// handle key release for the game world
void keyreleased(const SDL_keysym &keysym)
{
- switch( keysym.sym) {
- case SDLK_SPACE:
- camera::next_mode();
- break;
- default:
- break;
+ switch (keysym.sym) {
+ case SDLK_SPACE:
+ 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::key_left();
- break;
- case SDLK_RIGHT:
- camera::key_right();
- break;
- case SDLK_UP:
- camera::key_up();
- break;
- case SDLK_DOWN:
- camera::key_down();
- break;
- case SDLK_KP_PLUS:
- // TODO set core entity params
- 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);
- break;
- case SDLK_KP4:
- // TODO set core entity params
- 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);
- break;
- default:
- break;
+ switch (keysym.sym) {
+ case SDLK_LEFT:
+ camera::key_left();
+ break;
+ case SDLK_RIGHT:
+ camera::key_right();
+ break;
+ case SDLK_UP:
+ camera::key_up();
+ break;
+ case SDLK_DOWN:
+ camera::key_down();
+ break;
+ case SDLK_KP_PLUS:
+ // TODO set core entity params
+ core::localplayer.controled->target_thrust += 0.08f;
+ break;
+ case SDLK_KP_MINUS:
+ // TODO set core entity params
+ core::localplayer.controled->target_thrust -= 0.1f;
+ break;
+ case SDLK_KP4:
+ // TODO set core entity params
+ turn_offset += 5;
+ if (turn_offset > 90)
+ turn_offset = 90;
+ break;
+ case SDLK_KP6:
+ // TODO set core entity params
+ turn_offset -= 5;
+ if (turn_offset < -90)
+ turn_offset = -90;
+ break;
+ default:
+ break;
}
-
+
}
void frame(float seconds)
{
- SDL_Event event;
-
- 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 == '`' || event.key.keysym.sym == '~') {
- console::toggle();
- } else if (console::visible()) {
- // send key events to the console
- console::keypressed(event.key.keysym );
- } else if (core::connected()) {
- // send key events to the game world
- keypressed(event.key.keysym );
+ SDL_Event event;
+
+ while (SDL_PollEvent(&event)) {
+
+ switch (event.type) {
+ case SDL_KEYUP:
+ if (!console::visible() && core::connected() && core::localplayer.controled)
+ // send key events to the game world
+ keyreleased(event.key.keysym);
+ break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') {
+ console::toggle();
+ } else if (console::visible()) {
+ // send key events to the console
+ console::keypressed(event.key.keysym);
+ } else if (core::connected() && core::localplayer.controled) {
+ // send key events to the game world
+ keypressed(event.key.keysym);
+ }
+ break;
+ case SDL_QUIT:
+ core::application()->shutdown();
+ break;
}
- break;
- case SDL_QUIT:
- core::application()->shutdown();
- break;
- }
-
- }
-
+
+ }
+
+ if (!console::visible() && core::connected() && core::localplayer.controled) {
+ core::localplayer.controled->target_direction = math::degrees360f(core::localplayer.controled->direction+turn_offset);
+ }
}
} // namespace input
diff --git a/src/client/input.h b/src/client/input.h
index 8ab6c7d..daca0d6 100644
--- a/src/client/input.h
+++ b/src/client/input.h
@@ -7,9 +7,11 @@
#ifndef __INCLUDED_cLIENT_INPUT_H__
#define __INCLUDED_cLIENT_INPUT_H__
-namespace client {
+namespace client
+{
-namespace input {
+namespace input
+{
/// initialize the input subsystem
void init();
diff --git a/src/client/view.cc b/src/client/view.cc
index b6ef28a..5c54587 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -11,9 +11,8 @@
#include "client/draw.h"
#include "render/render.h"
#include "core/core.h"
-#include "game/game.h"
-#include "sys/sys.h"
#include "math/mathlib.h"
+#include "sys/sys.h"
#include <iostream>
#include <string>
@@ -152,7 +151,6 @@ 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 ced2ce5..bf98501 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -1,8 +1,8 @@
METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
-libcore_la_SOURCES = application.cc commandbuffer.cc cvar.cc entity.cc func.cc \
- gameinterface.cc player.cc
+libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc entity.cc \
+ func.cc gameinterface.cc player.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
diff --git a/src/core/application.cc b/src/core/application.cc
index 36d1c5a..c9239cf 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -4,15 +4,20 @@
the terms of the GNU General Public License version 2
*/
+#include <errno.h>
+#include <signal.h>
+
+#include <iostream>
+#include <vector>
+#include <sstream>
+
+#include "math/mathlib.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>
-#include <signal.h>
+#include "core/entity.h"
+#include "core/func.h"
namespace core
{
@@ -211,6 +216,8 @@ void Application::frame(float seconds)
current_time += seconds;
if (game() && game()->connected) {
+ entity::frame(seconds);
+
game()->current_time += seconds;
game()->frame(seconds);
}
@@ -220,3 +227,4 @@ void Application::frame(float seconds)
}
}
+
diff --git a/src/core/core.h b/src/core/core.h
index 0e23386..a3c5f0d 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -7,41 +7,31 @@
#ifndef __INCLUDED_CORE_H__
#define __INCLUDED_CORE_H__
+#include "core/entity.h"
#include "core/player.h"
#include "core/gameinterface.h"
#include "core/application.h"
+#include "core/commandbuffer.h"
+#include "core/cvar.h"
+#include "core/func.h"
/// core contains the basic functionality of the engine
namespace core
{
+
/// pointer to the current GameInterface
-inline GameInterface *game()
-{
- return GameInterface::instance();
-}
+GameInterface *game();
/// pointer to the current ApplicationInterface
-inline Application *application()
-{
- return Application::instance();
-}
+Application *application();
/// true if the core is connected to a game module
-inline bool connected()
-{
- return (GameInterface::instance() && GameInterface::instance()->connected);
-}
+bool connected();
/// return the time the core has been running, in seconds
-inline float time()
-{
- return Application::instance()->current_time;
-}
-};
+float time();
-#include "core/commandbuffer.h"
-#include "core/cvar.h"
-#include "core/func.h"
+}
#endif // __INCLUDED_CORE_H__
diff --git a/src/core/entity.cc b/src/core/entity.cc
index b0808fb..6115e71 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -6,6 +6,7 @@
#include "sys/sys.h"
#include "core/entity.h"
+
#include <iomanip>
namespace core
@@ -24,6 +25,7 @@ Entity::Entity(unsigned int entity_flags)
core::entity::add(this);
type = 0;
+ direction = 0;
}
Entity::~Entity()
@@ -31,19 +33,28 @@ Entity::~Entity()
// --- EntityDynamic ------------------------------------------
-EntityDynamic::EntityDynamic(unsigned int entity_flags) :
- Entity(entity_flags),
- speed(0,0,0)
+EntityDynamic::EntityDynamic(unsigned int entity_flags) :
+ Entity(entity_flags)
{
+ speed = 0.0f;
+}
+EntityDynamic::~EntityDynamic()
+{
}
// --- EntityControlable ------------------------------------------
-EntityControlable::EntityControlable(unsigned int entity_flags) :
+EntityControlable::EntityControlable(unsigned int entity_flags) :
EntityDynamic(entity_flags)
{
owner = 0;
+ target_direction = 0.0f;
+ target_thrust = 0.0f;
+}
+
+EntityControlable::~EntityControlable()
+{
}
// --- namespace entity -------------------------------------------
@@ -97,6 +108,17 @@ void list()
}
con_print << registry.size() << " registered entities" << std::endl;
}
+
+void frame(float seconds)
+{
+ std::vector<Entity *>::iterator it;
+ for (it=registry.begin(); it != registry.end(); it++) {
+ if ((*it)->core_type() == entity::Controlable) {
+ static_cast<EntityControlable *>(*it)->frame(seconds);
+ }
+ }
+}
+
}
}
diff --git a/src/core/entity.h b/src/core/entity.h
index 62b8a39..6ff3be1 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -7,9 +7,15 @@
#ifndef __INCLUDED_CORE_ENTITY_H__
#define __INCLUDED_CORE_ENTITY_H__
+namespace core
+{
+class EntityControlable;
+}
+
#include "core/core.h"
#include "core/player.h"
#include "math/mathlib.h"
+
#include <vector>
namespace core
@@ -24,7 +30,7 @@ enum Flags {Static=1, Solid=2};
/// Entity type constants
enum Type {Default = 0, Dynamic = 1, Controlable = 2};
-/// Entity shaoe constants
+/// Entity shape constants
enum Shape {Diamond=0, Sphere=1, Cube=2};
}
@@ -37,62 +43,103 @@ public:
Entity(unsigned int entity_flags = 0);
virtual ~Entity();
- /// core type of this entity
+ /**
+ * @brief core type id
+ */
virtual inline unsigned int core_type() { return entity::Default; }
- /// core shape
+ /// unique instance identifier, automaticly set
+ unsigned int id;
+
+ /// core shape id
entity::Shape core_shape;
- /// core color
+ /// core color id
math::Color core_color;
- /// core radius
+ /// core radius, in game units
float core_radius;
/// label
std::string label;
- /// custom game type of this entity
+ /// custom game type id of this entity
unsigned int type;
- /// id of the entity
- unsigned int id;
-
/// flags
unsigned int flags;
- /* updateable */
+ /* updateable by game */
/// location of the entity
math::Vector3f location;
+
+ /**
+ * @brief direction the entity is facing, in degrees
+ * A direction of 0 degrees means the entity is 'looking'
+ * along the positive X-axis.
+ */
+ float direction;
};
-/// an entity that can move around in the game world
+/**
+ * @brief an entity that can move around in the game world
+ */
class EntityDynamic : public Entity
{
public:
EntityDynamic(unsigned int entity_flags = 0);
+ virtual ~EntityDynamic();
- /// core type of this entity
+ /**
+ * @brief core type id
+ */
virtual inline unsigned int core_type() { return entity::Dynamic; }
- /* updateable */
+ /* updateable by game */
- /// speed vector, in game units / second
- math::Vector3f speed;
+ /**
+ * @brief current speed of the entity in game units per second
+ */
+ float speed;
};
-/// an entity that can be controlled by a player
+/**
+ * @brief an entity that can be controlled by a player
+ */
class EntityControlable : public EntityDynamic
{
public:
EntityControlable(unsigned int entity_flags = 0);
+ virtual ~EntityControlable();
- /// core type of this entity
+ /**
+ * @brief core type id
+ */
virtual inline unsigned int core_type() { return entity::Controlable; }
- /// owner of this controllable entity
+ /**
+ * @brief owner of this controllable entity
+ */
Player *owner;
+
+ /* updatable by client */
+
+ /**
+ * @brief the direction the client wants to travel the entity to
+ * @see direction
+ */
+ float target_direction;
+
+ /**
+ * @brief engine thrust as set by the client, 0.0f - 1.0f
+ */
+ float target_thrust;
+
+ /**
+ * @brief runs one game frame for the entity, to be implemented by game
+ */
+ virtual void frame(float seconds) = 0;
};
@@ -105,13 +152,21 @@ extern std::vector<Entity*> registry;
/// add an entity to the registry
void add(Entity *ent);
+/// remove one entity from the registry
+void remove(unsigned int entity_id);
+
/// clear the entity registry
void clear();
/// list the entity registry
void list();
+
+/// run a game frame on each entity in the registry
+void frame(float seconds);
+
}
}
#endif // __INCLUDED_CORE_ENTITY_H__
+
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 26e05da..ebca24b 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -4,11 +4,13 @@
the terms of the GNU General Public License version 2
*/
-#include "core/gameinterface.h"
-
+#include <stdlib.h>
#include <iostream>
-#include <stdlib.h>
+class GameInterface;
+
+#include "core/gameinterface.h"
+#include "core/player.h"
namespace core
{
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index b7df479..3e2a5f7 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -37,6 +37,9 @@ public:
/// a player joins the game
virtual void event_join(Player *player) = 0;
+ /// a player leaves the game
+ virtual void event_leave(Player *player) = 0;
+
/// a pointer to the current game instance
static GameInterface * instance();
diff --git a/src/core/player.cc b/src/core/player.cc
index 5eae8ec..1734d9b 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -9,18 +9,20 @@
namespace core
{
+Player localplayer;
+
Player::Player()
{
id = 0;
name.clear();
dirty = false;
+
+ controled=0;
}
Player::~Player()
{
}
-Player localplayer;
-
}
diff --git a/src/core/player.h b/src/core/player.h
index e5ff396..1f63d63 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -1,5 +1,5 @@
/*
- core/clientstate.h
+ core/player.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2.
*/
@@ -7,9 +7,15 @@
#ifndef __INCLUDED_CORE_PLAYER_H__
#define __INCLUDED_CORE_PLAYER_H__
-#include "core/core.h"
+namespace core
+{
+class Player;
+}
+
+#include "core/entity.h"
#include <string>
+
namespace core
{
@@ -27,6 +33,9 @@ public:
/// dirty state
bool dirty;
+
+ /// the entity the Player is currently controling
+ EntityControlable *controled;
};
extern Player localplayer;
diff --git a/src/game/game.cc b/src/game/game.cc
index 51bb565..25f8926 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -4,20 +4,28 @@
the terms of the GNU General Public License version 2
*/
-// project headers
+#include <vector>
+
#include "game/game.h"
#include "game/sector.h"
#include "game/ship.h"
#include "game/star.h"
-#include "filesystem/filesystem.h"
+#include "core/entity.h"
#include "sys/sys.h"
-
-// C++ headers
-#include <vector>
+#include "math/mathlib.h"
+#include "filesystem/filesystem.h"
namespace game
{
+Game::Game()
+{
+}
+
+Game::~Game()
+{
+}
+
bool Game::init()
{
using math::Vector3f;
@@ -102,11 +110,6 @@ bool Game::init()
star->location = Vector3f(256.0f, 0.0f, 256.0f);
star->label = "star: Sabishi Hoshi";
-
- ship = new Ship();
- ship->location = Vector3f(0,0,0);
- ship->label = "ship: Micron Vector";
-
core::Entity *cube = new core::Entity(core::entity::Solid & core::entity::Static);
cube->core_shape = core::entity::Cube;
cube->core_color = Color(0.0f, 0.8f, 0.0f);
@@ -151,7 +154,7 @@ void Game::shutdown()
void Game::frame(float seconds)
{
- ship->update(seconds);
+
}
void Game::event_join(core::Player *player)
@@ -160,8 +163,27 @@ void Game::event_join(core::Player *player)
return;
ship = new Ship();
- ship->location = Vector3f(0,0,0);
- ship->label = "ship: Micron Vector";
+ ship->location = math::Vector3f(0,0,0);
+ ship->label = "ship: <"+player->name+"> Micron Vector";
+ ship->owner = player;
+
+ player->controled = ship;
+
+ con_print << player->name << " joins" << std::endl;
}
-}; // namespace game
+void Game::event_leave(core::Player *player)
+{
+ if (!player)
+ return;
+
+ con_print << player->name << " leaves" << std::endl;
+
+ if (player->controled) {
+ // player only has one ship for now
+ core::entity::remove(player->controled->id);
+ }
+}
+
+} // namespace game
+
diff --git a/src/game/game.h b/src/game/game.h
index abe0c0d..9c993fe 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -26,6 +26,9 @@ namespace game
class Game : public core::GameInterface {
public:
+ Game();
+ ~Game();
+
/// initialize the game
bool init();
/// shutdown the game
@@ -36,6 +39,9 @@ public:
/// a player joins the game
void event_join(core::Player *player);
+ /// a player leaves the game
+ void event_leave(core::Player *player);
+
/// sectors in space
std::vector<Sector*> sectors;
diff --git a/src/game/ship.cc b/src/game/ship.cc
index d6333cd..baa97f1 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -17,62 +17,45 @@ using math::degrees180f;
namespace game {
-Ship::Ship() : core::Entity(0)
+Ship::Ship() : core::EntityControlable(0)
{
type = ship_enttype;
- speed = 0;
- yaw_current = 0;
- yaw_target = yaw_current;
-
- thrust_current = 0;
-
// ship specs
acceleration = 1.5f;
- speed_max = 4.0f;
- yaw_speed = 4.0f;
+ max_speed = 4.0f;
+ turn_speed = 0.5f;
}
Ship::~Ship()
{
}
-void Ship::set_yaw(float y)
+void Ship::frame(float seconds)
{
- yaw_target = degrees360f(y);
-}
-void Ship::set_thrust(float t)
-{
- if (t < 0)
- thrust_current = 0;
- else if (t > 1)
- thrust_current = 1;
- else
- thrust_current = t;
-}
+ if (target_thrust < 0) target_thrust = 0.0f;
+ else if(target_thrust > 1) target_thrust = 1.0f;
-void Ship::update(float elapsed)
-{
- // update yaw
- float yaw_offset = degrees180f(yaw_target - yaw_current);
- float d = yaw_speed * elapsed * yaw_offset;
- yaw_current = degrees360f(yaw_current + d);
+ // update direction
+ float direction_offset = degrees180f(target_direction - direction);
+ float d = turn_speed * seconds * direction_offset;
+ direction = degrees360f(direction + d);
- // update thrust
- if (speed < thrust_current * speed_max) {
- speed += acceleration * elapsed;
- if (speed > thrust_current * speed_max) {
- speed = thrust_current * speed_max;
+ // update speed
+ if (speed < target_thrust * max_speed) {
+ speed += acceleration * seconds;
+ if (speed > target_thrust * max_speed) {
+ speed = target_thrust * max_speed;
}
- } else if(speed > thrust_current * speed_max) {
- speed -= acceleration * elapsed;
+ } else if(speed > target_thrust * max_speed) {
+ speed -= acceleration * seconds;
if (speed < 0) speed = 0;
}
// location TODO avoid sin/cos calculations
- location.x += cosf(yaw_current * M_PI / 180) * speed * elapsed;
- location.z -= sinf(yaw_current * M_PI / 180) * speed * elapsed;
+ location.x += cosf(direction * M_PI / 180) * speed * seconds;
+ location.z -= sinf(direction * M_PI / 180) * speed * seconds;
}
} // namespace game
diff --git a/src/game/ship.h b/src/game/ship.h
index e919f38..d108223 100644
--- a/src/game/ship.h
+++ b/src/game/ship.h
@@ -13,43 +13,22 @@
namespace game {
-class Ship : public core::Entity
+class Ship : public core::EntityControlable
{
public:
Ship();
~Ship();
/// update the ship state
- void update(float elapsed);
-
- /// speed vector in units/second
- float speed;
-
- /// return the current yaw angle
- inline float yaw() const { return yaw_current; }
- /// set the target yaw angle
- void set_yaw(float y);
-
- /// return the current thruster power
- inline float thrust() const { return thrust_current; }
- /// set thruster power
- void set_thrust(float t);
+ void frame(float seconds);
/* -- Ship SPECS --*/
/// acceleration
float acceleration;
/// maximum speed
- float speed_max;
- /// yaw turn speed
- float yaw_speed;
-private:
- /// current yaw, angle in XZ plane, 0-360
- float yaw_current;
- /// target yaw angle, angle in XYplane, 0-360
- float yaw_target;
-
- /// current thruster power in % [0-1]
- float thrust_current;
+ float max_speed;
+ /// turn speed in rotations per second
+ float turn_speed;
};
} // namespace game
diff --git a/src/math/functions.h b/src/math/functions.h
index df86124..d9f78df 100644
--- a/src/math/functions.h
+++ b/src/math/functions.h
@@ -8,6 +8,8 @@
#define __INCLUDED_MATH_FUNCTIONS_H__
// C++ headers
+#include <math.h>
+
#include <cstdlib>
#include <cmath>
diff --git a/src/osirion.cc b/src/osirion.cc
index 058fe25..696104f 100644
--- a/src/osirion.cc
+++ b/src/osirion.cc
@@ -1,13 +1,21 @@
-/* client/main.cc
+/*
+ osirion.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"
+#include "game/game.h"
int main(int count, char **arguments)
{
+ // preload the game object
+ game::Game *game = new game::Game();
+
client::main(count, arguments);
+
+ game = 0; // prevents variable not used warning
+
return 0;
}
diff --git a/src/osiriond.cc b/src/osiriond.cc
index ea08f47..55bbbf5 100644
--- a/src/osiriond.cc
+++ b/src/osiriond.cc
@@ -1,13 +1,20 @@
/*
- server/main.cc
+ osiriond.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"
+#include "game/game.h"
int main(int count, char **arguments)
{
+ // preload the game object
+ game::Game *game = new game::Game();
+
server::main(count, arguments);
+
+ game = 0; // prevents variable not used warning
+
return 0;
}
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index 0b9ba48..0e7bde1 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -4,6 +4,5 @@ noinst_HEADERS = console.h server.h timer.h
noinst_LTLIBRARIES = libserver.la
INCLUDES = -I$(top_srcdir)/src
libserver_la_LDFLAGS = -avoid-version -no-undefined
-libserver_la_LIBADD = $(top_builddir)/src/math/libmath.la \
- $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la \
- $(top_builddir)/src/core/libcore.la $(top_builddir)/src/game/libgame.la
+libserver_la_LIBADD = $(top_builddir)/src/sys/libsys.la \
+ $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/core/libcore.la
diff --git a/src/server/server.cc b/src/server/server.cc
index b065eea..4f7d1e9 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -52,10 +52,6 @@ void main(int count, char **arguments)
void Server::init()
{
- // FIXME core should be able to load game.so -
- // force initialization of the game object
- server::game = new game::Game();
-
con_print << "Initializing server..." << std::endl;
core::Application::init();
diff --git a/src/server/server.h b/src/server/server.h
index 29656bd..4691e91 100644
--- a/src/server/server.h
+++ b/src/server/server.h
@@ -7,17 +7,12 @@
#ifndef __INCLUDED_SERVER_H__
#define __INCLUDED_SERVER_H__
-#include "game/game.h"
-
/// contains classes and functions to run a dedicated server
namespace server {
/// the server main loop
void main(int count, char **arguments);
-/// global Game instance
-extern game::Game *game;
-
} // namespace server
#endif // __INCLUDED_SERVER_H__