diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/entity.cc | 22 | ||||
-rw-r--r-- | src/core/entity.h | 22 |
2 files changed, 40 insertions, 4 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 64546a7..e7cd70a 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -22,7 +22,9 @@ namespace core { // maximal number of entities -const size_t MAX_ENTITY = 1048574; +const size_t MAX_ENTITY = 1048574; +// minimal speed +const float SPEED_THRESHOLD = 0.01f; using math::Color; using math::Vector3f; @@ -927,7 +929,14 @@ void EntityDynamic::frame(const unsigned long elapsed) if (entity_speed > 0) { set_dirty(); } - entity_speed = (float) entity_body->getLinearVelocity().length(); + + if (entity_speed < SPEED_THRESHOLD) { + entity_body->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + entity_speed = 0.0f; + } else { + entity_speed = (float) entity_body->getLinearVelocity().length(); + } + if (entity_speed > 0) { set_dirty(); } @@ -936,6 +945,9 @@ void EntityDynamic::frame(const unsigned long elapsed) if (entity_angular > 0) { set_dirty(); } + if (entity_angular < SPEED_THRESHOLD) { + entity_body->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f)); + } } } @@ -1058,6 +1070,7 @@ EntityControlable::EntityControlable() : EntityDynamic() entity_actioninterface = 0; entity_controlflags = 0; + entity_health = 100.0f; } EntityControlable::EntityControlable(std::istream & is) : @@ -1078,6 +1091,7 @@ EntityControlable::EntityControlable(std::istream & is) : entity_actioninterface = 0; entity_controlflags = 0; + entity_health = 100.0f; } @@ -1173,7 +1187,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(thrust() * 100.0f) << " "; + os << roundf(health()) << " "; } void EntityControlable::receive_server_update(std::istream &is) @@ -1181,6 +1196,7 @@ void EntityControlable::receive_server_update(std::istream &is) EntityDynamic::receive_server_update(is); is >> entity_thrust; entity_thrust /= 100.0f; + is >> entity_health; } void EntityControlable::set_target_thrust(float thrust) diff --git a/src/core/entity.h b/src/core/entity.h index 31ed67b..0be81b9 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -349,11 +349,20 @@ public: /** * @brief unset flag * */ - inline void unset_flag(Flags flag) { + inline void unset_flag(Flags flag) + { entity_flags &= ~((unsigned int) flag); } /** + * @brief set flags + * */ + inline void set_flags(unsigned int flags) + { + entity_flags = flags; + } + + /** * @brief add an inventory to this entity * If this entity already has an inventory, * the current inventory will be return @@ -725,6 +734,14 @@ public: return entity_actioninterface; } + /** + * @brief current health, 0 - 100 + * */ + inline const float health() const + { + return entity_health; + } + /*----- serializers ----------------------------------------------- */ /// serialize the entity to a stream @@ -810,6 +827,9 @@ protected: /// current thrust float entity_thrust; + + /// current health + float entity_health; /* target_ variables can be set by the client */ |