summaryrefslogtreecommitdiffstats
path: root/src/entities
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2020-05-19 00:49:09 +0200
committerNikolay Korolev <nickvnuk@gmail.com>2020-05-19 00:49:09 +0200
commit6510b15704998b14b89fa453ba9d142f85c30dd5 (patch)
treee194a3641474f3a0818bb4ff2dd139f2c293e804 /src/entities
parentfixes for braking and cloud rotation at high fps (diff)
downloadre3-6510b15704998b14b89fa453ba9d142f85c30dd5.tar
re3-6510b15704998b14b89fa453ba9d142f85c30dd5.tar.gz
re3-6510b15704998b14b89fa453ba9d142f85c30dd5.tar.bz2
re3-6510b15704998b14b89fa453ba9d142f85c30dd5.tar.lz
re3-6510b15704998b14b89fa453ba9d142f85c30dd5.tar.xz
re3-6510b15704998b14b89fa453ba9d142f85c30dd5.tar.zst
re3-6510b15704998b14b89fa453ba9d142f85c30dd5.zip
Diffstat (limited to 'src/entities')
-rw-r--r--src/entities/Building.cpp22
-rw-r--r--src/entities/Building.h2
-rw-r--r--src/entities/Dummy.cpp15
-rw-r--r--src/entities/Dummy.h2
-rw-r--r--src/entities/Entity.cpp17
-rw-r--r--src/entities/Entity.h2
6 files changed, 60 insertions, 0 deletions
diff --git a/src/entities/Building.cpp b/src/entities/Building.cpp
index 3c096636..3217e684 100644
--- a/src/entities/Building.cpp
+++ b/src/entities/Building.cpp
@@ -20,3 +20,25 @@ CBuilding::ReplaceWithNewModel(int32 id)
if(m_level == LEVEL_NONE || m_level == CGame::currLevel)
CStreaming::RequestModel(id, STREAMFLAGS_DONT_REMOVE);
}
+
+bool
+IsBuildingPointerValid(CBuilding* pBuilding)
+{
+ if (!pBuilding)
+ return false;
+ if (pBuilding->GetIsATreadable()) {
+ int index = CPools::GetTreadablePool()->GetJustIndex((CTreadable*)pBuilding);
+#ifdef FIX_BUGS
+ return index >= 0 && index < CPools::GetTreadablePool()->GetSize();
+#else
+ return index >= 0 && index <= CPools::GetTreadablePool()->GetSize();
+#endif
+ } else {
+ int index = CPools::GetBuildingPool()->GetJustIndex(pBuilding);
+#ifdef FIX_BUGS
+ return index >= 0 && index < CPools::GetBuildingPool()->GetSize();
+#else
+ return index >= 0 && index <= CPools::GetBuildingPool()->GetSize();
+#endif
+ }
+}
diff --git a/src/entities/Building.h b/src/entities/Building.h
index 29608c10..2c2dfb1f 100644
--- a/src/entities/Building.h
+++ b/src/entities/Building.h
@@ -16,3 +16,5 @@ public:
virtual bool GetIsATreadable(void) { return false; }
};
+
+bool IsBuildingPointerValid(CBuilding*);
diff --git a/src/entities/Dummy.cpp b/src/entities/Dummy.cpp
index 8a4bfd5f..92b69761 100644
--- a/src/entities/Dummy.cpp
+++ b/src/entities/Dummy.cpp
@@ -50,3 +50,18 @@ CDummy::Remove(void)
m_entryInfoList.DeleteNode(node);
}
}
+
+bool
+IsDummyPointerValid(CDummy* pDummy)
+{
+ if (!pDummy)
+ return false;
+ int index = CPools::GetDummyPool()->GetJustIndex(pDummy);
+#ifdef FIX_BUGS
+ if (index < 0 || index >= CPools::GetDummyPool()->GetSize())
+#else
+ if (index < 0 || index > CPools::GetDummyPool()->GetSize())
+#endif
+ return false;
+ return pDummy->m_entryInfoList.first;
+}
diff --git a/src/entities/Dummy.h b/src/entities/Dummy.h
index 7998a748..84b1ce1a 100644
--- a/src/entities/Dummy.h
+++ b/src/entities/Dummy.h
@@ -15,3 +15,5 @@ public:
static void *operator new(size_t);
static void operator delete(void*, size_t);
};
+
+bool IsDummyPointerValid(CDummy* pDummy);
diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp
index b35ddb25..e83df204 100644
--- a/src/entities/Entity.cpp
+++ b/src/entities/Entity.cpp
@@ -28,6 +28,8 @@
#include "Bones.h"
#include "Debug.h"
#include "Renderer.h"
+#include "Ped.h"
+#include "Dummy.h"
int gBuildings;
@@ -1028,3 +1030,18 @@ CEntity::LoadEntityFlags(uint8*& buf)
}
#endif
+
+bool IsEntityPointerValid(CEntity* pEntity)
+{
+ if (!pEntity)
+ return false;
+ switch (pEntity->GetType()) {
+ case ENTITY_TYPE_NOTHING: return false;
+ case ENTITY_TYPE_BUILDING: return IsBuildingPointerValid((CBuilding*)pEntity);
+ case ENTITY_TYPE_VEHICLE: return IsVehiclePointerValid((CVehicle*)pEntity);
+ case ENTITY_TYPE_PED: return IsPedPointerValid((CPed*)pEntity);
+ case ENTITY_TYPE_OBJECT: return IsObjectPointerValid((CObject*)pEntity);
+ case ENTITY_TYPE_DUMMY: return IsDummyPointerValid((CDummy*)pEntity);
+ }
+ return false;
+}
diff --git a/src/entities/Entity.h b/src/entities/Entity.h
index fa57519e..dc5378a5 100644
--- a/src/entities/Entity.h
+++ b/src/entities/Entity.h
@@ -180,3 +180,5 @@ public:
static void AddSteamsFromGround(CPtrList& list);
};
+
+bool IsEntityPointerValid(CEntity*);