diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gameconnection.cc | 42 |
1 files changed, 36 insertions, 6 deletions
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<EntityProjectile *>(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; |