Pool fixes

Mostly for Linux
This commit is contained in:
erorcun 2021-06-26 00:27:12 +03:00
parent af7573ddbe
commit 9b5caa190e
16 changed files with 71 additions and 49 deletions

View File

@ -23,25 +23,25 @@ cAudioScriptObject::Reset()
}
void *
cAudioScriptObject::operator new(size_t sz)
cAudioScriptObject::operator new(size_t sz) throw()
{
return CPools::GetAudioScriptObjectPool()->New();
}
void *
cAudioScriptObject::operator new(size_t sz, int handle)
cAudioScriptObject::operator new(size_t sz, int handle) throw()
{
return CPools::GetAudioScriptObjectPool()->New(handle);
}
void
cAudioScriptObject::operator delete(void *p, size_t sz)
cAudioScriptObject::operator delete(void *p, size_t sz) throw()
{
CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p);
}
void
cAudioScriptObject::operator delete(void *p, int handle)
cAudioScriptObject::operator delete(void *p, int handle) throw()
{
CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p);
}

View File

@ -12,10 +12,10 @@ public:
void Reset(); /// ok
static void* operator new(size_t);
static void* operator new(size_t, int);
static void operator delete(void*, size_t);
static void operator delete(void*, int);
static void* operator new(size_t) throw();
static void* operator new(size_t, int) throw();
static void operator delete(void*, size_t) throw();
static void operator delete(void*, int) throw();
static void LoadAllAudioScriptObjects(uint8 *buf, uint32 size);
static void SaveAllAudioScriptObjects(uint8 *buf, uint32 *size);

View File

@ -4,8 +4,8 @@
#include "Streaming.h"
#include "Pools.h"
void *CBuilding::operator new(size_t sz) { return CPools::GetBuildingPool()->New(); }
void CBuilding::operator delete(void *p, size_t sz) { CPools::GetBuildingPool()->Delete((CBuilding*)p); }
void *CBuilding::operator new(size_t sz) throw() { return CPools::GetBuildingPool()->New(); }
void CBuilding::operator delete(void *p, size_t sz) throw() { CPools::GetBuildingPool()->Delete((CBuilding*)p); }
void
CBuilding::ReplaceWithNewModel(int32 id)

View File

@ -9,8 +9,8 @@ public:
m_type = ENTITY_TYPE_BUILDING;
bUsesCollision = true;
}
static void *operator new(size_t);
static void operator delete(void*, size_t);
static void *operator new(size_t) throw();
static void operator delete(void*, size_t) throw();
void ReplaceWithNewModel(int32 id);

View File

@ -4,5 +4,5 @@
#include "Treadable.h"
#include "Pools.h"
void *CTreadable::operator new(size_t sz) { return CPools::GetTreadablePool()->New(); }
void CTreadable::operator delete(void *p, size_t sz) { CPools::GetTreadablePool()->Delete((CTreadable*)p); }
void *CTreadable::operator new(size_t sz) throw() { return CPools::GetTreadablePool()->New(); }
void CTreadable::operator delete(void *p, size_t sz) throw() { CPools::GetTreadablePool()->Delete((CTreadable*)p); }

View File

@ -5,8 +5,8 @@
class CTreadable : public CBuilding
{
public:
static void *operator new(size_t);
static void operator delete(void*, size_t);
static void *operator new(size_t) throw();
static void operator delete(void*, size_t) throw();
int16 m_nodeIndices[2][12]; // first car, then ped

View File

@ -7,7 +7,7 @@ protected:
public:
// disable allocation
static void *operator new(size_t);
static void *operator new(size_t) throw();
CPlaceable(void);
virtual ~CPlaceable(void);

View File

@ -4,8 +4,8 @@
#include "World.h"
#include "Dummy.h"
void *CDummy::operator new(size_t sz) { return CPools::GetDummyPool()->New(); }
void CDummy::operator delete(void *p, size_t sz) { CPools::GetDummyPool()->Delete((CDummy*)p); }
void *CDummy::operator new(size_t sz) throw() { return CPools::GetDummyPool()->New(); }
void CDummy::operator delete(void *p, size_t sz) throw() { CPools::GetDummyPool()->Delete((CDummy*)p); }
void
CDummy::Add(void)

View File

@ -12,8 +12,8 @@ public:
void Add(void);
void Remove(void);
static void *operator new(size_t);
static void operator delete(void*, size_t);
static void *operator new(size_t) throw();
static void operator delete(void*, size_t) throw();
};
VALIDATE_SIZE(CDummy, 0x68);

View File

