diff options
author | Stijn Buys <ingar@osirion.org> | 2008-08-05 13:31:12 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-08-05 13:31:12 +0000 |
commit | 37d132313dbed8007ee6e5cb3c61d59548fb3d4b (patch) | |
tree | 914fd90d3e8d01296fd0924c6c7428c5ccc781d6 /src/core/entity.cc | |
parent | 7ac353a7895f1ab30d09268968bc85ef9394cf41 (diff) |
server-side detection of entity zone changes, netserver ent/die responses, removed zone from sup messages
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r-- | src/core/entity.cc | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 060ceab..483f58c 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -14,17 +14,22 @@ namespace core { +// maximal number of entities +const size_t MAX_ENTITY = 1048574; + using math::Color; using math::Vector3f; /* ---- Static functions for the Entity registry ------------------- */ Entity::Registry Entity::entity_registry; +size_t Entity::entity_nextid = 0; void Entity::add(Entity *ent) { Registry::iterator it; - unsigned int id = 1; + entity_nextid = (entity_nextid % MAX_ENTITY) + 1; // lowest entity-id is 1 + unsigned int id = entity_nextid; for (it = entity_registry.begin(); it != entity_registry.end() && id == (*it).second->id(); it++) { id++; } @@ -103,6 +108,7 @@ Entity::Entity(unsigned int flags) : entity_clientstate = 0; entity_zone = 0; + entity_oldzone = 0; add(this); } @@ -111,6 +117,8 @@ Entity::Entity(std::istream & is) { entity_id = 0; entity_zone = 0; + entity_oldzone = 0; + entity_model = 0; entity_clientstate = 0; @@ -134,6 +142,13 @@ void Entity::die() entity_destroyed = true; } +void Entity::clear_updates() +{ + entity_created = false; + entity_dirty = false; + entity_oldzone = 0; +} + void Entity::set_zone(Zone *zone) { if (entity_zone == zone) @@ -142,6 +157,9 @@ void Entity::set_zone(Zone *zone) if (entity_zone) entity_zone->remove(this); + if (!entity_oldzone) + entity_oldzone = entity_zone; + entity_zone = zone; entity_dirty = true; @@ -292,7 +310,6 @@ void EntityDynamic::receive_client_update(std::istream &is) void EntityDynamic::serialize_server_update(std::ostream & os) const { - os << (entity_zone ? entity_zone->id() : 0) << " "; os << entity_location << " "; os << entity_axis.forward() << " "; os << entity_axis.left() << " "; @@ -301,26 +318,12 @@ void EntityDynamic::serialize_server_update(std::ostream & os) const void EntityDynamic::receive_server_update(std::istream &is) { - unsigned int zone_id; - is >> zone_id; is >> entity_location; // axis up vector is the crossproduct of forward and left is >> entity_axis[0]; is >> entity_axis[1]; entity_axis[2] = math::crossproduct(entity_axis.forward(), entity_axis.left()); is >> entity_speed; - - - if (!zone_id) { - if (entity_zone) { - entity_zone->remove(this); - entity_zone = 0; - } - } else { - if (zone_id != entity_zone->id()) { - set_zone(Zone::find(zone_id)); - } - } } /*----- EntityControlable ------------------------------------------ */ |