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/draw.cc94
-rw-r--r--src/core/entity.cc2
-rw-r--r--src/core/gameserver.cc16
-rw-r--r--src/game/game.cc6
-rw-r--r--src/game/ship.cc1
-rw-r--r--src/render/model.cc118
-rw-r--r--src/render/model.h32
7 files changed, 203 insertions, 66 deletions
diff --git a/src/client/draw.cc b/src/client/draw.cc
index cdf80c2..91032a8 100644
--- a/src/client/draw.cc
+++ b/src/client/draw.cc
@@ -53,39 +53,6 @@ void draw_entity_diamond(core::Entity *entity)
gl::end();
}
-// draw an entity of entity_type core::Entity::Default
-void draw_entity_default(core::Entity *entity)
-{
- render::Model *model = 0;
- if (entity->modelname().size())
- model = render::Model::get(entity->modelname());
-
- render::gl::push();
- render::gl::translate(entity->location());
-
- if (model) {
- render::gl::color(entity->color());
- model->draw();
- } else {
- switch(entity->shape()) {
- case core::Entity::Sphere:
- draw_entity_sphere(entity);
- break;
-
- case core::Entity::Diamond:
- draw_entity_diamond(entity);
- break;
-
- case core::Entity::Cube:
-
- default:
- draw_entity_cube(entity);
- break;
- }
- }
-
- render::gl::pop();
-}
math::Vector3f v0(1.0f, -1.0f, -1.0f);
@@ -105,10 +72,7 @@ void draw_ship(core::EntityControlable *entity)
using math::Color;
using namespace render;
- gl::push();
- gl::translate(entity->location());
gl::scale(0.2f, 0.2f, 0.2f);
- gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
Vector3f tl(0.25, 0.125, 0.125);
Vector3f br(-0.25, -0.125, -0.125);
@@ -169,8 +133,62 @@ void draw_ship(core::EntityControlable *entity)
gl::vertex(v6);
gl::vertex(v7);
gl::end();
+}
+
+
+// draw an entity of entity_type core::Entity::Default
+void draw_entity_default(core::Entity *entity)
+{
+ render::Model *model = 0;
+ if (entity->modelname().size())
+ model = render::Model::get(entity->modelname());
- gl::pop();
+ render::gl::push();
+ render::gl::translate(entity->location());
+ render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
+
+ if (model) {
+ model->draw(entity);
+ } else {
+ switch(entity->shape()) {
+ case core::Entity::Sphere:
+ draw_entity_sphere(entity);
+ break;
+
+ case core::Entity::Diamond:
+ draw_entity_diamond(entity);
+ break;
+
+ case core::Entity::Cube:
+
+ default:
+ draw_entity_cube(entity);
+ break;
+ }
+ }
+
+ render::gl::pop();
+}
+
+// draw an entity of entity_type core::Entity::Controlable
+void draw_entity_controlable(core::EntityControlable *entity)
+{
+ render::Model *model = 0;
+ if (entity->modelname().size())
+ model = render::Model::get(entity->modelname());
+
+ render::gl::push();
+ render::gl::translate(entity->location());
+ render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
+
+ if (model) {
+ model->draw(entity);
+ } else {
+ draw_ship(entity);
+ }
+
+ render::gl::pop();
+
}
void draw_spacegrid()
@@ -224,7 +242,7 @@ void draw_world(float seconds)
draw_entity_default((*it).second);
break;
case core::Entity::Controlable:
- draw_ship(static_cast<core::EntityControlable *> ((*it).second));
+ draw_entity_controlable(static_cast<core::EntityControlable *> ((*it).second));
break;
default:
break;
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 2a0518a..097b322 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -61,6 +61,8 @@ void Entity::remove(unsigned int id)
if (it != registry.end()) {
delete((*it).second);
registry.erase(it);
+ } else {
+ con_warn << "Could not remove entity " << id << "!\n";
}
}
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 6294a31..839ed03 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -271,6 +271,22 @@ void GameServer::frame(float seconds)
client->player()->player_dirty = false;
}
}
+
+ } else {
+
+ // local update stub
+ std::map<unsigned int, Entity *>::iterator it;
+ for (it=Entity::registry.begin(); it != Entity::registry.end(); it++) {
+
+ Entity *entity = (*it).second;
+ if (entity->entity_destroyed) {
+ core::Entity::remove(entity->id());
+ } else if (entity->entity_created) {
+ entity->entity_created = false;
+
+ }
+ entity->entity_dirty = false;
+ }
}
}
diff --git a/src/game/game.cc b/src/game/game.cc
index 828a35b..4aa505d 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -101,8 +101,8 @@ void Game::init()
cube->entity_shape = core::Entity::Diamond;
cube->entity_color = Color(0.5f, 1.0f, 5.0f);
cube->entity_location = Vector3f(16.0f, 20.0f, 0.0f);
- cube->entity_name = "wreck: Thornaider";
- cube->entity_modelname = "ship";
+ cube->entity_name = "wreck: Canasta";
+ cube->entity_modelname = "ships/canasta";
// Micron Vector
cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
@@ -110,7 +110,7 @@ void Game::init()
cube->entity_color = Color(0.5f, 1.0f, 5.0f);
cube->entity_location = Vector3f(18.0f, 22.0f, 0.0f);
cube->entity_name = "wreck: Micron Vector";
- cube->entity_modelname = "micron_vector";
+ cube->entity_modelname = "ships/micron_vector";
// the yellow sphere
core::Entity *sphere = new core::Entity(core::Entity::Solid & core::Entity::Static);
diff --git a/src/game/ship.cc b/src/game/ship.cc
index e2a42d8..37c8cd8 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -23,6 +23,7 @@ Ship::Ship(core::Player *owner) :
// entity properties
entity_name = "ship: <" + owner->name() + "> Micron Vector";
entity_owner = owner;
+ entity_modelname = "ships/micron_vector";
// ship specs
acceleration = 1.5f;
diff --git a/src/render/model.cc b/src/render/model.cc
index e486d75..907958a 100644
--- a/src/render/model.cc
+++ b/src/render/model.cc
@@ -22,6 +22,15 @@ namespace render
const float MAX_BOUNDS = 8192;
const float delta = 10e-10;
+Engine::Engine(math::Vector3f const & location) :
+ engine_location(location)
+{
+}
+
+Engine::~Engine()
+{
+}
+
std::map<std::string, Model*> Model::registry;
Model::Model(std::string const & name) :
@@ -52,10 +61,13 @@ Model::Model(std::string const & name) :
using math::Vector3f;
using math::Plane3f;
- std::vector<Plane3f *> planes;
- std::string classname;
- unsigned int level = 0;
- char data[1024];
+ std::vector<Plane3f *> planes;
+ unsigned int level = 0;
+ char data[1024];
+
+ std::string class_name;
+ math::Vector3f class_origin;
+ float class_angle;
while (ifs) {
ifs.getline(data, 1023);
@@ -71,7 +83,7 @@ Model::Model(std::string const & name) :
//cout << " LEVEL +" << level << std::endl;
} else if (firstword == "}") {
//cout << " LEVEL -" << level << std::endl;
- if ((level == 2) && (classname == "worldspawn")) {
+ if ((level == 2) && (class_name == "worldspawn")) {
//cout << "brush with " << planes.size() << " faces" << std::endl;
// for every face
@@ -85,23 +97,57 @@ Model::Model(std::string const & name) :
delete (*it);
}
planes.clear();
+
+ } else if ((level == 1) && (class_name == "target_engine")) {
+ //con_debug << " engine at " << class_origin << "\n";
+ add_engine(new Engine(class_origin * model_scale));
+ }
+
+ if (level == 1) {
+ class_angle = 0;
+ class_name.clear();
+ class_origin = Vector3f(0,0,0);
}
+
level--;
+
} else if (firstword == "\"classname\"") {
- classname.clear();
- if (linestream >> classname) {
- if (classname.size() > 2) {
- classname.erase(0,1);
- classname.erase(classname.size()-1, 1);
- linestream >> classname;
- //cout << " CLASS '" << classname << "'" << std::endl;
- } else
- classname.clear();
+ class_name.clear();
+ if (linestream >> class_name) {
+ if (class_name.size() > 2) {
+ class_name.erase(0,1);
+ class_name.erase(class_name.size()-1, 1);
+ //linestream >> class_name;
+ //con_debug << " classname '" << class_name << "'" << std::endl;
+ } else {
+ class_name.clear();
+ }
} else {
//cout << " EMPTY CLASS" << std::endl;
}
+ } else if (firstword == "\"origin\"") {
+ std::string tmp;
+ char c;
+ while ( (linestream.get(c)) && (c != '"'));
+ while ( (linestream.get(c)) && (c != '"'))
+ tmp += c;
+ std::istringstream is(tmp);
+ is >> class_origin.x;
+ is >> class_origin.y;
+ is >> class_origin.z;
+ //con_debug << " origin '" << class_origin << "'" << std::endl;
+
+ } else if (firstword == "\"angle\"") {
+ std::string tmp;
+ char c;
+ while ( (linestream.get(c)) && (c != '"'));
+ while ( (linestream.get(c)) && (c != '"'))
+ tmp += c;
+ std::istringstream is(tmp);
+ is >> class_angle;
+ //con_debug << " angle '" << class_angle << "'" << std::endl;
} else if (firstword == "(") {
- if ((level == 2) && (classname == "worldspawn")) {
+ if ((level == 2) && (class_name == "worldspawn")) {
//cout << " BRUSH PLANE" << std::endl;
Vector3f p1;
Vector3f p2;
@@ -141,10 +187,15 @@ Model::~Model()
{
// delete all faces
for (std::list<Face *>::iterator fit = model_face.begin(); fit != model_face.end(); fit++) {
- delete(*fit);
+ delete (*fit);
}
-
model_face.clear();
+
+ // delete all engines
+ for(std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) {
+ delete (*eit);
+ }
+ model_engine.clear();
}
void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes)
@@ -345,7 +396,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
Face *mf = new Face(n);
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
- mf->add_vertex(*(*it));
+ mf->add_vertex(*(*it) * model_scale);
}
//con_debug << "adding face\n";
@@ -367,15 +418,42 @@ void Model::add_face(Face *face)
model_face.push_back(face);
}
-void Model::draw()
+void Model::add_engine(Engine *engine)
{
- gl::scale(model_scale, model_scale, model_scale);
+ model_engine.push_back(engine);
+}
+
+void Model::draw(core::Entity const * entity)
+{
+ //gl::scale(model_scale, model_scale, model_scale);
+ render::gl::color(entity->color());
// draw all faces
for (std::list<Face *>::iterator fit = model_face.begin(); fit != model_face.end(); fit++) {
(*fit)->draw();
}
+}
+void Model::draw(core::EntityControlable const * entity)
+{
+ // draw the model
+ draw((core::Entity *) entity);
+
+ // draw engines
+ // all engines are assumed to point to the rear
+ if(model_engine.size() && entity->thrust()) {
+
+ gl::color(1.0f,0 ,0 );
+ gl::begin(gl::Lines);
+
+ for(std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++)
+ {
+ math::Vector3f const & v = (*eit)->location();
+ gl::vertex(v);
+ gl::vertex(v.x - 0.0625f*entity->thrust(), v.y, v.z);
+ }
+ gl::end();
+ }
}
Model *Model::find(std::string const & name)
diff --git a/src/render/model.h b/src/render/model.h
index ab6207e..dfde809 100644
--- a/src/render/model.h
+++ b/src/render/model.h
@@ -10,11 +10,25 @@
#include <map>
#include <list>
-#include "render/face.h"
#include "math/plane3f.h"
+#include "core/entity.h"
+#include "render/face.h"
namespace render {
+/// a spacecraft engine
+class Engine
+{
+public:
+ Engine(math::Vector3f const & location);
+ ~Engine();
+
+ inline math::Vector3f const & location() const { return engine_location; }
+
+private:
+ math::Vector3f engine_location;
+};
+
/// a 3D model contains a list of faces
class Model
{
@@ -26,13 +40,18 @@ public:
/// the name of the model
inline std::string const & name() const { return model_name; }
- void add_face(Face *face);
-
/// the Model registry
static std::map<std::string, Model*> registry;
- /// draw the model
- void draw();
+ /// draw the model for an entity
+ /** This will not draw attached engines, turrents and cannons
+ */
+ void draw(core::Entity const * entity);
+
+ /// draw the model for a controlable enity
+ /** This will draw all attached engines, turrents and cannons
+ */
+ void draw(core::EntityControlable const * entity);
/* ---- static functions for the Model registry -------------------- */
@@ -47,8 +66,11 @@ public:
private:
void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
+ void add_engine(Engine *engine);
+ void add_face(Face *face);
std::list<Face *> model_face;
+ std::list<Engine *> model_engine;
std::string model_name;
float model_scale;