1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-23 08:50:00 +00:00

Pool fixes from master

This commit is contained in:
Sergeanur 2020-12-08 07:52:03 +02:00
parent 579efc05fc
commit f3e9c82432
9 changed files with 38 additions and 23 deletions

View file

@ -1466,7 +1466,7 @@ static bool DoINeedToRefreshPointer(CEntity * pDoor, bool bIsDummy, uint8 nIndex
bool bNeedToFindDoorEntities = false; bool bNeedToFindDoorEntities = false;
if (pDoor) { if (pDoor) {
if (bIsDummy) { if (bIsDummy) {
if (CPools::GetDummyPool()->IsFreeSlot(CPools::GetDummyPool()->GetJustIndex((CDummy*)pDoor))) if (CPools::GetDummyPool()->IsFreeSlot(CPools::GetDummyPool()->GetJustIndex_NoFreeAssert((CDummy*)pDoor)))
return true; return true;
if (nIndex != (CPools::GetDummyPool()->GetIndex((CDummy*)pDoor) & 0x7F)) if (nIndex != (CPools::GetDummyPool()->GetIndex((CDummy*)pDoor) & 0x7F))
bNeedToFindDoorEntities = true; bNeedToFindDoorEntities = true;
@ -1474,7 +1474,7 @@ static bool DoINeedToRefreshPointer(CEntity * pDoor, bool bIsDummy, uint8 nIndex
return true; return true;
} }
else { else {
if (CPools::GetObjectPool()->IsFreeSlot(CPools::GetObjectPool()->GetJustIndex((CObject*)pDoor))) if (CPools::GetObjectPool()->IsFreeSlot(CPools::GetObjectPool()->GetJustIndex_NoFreeAssert((CObject*)pDoor)))
return true; return true;
if (nIndex != (CPools::GetObjectPool()->GetIndex((CObject*)pDoor) & 0x7F)) if (nIndex != (CPools::GetObjectPool()->GetIndex((CObject*)pDoor) & 0x7F))
bNeedToFindDoorEntities = true; bNeedToFindDoorEntities = true;

View file

@ -308,7 +308,7 @@ INITSAVEBUF
// Convert entity pointer to building pool index while saving // Convert entity pointer to building pool index while saving
if (phone->m_pEntity) { if (phone->m_pEntity) {
phone->m_pEntity = (CEntity*) (CPools::GetBuildingPool()->GetJustIndex((CBuilding*)phone->m_pEntity) + 1); phone->m_pEntity = (CEntity*) (CPools::GetBuildingPool()->GetJustIndex_NoFreeAssert((CBuilding*)phone->m_pEntity) + 1);
} }
} }
VALIDATESAVEBUF(*size) VALIDATESAVEBUF(*size)

View file

@ -1458,9 +1458,9 @@ INITSAVEBUF
CPickup *buf_pickup = WriteSaveBuf(buf, aPickUps[i]); CPickup *buf_pickup = WriteSaveBuf(buf, aPickUps[i]);
if (buf_pickup->m_eType != PICKUP_NONE) { if (buf_pickup->m_eType != PICKUP_NONE) {
if (buf_pickup->m_pObject != nil) if (buf_pickup->m_pObject != nil)
buf_pickup->m_pObject = (CObject*)(CPools::GetObjectPool()->GetJustIndex(buf_pickup->m_pObject) + 1); buf_pickup->m_pObject = (CObject*)(CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(buf_pickup->m_pObject) + 1);
if (buf_pickup->m_pExtraObject != nil) if (buf_pickup->m_pExtraObject != nil)
buf_pickup->m_pExtraObject = (CObject*)(CPools::GetObjectPool()->GetJustIndex(buf_pickup->m_pExtraObject) + 1); buf_pickup->m_pExtraObject = (CObject*)(CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(buf_pickup->m_pExtraObject) + 1);
} }
} }

View file

@ -1784,10 +1784,10 @@ INITSAVEBUF
handle = 0; handle = 0;
} else if (pBuilding->GetIsATreadable()) { } else if (pBuilding->GetIsATreadable()) {
type = 1; type = 1;
handle = CPools::GetTreadablePool()->GetJustIndex((CTreadable*)pBuilding) + 1; handle = CPools::GetTreadablePool()->GetJustIndex_NoFreeAssert((CTreadable*)pBuilding) + 1;
} else { } else {
type = 2; type = 2;
handle = CPools::GetBuildingPool()->GetJustIndex(pBuilding) + 1; handle = CPools::GetBuildingPool()->GetJustIndex_NoFreeAssert(pBuilding) + 1;
} }
WriteSaveBuf(buf, type); WriteSaveBuf(buf, type);
WriteSaveBuf(buf, handle); WriteSaveBuf(buf, handle);
@ -1805,19 +1805,19 @@ INITSAVEBUF
case ENTITY_TYPE_BUILDING: case ENTITY_TYPE_BUILDING:
if (((CBuilding*)pEntity)->GetIsATreadable()) { if (((CBuilding*)pEntity)->GetIsATreadable()) {
type = 1; type = 1;
handle = CPools::GetTreadablePool()->GetJustIndex((CTreadable*)pEntity) + 1; handle = CPools::GetTreadablePool()->GetJustIndex_NoFreeAssert((CTreadable*)pEntity) + 1;
} else { } else {
type = 2; type = 2;
handle = CPools::GetBuildingPool()->GetJustIndex((CBuilding*)pEntity) + 1; handle = CPools::GetBuildingPool()->GetJustIndex_NoFreeAssert((CBuilding*)pEntity) + 1;
} }
break; break;
case ENTITY_TYPE_OBJECT: case ENTITY_TYPE_OBJECT:
type = 3; type = 3;
handle = CPools::GetObjectPool()->GetJustIndex((CObject*)pEntity) + 1; handle = CPools::GetObjectPool()->GetJustIndex_NoFreeAssert((CObject*)pEntity) + 1;
break; break;
case ENTITY_TYPE_DUMMY: case ENTITY_TYPE_DUMMY:
type = 4; type = 4;
handle = CPools::GetDummyPool()->GetJustIndex((CDummy*)pEntity) + 1; handle = CPools::GetDummyPool()->GetJustIndex_NoFreeAssert((CDummy*)pEntity) + 1;
default: break; default: break;
} }
} }

