From 35613f0860a2d8cb643ca8de006de08503e48e53 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 18 Oct 2008 17:58:45 +0000 Subject: example module --- src/core/entity.cc | 83 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 23 deletions(-) (limited to 'src/core/entity.cc') diff --git a/src/core/entity.cc b/src/core/entity.cc index e74b8b5..27190a0 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -177,7 +177,7 @@ void Entity::set_label(char const *label) aux::to_label(entity_label); } -void Entity::set_label(std::string const &label) +void Entity::set_label(const std::string &label) { entity_label.assign(label); aux::to_label(entity_label); @@ -189,16 +189,35 @@ void Entity::set_name(char const *name) aux::strip_quotes(entity_name); } -void Entity::set_name(std::string const &name) +void Entity::set_name(const std::string &name) { entity_name.assign(name); aux::strip_quotes(entity_name); } +void Entity::set_visible(bool visible) +{ + if (visible) + show(); + else + hide(); +} + +void Entity::show() +{ + entity_visible = false; +} + +void Entity::hide() +{ + entity_visible = false; +} + void Entity::serialize_server_create(std::ostream & os) const { os << entity_moduletypeid << " " << entity_flags << " " + << (entity_visible ? 1 : 0) << " " << (entity_zone ? entity_zone->id() : 0) << " " << std::setprecision(8) << entity_location << " " << entity_color << " " @@ -216,10 +235,18 @@ void Entity::receive_server_create(std::istream &is) { unsigned int s; unsigned int zo; + unsigned int o = 0; std::string n; is >> entity_moduletypeid; is >> entity_flags; + + is >> o; + if (o) + entity_visible = true; + else + entity_visible = false; + is >> zo; set_zone(Zone::find(zo)); @@ -363,33 +390,43 @@ void EntityDynamic::receive_client_update(std::istream &is) void EntityDynamic::serialize_server_update(std::ostream & os) const { - os << std::setprecision(8) - << entity_location << " " - << entity_axis.forward() << " " - << entity_axis.left() << " " - << roundf(entity_speed * 100.0f) << " " - << entity_eventstate << " "; - - if (entity_eventstate != Normal) { - os << entity_timer << " "; + os << (visible() ? 1 : 0 ) << " "; + if (visible()) { + os << std::setprecision(8) + << entity_location << " " + << entity_axis.forward() << " " + << entity_axis.left() << " " + << roundf(entity_speed * 100.0f) << " " + << entity_eventstate << " "; + + if (entity_eventstate != Normal) { + os << entity_timer << " "; + } } } void EntityDynamic::receive_server_update(std::istream &is) { - 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; - entity_speed /= 100.0f; - is >> entity_eventstate; - - if (entity_eventstate != Normal) { - is >> entity_timer; + unsigned int o; + is >> o; // visibility + if (o) { + entity_visible = true; + 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; + entity_speed /= 100.0f; + is >> entity_eventstate; + + if (entity_eventstate != Normal) { + is >> entity_timer; + } else { + entity_timer = 0; + } } else { - entity_timer = 0; + entity_visible = false; } } -- cgit v1.2.3