From a743791e624590e0b41229f28f940db5272b60ba Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 7 Aug 2008 23:27:42 +0000 Subject: rotating planets, navpoints, network protocol updates, entity event state --- src/core/entity.cc | 104 +++++++++++++++++++++++++++++++---------------------- src/core/entity.h | 45 ++++++++++++++++------- src/core/net.h | 2 +- src/core/zone.cc | 3 +- 4 files changed, 96 insertions(+), 58 deletions(-) (limited to 'src/core') 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 != '"')); diff --git a/src/core/entity.h b/src/core/entity.h index 40d1ffa..2b2ed00 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -46,6 +46,9 @@ public: /// Entity shape constants enum Shape {Diamond=0, Sphere=1, Cube=2, Axis=3}; + /// EntityDynamic event state classes + enum Event {Normal=0, ImpulseInitiate=2, Impulse=3, JumpInitiate=4, Jump=5}; + /// create a new entity and add it to the registry Entity(unsigned int flags = 0); @@ -111,6 +114,8 @@ public: /// base radius of the entity inline float radius() const { return entity_radius; } +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -120,7 +125,6 @@ public: /// serialize a server-to-client update on a stream virtual void serialize_server_update(std::ostream & os) const; - /*----- mutators -------------------------------------------------- */ /// receive a client-to-server update from a stream @@ -227,7 +231,6 @@ public: virtual ~EntityDynamic(); - /*----- inspectors ------------------------------------------------ */ /// core type id virtual inline unsigned int type() const { return Entity::Dynamic; } @@ -235,6 +238,14 @@ public: /// current speed of the entity in game units per second inline float speed() const { return entity_speed; } + /// event state + inline unsigned int eventstate() const { return entity_eventstate; } + + /// event state timer + inline float timer() const { return entity_timer; } + +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -264,13 +275,17 @@ public: /// speed of the entity float entity_speed; + +protected: + unsigned int entity_eventstate; + float entity_timer; + }; /// an entity that can be controlled by a player class EntityControlable : public EntityDynamic { friend class Player; - public: /// create a controlable entity EntityControlable(Player *owner, unsigned int flags = 0); @@ -292,6 +307,8 @@ public: /// thrust inline float thrust() const { return entity_thrust; } +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -301,10 +318,6 @@ public: /// serialize a server-to-client update on a stream virtual void serialize_server_update(std::ostream & os) const; - /// autolevel mode - bool autolevel() const { return entity_autolevel; } - - /*----- mutators -------------------------------------------------- */ /// receive a client-to-server update from a stream @@ -322,9 +335,6 @@ public: /// set the target direction void set_direction(float direction); - /// set autolevel request - void set_autolevel(bool autolevel); - /// set the target pitch void set_pitch(float pitch); @@ -360,7 +370,6 @@ public: private: // owner of the entity Player *entity_owner; - bool entity_autolevel; }; /// a Globe entity @@ -372,14 +381,21 @@ public: ~EntityGlobe(); +/*----- inspectors ----------------------------------------------- */ + /// texture name + inline const std::string &texture() const { return entity_texture; } + + /// rotation speed in degrees per second + inline float rotationspeed() const { return entity_rotationspeed; } + +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; /// receive a server-to-client create from a stream virtual void receive_server_create(std::istream &is); - inline const std::string &texture() const { return entity_texture; } - /*----- inspectors ------------------------------------------------ */ /// core type id @@ -389,6 +405,9 @@ public: /// client side, texture id unsigned int render_texture; + + /// rotation speed in degrees/second; + float entity_rotationspeed; }; } diff --git a/src/core/net.h b/src/core/net.h index 0c2b5a6..d5a95a9 100644 --- a/src/core/net.h +++ b/src/core/net.h @@ -11,7 +11,7 @@ namespace core { /// network protocol version -const unsigned int PROTOCOLVERSION = 6; +const unsigned int PROTOCOLVERSION = 7; /// maximum lenght of a (compressed) network message block const unsigned int FRAMESIZE = 1152; diff --git a/src/core/zone.cc b/src/core/zone.cc index a81736d..87ab9b4 100644 --- a/src/core/zone.cc +++ b/src/core/zone.cc @@ -103,7 +103,8 @@ void Zone::list_zone(std::string const & searchname) con_print << " id " << std::setw(4) << entity->id() << " type " << std::setw(4) << entity->type() << ":" << std::setw(4) << entity->moduletype() - << " " << entity->label() << std::endl; + << " " << std::setw(24) << entity->label() + << " ^B" << entity->name() << "^N" << std::endl; } con_print << zone->zone_content.size() << " zone entities" << std::endl; } -- cgit v1.2.3