summaryrefslogtreecommitdiffstats
path: root/src/core/References.cpp
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2020-12-29 12:55:26 +0100
committerSergeanur <s.anureev@yandex.ua>2020-12-29 12:55:26 +0100
commitb9e97ab79db84785838f1b995188c37328c26071 (patch)
treec0c2fb73abab36a3f2e92b904287d91ef5032209 /src/core/References.cpp
parentFix error sound in when entering load/save menu (diff)
downloadre3-b9e97ab79db84785838f1b995188c37328c26071.tar
re3-b9e97ab79db84785838f1b995188c37328c26071.tar.gz
re3-b9e97ab79db84785838f1b995188c37328c26071.tar.bz2
re3-b9e97ab79db84785838f1b995188c37328c26071.tar.lz
re3-b9e97ab79db84785838f1b995188c37328c26071.tar.xz
re3-b9e97ab79db84785838f1b995188c37328c26071.tar.zst
re3-b9e97ab79db84785838f1b995188c37328c26071.zip
Diffstat (limited to 'src/core/References.cpp')
-rw-r--r--src/core/References.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/core/References.cpp b/src/core/References.cpp
index 52abbc3e..dc83d96d 100644
--- a/src/core/References.cpp
+++ b/src/core/References.cpp
@@ -22,6 +22,83 @@ CReferences::Init(void)
}
void
+CEntity::RegisterReference(CEntity **pent)
+{
+ if(IsBuilding())
+ return;
+ CReference *ref;
+ // check if already registered
+ for(ref = m_pFirstReference; ref; ref = ref->next)
+ if(ref->pentity == pent)
+ return;
+ // have to allocate new reference
+ ref = CReferences::pEmptyList;
+ if(ref){
+ CReferences::pEmptyList = ref->next;
+
+ ref->pentity = pent;
+ ref->next = m_pFirstReference;
+ m_pFirstReference = ref;
+ return;
+ }
+ return;
+}
+
+// Clean up the reference from *pent -> 'this'
+void
+CEntity::CleanUpOldReference(CEntity **pent)
+{
+ CReference* ref, ** lastnextp;
+ lastnextp = &m_pFirstReference;
+ for (ref = m_pFirstReference; ref; ref = ref->next) {
+ if (ref->pentity == pent) {
+ *lastnextp = ref->next;
+ ref->next = CReferences::pEmptyList;
+ CReferences::pEmptyList = ref;
+ break;
+ }
+ lastnextp = &ref->next;
+ }
+}
+
+// Clear all references to this entity
+void
+CEntity::ResolveReferences(void)
+{
+ CReference *ref;
+ // clear pointers to this entity
+ for(ref = m_pFirstReference; ref; ref = ref->next)
+ if(*ref->pentity == this)
+ *ref->pentity = nil;
+ // free list
+ if(m_pFirstReference){
+ for(ref = m_pFirstReference; ref->next; ref = ref->next)
+ ;
+ ref->next = CReferences::pEmptyList;
+ CReferences::pEmptyList = m_pFirstReference;
+ m_pFirstReference = nil;
+ }
+}
+
+// Free all references that no longer point to this entity
+void
+CEntity::PruneReferences(void)
+{
+ CReference *ref, *next, **lastnextp;
+ lastnextp = &m_pFirstReference;
+ for(ref = m_pFirstReference; ref; ref = next){
+ next = ref->next;
+ if(*ref->pentity == this)
+ lastnextp = &ref->next;
+ else{
+ *lastnextp = ref->next;
+ ref->next = CReferences::pEmptyList;
+ CReferences::pEmptyList = ref;
+ }
+ }
+}
+
+void
CReferences::RemoveReferencesToPlayer(void)
{
if(FindPlayerVehicle())