From e77f8bdd8aba9744188a35e0c7eefc5c3a77f5a3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 1 May 2013 17:29:20 +0000 Subject: Delete client-side projectiles outside effects range. --- src/core/gameconnection.cc | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index de0b4e5..7bdadad 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -14,6 +14,7 @@ #include "core/entityprojectile.h" #include "core/gameconnection.h" #include "core/net.h" +#include "core/range.h" namespace core @@ -226,20 +227,49 @@ void GameConnection::frame(unsigned long timestamp) // get incoming messages connection_network->frame(); + // determine player location + math::Vector3f player_location; + + if (localplayer()->view()) { + player_location.assign(localplayer()->view()->location()); + } else if (localcontrol()) { + player_location.assign(localcontrol()->location()); + } + // update client-sde state - 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->type() == Entity::Projectile) { EntityProjectile *projectile = static_cast(entity); - if (projectile->state() == Entity::Normal) { - unsigned long elapsed = application()->timestamp() - projectile->timestamp(); - if (elapsed > 0) { - projectile->set_location(projectile->location() + projectile->axis().forward() * projectile->speed() * ((float) elapsed / 1000.0f)); - projectile->set_timestamp(application()->timestamp()); + + if (projectile->zone() == localplayer()->zone()) { + + // delete projectile if it goes out of range + if (math::distance(projectile->location(), player_location) > range::fxdistance) { + projectile->die(); + + } else if (projectile->state() == Entity::Normal) { + unsigned long elapsed = application()->timestamp() - projectile->timestamp(); + + if (elapsed > 0) { + projectile->set_location(projectile->location() + projectile->axis().forward() * projectile->speed() * ((float) elapsed / 1000.0f)); + projectile->set_timestamp(application()->timestamp()); + } } + } else { + projectile->die(); } } + + // delete entities were required + if (entity->destroyed()) { + Entity::registry().erase(it++); + } else { + ++it; + } + + } float f = 0; -- cgit v1.2.3