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/camera.cc58
-rw-r--r--src/client/draw.cc21
-rw-r--r--src/core/entity.cc25
-rw-r--r--src/core/entity.h45
-rw-r--r--src/core/gameinterface.h7
-rw-r--r--src/game/Makefile.am3
-rw-r--r--src/game/game.cc28
-rw-r--r--src/game/game.h10
-rw-r--r--src/game/ship.cc6
-rw-r--r--src/game/star.cc10
10 files changed, 134 insertions, 79 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 45cd65a..2def781 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -40,18 +40,26 @@ Mode mode;
float yaw_current;
// current pitch, angle in XY, positive is looking up
float pitch_current;
-// default pitch in mode::Track
-float pitch_track;
+
// default pitch in mode::Overview
float pitch_overview;
-// default offset increment
-float offset_inc;
+
+
+// current x offset
+float x_offset;
+// current z offset
+float z_offset;
+
+// default pitch in mode::Track
+const float pitch_track = -15.0f;
+// default rotate offset increase/decrease
+float rotate_offset_inc;
+// default translate offset increase/decrease
+const float translate_offset_inc = 0.1;
void init()
{
- pitch_overview = -60.0f;
- pitch_track = -15.0f;
- offset_inc = 5.0f;
+ rotate_offset_inc = 5.0f;
yaw_current = 0;
yaw_target = 0;
@@ -96,10 +104,10 @@ void draw(float elapsed)
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);
+ case Overview:
+ gl::rotate(75.0f, 0.0f, 0.0f, 1.0f);
+ gl::translate(0.0f, -distance, 0.0f);
+ //gl::translate(x_offset, 0.0f, z_offset);
gl::translate(-1*target);
break;
default:
@@ -109,31 +117,39 @@ void draw(float elapsed)
void key_right()
{
- if (mode == Free || mode == Overview) {
- yaw_target = degrees360f( yaw_target + offset_inc);
+ if (mode == Free) {
+ yaw_target = degrees360f( yaw_target + rotate_offset_inc);
+ } else if (mode == Overview) {
+ z_offset += translate_offset_inc;
}
}
void key_left()
{
- if (mode == Free || mode == Overview) {
- yaw_target = degrees360f( yaw_target - offset_inc);
+ if (mode == Free) {
+ yaw_target = degrees360f( yaw_target - rotate_offset_inc);
+ } else if (mode == Overview) {
+ z_offset -= translate_offset_inc;
}
}
void key_up()
{
if (mode == Free) {
- pitch_target = pitch_target - offset_inc;
+ pitch_target = pitch_target - rotate_offset_inc;
if (pitch_target < -90.0f) pitch_target = -90.0f;
+ } else if (mode == Overview) {
+ x_offset += translate_offset_inc;
}
}
void key_down()
{
if (mode == Free) {
- pitch_target = pitch_target + offset_inc;
+ pitch_target = pitch_target + rotate_offset_inc;
if (pitch_target > 90.0f) pitch_target = 90.0f;
+ } else if (mode == Overview) {
+ x_offset -= translate_offset_inc;
}
}
@@ -160,11 +176,9 @@ void next_mode() {
case Free:
// switch camera to Overview mode
mode = Overview;
- yaw_target = 0;
- yaw_current = 0;
- pitch_target = pitch_overview;
- pitch_current = pitch_target;
- distance = 10.0f;
+ x_offset = 0;
+ z_offset = 0;
+ distance = 20.0f;
default:
break;
}
diff --git a/src/client/draw.cc b/src/client/draw.cc
index 1e3e5b0..8d83ba8 100644
--- a/src/client/draw.cc
+++ b/src/client/draw.cc
@@ -20,16 +20,16 @@ render::Box cube(math::Vector3f(0.5f, 0.5f, 0.5f), math::Vector3f(-0.5f, -0.5f,
void draw_entity_sphere(core::Entity *entity)
{
- render::gl::color(entity->base_color);
- sphere.radius = entity->base_radius;
+ render::gl::color(entity->core_color);
+ sphere.radius = entity->core_radius;
sphere.draw();
}
void draw_entity_cube(core::Entity *entity)
{
- cube.topcolor = entity->base_color;
- cube.bottomcolor = entity->base_color * 0.7f;
- cube.radius = entity->base_radius;
+ cube.topcolor = entity->core_color;
+ cube.bottomcolor = entity->core_color * 0.7f;
+ cube.radius = entity->core_radius;
cube.draw();
}
@@ -37,11 +37,11 @@ void draw_entity_cube(core::Entity *entity)
void draw_entity_diamond(core::Entity *entity)
{
using namespace render;
- float r = entity->base_radius;
+ float r = entity->core_radius;
gl::begin(gl::Lines);
gl::color(1.0f, 0.0f, 0.0f);
gl::vertex(r,0.0f,0.0f);
- gl::color(entity->base_color);
+ gl::color(entity->core_color);
gl::vertex(-r,0.0f,0.0f);
gl::vertex(0.0f,0.0f,r/2);
@@ -52,13 +52,13 @@ void draw_entity_diamond(core::Entity *entity)
gl::end();
}
-// draw an entity of type core::entity::Default
+// draw an entity of core_type core::entity::Default
void draw_entity_default(core::Entity *entity)
{
render::gl::push();
render::gl::translate(entity->location);
- switch(entity->base_shape) {
+ switch(entity->core_shape) {
case core::entity::Sphere:
draw_entity_sphere(entity);
break;
@@ -194,6 +194,7 @@ void draw_spacegrid()
void draw_world(float elapsed)
{
+ // used for animations
angle += 180.0f * elapsed;
if( angle > 360.0f ) {
angle -= 360.0f;
@@ -203,7 +204,7 @@ void draw_world(float elapsed)
using namespace render;
std::vector<core::Entity *>::iterator it;
for (it=core::entity::registry.begin(); it != core::entity::registry.end(); it++) {
- switch ( (*it)->type) {
+ switch ( (*it)->core_type()) {
case core::entity::Default:
draw_entity_default((*it));
break;
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 3854fd0..b0808fb 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -13,16 +13,16 @@ namespace core
// --- Entity -----------------------------------------------------
-Entity::Entity(unsigned int entity_flags, unsigned int entity_type)
+Entity::Entity(unsigned int entity_flags)
{
flags = entity_flags;
- type = entity_type;
-
- base_shape = entity::Diamond;
- base_color = math::Color(1.0f, 1.0f, 1.0f);
- base_radius = 1.0f;
+
+ core_shape = entity::Diamond;
+ core_color = math::Color(1.0f, 1.0f, 1.0f);
+ core_radius = 1.0f;
core::entity::add(this);
+ type = 0;
}
@@ -31,8 +31,8 @@ Entity::~Entity()
// --- EntityDynamic ------------------------------------------
-EntityDynamic::EntityDynamic(unsigned int entity_flags, unsigned int entity_type) :
- Entity(entity_type, entity_flags),
+EntityDynamic::EntityDynamic(unsigned int entity_flags) :
+ Entity(entity_flags),
speed(0,0,0)
{
@@ -40,8 +40,8 @@ EntityDynamic::EntityDynamic(unsigned int entity_flags, unsigned int entity_type
// --- EntityControlable ------------------------------------------
-EntityControlable::EntityControlable(unsigned int entity_flags, unsigned int entity_type) :
- EntityDynamic(entity_type, entity_flags)
+EntityControlable::EntityControlable(unsigned int entity_flags) :
+ EntityDynamic(entity_flags)
{
owner = 0;
}
@@ -90,8 +90,9 @@ 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(3) << (*it)->type
+ con_print << " id " << std::setw(4) << (*it)->id
+ << " type " << std::setw(4) << (*it)->core_type()
+ << ":" << std::setw(4) << (*it)->type
<< " " << (*it)->label << std::endl;
}
con_print << registry.size() << " registered entities" << std::endl;
diff --git a/src/core/entity.h b/src/core/entity.h
index 518166b..62b8a39 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -34,41 +34,47 @@ class Entity
{
public:
/// create a new entity and add it to the registry
- Entity(unsigned int entity_flags = 0, unsigned int entity_type = entity::Default);
+ Entity(unsigned int entity_flags = 0);
virtual ~Entity();
- /// id of the entity
- unsigned int id;
+ /// core type of this entity
+ virtual inline unsigned int core_type() { return entity::Default; }
- /// flags
- unsigned int flags;
-
- /// type
- unsigned int type;
-
- /// base shape
- entity::Shape base_shape;
+ /// core shape
+ entity::Shape core_shape;
- /// base color
- math::Color base_color;
+ /// core color
+ math::Color core_color;
- /// base radius
- float base_radius;
+ /// core radius
+ float core_radius;
/// label
std::string label;
+ /// custom game type of this entity
+ unsigned int type;
+
+ /// id of the entity
+ unsigned int id;
+
+ /// flags
+ unsigned int flags;
+
/* updateable */
/// location of the entity
math::Vector3f location;
};
-/// an entity that can move
+/// an entity that can move around in the game world
class EntityDynamic : public Entity
{
public:
- EntityDynamic(unsigned int entity_flags = 0, unsigned int entity_type=entity::Dynamic);
+ EntityDynamic(unsigned int entity_flags = 0);
+
+ /// core type of this entity
+ virtual inline unsigned int core_type() { return entity::Dynamic; }
/* updateable */
@@ -80,7 +86,10 @@ public:
class EntityControlable : public EntityDynamic
{
public:
- EntityControlable(unsigned int entity_flags = 0, unsigned int entity_type=entity::Controlable);
+ EntityControlable(unsigned int entity_flags = 0);
+
+ /// core type of this entity
+ virtual inline unsigned int core_type() { return entity::Controlable; }
/// owner of this controllable entity
Player *owner;
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index 2e61ffb..b7df479 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -7,6 +7,8 @@
#ifndef __INCLUDED_CORE_GAMEINTERFACE_H__
#define __INCLUDED_CORE_GAMEINTERFACE_H__
+#include "core/player.h"
+
namespace core
{
@@ -26,12 +28,15 @@ public:
/// shutdown the game
virtual void shutdown() = 0;
-
+
/// run one frame of the game
/** @param sec time since the previous frame, in seconds
*/
virtual void frame(float seconds) = 0;
+ /// a player joins the game
+ virtual void event_join(Player *player) = 0;
+
/// a pointer to the current game instance
static GameInterface * instance();
diff --git a/src/game/Makefile.am b/src/game/Makefile.am
index 584981a..f86c814 100644
--- a/src/game/Makefile.am
+++ b/src/game/Makefile.am
@@ -5,5 +5,4 @@ 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 shared.h ship.h shipspecs.h star.h \
- world.h
+noinst_HEADERS = game.h player.h sector.h ship.h shipspecs.h star.h world.h
diff --git a/src/game/game.cc b/src/game/game.cc
index 197700f..51bb565 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -108,26 +108,28 @@ bool Game::init()
ship->label = "ship: Micron Vector";
core::Entity *cube = new core::Entity(core::entity::Solid & core::entity::Static);
- cube->base_shape = core::entity::Cube;
- cube->base_color = Color(0.0f, 0.8f, 0.0f);
+ cube->core_shape = core::entity::Cube;
+ cube->core_color = Color(0.0f, 0.8f, 0.0f);
cube->location = Vector3f(24.0f, 0.0f, -24.0f);
cube->label ="cube: Borg cube green";
+ cube->type = cube_enttype;
cube = new core::Entity(core::entity::Solid & core::entity::Static);
- cube->base_shape = core::entity::Cube;
- cube->base_color = Color(1.0f, 0.0f, 0.0f);
+ cube->core_shape = core::entity::Cube;
+ cube->core_color = Color(1.0f, 0.0f, 0.0f);
cube->location = Vector3f(16.0f, 0.0f, -16.0f);
cube->label ="cube: Borg cube red";
+ cube->type = cube_enttype;
core::Entity *sphere = new core::Entity(core::entity::Solid & core::entity::Static);
- sphere->base_shape = core::entity::Sphere;
- sphere->base_color = Color(0.8f, 0.8f, 0.0f);
+ sphere->core_shape = core::entity::Sphere;
+ sphere->core_color = Color(0.8f, 0.8f, 0.0f);
sphere->location = Vector3f(0.0f, 0.0f, -32.0f);
sphere->label ="sphere: The Sphere";
core::Entity *axis = new core::Entity(core::entity::Static);
- axis->base_shape = core::entity::Diamond;
- axis->base_color = Color(1.0f, 1.0f, 0.0f);
+ axis->core_shape = core::entity::Diamond;
+ axis->core_color = Color(1.0f, 1.0f, 0.0f);
axis->location = Vector3f(0, 0, 0);
axis->label = "axis: Origin";
@@ -152,4 +154,14 @@ void Game::frame(float seconds)
ship->update(seconds);
}
+void Game::event_join(core::Player *player)
+{
+ if (!player)
+ return;
+
+ ship = new Ship();
+ ship->location = Vector3f(0,0,0);
+ ship->label = "ship: Micron Vector";
+}
+
}; // namespace game
diff --git a/src/game/game.h b/src/game/game.h
index bceb62d..abe0c0d 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -33,6 +33,9 @@ public:
/// execute one game grame
void frame(float seconds);
+ /// a player joins the game
+ void event_join(core::Player *player);
+
/// sectors in space
std::vector<Sector*> sectors;
@@ -47,6 +50,13 @@ private:
std::string author;
};
+// entity type constants
+const unsigned int ship_enttype = 256;
+const unsigned int star_enttype = 257;
+const unsigned int cube_enttype = 258;
+const unsigned int sphere_enttype = 259;
+const unsigned int axis_enttype = 260;
+
}
#endif // __INCLUDED_GAME_H__
diff --git a/src/game/ship.cc b/src/game/ship.cc
index 1ef4b9d..d6333cd 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -5,7 +5,7 @@
*/
// project headers
-#include "game/shared.h"
+#include "game/game.h"
#include "game/ship.h"
#include "math/mathlib.h"
@@ -17,8 +17,10 @@ using math::degrees180f;
namespace game {
-Ship::Ship() : core::Entity(0, ship_enttype)
+Ship::Ship() : core::Entity(0)
{
+ type = ship_enttype;
+
speed = 0;
yaw_current = 0;
yaw_target = yaw_current;
diff --git a/src/game/star.cc b/src/game/star.cc
index 5fed82a..10bb6ee 100644
--- a/src/game/star.cc
+++ b/src/game/star.cc
@@ -4,7 +4,7 @@
the terms of the GNU General Public License version 2.
*/
-#include "game/shared.h"
+#include "game/game.h"
#include "game/star.h"
@@ -12,9 +12,11 @@ namespace game {
Star::Star() : core::Entity(core::entity::Static & core::entity::Solid)
{
- base_shape = core::entity::Sphere; // a star is a sphere
- base_color = math::Color(1,1,1,1); // white
- base_radius = 48; // 48 game units
+ core_shape = core::entity::Sphere; // a star is a sphere
+ core_color = math::Color(1,1,1,1); // white
+ core_radius = 48; // 48 game units
+
+ type = star_enttype;
}
Star::~Star()