@ -16,10 +16,32 @@
int16 CObject::nNoTempObjects;
int16 CObject::nBodyCastHealth = 1000;
void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); }
void *CObject::operator new(size_t sz, int handle) { return CPools::GetObjectPool()->New(handle);};
void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); }
void CObject::operator delete(void *p, int handle) { CPools::GetObjectPool()->Delete((CObject*)p); }
// Object pools tends to be full sometimes, let's free a temp. object in this case.
#ifdef FIX_BUGS
void *CObject::operator new(size_t sz) throw() {
CObject *obj = CPools::GetObjectPool()->New();
if (!obj) {
CObjectPool *objectPool = CPools::GetObjectPool();
for (int32 i = 0; i < objectPool->GetSize(); i++) {
CObject *existing = objectPool->GetSlot(i);
if (existing && existing->ObjectCreatedBy == TEMP_OBJECT) {
int32 handle = objectPool->GetIndex(existing);
CWorld::Remove(existing);
delete existing;
obj = objectPool->New(handle);
break;
}
}
}
return obj;
}
#else
void *CObject::operator new(size_t sz) throw() { return CPools::GetObjectPool()->New(); }
#endif
void *CObject::operator new(size_t sz, int handle) throw() { return CPools::GetObjectPool()->New(handle); };
void CObject::operator delete(void *p, size_t sz) throw() { CPools::GetObjectPool()->Delete((CObject*)p); }
void CObject::operator delete(void *p, int handle) throw() { CPools::GetObjectPool()->Delete((CObject*)p); }
CObject::CObject(void)
{

View File

@ -65,10 +65,10 @@ public:
static int16 nNoTempObjects;
static int16 nBodyCastHealth;
static void *operator new(size_t);
static void *operator new(size_t, int);
static void operator delete(void*, size_t);
static void operator delete(void*, int);
static void *operator new(size_t) throw();
static void *operator new(size_t, int) throw();
static void operator delete(void*, size_t) throw();
static void operator delete(void*, int) throw();
CObject(void);
CObject(int32, bool);

View File

@ -47,10 +47,10 @@ bool CPed::bPedCheat2;
bool CPed::bPedCheat3;
CVector2D CPed::ms_vec2DFleePosition;
void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); }
void *CPed::operator new(size_t sz, int handle) { return CPools::GetPedPool()->New(handle); }
void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); }
void CPed::operator delete(void *p, int handle) { CPools::GetPedPool()->Delete((CPed*)p); }
void *CPed::operator new(size_t sz) throw() { return CPools::GetPedPool()->New(); }
void *CPed::operator new(size_t sz, int handle) throw() { return CPools::GetPedPool()->New(handle); }
void CPed::operator delete(void *p, size_t sz) throw() { CPools::GetPedPool()->Delete((CPed*)p); }
void CPed::operator delete(void *p, int handle) throw() { CPools::GetPedPool()->Delete((CPed*)p); }
#ifdef DEBUGMENU
bool CPed::bPopHeadsOnHeadshot = false;

View File

@ -515,10 +515,10 @@ public:
CVector m_vecSeekPosEx; // used for OBJECTIVE_GUARD_SPOT
float m_distanceToCountSeekDoneEx; // used for OBJECTIVE_GUARD_SPOT
static void *operator new(size_t);
static void *operator new(size_t, int);
static void operator delete(void*, size_t);
static void operator delete(void*, int);
static void *operator new(size_t) throw();
static void *operator new(size_t, int) throw();
static void operator delete(void*, size_t) throw();
static void operator delete(void*, int) throw();
CPed(uint32 pedType);
~CPed(void);

View File

@ -28,10 +28,10 @@ RwMemoryFunctions memFuncs = {
#ifdef USE_CUSTOM_ALLOCATOR
// game seems to be using heap directly here, but this is nicer
void *operator new(size_t sz) { return MemoryMgrMalloc(sz); }
void *operator new[](size_t sz) { return MemoryMgrMalloc(sz); }
void operator delete(void *ptr) noexcept { MemoryMgrFree(ptr); }
void operator delete[](void *ptr) noexcept { MemoryMgrFree(ptr); }
void *operator new(size_t sz) throw() { return MemoryMgrMalloc(sz); }
void *operator new[](size_t sz) throw() { return MemoryMgrMalloc(sz); }
void operator delete(void *ptr) throw() { MemoryMgrFree(ptr); }
void operator delete[](void *ptr) throw() { MemoryMgrFree(ptr); }
#endif
void*

View File

@ -29,10 +29,10 @@ bool CVehicle::bAltDodoCheat;
#endif
bool CVehicle::m_bDisableMouseSteering = true;
void *CVehicle::operator new(size_t sz) { return CPools::GetVehiclePool()->New(); }
void *CVehicle::operator new(size_t sz, int handle) { return CPools::GetVehiclePool()->New(handle); }
void CVehicle::operator delete(void *p, size_t sz) { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
void CVehicle::operator delete(void *p, int handle) { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
void *CVehicle::operator new(size_t sz) throw() { return CPools::GetVehiclePool()->New(); }
void *CVehicle::operator new(size_t sz, int handle) throw() { return CPools::GetVehiclePool()->New(handle); }
void CVehicle::operator delete(void *p, size_t sz) throw() { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
void CVehicle::operator delete(void *p, int handle) throw() { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
#ifdef FIX_BUGS
// I think they meant that

View File

@ -193,10 +193,10 @@ public:
float m_fSteerInput;
eVehicleType m_vehType;
static void *operator new(size_t);
static void *operator new(size_t sz, int slot);
static void operator delete(void*, size_t);
static void operator delete(void*, int);
static void *operator new(size_t) throw();
static void *operator new(size_t sz, int slot) throw();
static void operator delete(void*, size_t) throw();
static void operator delete(void*, int) throw();
CVehicle(void) {} // FAKE
CVehicle(uint8 CreatedBy);