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

some more GTA_VERSIONs and CGame tidy-up (not much actual memory moving yet)

This commit is contained in:
aap 2020-12-01 17:42:18 +01:00
parent b8bc54640d
commit 83bbb631d1
8 changed files with 209 additions and 12 deletions

View file

@ -82,3 +82,14 @@ CAnimBlendHierarchy::RemoveUncompressedData(void)
#endif #endif
compressed = 1; compressed = 1;
} }
#ifdef USE_CUSTOM_ALLOCATOR
void
CAnimBlendHierarchy::MoveMemory(bool onlyone)
{
int i;
for(i = 0; i < numSequences; i++)
if(sequences[i].MoveMemory() && onlyone)
return;
}
#endif

View file

@ -2,6 +2,10 @@
#include "templates.h" #include "templates.h"
#ifdef MoveMemory
#undef MoveMemory // windows shit
#endif
class CAnimBlendSequence; class CAnimBlendSequence;
// A collection of sequences // A collection of sequences
@ -23,6 +27,7 @@ public:
void RemoveAnimSequences(void); void RemoveAnimSequences(void);
void Uncompress(void); void Uncompress(void);
void RemoveUncompressedData(void); void RemoveUncompressedData(void);
void MoveMemory(bool onlyone = false);
}; };
VALIDATE_SIZE(CAnimBlendHierarchy, 0x28); VALIDATE_SIZE(CAnimBlendHierarchy, 0x28);

View file

@ -176,3 +176,24 @@ CAnimBlendSequence::RemoveUncompressedData(void)
keyFrames = nil; keyFrames = nil;
} }
#ifdef USE_CUSTOM_ALLOCATOR
bool
CAnimBlendSequence::MoveMemory(void)
{
if(keyFrames){
void *newaddr = gMainHeap.MoveMemory(keyFrames);
if(newaddr != keyFrames){
keyFrames = newaddr;
return true;
}
}else if(keyFramesCompressed){
void *newaddr = gMainHeap.MoveMemory(keyFramesCompressed);
if(newaddr != keyFramesCompressed){
keyFramesCompressed = newaddr;
return true;
}
}
return false;
}
#endif

View file

