summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2017-06-15 17:06:50 +0200
committerworktycho <work.tycho@gmail.com>2017-06-15 17:06:50 +0200
commit885d80ccdb97c984abe85eaeaecf1aedc3e36d25 (patch)
treea601ae53a96c7aae83900571af1d38bc0cd1b33a /src/Entities/Entity.cpp
parentReplace evdns with getaddrinfo and getnameinfo (#3766) (diff)
downloadcuberite-885d80ccdb97c984abe85eaeaecf1aedc3e36d25.tar
cuberite-885d80ccdb97c984abe85eaeaecf1aedc3e36d25.tar.gz
cuberite-885d80ccdb97c984abe85eaeaecf1aedc3e36d25.tar.bz2
cuberite-885d80ccdb97c984abe85eaeaecf1aedc3e36d25.tar.lz
cuberite-885d80ccdb97c984abe85eaeaecf1aedc3e36d25.tar.xz
cuberite-885d80ccdb97c984abe85eaeaecf1aedc3e36d25.tar.zst
cuberite-885d80ccdb97c984abe85eaeaecf1aedc3e36d25.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 5d26f501b..9ff57602e 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -19,15 +19,21 @@
-UInt32 cEntity::m_EntityCount = 0;
-cCriticalSection cEntity::m_CSCount;
+static UInt32 GetNextUniqueID(void)
+{
+ 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):
- m_UniqueID(INVALID_ID), // Proper ID will be assigned later in the constructor code
+ m_UniqueID(GetNextUniqueID()),
m_Health(1),
m_MaxHealth(1),
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_InvulnerableTicks(0)
{
- // Assign a proper ID:
- cCSLock Lock(m_CSCount);
- m_EntityCount++;
- m_UniqueID = m_EntityCount;
}