View file

@ -35,7 +35,7 @@
CColPoint gaTempSphereColPoints[MAX_COLLISION_POINTS]; CColPoint gaTempSphereColPoints[MAX_COLLISION_POINTS];
CPtrList CWorld::ms_bigBuildingsList[4]; CPtrList CWorld::ms_bigBuildingsList[NUM_LEVELS];
CPtrList CWorld::ms_listMovingEntityPtrs; CPtrList CWorld::ms_listMovingEntityPtrs;
CSector CWorld::ms_aSectors[NUMSECTORS_Y][NUMSECTORS_X]; CSector CWorld::ms_aSectors[NUMSECTORS_Y][NUMSECTORS_X];
uint16 CWorld::ms_nCurrentScanCode; uint16 CWorld::ms_nCurrentScanCode;
@ -1781,21 +1781,29 @@ CWorld::ShutDown(void)
CWorld::Remove(pEntity); CWorld::Remove(pEntity);
delete pEntity; delete pEntity;
} }
#ifndef FIX_BUGS
pSector->m_lists[ENTITYLIST_BUILDINGS].Flush(); pSector->m_lists[ENTITYLIST_BUILDINGS].Flush();
pSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP].Flush(); pSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES].Flush(); pSector->m_lists[ENTITYLIST_DUMMIES].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES_OVERLAP].Flush(); pSector->m_lists[ENTITYLIST_DUMMIES_OVERLAP].Flush();
#endif
} }
for(int32 i = 0; i < 4; i++) { for(int32 i = 0; i < NUM_LEVELS; i++) {
for(CPtrNode *pNode = GetBigBuildingList((eLevelName)i).first; pNode; pNode = pNode->next) { for(CPtrNode *pNode = ms_bigBuildingsList[i].first; pNode; pNode = pNode->next) {
CEntity *pEntity = (CEntity *)pNode->item; CEntity *pEntity = (CEntity *)pNode->item;
// Maybe remove from world here? // Maybe remove from world here?
delete pEntity; delete pEntity;
} }
GetBigBuildingList((eLevelName)i).Flush(); ms_bigBuildingsList[i].Flush();
} }
for(int i = 0; i < NUMSECTORS_X * NUMSECTORS_Y; i++) { for(int i = 0; i < NUMSECTORS_X * NUMSECTORS_Y; i++) {
CSector *pSector = GetSector(i % NUMSECTORS_X, i / NUMSECTORS_Y); CSector *pSector = GetSector(i % NUMSECTORS_X, i / NUMSECTORS_Y);
#ifdef FIX_BUGS
pSector->m_lists[ENTITYLIST_BUILDINGS].Flush();
pSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES_OVERLAP].Flush();
#endif
if(pSector->m_lists[ENTITYLIST_BUILDINGS].first) { if(pSector->m_lists[ENTITYLIST_BUILDINGS].first) {
sprintf(gString, "Building list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y); sprintf(gString, "Building list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_BUILDINGS].Flush(); pSector->m_lists[ENTITYLIST_BUILDINGS].Flush();

View file

@ -55,7 +55,7 @@ struct CStoredCollPoly;
class CWorld class CWorld
{ {
static CPtrList ms_bigBuildingsList[4]; static CPtrList ms_bigBuildingsList[NUM_LEVELS];
static CPtrList ms_listMovingEntityPtrs; static CPtrList ms_listMovingEntityPtrs;
static CSector ms_aSectors[NUMSECTORS_Y][NUMSECTORS_X]; static CSector ms_aSectors[NUMSECTORS_Y][NUMSECTORS_X];
static uint16 ms_nCurrentScanCode; static uint16 ms_nCurrentScanCode;

View file

@ -124,12 +124,18 @@ public:
(T*)&m_entries[handle >> 8] : nil; (T*)&m_entries[handle >> 8] : nil;
} }
int GetIndex(T *entry){ int GetIndex(T *entry){
int i = GetJustIndex(entry); int i = GetJustIndex_NoFreeAssert(entry);
return m_flags[i].u + (i<<8); return m_flags[i].u + (i<<8);
} }
int GetJustIndex(T *entry){ int GetJustIndex(T *entry){
// TODO: the cast is unsafe int index = GetJustIndex_NoFreeAssert(entry);
return (int)((U*)entry - m_entries); assert(!IsFreeSlot(index));
return index;
}
int GetJustIndex_NoFreeAssert(T* entry){
int index = ((U*)entry - m_entries);
assert((U*)entry == (U*)&m_entries[index]); // cast is unsafe - check required
return index;
} }
int GetNoOfUsedSpaces(void) const { int GetNoOfUsedSpaces(void) const {
int i; int i;

View file

@ -1213,7 +1213,8 @@ CBike::ProcessControl(void)
// Balance bike // Balance bike
if(bBalancedByRider || bIsBeingPickedUp || bIsStanding){ if(bBalancedByRider || bIsBeingPickedUp || bIsStanding){
float onSideness = clamp(DotProduct(GetRight(), m_vecAvgSurfaceNormal), -1.0f, 1.0f); float onSideness = DotProduct(GetRight(), m_vecAvgSurfaceNormal);
onSideness = clamp(onSideness, -1.0f, 1.0f);
CVector worldCOM = Multiply3x3(GetMatrix(), m_vecCentreOfMass); CVector worldCOM = Multiply3x3(GetMatrix(), m_vecCentreOfMass);
// Keep bike upright // Keep bike upright
if(bBalancedByRider){ if(bBalancedByRider){

View file

@ -629,11 +629,11 @@ void CCranes::Save(uint8* buf, uint32* size)
for (int i = 0; i < NUM_CRANES; i++) { for (int i = 0; i < NUM_CRANES; i++) {
CCrane *pCrane = WriteSaveBuf(buf, aCranes[i]); CCrane *pCrane = WriteSaveBuf(buf, aCranes[i]);
if (pCrane->m_pCraneEntity != nil) if (pCrane->m_pCraneEntity != nil)
pCrane->m_pCraneEntity = (CBuilding*)(CPools::GetBuildingPool()->GetJustIndex(pCrane->m_pCraneEntity) + 1); pCrane->m_pCraneEntity = (CBuilding*)(CPools::GetBuildingPool()->GetJustIndex_NoFreeAssert(pCrane->m_pCraneEntity) + 1);
if (pCrane->m_pHook != nil) if (pCrane->m_pHook != nil)
pCrane->m_pHook = (CObject*)(CPools::GetObjectPool()->GetJustIndex(pCrane->m_pHook) + 1); pCrane->m_pHook = (CObject*)(CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(pCrane->m_pHook) + 1);
if (pCrane->m_pVehiclePickedUp != nil) if (pCrane->m_pVehiclePickedUp != nil)
pCrane->m_pVehiclePickedUp = (CVehicle*)(CPools::GetVehiclePool()->GetJustIndex(pCrane->m_pVehiclePickedUp) + 1); pCrane->m_pVehiclePickedUp = (CVehicle*)(CPools::GetVehiclePool()->GetJustIndex_NoFreeAssert(pCrane->m_pVehiclePickedUp) + 1);
} }
VALIDATESAVEBUF(*size); VALIDATESAVEBUF(*size);