summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2020-12-01 17:42:18 +0100
committeraap <aap@papnet.eu>2020-12-01 17:42:18 +0100
commit83bbb631d1105502fb3c5b3af90578226ba35583 (patch)
treef317568c6c19250fa29b41ac0d2a99003f4cc169
parentfix cam-fix (diff)
downloadre3-83bbb631d1105502fb3c5b3af90578226ba35583.tar
re3-83bbb631d1105502fb3c5b3af90578226ba35583.tar.gz
re3-83bbb631d1105502fb3c5b3af90578226ba35583.tar.bz2
re3-83bbb631d1105502fb3c5b3af90578226ba35583.tar.lz
re3-83bbb631d1105502fb3c5b3af90578226ba35583.tar.xz
re3-83bbb631d1105502fb3c5b3af90578226ba35583.tar.zst
re3-83bbb631d1105502fb3c5b3af90578226ba35583.zip
-rw-r--r--src/animation/AnimBlendHierarchy.cpp11
-rw-r--r--src/animation/AnimBlendHierarchy.h5
-rw-r--r--src/animation/AnimBlendSequence.cpp21
-rw-r--r--src/animation/AnimBlendSequence.h5
-rw-r--r--src/core/Game.cpp175
-rw-r--r--src/core/main.cpp1
-rw-r--r--src/rw/MemoryHeap.cpp2
-rw-r--r--src/rw/MemoryHeap.h1
8 files changed, 209 insertions, 12 deletions
diff --git a/src/animation/AnimBlendHierarchy.cpp b/src/animation/AnimBlendHierarchy.cpp
index 67b19019..c7800de5 100644
--- a/src/animation/AnimBlendHierarchy.cpp
+++ b/src/animation/AnimBlendHierarchy.cpp
@@ -82,3 +82,14 @@ CAnimBlendHierarchy::RemoveUncompressedData(void)
#endif
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
diff --git a/src/animation/AnimBlendHierarchy.h b/src/animation/AnimBlendHierarchy.h
index 0144108d..e35b4925 100644
--- a/src/animation/AnimBlendHierarchy.h
+++ b/src/animation/AnimBlendHierarchy.h
@@ -2,6 +2,10 @@
#include "templates.h"
+#ifdef MoveMemory
+#undef MoveMemory // windows shit
+#endif
+
class CAnimBlendSequence;
// A collection of sequences
@@ -23,6 +27,7 @@ public:
void RemoveAnimSequences(void);
void Uncompress(void);
void RemoveUncompressedData(void);
+ void MoveMemory(bool onlyone = false);
};
VALIDATE_SIZE(CAnimBlendHierarchy, 0x28); \ No newline at end of file
diff --git a/src/animation/AnimBlendSequence.cpp b/src/animation/AnimBlendSequence.cpp
index 5a2fa605..c958b71a 100644
--- a/src/animation/AnimBlendSequence.cpp
+++ b/src/animation/AnimBlendSequence.cpp
@@ -176,3 +176,24 @@ CAnimBlendSequence::RemoveUncompressedData(void)
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
+
diff --git a/src/animation/AnimBlendSequence.h b/src/animation/AnimBlendSequence.h
index e51e5aaa..c6e70f22 100644
--- a/src/animation/AnimBlendSequence.h
+++ b/src/animation/AnimBlendSequence.h
@@ -2,6 +2,10 @@
#include "Quaternion.h"
+#ifdef MoveMemory
+#undef MoveMemory // windows shit
+#endif
+
// TODO: put them somewhere else?
struct KeyFrame {
CQuaternion rotation;
@@ -53,6 +57,7 @@ public:
void Uncompress(void);
void CompressKeyframes(void);
void RemoveUncompressedData(void);
+ bool MoveMemory(void);
#ifdef PED_SKIN
void SetBoneTag(int tag) { boneTag = tag; }
diff --git a/src/core/Game.cpp b/src/core/Game.cpp
index 7043a5b2..262aa54a 100644
--- a/src/core/Game.cpp
+++ b/src/core/Game.cpp
@@ -167,6 +167,7 @@ void ReplaceAtomicPipeCallback();
#endif // PS2_ALPHA_TEST
#endif // !LIBRW
+// missing altogether on PS2, mostly done in GameInit there it seems
bool
CGame::InitialiseRenderWare(void)
{
@@ -233,6 +234,7 @@ CGame::InitialiseRenderWare(void)
return (true);
}
+// missing altogether on PS2
void CGame::ShutdownRenderWare(void)
{
CMBlur::MotionBlurClose();
@@ -321,6 +323,7 @@ bool CGame::InitialiseOnceAfterRW(void)
return true;
}
+// missing altogether on PS2
void
CGame::FinalShutdown(void)
{
@@ -657,13 +660,11 @@ void CGame::ReInitGameObjectVariables(void)
CGameLogic::InitAtStartOfGame();
#ifdef PS2_MENU
if ( !TheMemoryCard.m_bWantToLoad )
- {
#endif
- TheCamera.Init();
- TheCamera.SetRwCamera(Scene.camera);
-#ifdef PS2_MENU
+ {
+ TheCamera.Init();
+ TheCamera.SetRwCamera(Scene.camera);
}
-#endif
CDebug::DebugInitTextBuffer();
CWeather::Init();
CUserDisplay::Init();
@@ -769,8 +770,10 @@ void CGame::ReloadIPLs(void)
void CGame::ShutDownForRestart(void)
{
+#ifndef GTA_PS2 // TODO: right define
CReplay::FinishPlayback();
CReplay::EmptyReplayBuffer();
+#endif
DMAudio.DestroyAllGameCreatedEntities();
for (int i = 0; i < NUMPLAYERS; i++)
@@ -788,7 +791,7 @@ void CGame::ShutDownForRestart(void)
CRadar::RemoveRadarSections();
FrontEndMenuManager.UnloadTextures();
CParticleObject::RemoveAllParticleObjects();
-#ifndef PS2
+#if GTA_VERSION >= GTA3_PS2_160
CPedType::Shutdown();
CSpecialFX::Shutdown();
#endif
@@ -974,7 +977,9 @@ void CGame::Process(void)
CSkidmarks::Update();
CAntennas::Update();
CGlass::Update();
+#ifndef GTA_PS2 // TODO: define
CSceneEdit::Update();
+#endif
CEventList::Update();
CParticle::Update();
gFireManager.Update();
@@ -988,7 +993,9 @@ void CGame::Process(void)
CMovingThings::Update();
CWaterCannons::Update();
CUserDisplay::Process();
+#ifndef GTA_PS2 // TODO: define
CReplay::Update();
+#endif
PUSH_MEMID(MEMID_WORLD);
CWorld::Process();
@@ -1001,10 +1008,14 @@ void CGame::Process(void)
CRubbish::Update();
CSpecialFX::Update();
CTimeCycle::Update();
+#ifndef GTA_PS2 // TODO: define
if (CReplay::ShouldStandardCameraBeProcessed())
+#endif
TheCamera.Process();
CCullZones::Update();
+#ifndef GTA_PS2 // TODO: define
if (!CReplay::IsPlayingBack())
+#endif
CGameLogic::Update();
CBridge::Update();
CCoronas::DoSunAndMoon();
@@ -1012,7 +1023,9 @@ void CGame::Process(void)
CShadows::UpdateStaticShadows();
CShadows::UpdatePermanentShadows();
gPhoneInfo.Update();
+#ifndef GTA_PS2 // TODO: define
if (!CReplay::IsPlayingBack())
+#endif
{
PUSH_MEMID(MEMID_CARS);
CCarCtrl::GenerateRandomCars();
@@ -1026,23 +1039,163 @@ void CGame::Process(void)
#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
- // 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
}
-void CGame::TidyUpMemory(bool, bool)
+void CGame::TidyUpMemory(bool moveTextures, bool flushDraw)
{
#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
}
void CGame::ProcessTidyUpMemory(void)
{
#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
}
diff --git a/src/core/main.cpp b/src/core/main.cpp
index 102548b6..fa16b6c2 100644
--- a/src/core/main.cpp
+++ b/src/core/main.cpp
@@ -415,6 +415,7 @@ PluginAttach(void)
return TRUE;
}
+// rather different on PS2
static RwBool
Initialise3D(void *param)
{
diff --git a/src/rw/MemoryHeap.cpp b/src/rw/MemoryHeap.cpp
index 0b333ce1..469262d3 100644
--- a/src/rw/MemoryHeap.cpp
+++ b/src/rw/MemoryHeap.cpp
@@ -187,7 +187,7 @@ CMemoryHeap::Malloc(uint32 size)
void *mem = Malloc(size);
if (removeCollision) {
CTimer::Stop();
- // different on PS2
+ // TODO: different on PS2
CFileLoader::LoadCollisionFromDatFile(CCollision::ms_collisionInMemory);
removeCollision = false;
CTimer::Update();
diff --git a/src/rw/MemoryHeap.h b/src/rw/MemoryHeap.h
index 484cbfab..23163c1c 100644
--- a/src/rw/MemoryHeap.h
+++ b/src/rw/MemoryHeap.h
@@ -198,6 +198,7 @@ public:
void TidyHeap(void);
uint32 GetMemoryUsed(int32 id);
uint32 GetBlocksUsed(int32 id);
+ int32 GetLargestFreeBlock(void) { return m_freeList.m_last.m_prev->m_size; }
void ParseHeap(void);