Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-11-10 22:23:50 +0000
committerStijn Buys <ingar@osirion.org>2013-11-10 22:23:50 +0000
commit8039544940b6145dcc8c63bcd4e06073ed61801e (patch)
treef3adf9eebb1ffe6a8c53e57c64546eeaa61a3517 /src/core
parent3b75b41676bd2851b6d2b61d3e3213ee50078870 (diff)
Renamed entity_destroyed to entity_died to prevent confusion with the Entity::Destroyed state,
fixed a potential memory leak.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/entity.cc10
-rw-r--r--src/core/entity.h60
-rw-r--r--src/core/entityprojectile.cc2
-rw-r--r--src/core/gameconnection.cc8
-rw-r--r--src/core/gameserver.cc8
-rw-r--r--src/core/netserver.cc4
6 files changed, 59 insertions, 33 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 7d538a0..efd6248 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -152,7 +152,7 @@ Entity::Entity() :
entity_shape = Diamond;
entity_created = true;
- entity_destroyed = false;
+ entity_died = false;
entity_dirty = false;
entity_keepalive = 0;
@@ -190,7 +190,7 @@ Entity::Entity(std::istream & is)
entity_speed = 0.0f;
entity_created = true;
- entity_destroyed = false;
+ entity_died = false;
entity_inventory = 0;
entity_slots = 0;
@@ -363,7 +363,7 @@ void Entity::print_inventory() const
void Entity::die()
{
- entity_destroyed = true;
+ entity_died = true;
}
void Entity::clear_updates()
@@ -884,7 +884,7 @@ void EntityDynamic::reset()
}
// remove Docked and Destroyed entities from the physics simulation
- if (destroyed() || (state() == core::Entity::Docked) || (state() == core::Entity::Destroyed)) {
+ if (died() || (state() == core::Entity::Docked) || (state() == core::Entity::Destroyed)) {
if (entity_body) {
@@ -1468,7 +1468,7 @@ void EntityControlable::reset()
}
// remove Docked and Destroyed entities from the physics simulation
- if (destroyed() || (state() == core::Entity::Docked) || (state() == core::Entity::Destroyed)) {
+ if (died() || (state() == core::Entity::Docked) || (state() == core::Entity::Destroyed)) {
if (entity_body) {
diff --git a/src/core/entity.h b/src/core/entity.h
index f5a6d52..5a028bf 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -36,7 +36,9 @@ class EntityControlable;
namespace core
{
-/// The base world entity. All gameworld entities must derive from this class.
+/**
+ * @brief The base world entity. All gameworld entities must derive from this class.
+ * */
class Entity : public Label
{
friend class Extension;
@@ -52,28 +54,49 @@ public:
* */
enum Flags { NonSolid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16, KeepAlive = 32 };
- /// Entity type constants
+ /**
+ * @brief Entity type constants
+ * @see Entity::type()
+ * */
enum Type { Default = 0, Dynamic = 1, Controlable = 2, Globe = 3, Projectile = 4 };
- /// Entity shape constants
+ /**
+ * @brief Entity shape constants
+ * @see Entity::shape()
+ * */
enum Shape { Diamond = 0, Sphere = 1, Cube = 2, Axis = 3 };
- /// EntityDynamic State constants
+ /**
+ * @brief EntityDynamic state constants
+ * @see EntityDynamic::state()
+ * */
enum State { Normal = 0, NoPower = 1, ImpulseInitiate = 2, Impulse = 3, JumpInitiate = 4, Jump = 5, Docked = 6, Destroyed = 7 };
- /// entity menus collection typedef
+ /**
+ * @brief entity menu collection type definition
+ * */
typedef std::list<MenuDescription *> Menus;
- /// type definition for entity bullet shapes collection
+ /**
+ * @brief entity bullet shapes collection type definition
+ * */
typedef std::list<btCollisionShape *> CollisionShapes;
- /// create a new entity and add it to the registry
+ /**
+ * @brief server-side constructor
+ * create a new entity and add it to the registry
+ * */
Entity();
- /// create an entity from stream data
+ /**
+ * @brief client-side constructor
+ * create an entity from stream data
+ * */
Entity(std::istream & is);
- /// destroy an entity
+ /**
+ * @brief destructor
+ * */
virtual ~Entity();
/**
@@ -241,12 +264,12 @@ public:
MenuDescription *find_menu(const std::string &label);
/// true if the entity is to be deleted
- inline bool destroyed() const {
- return entity_destroyed;
+ inline const bool died() const {
+ return entity_died;
}
/// time when the entity was last alive
- inline unsigned long keepalive() const {
+ inline const unsigned long keepalive() const {
return entity_keepalive;
}
@@ -283,10 +306,10 @@ public:
}
/**
- * @brief mark the entity as destroyed
+ * @brief mark the entity as dead
* die() should be called by the game module when it needs to destroy an entity,
* the game server will broadcast the delete event to the clients.
- * The game module should not delete an entity directly.
+ * The game module should not delete entities directly.
*/
virtual void die();
@@ -513,12 +536,15 @@ public:
return entity_registry;
}
- /* entity_ variables can be set by the module */
-
+ /**
+ * @brief game module type id
+ * this id can be assigned by the game module
+ * */
unsigned int entity_moduletypeid;
bool entity_created;
- bool entity_destroyed;
+
+ bool entity_died;
/// timestamp when entity data was received from the server
float entity_servertimestamp;
diff --git a/src/core/entityprojectile.cc b/src/core/entityprojectile.cc
index 108d347..440c46b 100644
--- a/src/core/entityprojectile.cc
+++ b/src/core/entityprojectile.cc
@@ -104,7 +104,7 @@ void EntityProjectile::reset()
}
// remove Docked and Destroyed entities from the physics simulation
- if (destroyed() || (state() == Entity::Docked) || (state() == Entity::Destroyed)) {
+ if (died() || (state() == Entity::Docked) || (state() == Entity::Destroyed)) {
if (entity_body) {
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index 7bdadad..1fbcf26 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -262,14 +262,14 @@ void GameConnection::frame(unsigned long timestamp)
}
}
- // delete entities were required
- if (entity->destroyed()) {
+ // remove deleted entities
+ if ((*it).second->died()) {
+ delete (*it).second;
+ (*it).second = 0;
Entity::registry().erase(it++);
} else {
++it;
}
-
-
}
float f = 0;
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 9e24c64..86f130f 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -652,7 +652,7 @@ void GameServer::frame(const unsigned long timestamp)
// run entity game frames
for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); ++it) {
Entity *entity = (*it).second;
- if (!entity->destroyed()) {
+ if (!entity->died()) {
entity->frame(elapsed);
}
@@ -670,7 +670,7 @@ void GameServer::frame(const unsigned long timestamp)
for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); ++it) {
Entity *entity = (*it).second;
Zone *zone = entity->zone();
- if (zone && entity->has_flag(Entity::KeepAlive) && !entity->destroyed()) {
+ if (zone && entity->has_flag(Entity::KeepAlive) && !entity->died()) {
// reset timeout counter if the zone is active
if (zone->keepalive_run() && zone->keepalive_box().inside(entity->location())) {
entity->set_keepalive(this->timestamp());
@@ -723,7 +723,7 @@ void GameServer::frame(const unsigned long timestamp)
}
// view is to be deleted
- if (view->destroyed()) {
+ if (view->died()) {
if (control) {
// player is docked at deleted entity
if (control->state() == Entity::Docked) {
@@ -750,7 +750,7 @@ void GameServer::frame(const unsigned long timestamp)
// remove deleted entities and mark remaining entities as updated
for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) {
// remove deleted entities
- if ((*it).second->destroyed()) {
+ if ((*it).second->died()) {
delete (*it).second;
(*it).second = 0;
Entity::registry().erase(it++);
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 84ed76c..17fef86 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -356,7 +356,7 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp)
for (Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); ++it) {
Entity *entity = (*it);
- if (!entity->entity_destroyed) {
+ if (!entity->died()) {
send_entity_create(client, entity);
}
}
@@ -381,7 +381,7 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp)
Entity *entity = (*it).second;
if (entity->zone() == zone) {
- if (entity->entity_destroyed) {
+ if (entity->died()) {
if (!entity->entity_created) {
send_entity_delete(client, entity);
}