@ -2,6 +2,10 @@
#include "Quaternion.h" #include "Quaternion.h"
#ifdef MoveMemory
#undef MoveMemory // windows shit
#endif
// TODO: put them somewhere else? // TODO: put them somewhere else?
struct KeyFrame { struct KeyFrame {
CQuaternion rotation; CQuaternion rotation;
@ -53,6 +57,7 @@ public:
void Uncompress(void); void Uncompress(void);
void CompressKeyframes(void); void CompressKeyframes(void);
void RemoveUncompressedData(void); void RemoveUncompressedData(void);
bool MoveMemory(void);
#ifdef PED_SKIN #ifdef PED_SKIN
void SetBoneTag(int tag) { boneTag = tag; } void SetBoneTag(int tag) { boneTag = tag; }

View file

@ -167,6 +167,7 @@ void ReplaceAtomicPipeCallback();
#endif // PS2_ALPHA_TEST #endif // PS2_ALPHA_TEST
#endif // !LIBRW #endif // !LIBRW
// missing altogether on PS2, mostly done in GameInit there it seems
bool bool
CGame::InitialiseRenderWare(void) CGame::InitialiseRenderWare(void)
{ {
@ -233,6 +234,7 @@ CGame::InitialiseRenderWare(void)
return (true); return (true);
} }
// missing altogether on PS2
void CGame::ShutdownRenderWare(void) void CGame::ShutdownRenderWare(void)
{ {
CMBlur::MotionBlurClose(); CMBlur::MotionBlurClose();
@ -321,6 +323,7 @@ bool CGame::InitialiseOnceAfterRW(void)
return true; return true;
} }
// missing altogether on PS2
void void
CGame::FinalShutdown(void) CGame::FinalShutdown(void)
{ {
@ -657,13 +660,11 @@ void CGame::ReInitGameObjectVariables(void)
CGameLogic::InitAtStartOfGame(); CGameLogic::InitAtStartOfGame();
#ifdef PS2_MENU #ifdef PS2_MENU
if ( !TheMemoryCard.m_bWantToLoad ) if ( !TheMemoryCard.m_bWantToLoad )
{
#endif #endif
{
TheCamera.Init(); TheCamera.Init();
TheCamera.SetRwCamera(Scene.camera); TheCamera.SetRwCamera(Scene.camera);
#ifdef PS2_MENU
} }
#endif
CDebug::DebugInitTextBuffer(); CDebug::DebugInitTextBuffer();
CWeather::Init(); CWeather::Init();
CUserDisplay::Init(); CUserDisplay::Init();
@ -769,8 +770,10 @@ void CGame::ReloadIPLs(void)
void CGame::ShutDownForRestart(void) void CGame::ShutDownForRestart(void)
{ {
#ifndef GTA_PS2 // TODO: right define
CReplay::FinishPlayback(); CReplay::FinishPlayback();
CReplay::EmptyReplayBuffer(); CReplay::EmptyReplayBuffer();
#endif
DMAudio.DestroyAllGameCreatedEntities(); DMAudio.DestroyAllGameCreatedEntities();
for (int i = 0; i < NUMPLAYERS; i++) for (int i = 0; i < NUMPLAYERS; i++)
@ -788,7 +791,7 @@ void CGame::ShutDownForRestart(void)
CRadar::RemoveRadarSections(); CRadar::RemoveRadarSections();
FrontEndMenuManager.UnloadTextures(); FrontEndMenuManager.UnloadTextures();
CParticleObject::RemoveAllParticleObjects(); CParticleObject::RemoveAllParticleObjects();
#ifndef PS2 #if GTA_VERSION >= GTA3_PS2_160
CPedType::Shutdown(); CPedType::Shutdown();
CSpecialFX::Shutdown(); CSpecialFX::Shutdown();
#endif #endif
@ -974,7 +977,9 @@ void CGame::Process(void)
CSkidmarks::Update(); CSkidmarks::Update();
CAntennas::Update(); CAntennas::Update();
CGlass::Update(); CGlass::Update();
#ifndef GTA_PS2 // TODO: define
CSceneEdit::Update(); CSceneEdit::Update();
#endif
CEventList::Update(); CEventList::Update();
CParticle::Update(); CParticle::Update();
gFireManager.Update(); gFireManager.Update();
@ -988,7 +993,9 @@ void CGame::Process(void)
CMovingThings::Update(); CMovingThings::Update();
CWaterCannons::Update(); CWaterCannons::Update();
CUserDisplay::Process(); CUserDisplay::Process();
#ifndef GTA_PS2 // TODO: define
CReplay::Update(); CReplay::Update();
#endif
PUSH_MEMID(MEMID_WORLD); PUSH_MEMID(MEMID_WORLD);
CWorld::Process(); CWorld::Process();
@ -1001,10 +1008,14 @@ void CGame::Process(void)
CRubbish::Update(); CRubbish::Update();
CSpecialFX::Update(); CSpecialFX::Update();
CTimeCycle::Update(); CTimeCycle::Update();
#ifndef GTA_PS2 // TODO: define
if (CReplay::ShouldStandardCameraBeProcessed()) if (CReplay::ShouldStandardCameraBeProcessed())
#endif
TheCamera.Process(); TheCamera.Process();
CCullZones::Update(); CCullZones::Update();
#ifndef GTA_PS2 // TODO: define
if (!CReplay::IsPlayingBack()) if (!CReplay::IsPlayingBack())
#endif
CGameLogic::Update(); CGameLogic::Update();
CBridge::Update(); CBridge::Update();
CCoronas::DoSunAndMoon(); CCoronas::DoSunAndMoon();
@ -1012,7 +1023,9 @@ void CGame::Process(void)
CShadows::UpdateStaticShadows(); CShadows::UpdateStaticShadows();
CShadows::UpdatePermanentShadows(); CShadows::UpdatePermanentShadows();
gPhoneInfo.Update(); gPhoneInfo.Update();
#ifndef GTA_PS2 // TODO: define
if (!CReplay::IsPlayingBack()) if (!CReplay::IsPlayingBack())
#endif
{ {
PUSH_MEMID(MEMID_CARS); PUSH_MEMID(MEMID_CARS);
CCarCtrl::GenerateRandomCars(); CCarCtrl::GenerateRandomCars();
@ -1026,23 +1039,163 @@ void CGame::Process(void)
#endif #endif
} }
void CGame::DrasticTidyUpMemory(bool) int32 gNumMemMoved;
RwTexture *
MoveTextureMemoryCB(RwTexture *texture, void *pData)
{
// TODO
return texture;
}
bool
TidyUpModelInfo(CBaseModelInfo *,bool)
{
// TODO
return false;
}
void CGame::DrasticTidyUpMemory(bool flushDraw)
{ {
#ifdef USE_CUSTOM_ALLOCATOR #ifdef USE_CUSTOM_ALLOCATOR
// meow bool removedCol = false;
TidyUpMemory(true, flushDraw);
if(gMainHeap.GetLargestFreeBlock() < 200000 && !playingIntro){
CStreaming::RemoveIslandsNotUsed(LEVEL_INDUSTRIAL);
CStreaming::RemoveIslandsNotUsed(LEVEL_COMMERCIAL);
CStreaming::RemoveIslandsNotUsed(LEVEL_SUBURBAN);
TidyUpMemory(true, flushDraw);
}
if(gMainHeap.GetLargestFreeBlock() < 200000 && !playingIntro){
CModelInfo::RemoveColModelsFromOtherLevels(LEVEL_GENERIC);
TidyUpMemory(true, flushDraw);
removedCol = true;
}
if(gMainHeap.GetLargestFreeBlock() < 200000 && !playingIntro){
CStreaming::RemoveBigBuildings(LEVEL_INDUSTRIAL);
CStreaming::RemoveBigBuildings(LEVEL_COMMERCIAL);
CStreaming::RemoveBigBuildings(LEVEL_SUBURBAN);
TidyUpMemory(true, flushDraw);
}
if(removedCol){
// different on PS2
CFileLoader::LoadCollisionFromDatFile(CCollision::ms_collisionInMemory);
}
if(!playingIntro)
CStreaming::RequestBigBuildings(currLevel);
CStreaming::LoadAllRequestedModels(true);
#endif #endif
} }
void CGame::TidyUpMemory(bool, bool) void CGame::TidyUpMemory(bool moveTextures, bool flushDraw)
{ {
#ifdef USE_CUSTOM_ALLOCATOR #ifdef USE_CUSTOM_ALLOCATOR
// meow printf("Largest free block before tidy %d\n", gMainHeap.GetLargestFreeBlock());
if(moveTextures){
if(flushDraw){
#ifdef GTA_PS2
for(int i = 0; i < sweMaxFlips+1; i++){
#else
for(int i = 0; i < 5; i++){ // probably more than needed
#endif
RwCameraBeginUpdate(Scene.camera);
RwCameraEndUpdate(Scene.camera);
RwCameraShowRaster(Scene.camera, nil, 0);
}
}
int fontSlot = CTxdStore::FindTxdSlot("fonts");
for(int i = 0; i < TXDSTORESIZE; i++){
if(i == fontSlot ||
CTxdStore::GetSlot(i) == nil)
continue;
RwTexDictionary *txd = CTxdStore::GetSlot(i)->texDict;
if(txd)
RwTexDictionaryForAllTextures(txd, MoveTextureMemoryCB, nil);
}
}
// animations
for(int i = 0; i < NUMANIMATIONS; i++){
CAnimBlendHierarchy *anim = CAnimManager::GetAnimation(i);
if(anim == nil)
continue; // cannot happen
anim->MoveMemory();
}
// model info
for(int i = 0; i < MODELINFOSIZE; i++){
CBaseModelInfo *mi = CModelInfo::GetModelInfo(i);
if(mi == nil)
continue;
TidyUpModelInfo(mi, false);
}
printf("Largest free block after tidy %d\n", gMainHeap.GetLargestFreeBlock());
#endif #endif
} }
void CGame::ProcessTidyUpMemory(void) void CGame::ProcessTidyUpMemory(void)
{ {
#ifdef USE_CUSTOM_ALLOCATOR #ifdef USE_CUSTOM_ALLOCATOR
// meow static int32 modelIndex = 0;
static int32 animIndex = 0;
static int32 txdIndex = 0;
bool txdReturn = false;
RwTexDictionary *txd = nil;
gNumMemMoved = 0;
// model infos
for(int numCleanedUp = 0; numCleanedUp < 10; numCleanedUp++){
CBaseModelInfo *mi;
do{
mi = CModelInfo::GetModelInfo(modelIndex);
modelIndex++;
if(modelIndex >= MODELINFOSIZE)
modelIndex = 0;
}while(mi == nil);
if(TidyUpModelInfo(mi, true))
return;
}
// tex dicts
for(int numCleanedUp = 0; numCleanedUp < 3; numCleanedUp++){
if(gNumMemMoved > 80)
break;
do{
#ifdef FIX_BUGS
txd = nil;
#endif
if(CTxdStore::GetSlot(txdIndex))
txd = CTxdStore::GetSlot(txdIndex)->texDict;
txdIndex++;
if(txdIndex >= TXDSTORESIZE)
txdIndex = 0;
}while(txd == nil);
RwTexDictionaryForAllTextures(txd, MoveTextureMemoryCB, &txdReturn);
if(txdReturn)
return;
}
// animations
CAnimBlendHierarchy *anim;
do{
anim = CAnimManager::GetAnimation(animIndex);
animIndex++;
if(animIndex >= NUMANIMATIONS)
animIndex = 0;
}while(anim == nil); // always != nil
anim->MoveMemory(true);
#endif #endif
} }

View file

@ -415,6 +415,7 @@ PluginAttach(void)
return TRUE; return TRUE;
} }
// rather different on PS2
static RwBool static RwBool
Initialise3D(void *param) Initialise3D(void *param)
{ {

View file

@ -187,7 +187,7 @@ CMemoryHeap::Malloc(uint32 size)
void *mem = Malloc(size); void *mem = Malloc(size);
if (removeCollision) { if (removeCollision) {
CTimer::Stop(); CTimer::Stop();
// different on PS2 // TODO: different on PS2
CFileLoader::LoadCollisionFromDatFile(CCollision::ms_collisionInMemory); CFileLoader::LoadCollisionFromDatFile(CCollision::ms_collisionInMemory);
removeCollision = false; removeCollision = false;
CTimer::Update(); CTimer::Update();

View file

@ -198,6 +198,7 @@ public:
void TidyHeap(void); void TidyHeap(void);
uint32 GetMemoryUsed(int32 id); uint32 GetMemoryUsed(int32 id);
uint32 GetBlocksUsed(int32 id); uint32 GetBlocksUsed(int32 id);
int32 GetLargestFreeBlock(void) { return m_freeList.m_last.m_prev->m_size; }
void ParseHeap(void); void ParseHeap(void);