summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-03-24 13:09:41 +0100
committerMattes D <github@xoft.cz>2015-03-24 13:09:41 +0100
commite5a7a730ed4f26eae896c56391bf3d2b5fecb852 (patch)
tree0209c1567f60af60999f3aeeb513a72f9eab2743 /src/Entities
parentMerge pull request #1775 from tommysanterre/terrainheightfix (diff)
parentAdded VarInt64, normalized cPacketizer datatype names. (diff)
downloadcuberite-e5a7a730ed4f26eae896c56391bf3d2b5fecb852.tar
cuberite-e5a7a730ed4f26eae896c56391bf3d2b5fecb852.tar.gz
cuberite-e5a7a730ed4f26eae896c56391bf3d2b5fecb852.tar.bz2
cuberite-e5a7a730ed4f26eae896c56391bf3d2b5fecb852.tar.lz
cuberite-e5a7a730ed4f26eae896c56391bf3d2b5fecb852.tar.xz
cuberite-e5a7a730ed4f26eae896c56391bf3d2b5fecb852.tar.zst
cuberite-e5a7a730ed4f26eae896c56391bf3d2b5fecb852.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp75
-rw-r--r--src/Entities/Entity.h13
-rw-r--r--src/Entities/ItemFrame.h2
-rw-r--r--src/Entities/Minecart.cpp11
-rw-r--r--src/Entities/ProjectileEntity.cpp2
-rw-r--r--src/Entities/ProjectileEntity.h12
6 files changed, 62 insertions, 53 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 039c58ee4..c8df6b4b1 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -18,49 +18,50 @@
-int cEntity::m_EntityCount = 0;
+UInt32 cEntity::m_EntityCount = 0;
cCriticalSection cEntity::m_CSCount;
-cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height)
- : m_UniqueID(0)
- , m_Health(1)
- , m_MaxHealth(1)
- , m_AttachedTo(nullptr)
- , m_Attachee(nullptr)
- , m_bDirtyHead(true)
- , m_bDirtyOrientation(true)
- , m_bHasSentNoSpeed(true)
- , m_bOnGround(false)
- , m_Gravity(-9.81f)
- , m_LastPos(a_X, a_Y, a_Z)
- , m_IsInitialized(false)
- , m_WorldTravellingFrom(nullptr)
- , m_EntityType(a_EntityType)
- , m_World(nullptr)
- , m_IsFireproof(false)
- , m_TicksSinceLastBurnDamage(0)
- , m_TicksSinceLastLavaDamage(0)
- , m_TicksSinceLastFireDamage(0)
- , m_TicksLeftBurning(0)
- , m_TicksSinceLastVoidDamage(0)
- , m_IsSwimming(false)
- , m_IsSubmerged(false)
- , m_AirLevel(0)
- , m_AirTickTimer(0)
- , m_TicksAlive(0)
- , m_HeadYaw(0.0)
- , m_Rot(0.0, 0.0, 0.0)
- , m_Pos(a_X, a_Y, a_Z)
- , m_WaterSpeed(0, 0, 0)
- , m_Mass (0.001) // Default 1g
- , m_Width(a_Width)
- , m_Height(a_Height)
- , m_InvulnerableTicks(0)
-{
+cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height):
+ m_UniqueID(INVALID_ID), // Proper ID will be assigned later in the constructor code
+ m_Health(1),
+ m_MaxHealth(1),
+ m_AttachedTo(nullptr),
+ m_Attachee(nullptr),
+ m_bDirtyHead(true),
+ m_bDirtyOrientation(true),
+ m_bHasSentNoSpeed(true),
+ m_bOnGround(false),
+ m_Gravity(-9.81f),
+ m_LastPos(a_X, a_Y, a_Z),
+ m_IsInitialized(false),
+ m_WorldTravellingFrom(nullptr),
+ m_EntityType(a_EntityType),
+ m_World(nullptr),
+ m_IsFireproof(false),
+ m_TicksSinceLastBurnDamage(0),
+ m_TicksSinceLastLavaDamage(0),
+ m_TicksSinceLastFireDamage(0),
+ m_TicksLeftBurning(0),
+ m_TicksSinceLastVoidDamage(0),
+ m_IsSwimming(false),
+ m_IsSubmerged(false),
+ m_AirLevel(0),
+ m_AirTickTimer(0),
+ m_TicksAlive(0),
+ m_HeadYaw(0.0),
+ m_Rot(0.0, 0.0, 0.0),
+ m_Pos(a_X, a_Y, a_Z),
+ m_WaterSpeed(0, 0, 0),
+ m_Mass (0.001), // Default 1g
+ m_Width(a_Width),
+ m_Height(a_Height),
+ m_InvulnerableTicks(0)
+{
+ // Assign a proper ID:
cCSLock Lock(m_CSCount);
m_EntityCount++;
m_UniqueID = m_EntityCount;
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 809e974d2..9bb1837f1 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -142,6 +142,10 @@ public:
static const int VOID_BOUNDARY = -46; ///< Y position to begin applying void damage
static const int FALL_DAMAGE_HEIGHT = 4; ///< Y difference after which fall damage is applied
+
+ /** Special ID that is considered an "invalid value", signifying no entity. */
+ static const UInt32 INVALID_ID = 0; // Exported to Lua in ManualBindings.cpp, ToLua doesn't parse initialized constants.
+
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
virtual ~cEntity();
@@ -248,7 +252,7 @@ public:
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways);
void SteerVehicle(float a_Forward, float a_Sideways);
- inline int GetUniqueID(void) const { return m_UniqueID; }
+ inline UInt32 GetUniqueID(void) const { return m_UniqueID; }
inline bool IsDestroyed(void) const { return !m_IsInitialized; }
/// Schedules the entity for destroying; if a_ShouldBroadcast is set to true, broadcasts the DestroyEntity packet
@@ -464,12 +468,15 @@ public:
protected:
static cCriticalSection m_CSCount;
- static int m_EntityCount;
+ static UInt32 m_EntityCount;
/** Measured in meter/second (m/s) */
Vector3d m_Speed;
- int m_UniqueID;
+ /** The ID of the entity that is guaranteed to be unique within a single run of the server.
+ Always nonzero (a zero UniqueID (cEntity::INVALID_ID) is used for error reporting).
+ Note that the UniqueID is not persisted through storage. */
+ UInt32 m_UniqueID;
int m_Health;
int m_MaxHealth;
diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h
index 2444b26a3..ff43e5ee1 100644
--- a/src/Entities/ItemFrame.h
+++ b/src/Entities/ItemFrame.h
@@ -24,7 +24,7 @@ public:
// tolua_begin
/** Returns the item in the frame */
- const cItem & GetItem(void) { return m_Item; }
+ const cItem & GetItem(void) const { return m_Item; }
/** Set the item in the frame */
void SetItem(cItem & a_Item) { m_Item = a_Item; }
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index a32926838..ee10cf6b3 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -24,7 +24,7 @@ class cMinecartCollisionCallback :
public cEntityCallback
{
public:
- cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, int a_UniqueID, int a_AttacheeUniqueID) :
+ cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, UInt32 a_UniqueID, UInt32 a_AttacheeUniqueID) :
m_DoesInteserct(false),
m_CollidedEntityPos(0, 0, 0),
m_Pos(a_Pos),
@@ -77,8 +77,8 @@ protected:
Vector3d m_Pos;
double m_Height, m_Width;
- int m_UniqueID;
- int m_AttacheeUniqueID;
+ UInt32 m_UniqueID;
+ UInt32 m_AttacheeUniqueID;
};
@@ -824,7 +824,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
- cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == nullptr) ? -1 : m_Attachee->GetUniqueID()));
+ cMinecartCollisionCallback MinecartCollisionCallback(
+ GetPosition(), GetHeight(), GetWidth(), GetUniqueID(),
+ ((m_Attachee == nullptr) ? cEntity::INVALID_ID : m_Attachee->GetUniqueID())
+ );
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback);
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index 21ec4e63a..4684e3e09 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -221,7 +221,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a
super(etProjectile, a_X, a_Y, a_Z, a_Width, a_Height),
m_ProjectileKind(a_Kind),
m_CreatorData(
- ((a_Creator != nullptr) ? a_Creator->GetUniqueID() : -1),
+ ((a_Creator != nullptr) ? a_Creator->GetUniqueID() : cEntity::INVALID_ID),
((a_Creator != nullptr) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""),
((a_Creator != nullptr) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments())
),
diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h
index 93e442d8c..de460a8ad 100644
--- a/src/Entities/ProjectileEntity.h
+++ b/src/Entities/ProjectileEntity.h
@@ -69,7 +69,7 @@ public:
/** Returns the unique ID of the entity who created this projectile
May return an ID <0
*/
- int GetCreatorUniqueID(void) { return m_CreatorData.m_UniqueID; }
+ UInt32 GetCreatorUniqueID(void) { return m_CreatorData.m_UniqueID; }
/** Returns the name of the player that created the projectile
Will be empty for non-player creators
@@ -90,18 +90,17 @@ public:
protected:
/** A structure that stores the Entity ID and Playername of the projectile's creator
- Used to migitate invalid pointers caused by the creator being destroyed
- */
+ Used to migitate invalid pointers caused by the creator being destroyed. */
struct CreatorData
{
- CreatorData(int a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
+ CreatorData(UInt32 a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
m_UniqueID(a_UniqueID),
m_Name(a_Name),
m_Enchantments(a_Enchantments)
{
}
- const int m_UniqueID;
+ const UInt32 m_UniqueID;
AString m_Name;
cEnchantments m_Enchantments;
};
@@ -110,8 +109,7 @@ protected:
eKind m_ProjectileKind;
/** The structure for containing the entity ID and name who has created this projectile
- The ID and/or name may be nullptr (e.g. for dispensers/mobs)
- */
+ The ID and/or name may be nullptr (e.g. for dispensers/mobs). */
CreatorData m_CreatorData;
/** True if the projectile has hit the ground and is stuck there */