diff options
author | Stijn Buys <ingar@osirion.org> | 2010-10-18 23:41:41 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-10-18 23:41:41 +0000 |
commit | 7a373c3f1fb8ea9dbef7690154bbe332fc386eca (patch) | |
tree | e56652c9b6197017d7eb8e86e5cd431bf9861d57 /src/core/gameserver.cc | |
parent | 4c5b00221c9405c5af06143974fbc6296ebe46b5 (diff) |
bullet ActionInterface for controlable entities, KeepAlive flag and g_keepalive
Diffstat (limited to 'src/core/gameserver.cc')
-rw-r--r-- | src/core/gameserver.cc | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 597de33..e6c44d0 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -15,6 +15,7 @@ #include "core/loader.h" #include "core/parser.h" #include "core/physics.h" +#include "core/range.h" #include "core/netserver.h" #include "filesystem/filesystem.h" #include "sys/sys.h" @@ -564,8 +565,7 @@ void GameServer::frame(unsigned long timestamp) } // view is to be deleted - if (view->destroyed()) - { + if (view->destroyed()) { if (control) { // player is docked at deleted entity if (control->state() == Entity::Docked) { @@ -590,15 +590,42 @@ void GameServer::frame(unsigned long timestamp) } // mark all entities as updated + const float keepalive_distance_squared = range::fxdistance * range::fxdistance; + for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) { - Entity *entity = (*it).second; + + // perform a keep-alive pass + if ((*it).second->flag_is_set(Entity::KeepAlive) && ((*it).second->type() == Entity::Dynamic) && (*it).second->zone()) { + + bool keepalive = false; + EntityDynamic *entity = static_cast<EntityDynamic *>((*it).second); + + for (Zone::Content::const_iterator zit = entity->zone()->content().begin(); zit != entity->zone()->content().end(); zit++) { + + if (( (*zit)->type() == Entity::Controlable) && ( (*zit) != entity)) { + + const EntityControlable *other = static_cast<const EntityControlable *>(*zit); + if (other->owner() && (other->state() != Entity::Docked) && (math::distancesquared(entity->location(), other->location()) < keepalive_distance_squared)) { + keepalive = true; + } + } + + } + + if (keepalive) { + entity->set_keepalive_time(time() + entity->keepalive_timeout()); + } else if ((entity->keepalive_time() > 0.0f) && (entity->keepalive_time() < time())) { + entity->die(); + } + } - if (entity->entity_destroyed) { - delete entity; - (*it).second = entity = 0; + // delete the entity if necessary + if ((*it).second->entity_destroyed) { + delete (*it).second; + (*it).second = 0; Entity::registry().erase(it++); } else { - entity->clear_updates(); + (*it).second->clear_updates(); ++it; } } @@ -607,10 +634,6 @@ void GameServer::frame(unsigned long timestamp) application()->notify_zonechange(); localplayer()->set_zonechange(false); } - - /*if (!Cvar::sv_dedicated->value()) { - update_clientstate(); - }*/ } void GameServer::save_config() |