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>2008-08-04 18:24:36 +0000
committerStijn Buys <ingar@osirion.org>2008-08-04 18:24:36 +0000
commit50a1e2b2fe3c207c7227df4941f2f66990db0c2c (patch)
tree5c4293babed4434d81cf9284f522dd0e74482cf0 /src/core/entity.cc
parentebd5cd9daabb2d2eb6f5e06f9433cc8e6a4e0f7a (diff)
network protocol version 5, netserver per-client updates, zone change protocol
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r--src/core/entity.cc179
1 files changed, 97 insertions, 82 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 20e1b05..060ceab 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -77,7 +77,7 @@ void Entity::list()
con_print << entity_registry.size() << " registered entities" << std::endl;
}
-/*----- Entity ----------------------------------------------------- */
+/*----- class Entity ----------------------------------------------- */
Entity::Entity(unsigned int flags) :
entity_location(0.0f, 0.0f, 0.0f),
@@ -109,65 +109,13 @@ Entity::Entity(unsigned int flags) :
Entity::Entity(std::istream & is)
{
+ entity_id = 0;
entity_zone = 0;
-
- // type is already determined
- unsigned int s;
- std::string n;
-
- is >> entity_id;
- is >> entity_moduletypeid;
- is >> entity_flags;
- is >> s;
-
- set_zone(Zone::find(s));
- if (entity_zone && !s) {
- con_warn << "Received entity " << entity_id << " for unknown zone " << s << "!" << std::endl;
- }
-
- is >> entity_location;
- is >> entity_color;
- is >> entity_color_second;
-
- is >> s; // shape
- entity_shape = (Shape) s;
-
- is >> entity_radius;
-
- is >> entity_axis[0];
- is >> entity_axis[1];
- entity_axis[2] = math::crossproduct(entity_axis.forward(), entity_axis.left());
-
- char c;
- // read label
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
- entity_label = n;
- n.clear();
-
- // read name
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
- entity_name = n;
- n.clear();
-
- // read model name
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
- entity_modelname = n;
- entity_model = 0; // this will be resolved later
+ entity_model = 0;
+ entity_clientstate = 0;
entity_created = true;
entity_destroyed = false;
- entity_dirty = false;
-
- // this entity is created clientside
- entity_clientstate = 0;
-
- add(this, entity_id);
}
Entity::~Entity()
@@ -201,11 +149,9 @@ void Entity::set_zone(Zone *zone)
entity_zone->add(this);
}
-void Entity::serialize(std::ostream & os) const
+void Entity::serialize_server_create(std::ostream & os) const
{
- os << type() << " "
- << entity_id << " "
- << entity_moduletypeid << " "
+ os << entity_moduletypeid << " "
<< entity_flags << " "
<< (entity_zone ? entity_zone->id() : 0) << " "
<< entity_location << " "
@@ -220,6 +166,58 @@ void Entity::serialize(std::ostream & os) const
<< "\"" << entity_modelname << "\"";
}
+void Entity::receive_server_create(std::istream &is)
+{
+ unsigned int s;
+ unsigned int zo;
+ std::string n;
+
+ is >> entity_moduletypeid;
+ is >> entity_flags;
+ is >> zo;
+
+ set_zone(Zone::find(zo));
+ if (entity_zone && !zo) {
+ con_warn << "Received entity " << entity_id << " for unknown zone " << zo << "!" << std::endl;
+ }
+
+ is >> entity_location;
+ is >> entity_color;
+ is >> entity_color_second;
+
+ is >> s; // shape
+ entity_shape = (Shape) s;
+
+ is >> entity_radius;
+
+ is >> entity_axis[0];
+ is >> entity_axis[1];
+ entity_axis[2] = math::crossproduct(entity_axis.forward(), entity_axis.left());
+
+ char c;
+ // read label
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+ entity_label = n;
+ n.clear();
+
+ // read name
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+ entity_name = n;
+ n.clear();
+
+ // read model name
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+ entity_modelname = n;
+
+ entity_dirty = false;
+}
+
void Entity::serialize_client_update(std::ostream & os) const
{
}
@@ -241,7 +239,7 @@ void Entity::frame(float seconds)
{
}
-/* ---- EntityDynamic ---------------------------------------------- */
+/* ---- class EntityDynamic ---------------------------------------- */
EntityDynamic::EntityDynamic(unsigned int flags) :
Entity(flags)
@@ -252,7 +250,7 @@ EntityDynamic::EntityDynamic(unsigned int flags) :
EntityDynamic::EntityDynamic(std::istream & is) :
Entity(is)
{
- is >> entity_speed;
+ entity_speed = 0.0f;
}
EntityDynamic::~EntityDynamic()
@@ -272,12 +270,18 @@ void EntityDynamic::frame(float seconds)
entity_dirty = true;
}
-void EntityDynamic::serialize(std::ostream & os) const
+void EntityDynamic::serialize_server_create(std::ostream & os) const
{
- Entity::serialize(os);
+ Entity::serialize_server_create(os);
os << " " << entity_speed;
}
+void EntityDynamic::receive_server_create(std::istream &is)
+{
+ Entity::receive_server_create(is);
+ is >> entity_speed;
+}
+
void EntityDynamic::serialize_client_update(std::ostream & os) const
{
}
@@ -340,8 +344,6 @@ EntityControlable::EntityControlable(Player *owner, unsigned int flags) :
EntityControlable::EntityControlable(std::istream & is) :
EntityDynamic(is)
{
- unsigned int o;
-
entity_thrust = 0;
entity_autolevel = false;
@@ -350,10 +352,6 @@ EntityControlable::EntityControlable(std::istream & is) :
target_pitch = 0.0f;
target_roll = 0.0f;
- is >> entity_thrust;
- is >> o;
-
- // FIXME resolve owner
entity_owner = 0;
}
@@ -364,13 +362,25 @@ EntityControlable::~EntityControlable()
entity_owner->remove_asset(this);
}
-void EntityControlable::serialize(std::ostream & os) const
+void EntityControlable::serialize_server_create(std::ostream & os) const
{
- EntityDynamic::serialize(os);
+ EntityDynamic::serialize_server_create(os);
os << " " << entity_thrust;
os << " " << ( entity_owner ? entity_owner->id() : 0);
}
+void EntityControlable::receive_server_create(std::istream &is)
+{
+ unsigned int o;
+
+ EntityDynamic::receive_server_create(is);
+ is >> entity_thrust;
+ is >> o;
+
+ // FIXME resolve owner
+ entity_owner = 0;
+}
+
void EntityControlable::serialize_client_update(std::ostream & os) const
{
EntityDynamic::serialize_client_update(os);
@@ -483,6 +493,21 @@ EntityGlobe::EntityGlobe(std::istream & is) :
{
render_texture = 0;
entity_shape = Sphere;
+}
+
+EntityGlobe::~EntityGlobe()
+{
+}
+
+void EntityGlobe::serialize_server_create(std::ostream & os) const
+{
+ Entity::serialize_server_create(os);
+ os << " \"" << entity_texture << "\"";
+}
+
+void EntityGlobe::receive_server_create(std::istream &is)
+{
+ Entity::receive_server_create(is);
std::string n;
char c;
@@ -494,15 +519,5 @@ EntityGlobe::EntityGlobe(std::istream & is) :
}
-EntityGlobe::~EntityGlobe()
-{
-}
-
-void EntityGlobe::serialize(std::ostream & os) const
-{
- Entity::serialize(os);
- os << " \"" << entity_texture << "\"";
-}
-
}