Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-10-24 16:02:09 +0000
committerStijn Buys <ingar@osirion.org>2010-10-24 16:02:09 +0000
commita704318f507f486ac04834747eb209d0a9410702 (patch)
treeb6f3f6df4b285be0b9c6e91c0486271daf0bb6ee /src/core/gameserver.cc
parentc2a6f7c2ee6245109c897ee23b093b5277a30594 (diff)
keepalive optimizations, r_lights engine variable, OpenGL VBO support
Diffstat (limited to 'src/core/gameserver.cc')
-rw-r--r--src/core/gameserver.cc41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index e6c44d0..344c069 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -588,38 +588,35 @@ void GameServer::frame(unsigned long timestamp)
// send network updates
server_network->frame(server_timestamp);
}
-
- // mark all entities as updated
+
const float keepalive_distance_squared = range::fxdistance * range::fxdistance;
+
+ // FIXME KeepAlive sweep has to be done in linear order, O(n^2) is extremely slow with a large number of entities
- for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) {
+ for (Entity::Registry::const_iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) {
- // perform a keep-alive pass
- if ((*it).second->flag_is_set(Entity::KeepAlive) && ((*it).second->type() == Entity::Dynamic) && (*it).second->zone()) {
+ // set keepalive timeout
+ if ((*it).second->type() == Entity::Controlable) {
+ const EntityControlable *controlable = static_cast<const EntityControlable *>((*it).second);
- 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)) {
+ if ( (controlable->state() != Entity::Docked) && controlable->owner() && controlable->zone() ) {
+ for (Zone::Content::iterator zit = controlable->zone()->content().begin(); zit != controlable->zone()->content().end(); zit++) {
- 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 ( ((*zit)->flag_is_set(Entity::KeepAlive)) && ((*zit)->type() == Entity::Dynamic) && ((*zit) != controlable) ) {
+ EntityDynamic *dynamic = static_cast<EntityDynamic *>(*zit);
+ if (math::distancesquared(controlable->location(), dynamic->location()) < keepalive_distance_squared) {
+ dynamic->set_keepalive_time(time() + dynamic->keepalive_timeout());
+ }
}
}
-
}
- if (keepalive) {
- entity->set_keepalive_time(time() + entity->keepalive_timeout());
- } else if ((entity->keepalive_time() > 0.0f) && (entity->keepalive_time() < time())) {
- entity->die();
- }
}
-
- // delete the entity if necessary
+ }
+
+ // remove deleted entities and mark remaining entities as updated
+ for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) {
+ // remove deleted entities
if ((*it).second->entity_destroyed) {
delete (*it).second;
(*it).second = 0;