From 7888930bf0a75999e103f7781c095e04b6860ee5 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 15 Nov 2009 15:35:59 +0000 Subject: added entity request network message --- src/core/entity.cc | 33 +++--- src/core/entity.h | 14 ++- src/core/gameconnection.cc | 2 +- src/core/netconnection.cc | 245 ++++++++++++++++++++++++++---------------- src/core/netconnection.h | 5 +- src/core/netserver.cc | 130 ++++++++++++---------- src/game/base/jumppoint.cc | 4 +- src/game/base/navpoint.cc | 8 +- src/game/base/planet.cc | 4 +- src/game/base/ship.cc | 27 ++--- src/game/base/star.cc | 5 +- src/game/example/spectator.cc | 9 +- src/game/intro/convoy.cc | 5 +- 13 files changed, 298 insertions(+), 193 deletions(-) diff --git a/src/core/entity.cc b/src/core/entity.cc index ece1e9b..aa9e45b 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -112,13 +112,13 @@ void Entity::list() /* ---- class Entity ----------------------------------------------- */ -Entity::Entity(const unsigned int flags) : +Entity::Entity() : entity_location(0.0f, 0.0f, 0.0f), entity_color(1.0f, 1.0f, 1.0f, 1.0f), entity_color_second(1.0f, 1.0f, 1.0f, 1.0f) { entity_id = 0; - entity_flags = flags; + entity_flags = 0; entity_moduletypeid = 0; entity_speed = 0.0f; @@ -391,15 +391,13 @@ void Entity::remove_menu(std::string const &label) /* ---- class EntityDynamic ---------------------------------------- */ -EntityDynamic::EntityDynamic(unsigned int flags) : - Entity(flags) +EntityDynamic::EntityDynamic() : Entity() { entity_state = Normal; entity_timer = 0; } -EntityDynamic::EntityDynamic(std::istream & is) : - Entity(is) +EntityDynamic::EntityDynamic(std::istream & is) : Entity(is) { entity_state = Normal; entity_timer = 0; @@ -507,8 +505,7 @@ void EntityDynamic::receive_server_update(std::istream &is) /*----- EntityControlable ------------------------------------------ */ -EntityControlable::EntityControlable(Player *owner, unsigned int flags) : - EntityDynamic(flags) +EntityControlable::EntityControlable() : EntityDynamic() { entity_thrust = 0; entity_movement = 0; @@ -521,8 +518,6 @@ EntityControlable::EntityControlable(Player *owner, unsigned int flags) : target_afterburner = 0.0f; entity_owner = 0; - if (owner) - owner->add_asset(this); } EntityControlable::EntityControlable(std::istream & is) : @@ -548,6 +543,18 @@ EntityControlable::~EntityControlable() entity_owner->remove_asset(this); } +void EntityControlable::set_owner(Player *owner) +{ + if (entity_owner) + entity_owner->remove_asset(this); + + entity_owner = owner; + + if (entity_owner) + entity_owner->add_asset(this); + +} + void EntityControlable::serialize_server_create(std::ostream & os) const { EntityDynamic::serialize_server_create(os); @@ -696,16 +703,14 @@ void EntityControlable::set_afterburner(float afterburner) /*----- EntityGlobe ------------------------------------------------ */ -EntityGlobe::EntityGlobe(unsigned int flags) : - Entity(flags) +EntityGlobe::EntityGlobe() : Entity() { render_texture = 0; entity_rotationspeed = 0; entity_shape = Sphere; } -EntityGlobe::EntityGlobe(std::istream & is) : - Entity(is) +EntityGlobe::EntityGlobe(std::istream & is) : Entity(is) { render_texture = 0; entity_rotationspeed = 0; diff --git a/src/core/entity.h b/src/core/entity.h index ae2585d..1bc93a1 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -56,7 +56,7 @@ public: typedef std::list Menus; /// create a new entity and add it to the registry - Entity(const unsigned int flags = 0); + Entity(); /// create an entity from stream data Entity(std::istream & is); @@ -413,7 +413,7 @@ class EntityDynamic : public Entity { public: /// create a dynamic entity - EntityDynamic(const unsigned int flags = 0); + EntityDynamic(); /// create a dynamic entity from stream data EntityDynamic(std::istream & is); @@ -479,8 +479,8 @@ class EntityControlable : public EntityDynamic { friend class Player; public: - /// create a controlable entity - EntityControlable(Player *owner, const unsigned int flags = 0); + /// server-side constructor, create a controlable entity + EntityControlable(); /// create a controlable entity from stream data EntityControlable(std::istream & is); @@ -531,6 +531,9 @@ public: /// receive a server-to-client update from a stream virtual void receive_server_update(std::istream &is); + /// set the player who owns this entity + void set_owner(Player *owner); + /// set the target thrust void set_thrust(float thrust); @@ -591,7 +594,8 @@ private: class EntityGlobe : public Entity { public: - EntityGlobe(const unsigned int flags = 0); + /// server-side constructor + EntityGlobe(); EntityGlobe(std::istream & is); virtual ~EntityGlobe(); diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index f0dfbc6..0da1803 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -205,7 +205,7 @@ void GameConnection::frame(unsigned long timestamp) if (connection_network->state() == NetConnection::Connected) { if (localcontrol() && localcontrol()->dirty()) { - connection_network->send_clientupdate(localcontrol()); + connection_network->send_client_update(localcontrol()); localcontrol()->set_dirty(false); } diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 1318467..0a816b8 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -356,7 +356,7 @@ void NetConnection::send_playerinfo() } // send a "cup" client update message to the server -void NetConnection::send_clientupdate(Entity *entity) +void NetConnection::send_client_update(Entity *entity) { // cup std::ostringstream msg; @@ -366,6 +366,15 @@ void NetConnection::send_clientupdate(Entity *entity) this->send_raw(msg.str()); } +// send a "req" entity request +void NetConnection::send_entity_request(Entity *entity) +{ + // req + std::ostringstream msg; + msg << "req " << entity->id() << '\n'; + this->send_raw(msg.str()); +} + // send a "cmd" command line message to the server void NetConnection::send_command(std::string const &cmdline) { @@ -440,12 +449,12 @@ void NetConnection::send_info_request(Info *info) * msg rcon * msg snd * die - * ent + * ent * frame - * sup + * sup * pif * pid - * inf + * inf