diff options
author | Stijn Buys <ingar@osirion.org> | 2008-03-23 19:16:12 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-03-23 19:16:12 +0000 |
commit | 772338f8cd62594d222d48466f558b002eb1efb8 (patch) | |
tree | 7cc5dc3bd2066d9d7cf7e00819cd67bd860881af /src | |
parent | 22e136d88817b64ec904a7e7232a2cf9e80e74bd (diff) |
model pointer caching
Diffstat (limited to 'src')
-rw-r--r-- | src/core/entity.cc | 2 | ||||
-rw-r--r-- | src/core/entity.h | 5 | ||||
-rw-r--r-- | src/core/model.h | 5 | ||||
-rw-r--r-- | src/render/draw.cc | 100 |
4 files changed, 64 insertions, 48 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index fd28a1c..ebf9723 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -98,6 +98,7 @@ Entity::Entity(unsigned int flags) : entity_destroyed = false; entity_dirty = false; + entity_model = 0; entity_modelname.clear(); entity_name.clear(); @@ -131,6 +132,7 @@ Entity::Entity(std::istream & is) while ( (is.get(c)) && (c != '"')) n += c; entity_modelname = n; + entity_model = 0; // this will be resolved later entity_created = true; entity_destroyed = false; diff --git a/src/core/entity.h b/src/core/entity.h index 323eec7..54479be 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -13,6 +13,7 @@ class Entity; class EntityControlable; } +#include "core/model.h" #include "core/player.h" #include "math/mathlib.h" @@ -65,6 +66,9 @@ public: /// entity model name inline std::string const & modelname() { return entity_modelname; } + /// pointer to the model, is used client-side + inline Model * model() { return entity_model; } + /// dirty flag inline bool dirty() const { return entity_dirty; } @@ -128,6 +132,7 @@ public: float entity_radius; std::string entity_name; std::string entity_modelname; + Model *entity_model; Shape entity_shape; math::Vector3f entity_location; math::Color entity_color; diff --git a/src/core/model.h b/src/core/model.h index 5deee35..5a3cd72 100644 --- a/src/core/model.h +++ b/src/core/model.h @@ -7,6 +7,11 @@ #ifndef __INCLUDED_CORE_MODEL_H__ #define __INCLUDED_CORE_MODEL_H__ +namespace core +{ +class Model; +} + #include <vector> #include <map> #include <list> diff --git a/src/render/draw.cc b/src/render/draw.cc index 77f8457..8a03e40 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -121,12 +121,12 @@ void draw_entity_axis(core::Entity *entity) /* ----- Entity models --------------------------------------------- */ -void draw_model_vertex(core::Model *model, core::Entity *entity) +void draw_model_vertex(core::Entity *entity) { // draw model vertices - if (model->vertex_count()) { - size_t index = model->first_vertex(); - size_t count = model->vertex_count(); + if (entity->model()->vertex_count()) { + size_t index = entity->model()->first_vertex(); + size_t count = entity->model()->vertex_count(); if (r_drawwireframe && r_drawwireframe->value()) { glDrawArrays(gl::LineLoop, index, count); @@ -138,12 +138,12 @@ void draw_model_vertex(core::Model *model, core::Entity *entity) } } -void draw_model_evertex(core::Model *model, core::Entity *entity) +void draw_model_evertex(core::Entity *entity) { // draw model evertices - if (model->evertex_count()) { - size_t index = model->first_evertex(); - size_t count = model->evertex_count(); + if (entity->model()->evertex_count()) { + size_t index = entity->model()->first_evertex(); + size_t count = entity->model()->evertex_count(); render::gl::color(entity->color()); glVertexPointer(3, GL_FLOAT, 0, core::VertexArray::evertex); @@ -162,8 +162,10 @@ void draw_model_evertex(core::Model *model, core::Entity *entity) } } -void draw_model_lights(core::Model *model, core::Entity *entity) +void draw_model_lights(core::Entity *entity) { + core::Model *model = entity->model(); + if (model->model_light.size()) { glPointSize(10); gl::begin(gl::Points); @@ -179,8 +181,10 @@ void draw_model_lights(core::Model *model, core::Entity *entity) } } -void draw_model_engines(core::Model *model, core::EntityControlable *entity) +void draw_model_engines(core::EntityControlable *entity) { + core::Model *model = entity->model(); + if (model->model_engine.size() && entity->thrust()) { gl::color(1.0f, 0.0f ,0.0f, 1.0f); gl::begin(gl::Lines); @@ -195,20 +199,20 @@ void draw_model_engines(core::Model *model, core::EntityControlable *entity) } -void draw_model_radius(core::Model *model, core::Entity *entity) +void draw_model_radius(core::Entity *entity) { sphere.sphere_color = entity->color(); sphere.sphere_color.a = 0.25f; - sphere.radius = model->radius(); + sphere.radius = entity->model()->radius(); sphere.draw(); Stats::spheres += 1; } -void draw_model_shield(core::Model *model, core::EntityControlable *entity) +void draw_model_shield(core::EntityControlable *entity) { // shield rotation gl::rotate(angle, 0.0f, 0.0f, 1.0f ); - gl::scale(model->radius(), model->radius(), model->radius()); + gl::scale(entity->model()->radius(), entity->model()->radius(), entity->model()->radius()); // draw the shield gl::color(math::Color(0.0f, 1.0f ,0.0f)); @@ -242,14 +246,20 @@ void draw_model_shield(core::Model *model, core::EntityControlable *entity) /* ----- Render passes --------------------------------------------- */ -inline bool test_draw_distance(core::Model *model, core::Entity *entity) +inline bool test_draw_distance(core::Entity *entity) { - return (model && (math::distancesquared(camera_target, entity->location()) <= (drawdistance*drawdistance*model->radius()))); + if (!entity->model()) + return false; + else + return (math::distancesquared(camera_target, entity->location()) <= (drawdistance*drawdistance*entity->model()->radius())); } -inline bool test_drawfx_distance(core::Model *model, core::Entity *entity) +inline bool test_drawfx_distance(core::Entity *entity) { - return (model && (math::distancesquared(camera_target, entity->location()) <= (drawfxdistance*drawfxdistance*model->radius()))); + if (!entity->model()) + return false; + else + return (math::distancesquared(camera_target, entity->location()) <= (drawfxdistance*drawfxdistance*entity->model()->radius())); } /* Draw entities without model */ @@ -259,7 +269,16 @@ void draw_pass_default() for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { core::Entity *entity = (*it).second; - if (!entity->modelname().size()) { + // load entity models if necessary + if (!entity->model() && entity->modelname().size()) { + entity->entity_model = core::Model::get(entity->modelname()); + + if (!entity->model()) + entity->entity_modelname.clear(); + } + + // draw entities without model + if (!entity->model()) { gl::push(); gl::translate(entity->location()); gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); @@ -305,19 +324,15 @@ void draw_pass_model_vertex() std::map<unsigned int, core::Entity *>::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { - core::Entity *entity = (*it).second; - core::Model *model = 0; - if (entity->modelname().size()) { - model = core::Model::get(entity->modelname()); - } + core::Entity *entity = (*it).second; - if (test_draw_distance(model, entity)) { + if (test_draw_distance(entity)) { gl::push(); gl::translate(entity->location()); gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); - draw_model_vertex(model, entity); + draw_model_vertex(entity); gl::pop(); } @@ -339,19 +354,15 @@ void draw_pass_model_evertex() std::map<unsigned int, core::Entity *>::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { - core::Entity *entity = (*it).second; - core::Model *model = 0; - if (entity->modelname().size()) { - model = core::Model::get(entity->modelname()); - } + core::Entity *entity = (*it).second; - if (test_draw_distance(model, entity)) { + if (test_draw_distance(entity)) { gl::push(); gl::translate(entity->location()); gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); - draw_model_evertex(model, entity); + draw_model_evertex(entity); gl::pop(); } @@ -365,24 +376,20 @@ void draw_pass_model_evertex() void draw_pass_model_fx() { for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { - core::Entity *entity = (*it).second; - core::Model *model = 0; - if (entity->modelname().size()) { - model = core::Model::get(entity->modelname()); - } + core::Entity *entity = (*it).second; - if (test_drawfx_distance(model, entity) && (model->model_light.size() || (entity->type() == core::Entity::Controlable))) { + if (test_drawfx_distance(entity)) { gl::push(); gl::translate(entity->location()); gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); - draw_model_lights(model, entity); + draw_model_lights(entity); if (entity->type() == core::Entity::Controlable) { - draw_model_engines(model, (core::EntityControlable *)entity); - draw_model_shield(model, (core::EntityControlable *)entity); + draw_model_engines((core::EntityControlable *)entity); + draw_model_shield((core::EntityControlable *)entity); } gl::pop(); } @@ -395,17 +402,14 @@ void draw_pass_model_radius() return; for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + core::Entity *entity = (*it).second; - core::Model *model = 0; - if (entity->modelname().size()) { - model = core::Model::get(entity->modelname()); - } - if (test_draw_distance(model, entity)) { + if (test_draw_distance(entity)) { gl::push(); gl::translate(entity->location()); - draw_model_radius(model, entity); + draw_model_radius(entity); gl::pop(); } |