diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/input.cc | 1 | ||||
-rw-r--r-- | src/core/clientstate.cc | 17 | ||||
-rw-r--r-- | src/core/clientstate.h | 10 | ||||
-rw-r--r-- | src/core/entity.cc | 5 | ||||
-rw-r--r-- | src/core/gameinterface.cc | 12 | ||||
-rw-r--r-- | src/core/gameserver.cc | 44 | ||||
-rw-r--r-- | src/core/netserver.cc | 10 | ||||
-rw-r--r-- | src/math/functions.cc | 5 | ||||
-rw-r--r-- | src/render/draw.cc | 76 | ||||
-rw-r--r-- | src/render/dust.cc | 14 | ||||
-rw-r--r-- | src/sys/sys.cc | 5 |
11 files changed, 99 insertions, 100 deletions
diff --git a/src/client/input.cc b/src/client/input.cc index 052ffb2..b5d4c0d 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -580,6 +580,7 @@ void frame(float seconds) Key *key = 0; bool pressed = false; + memset(&event, 0, sizeof(SDL_Event)); while (SDL_PollEvent(&event)) { pressed = false; key = 0; diff --git a/src/core/clientstate.cc b/src/core/clientstate.cc index 57802fa..865c0bb 100644 --- a/src/core/clientstate.cc +++ b/src/core/clientstate.cc @@ -6,6 +6,7 @@ #include "core/clientstate.h" #include "core/application.h" +#include "sys/sys.h" namespace core { @@ -14,18 +15,24 @@ ClientState::ClientState() state_visible = false; state_detailvisible = false; state_targetable = false; - state_enginesound = 0; - for (size_t i = 0; i < 3; i++) - state_screenlocation[i] = 0; + state_enginesound = 0; + state_engine_trail_offset = 0; state_fuzz = math::randomf(); - state_engine_trail_offset = 0; } ClientState::ClientState(Entity *entity) { - ClientState(); + state_visible = false; + state_detailvisible = false; + state_targetable = false; + + state_enginesound = 0; + state_engine_trail_offset = 0; + + state_fuzz = math::randomf(); + assign(entity); } diff --git a/src/core/clientstate.h b/src/core/clientstate.h index 91cd3e1..42ead3d 100644 --- a/src/core/clientstate.h +++ b/src/core/clientstate.h @@ -29,13 +29,13 @@ public: ~ClientState(); - inline math::Vector3f const & location() { return state_location; } + inline math::Vector3f const & location() const { return state_location; } - inline math::Vector3f const & previouslocation() { return state_previouslocation; } + inline math::Vector3f const & previouslocation() const { return state_previouslocation; } - inline math::Axis const & previousaxis() { return state_previousaxis; } + inline math::Axis const & previousaxis() const { return state_previousaxis; } - inline math::Axis const & axis() { return state_axis; } + inline math::Axis const & axis() const { return state_axis; } inline bool visible() const { return state_visible; } @@ -58,8 +58,6 @@ public: math::Vector3f state_previouslocation; math::Axis state_previousaxis; - double state_screenlocation[3]; - bool state_visible; bool state_detailvisible; bool state_targetable; diff --git a/src/core/entity.cc b/src/core/entity.cc index 98fef0e..20e1b05 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -56,6 +56,7 @@ void Entity::erase(unsigned int id) Registry::iterator it = entity_registry.find(id); if (it != entity_registry.end()) { delete((*it).second); + (*it).second = 0; entity_registry.erase(it); } else { con_warn << "Could not erase entity " << id << "!\n"; @@ -171,8 +172,10 @@ Entity::Entity(std::istream & is) Entity::~Entity() { - if (entity_clientstate) + if (entity_clientstate) { delete entity_clientstate; + entity_clientstate = 0; + } if (entity_zone) entity_zone->remove(this); diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index 7833bf5..ecb58fc 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -83,18 +83,22 @@ void GameInterface::clear() Zone::registry().clear(); // remove all game functions - for (Func::Registry::iterator it = Func::registry().begin(); it != Func::registry().end(); it++) { + for (Func::Registry::iterator it = Func::registry().begin(); it != Func::registry().end();) { if ( ((*it).second->flags() & Func::Game) == Func::Game) { delete (*it).second; - Func::registry().erase(it); + Func::registry().erase(it++); + } else { + ++it; } } // remove all game cvars - for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) { + for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); ) { if ( ((*it).second->flags() & Cvar::Game) == Cvar::Game) { delete (*it).second; - Cvar::registry().erase(it); + Cvar::registry().erase(it++); + } else { + ++it; } } diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index db8852a..53698c2 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -564,7 +564,7 @@ void GameServer::frame(float seconds) server_network->broadcast_frame(server_time, server_previoustime); // send changes in the world - for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); it++) { + for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) { Entity *entity = (*it).second; @@ -574,19 +574,24 @@ void GameServer::frame(float seconds) server_network->broadcast_entity_delete(entity); } - core::Entity::erase(entity->id()); + delete entity; + (*it).second = entity = 0; + Entity::registry().erase(it++); - } else if (entity->entity_created) { - - server_network->broadcast_entity_create(entity); - entity->entity_created = false; - - } else if (entity->dirty()) { - - server_network->broadcast_entity_update(entity); + } else { + if (entity->entity_created) { + + server_network->broadcast_entity_create(entity); + entity->entity_created = false; + entity->entity_dirty = false; + + } else if (entity->dirty()) { + + server_network->broadcast_entity_update(entity); + entity->entity_dirty = false; + } + ++it; } - - entity->entity_dirty = false; } // update player info @@ -598,17 +603,18 @@ void GameServer::frame(float seconds) } else { // local update stub - for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); it++) { - + for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) { Entity *entity = (*it).second; - if (entity->entity_destroyed) { - Entity::erase(entity->id()); - } else if (entity->entity_created) { + if (entity->entity_destroyed) { + delete entity; + (*it).second = entity = 0; + Entity::registry().erase(it++); + } else { entity->entity_created = false; - + entity->entity_dirty = false; + ++it; } - entity->entity_dirty = false; } } diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 10fd554..dd5dc38 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -125,7 +125,7 @@ void NetServer::abort() { // remove disconnected clients void NetServer::reap() { - for (Clients:: iterator it = clients.begin(); it != clients.end(); it++) { + for (Clients:: iterator it = clients.begin(); it != clients.end(); ) { NetClient *client = *it; if (client->client_timeout + NETTIMEOUT < application()->time()) { @@ -151,10 +151,12 @@ void NetServer::reap() server()->player_disconnect((*it)->player()); // remove the client - clients.erase(it); delete client; - it=clients.begin(); - } + clients.erase(it++); + + } else { + ++it; + } } } diff --git a/src/math/functions.cc b/src/math/functions.cc index 40f0f4e..2942eb5 100644 --- a/src/math/functions.cc +++ b/src/math/functions.cc @@ -5,6 +5,7 @@ */ #include "math/functions.h" +#include <stdlib.h> namespace math { @@ -33,12 +34,12 @@ int max(int a, int b) float randomf(const float max) { - return ((float) rand() / (float) RAND_MAX) * max; + return ((float) random() / (float) RAND_MAX) * max; } unsigned randomi(const unsigned int max) { - return ((unsigned int)(rand() % max)); + return ((unsigned int)(random() % max)); } float degrees180f(float angle) diff --git a/src/render/draw.cc b/src/render/draw.cc index 13f9ee6..c575f20 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -43,10 +43,8 @@ const float drawdistance = 128.0f; const float drawfxdistance = 64.0f; core::Zone *zone = 0; -float angle = 0; - // function to test flags -inline bool flag_is_set(unsigned int spawnflags, unsigned int flag) { +inline bool flag_is_set(unsigned int const spawnflags, unsigned int const flag) { return ((spawnflags & flag) == flag); } @@ -497,24 +495,6 @@ void pass_prepare(float seconds) } } } - - /* - // calculate screen position - if (entity->state()->visible()) { - GLdouble x = 0; - GLdouble y = 0; - GLdouble z = 0; - - math::Vector3f const & pos = entity->state()->location(); - if (gluProject((GLdouble) pos.x , (GLdouble)pos.y, (GLdouble)pos.z, gl_model_matrix, gl_projection_matrix, gl_viewport, &x, &y, &z) == GL_TRUE) { - entity->state()->state_screenlocation[0] = x; - entity->state()->state_screenlocation[1] = y; - entity->state()->state_screenlocation[2] = z; - entity->state()->state_targetable = true; - } - } - */ - } } @@ -639,9 +619,14 @@ void draw_pass_model_fx(float elapsed) math::Vector3f offset; math::Color color; - + model::Light *light; + model::Flare *flare; + model::Engine *engine; + + math::Axis flare_axis; + size_t circle_texture = Textures::load("bitmaps/fx/circle00"); - size_t flare_texture = Textures::bind("bitmaps/fx/flare00"); + size_t current_texture = Textures::bind("bitmaps/fx/flare00"); gl::enable(GL_TEXTURE_2D); gl::begin(gl::Quads); @@ -649,28 +634,26 @@ void draw_pass_model_fx(float elapsed) for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { core::Entity *entity = (*it); - if (entity->model() && entity->state()->detailvisible()) { + if (entity->model() && entity->state() && entity->state()->detailvisible()) { // draw model lights for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) { - model::Light *light = (*lit); + light = (*lit); // strobe frequency t = 1.0f; if (light->strobe()) - t = (core::application()->time() + entity->state()->fuzz() - light->offset()) * light->frequency(); - + t = (core::application()->time() - light->offset() - entity->state()->fuzz()) * light->frequency(); if ((!light->strobe()) || (( t - floorf(t)) <= light->time())) { location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * light->location())); light_size = 0.0625 * light->radius(); - if (flare_texture != light->texture()) { + if (current_texture != light->texture()) { gl::end(); - flare_texture = Textures::bind(light->texture()); + current_texture = Textures::bind(light->texture()); gl::begin(gl::Quads); } - if (light->entity()) { color.assign(entity->color()); } else { @@ -687,16 +670,13 @@ void draw_pass_model_fx(float elapsed) gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * light_size); glTexCoord2f(1,1); gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * light_size); - Stats::quads++; - } } // draw flares - for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { - - model::Flare *flare = (*flit); + for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { + flare = (*flit); // strobe frequency t = 1.0f; @@ -704,16 +684,16 @@ void draw_pass_model_fx(float elapsed) t = (core::application()->time() + entity->state()->fuzz() - flare->offset()) * flare->frequency(); if ((!flare->strobe()) || (( t - floorf(t)) <= flare->time())) { - math::Axis flare_axis(entity->state()->axis()); + flare_axis.assign(entity->state()->axis()); if (flare->angle()) flare_axis.change_direction(flare->angle()); location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * flare->location())); light_size = 0.0625 * flare->radius(); - if (flare_texture != flare->texture()) { + if (current_texture != flare->texture()) { gl::end(); - flare_texture = Textures::bind(flare->texture()); + current_texture = Textures::bind(flare->texture()); gl::begin(gl::Quads); } @@ -723,6 +703,7 @@ void draw_pass_model_fx(float elapsed) color.assign(flare->color()); } + // FIXME Camera::axis().forward() should be the vector flare_location - camera_eye a = dotproduct(flare_axis.forward(), Camera::axis().forward()); if (a < -0.1f) { color.a = -a - 0.1f; @@ -755,21 +736,20 @@ void draw_pass_model_fx(float elapsed) if (t > 1.0f) t -= 1.0f; math::clamp(t, 0.0f, 1.0f); - entity->state()->state_engine_trail_offset = t; for(model::Model::Engines::iterator eit = entity->model()->engines().begin(); eit != entity->model()->engines().end(); eit++) { - model::Engine *engine = (*eit); + engine = (*eit); location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * engine->location())); engine_size = 0.0625 * engine->radius(); color.assign(engine->color()); color.a = 0.9f * u; - if (flare_texture != engine->texture() ) { + if (current_texture != engine->texture() ) { gl::end(); - flare_texture = Textures::bind(engine->texture()); + current_texture = Textures::bind(engine->texture()); gl::begin(gl::Quads); } @@ -790,15 +770,15 @@ void draw_pass_model_fx(float elapsed) Stats::quads++; // draw the engine trail - if (flare_texture != circle_texture) { + if (current_texture != circle_texture) { gl::end(); - flare_texture = Textures::bind(circle_texture); + current_texture = Textures::bind(circle_texture); gl::begin(gl::Quads); } color.assign(1.0f, 1.0f); offset.assign(entity->state()->axis().forward() * engine_size); - if (t) + if (t > 0) location -= offset * t; for (size_t i = count; i > 0; i--) { @@ -937,12 +917,6 @@ void draw(float seconds) zone = core::localplayer()->zone(); if (!zone) return; - - // used for animations - angle += 180.0f * seconds; - if( angle > 360.0f ) { - angle -= 360.0f; - } Camera::frame(seconds); Camera::draw(); // draw the current camera transformation diff --git a/src/render/dust.cc b/src/render/dust.cc index a3eac6d..b0926dc 100644 --- a/src/render/dust.cc +++ b/src/render/dust.cc @@ -66,10 +66,6 @@ void Dust::draw() return; } - if (!core::localcontrol()) { - return; - } - if ((size_t) r_dustsize->value() != dustsize) { con_debug << " changing dust size..." << std::endl; if (dust) { @@ -88,6 +84,13 @@ void Dust::draw() return; } + if (!core::localcontrol()) { + return; + } + + if (! core::localcontrol()->speed()) + return; + if (!dust) { con_debug << " generating dust..." << std::endl; dust = new float[dustsize*3]; @@ -99,9 +102,6 @@ void Dust::draw() } } - if (! core::localcontrol()->speed()) - return; - math::Color color(1.0f, 1.0f); alpha = core::localcontrol()->speed() / LOWSPEEDLIMIT; if (alpha > DUSTMAXALPHA) diff --git a/src/sys/sys.cc b/src/sys/sys.cc index 10b7897..da9b08d 100644 --- a/src/sys/sys.cc +++ b/src/sys/sys.cc @@ -13,6 +13,7 @@ #include <unistd.h> #include <signal.h> +#include <string.h> #include <sys/time.h> #include <sys/stat.h> #include <sys/types.h> @@ -46,8 +47,10 @@ void signal(int signum, signalfunc handler) #ifndef _WIN32 struct sigaction sa; - sa.sa_handler = handler; + sa.sa_sigaction = 0; + memset(&sa.sa_mask, 0 ,sizeof(sigset_t)); sa.sa_flags = 0; + sa.sa_handler = handler; ::sigaction(signum, &sa, 0); #endif |