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-07 23:27:42 +0000
committerStijn Buys <ingar@osirion.org>2008-08-07 23:27:42 +0000
commita743791e624590e0b41229f28f940db5272b60ba (patch)
tree6a6ec736e4ed34d5254a292889e6e33300919a63 /src/core/entity.cc
parent1f36b993d603c56251aa15eb6edc6b92ecf599ae (diff)
rotating planets, navpoints, network protocol updates, entity event state
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r--src/core/entity.cc104
1 files changed, 61 insertions, 43 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 483f58c..a4b6ee5 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -170,18 +170,18 @@ void Entity::set_zone(Zone *zone)
void Entity::serialize_server_create(std::ostream & os) const
{
os << entity_moduletypeid << " "
- << entity_flags << " "
- << (entity_zone ? entity_zone->id() : 0) << " "
- << entity_location << " "
- << entity_color << " "
- << entity_color_second << " "
- << entity_shape << " "
- << entity_radius << " "
- << entity_axis.forward() << " "
- << entity_axis.left() << " "
- << "\"" << entity_label << "\" "
- << "\"" << entity_name << "\" "
- << "\"" << entity_modelname << "\"";
+ << entity_flags << " "
+ << (entity_zone ? entity_zone->id() : 0) << " "
+ << entity_location << " "
+ << entity_color << " "
+ << entity_color_second << " "
+ << entity_shape << " "
+ << entity_radius << " "
+ << entity_axis.forward() << " "
+ << entity_axis.left() << " "
+ << "\"" << entity_label << "\" "
+ << "\"" << entity_name << "\" "
+ << "\"" << entity_modelname << "\" ";
}
void Entity::receive_server_create(std::istream &is)
@@ -263,12 +263,16 @@ EntityDynamic::EntityDynamic(unsigned int flags) :
Entity(flags)
{
entity_speed = 0.0f;
+ entity_eventstate = Normal;
+ entity_timer = 0;
}
EntityDynamic::EntityDynamic(std::istream & is) :
Entity(is)
{
entity_speed = 0.0f;
+ entity_eventstate = Normal;
+ entity_timer = 0;
}
EntityDynamic::~EntityDynamic()
@@ -291,13 +295,26 @@ void EntityDynamic::frame(float seconds)
void EntityDynamic::serialize_server_create(std::ostream & os) const
{
Entity::serialize_server_create(os);
- os << " " << entity_speed;
+ os << roundf(entity_speed * 100.0f) << " "
+ << entity_eventstate << " ";
+
+ if (entity_eventstate != Normal) {
+ os << entity_timer << " ";
+ }
}
void EntityDynamic::receive_server_create(std::istream &is)
{
Entity::receive_server_create(is);
is >> entity_speed;
+ entity_speed /= 100.0f;
+ is >> entity_eventstate;
+
+ if (entity_eventstate != Normal) {
+ is >> entity_timer;
+ } else {
+ entity_timer = 0;
+ }
}
void EntityDynamic::serialize_client_update(std::ostream & os) const
@@ -310,10 +327,15 @@ void EntityDynamic::receive_client_update(std::istream &is)
void EntityDynamic::serialize_server_update(std::ostream & os) const
{
- os << entity_location << " ";
- os << entity_axis.forward() << " ";
- os << entity_axis.left() << " ";
- os << entity_speed;
+ os << 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)
@@ -324,6 +346,14 @@ void EntityDynamic::receive_server_update(std::istream &is)
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;
+ }
}
/*----- EntityControlable ------------------------------------------ */
@@ -332,7 +362,6 @@ EntityControlable::EntityControlable(Player *owner, unsigned int flags) :
EntityDynamic(flags)
{
entity_thrust = 0;
- entity_autolevel = false;
target_direction = 0.0f;
target_thrust = 0.0f;
@@ -348,7 +377,6 @@ EntityControlable::EntityControlable(std::istream & is) :
EntityDynamic(is)
{
entity_thrust = 0;
- entity_autolevel = false;
target_direction = 0.0f;
target_thrust = 0.0f;
@@ -368,8 +396,8 @@ EntityControlable::~EntityControlable()
void EntityControlable::serialize_server_create(std::ostream & os) const
{
EntityDynamic::serialize_server_create(os);
- os << " " << entity_thrust;
- os << " " << ( entity_owner ? entity_owner->id() : 0);
+ os << roundf(entity_thrust*100.0f) << " "
+ << ( entity_owner ? entity_owner->id() : 0) << " ";
}
void EntityControlable::receive_server_create(std::istream &is)
@@ -378,6 +406,7 @@ void EntityControlable::receive_server_create(std::istream &is)
EntityDynamic::receive_server_create(is);
is >> entity_thrust;
+ entity_thrust /= 100.0f;
is >> o;
// FIXME resolve owner
@@ -387,12 +416,10 @@ void EntityControlable::receive_server_create(std::istream &is)
void EntityControlable::serialize_client_update(std::ostream & os) const
{
EntityDynamic::serialize_client_update(os);
- os << " " << target_direction;
- os << " " << target_pitch;
- os << " " << target_thrust;
- os << " " << target_roll;
- os << " " << (autolevel() ? 1 : 0);
-
+ os << target_direction << " ";
+ os << target_pitch << " ";
+ os << target_thrust << " ";
+ os << target_roll << " ";
}
void EntityControlable::receive_client_update(std::istream &is)
@@ -402,25 +429,19 @@ void EntityControlable::receive_client_update(std::istream &is)
is >> target_pitch;
is >> target_thrust;
is >> target_roll;
-
- unsigned int b = 0;
- is >> b;
- if (b)
- entity_autolevel = true;
- else
- entity_autolevel = false;
}
void EntityControlable::serialize_server_update(std::ostream & os) const
{
EntityDynamic::serialize_server_update(os);
- os << " " << entity_thrust;
+ os << roundf(entity_thrust*100.0f) << " ";
}
void EntityControlable::receive_server_update(std::istream &is)
{
EntityDynamic::receive_server_update(is);
is >> entity_thrust;
+ entity_thrust /= 100.0f;
}
void EntityControlable::frame(float seconds)
@@ -442,13 +463,6 @@ void EntityControlable::set_thrust(float thrust)
}
}
-void EntityControlable::set_autolevel(bool autolevel)
-{
- if (entity_autolevel != autolevel) {
- entity_autolevel = autolevel;
- entity_dirty = true;
- }
-}
void EntityControlable::set_direction(float direction)
{
if ((flags() & Static) == Static)
@@ -488,6 +502,7 @@ EntityGlobe::EntityGlobe(unsigned int flags) :
Entity(flags)
{
render_texture = 0;
+ entity_rotationspeed = 0;
entity_shape = Sphere;
}
@@ -495,6 +510,7 @@ EntityGlobe::EntityGlobe(std::istream & is) :
Entity(is)
{
render_texture = 0;
+ entity_rotationspeed = 0;
entity_shape = Sphere;
}
@@ -505,13 +521,15 @@ EntityGlobe::~EntityGlobe()
void EntityGlobe::serialize_server_create(std::ostream & os) const
{
Entity::serialize_server_create(os);
- os << " \"" << entity_texture << "\"";
+ os << entity_rotationspeed << " \"" << entity_texture << "\" ";
}
void EntityGlobe::receive_server_create(std::istream &is)
{
Entity::receive_server_create(is);
+ is >> entity_rotationspeed;
+
std::string n;
char c;
while ( (is.get(c)) && (c != '"'));