Entity: Replaced a mutexed counter with a std::atomic. (#3773)
This commit is contained in:
parent
035ecdc9e2
commit
885d80ccdb
@ -19,15 +19,21 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
UInt32 cEntity::m_EntityCount = 0;
|
static UInt32 GetNextUniqueID(void)
|
||||||
cCriticalSection cEntity::m_CSCount;
|
{
|
||||||
|
static std::atomic<UInt32> counter(1);
|
||||||
|
return counter.fetch_add(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// cEntity:
|
||||||
|
|
||||||
cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height):
|
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_UniqueID(GetNextUniqueID()),
|
||||||
m_Health(1),
|
m_Health(1),
|
||||||
m_MaxHealth(1),
|
m_MaxHealth(1),
|
||||||
m_AttachedTo(nullptr),
|
m_AttachedTo(nullptr),
|
||||||
@ -65,10 +71,6 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d
|
|||||||
m_Height(a_Height),
|
m_Height(a_Height),
|
||||||
m_InvulnerableTicks(0)
|
m_InvulnerableTicks(0)
|
||||||
{
|
{
|
||||||
// Assign a proper ID:
|
|
||||||
cCSLock Lock(m_CSCount);
|
|
||||||
m_EntityCount++;
|
|
||||||
m_UniqueID = m_EntityCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,12 @@
|
|||||||
#define POSZ_TOINT FloorC(GetPosZ())
|
#define POSZ_TOINT FloorC(GetPosZ())
|
||||||
#define POS_TOINT GetPosition().Floor()
|
#define POS_TOINT GetPosition().Floor()
|
||||||
|
|
||||||
#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == nullptr) || !ChunkVarName->IsValid()) { return; }
|
#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) \
|
||||||
|
cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); \
|
||||||
|
if ((ChunkVarName == nullptr) || !ChunkVarName->IsValid()) \
|
||||||
|
{ \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -518,9 +523,6 @@ protected:
|
|||||||
bool m_ShouldPreventTeleportation;
|
bool m_ShouldPreventTeleportation;
|
||||||
};
|
};
|
||||||
|
|
||||||
static cCriticalSection m_CSCount;
|
|
||||||
static UInt32 m_EntityCount;
|
|
||||||
|
|
||||||
/** Measured in meters / second (m / s) */
|
/** Measured in meters / second (m / s) */
|
||||||
Vector3d m_Speed;
|
Vector3d m_Speed;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user