diff options
author | Stijn Buys <ingar@osirion.org> | 2010-11-24 23:00:28 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-11-24 23:00:28 +0000 |
commit | 02b285bf20603bab6fc75d106acbaccead645eb9 (patch) | |
tree | 7be22d06339e1bb70b7ef5011312c13865976ced /src/core | |
parent | f66a28a68114f3c9efe109b6948ecec163cdb153 (diff) |
Actually add entities in the intro to their zone,
removed core::EntityControlable::movement(),
cleaned up core::EntityGlobe,
adds support for a per-globe corona,
adds core::EntityControlable::control_flags(),
bumps network protocol version to 21
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/entity.cc | 32 | ||||
-rw-r--r-- | src/core/entity.h | 91 | ||||
-rw-r--r-- | src/core/net.h | 2 | ||||
-rw-r--r-- | src/core/parser.cc | 26 |
4 files changed, 120 insertions, 31 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 013e66d..d6b0a10 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -711,7 +711,7 @@ void EntityControlable::ActionInterface::debugDraw(btIDebugDraw* debugDrawer) EntityControlable::EntityControlable() : EntityDynamic() { entity_thrust = 0; - entity_movement = 0; + entity_control_flags = 0; target_direction = 0.0f; target_thrust = 0.0f; @@ -729,7 +729,7 @@ EntityControlable::EntityControlable(std::istream & is) : EntityDynamic(is) { entity_thrust = 0; - entity_movement = 0; + entity_control_flags = 0; target_direction = 0.0f; target_thrust = 0.0f; @@ -828,8 +828,8 @@ void EntityControlable::receive_client_update(std::istream &is) void EntityControlable::serialize_server_update(std::ostream & os) const { EntityDynamic::serialize_server_update(os); - os << roundf(entity_thrust*100.0f) << " "; - os << roundf(entity_movement * 100.0f) << " "; + os << roundf(entity_thrust * 100.0f) << " "; + os << roundf(entity_control_flags) << " "; } void EntityControlable::receive_server_update(std::istream &is) @@ -837,8 +837,8 @@ void EntityControlable::receive_server_update(std::istream &is) EntityDynamic::receive_server_update(is); is >> entity_thrust; entity_thrust /= 100.0f; - is >> entity_movement; - entity_movement /= 100.0f; + + is >> entity_control_flags; } void EntityControlable::set_thrust(float thrust) @@ -1017,14 +1017,16 @@ void EntityControlable::frame(float seconds) EntityGlobe::EntityGlobe() : Entity() { - render_texture = 0; + entity_texture_id = 0; + entity_corona_id = 0; entity_rotationspeed = 0; set_shape(Sphere); } EntityGlobe::EntityGlobe(std::istream & is) : Entity(is) { - render_texture = 0; + entity_texture_id = 0; + entity_corona_id = 0; entity_rotationspeed = 0; set_shape(Sphere); } @@ -1036,7 +1038,7 @@ EntityGlobe::~EntityGlobe() void EntityGlobe::serialize_server_create(std::ostream & os) const { Entity::serialize_server_create(os); - os << entity_rotationspeed << " \"" << entity_texture << "\" "; + os << entity_rotationspeed << " \"" << texturename() << "\" \"" << coronaname() << "\" "; } void EntityGlobe::receive_server_create(std::istream &is) @@ -1047,12 +1049,20 @@ void EntityGlobe::receive_server_create(std::istream &is) std::string n; char c; + + // read texture name while ((is.get(c)) && (c != '"')); while ((is.get(c)) && (c != '"')) n += c; - entity_texture = n; + + entity_texturename.assign(n); + + // read corona name n.clear(); - + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; + entity_coronaname.assign(n); } } diff --git a/src/core/entity.h b/src/core/entity.h index 5c34f97..2d79132 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -595,6 +595,10 @@ class EntityControlable : public EntityDynamic { friend class Player; public: + + /// control flags + enum ControlFlags {ControlFlagNone = 0, ControlFlagImpulse = 1}; + /// bullet action interface class class ActionInterface: public btActionInterface { public: @@ -634,9 +638,9 @@ public: return entity_thrust; } - /// movement indicator - inline float movement() const { - return entity_movement; + /// control flags + inline unsigned int control_flags() const { + return entity_control_flags; } /// physics action @@ -656,6 +660,21 @@ public: virtual void serialize_server_update(std::ostream & os) const; /*----- mutators -------------------------------------------------- */ + + /// set all control flags + inline void set_control_flags(unsigned int control_flags) { + entity_control_flags = control_flags; + } + + /// set a single control flag + inline void set_control_flag(ControlFlags control_flag) { + entity_control_flags |= control_flag; + } + + /// unset a single control flag + inline void unset_control_flag(ControlFlags control_flag) { + entity_control_flags &= ~control_flag; + } /** * @brief set the zone the entity is currently in @@ -748,7 +767,7 @@ protected: float target_vstrafe; - float entity_movement; + unsigned int entity_control_flags; ActionInterface *entity_actioninterface; @@ -768,16 +787,58 @@ public: virtual ~EntityGlobe(); /*----- inspectors ----------------------------------------------- */ + /// core type id + virtual inline const unsigned int type() const { + return Entity::Globe; + } + /// texture name - inline const std::string &texture() const { - return entity_texture; + inline const std::string &texturename() const { + return entity_texturename; + } + + /// texture render id + inline size_t texture_id() const { + return entity_texture_id; + } + + /// corona texture name + inline const std::string &coronaname() const { + return entity_coronaname; } + /// corona texture id + inline size_t corona_id() const { + return entity_corona_id; + } + /// rotation speed in degrees per second inline float rotationspeed() const { return entity_rotationspeed; } + /*----- mutators -------------------------------------------------- */ + + inline void set_rotationspeed(const float rotationspeed) { + entity_rotationspeed = rotationspeed; + } + + inline void set_texture_id(size_t texture_id) { + entity_texture_id = texture_id; + } + + inline void set_corona_id(size_t texture_id) { + entity_corona_id = texture_id; + } + + inline void set_texturename(const std::string & texturename) { + entity_texturename.assign(texturename); + } + + inline void set_coronaname(const std::string & texturename) { + entity_coronaname.assign(texturename); + } + /*----- serializers ----------------------------------------------- */ /// serialize the entity to a stream @@ -786,20 +847,12 @@ public: /// receive a server-to-client create from a stream virtual void receive_server_create(std::istream &is); - /*----- inspectors ------------------------------------------------ */ - - /// core type id - virtual inline const unsigned int type() const { - return Entity::Globe; - } - - std::string entity_texture; - - /// client side, texture id - unsigned int render_texture; - - /// rotation speed in degrees/second; +private: float entity_rotationspeed; + size_t entity_texture_id; + size_t entity_corona_id; + std::string entity_texturename; + std::string entity_coronaname; }; } diff --git a/src/core/net.h b/src/core/net.h index 31fc6d7..f89d0d8 100644 --- a/src/core/net.h +++ b/src/core/net.h @@ -11,7 +11,7 @@ namespace core { /// network protocol version -const unsigned int PROTOCOLVERSION = 20; +const unsigned int PROTOCOLVERSION = 21; /// maximum lenght of a (compressed) network message block const unsigned int FRAMESIZE = 1152; diff --git a/src/core/parser.cc b/src/core/parser.cc index efcc58b..943cfb7 100644 --- a/src/core/parser.cc +++ b/src/core/parser.cc @@ -122,6 +122,32 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity) return true; } + // special globe keys + if (entity->type() == Entity::Globe) { + EntityGlobe *globe = static_cast<EntityGlobe *>(entity); + + if (inifile.got_key_string("texture", strval)) { + globe->set_texturename(strval); + return true; + + } else if (inifile.got_key_string("corona", strval)) { + globe->set_coronaname(strval); + return true; + + } else if (inifile.got_key_float("rotationspeed", f)) { + globe->set_rotationspeed(f); + return true; + + } else if (inifile.got_key_bool("bright", blnval)) { + if (blnval) { + globe->set_flag(core::Entity::Bright); + } else { + globe->unset_flag(core::Entity::Bright); + } + return true; + } + } + return false; } |