diff options
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/draw.cc | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc index 1017746..b0671de 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -44,19 +44,6 @@ math::Axis camera_axis; float angle = 0; - -/* ----- Distance test functions ----------------------------------- */ - -inline bool test_draw_distance(core::Entity *entity) -{ - return (entity->entity_renderstate > 0); -} - -inline bool test_drawfx_distance(core::Entity *entity) -{ - return ((entity->entity_renderstate & core::Entity::InCloseRange) == core::Entity::InCloseRange); -} - // function to test flags inline bool flag_is_set(unsigned int spawnflags, unsigned int flag) { return ((spawnflags & flag) == flag); @@ -162,7 +149,7 @@ void draw_entity_axis(core::Entity *entity) void draw_model_vertex(core::Entity *entity) { size_t count = entity->model()->vertex_structural(); - if (test_drawfx_distance(entity)) + if (entity->state()->detailvisible()) count += entity->model()->vertex_detail(); // draw model vertices @@ -176,7 +163,7 @@ void draw_model_vertex(core::Entity *entity) void draw_model_evertex(core::Entity *entity) { size_t count = entity->model()->evertex_structural(); - if (test_drawfx_distance(entity)) + if (entity->state()->detailvisible()) count += entity->model()->evertex_detail(); // draw model evertices @@ -245,15 +232,19 @@ void draw_model_shield(core::EntityControlable *entity) /* ----- Render passes --------------------------------------------- */ /* calculate entity visibility */ -void pass_visibility() +void pass_prepare() { 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; - entity->entity_renderstate = 0; + if (!entity->state()) { + entity->entity_clientstate = new core::ClientState(); + } + entity->state()->state_visible = false; + entity->state()->state_detailvisible = false; - // load entity models if necessary + // load entity models and light flare textures if (!entity->model() && entity->modelname().size()) { entity->entity_model = model::Model::load(entity->modelname()); @@ -271,25 +262,40 @@ void pass_visibility() } } - if (entity->model()) { + // update client state + if (entity->state() && flag_is_set(entity->flags(), core::Entity::Static)) { + entity->state()->state_location = entity->state()->previouslocation() + + (entity->location() - entity->state()->previouslocation()) * core::game()->timeoffset(); + } + + // calculate visibility for entities with models + if (entity->model()) { float dq = math::distancesquared(camera_eye, entity->location()); if (dq <= drawfxdistance*drawfxdistance*entity->model()->radius()) { - // entites withint drawfxdistance - entity->entity_renderstate = core::Entity::InCloseRange; + // entites within drawing distance + entity->state()->state_visible = true; + entity->state()->state_detailvisible = true; } else if (dq <= drawdistance*drawdistance*entity->model()->radius()) { // entities within drawdistance - entity->entity_renderstate = core::Entity::InRange; + entity->state()->state_visible = true; + entity->state()->state_detailvisible = false; } - } else if ((entity->type() == core::Entity::Globe) && flag_is_set(entity->flags(), core::Entity::Bright)) { - // bright globes set level light - GLfloat light_position[4]; - for (size_t i=0; i <3; i++) - light_position[i] = entity->location()[i]; - light_position[3] = 1.0f; + } else { - glLightfv(GL_LIGHT0, GL_POSITION, light_position); + entity->state()->state_visible = true; + + if ((entity->type() == core::Entity::Globe) && flag_is_set(entity->flags(), core::Entity::Bright)) { + + // bright globes set level light + GLfloat light_position[4]; + for (size_t i=0; i <3; i++) + light_position[i] = entity->location()[i]; + light_position[3] = 1.0f; + + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + } } } } @@ -345,7 +351,7 @@ void draw_pass_model_vertex() for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { core::Entity *entity = (*it).second; - if (test_draw_distance(entity)) { + if (entity->model() && entity->state()->visible()) { gl::push(); gl::translate(entity->location()); gl::multmatrix(entity->axis()); @@ -365,7 +371,7 @@ void draw_pass_model_evertex() core::Entity *entity = (*it).second; - if (test_draw_distance(entity)) { + if (entity->model() && entity->state()->visible()) { gl::push(); gl::translate(entity->location()); gl::multmatrix(entity->axis()); @@ -384,7 +390,7 @@ void draw_pass_model_shields() { core::Entity *entity = (*it).second; - if (test_drawfx_distance(entity)) { + if (entity->model() && entity->state()->detailvisible()) { if (entity->type() == core::Entity::Controlable) { @@ -415,7 +421,7 @@ 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; - if (test_drawfx_distance(entity)) { + if (entity->model() && entity->state()->detailvisible()) { // draw model lights for (std::list<model::Light *>::iterator lit = entity->model()->model_light.begin(); lit != entity->model()->model_light.end(); lit++) { @@ -423,7 +429,7 @@ void draw_pass_model_fx() // strobe frequency t = 1.0f; if ((*lit)->strobe()) - t = (core::application()->time() + entity->fuzz() + (*lit)->offset()) * (*lit)->frequency(); + t = (core::application()->time() + entity->state()->fuzz() + (*lit)->offset()) * (*lit)->frequency(); if (!(*lit)->strobe() || (( t - floorf(t)) <= (*lit)->time())) { math::Vector3f location = entity->location() + (entity->axis() * (*lit)->location()); @@ -469,7 +475,7 @@ void draw_pass_model_fx() float u = static_cast<core::EntityControlable *>(entity)->thrust(); - t = entity->fuzz() + core::application()->time() * 4; + t = entity->state()->fuzz() + core::application()->time() * 4; t = t - floorf(t); if (t > 0.5) @@ -510,7 +516,7 @@ void draw_pass_model_corona() for (std::map<unsigned int, core::Entity *>::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { core::Entity *entity = (*it).second; - if (test_draw_distance(entity)) { + if (entity->state()->visible() && (entity->shape() != core::Entity::Sphere)) { gl::push(); gl::translate(entity->location()); math::Color color = entity->color(); @@ -574,7 +580,7 @@ void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f cons camera_eye.assign(eye); camera_axis.assign(axis); - pass_visibility(); + pass_prepare(); gl::enable(GL_DEPTH_TEST); // enable depth buffer writing gl::enable(GL_CULL_FACE); // enable culling @@ -618,7 +624,7 @@ void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f cons gl::enable(GL_LIGHTING); gl::enable(GL_RESCALE_NORMAL); - draw_pass_model_corona(); // draw entity radius and star corona + draw_pass_model_corona(); // draw entity radius glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); |