Merge pull request #841 from aap/master

start using CMemoryHeap; also some PS2 define cleanup
This commit is contained in:
aap 2020-11-28 18:52:44 +01:00 committed by GitHub
commit c57fee38ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 720 additions and 299 deletions

View File

@ -5,7 +5,7 @@
#include "RpAnimBlend.h" #include "RpAnimBlend.h"
#include "AnimManager.h" #include "AnimManager.h"
#include "AnimBlendAssociation.h" #include "AnimBlendAssociation.h"
#include "RwHelper.h" #include "MemoryMgr.h"
CAnimBlendAssociation::CAnimBlendAssociation(void) CAnimBlendAssociation::CAnimBlendAssociation(void)
{ {

View File

@ -1,7 +1,7 @@
#include "common.h" #include "common.h"
#include "AnimBlendClumpData.h" #include "AnimBlendClumpData.h"
#include "RwHelper.h" #include "MemoryMgr.h"
CAnimBlendClumpData::CAnimBlendClumpData(void) CAnimBlendClumpData::CAnimBlendClumpData(void)

View File

@ -1,6 +1,7 @@
#include "common.h" #include "common.h"
#include "AnimBlendSequence.h" #include "AnimBlendSequence.h"
#include "MemoryHeap.h"
CAnimBlendSequence::CAnimBlendSequence(void) CAnimBlendSequence::CAnimBlendSequence(void)
{ {
@ -70,6 +71,8 @@ CAnimBlendSequence::Uncompress(void)
if(numFrames == 0) if(numFrames == 0)
return; return;
PUSH_MEMID(MEMID_ANIMATION);
float rotScale = 1.0f/4096.0f; float rotScale = 1.0f/4096.0f;
float timeScale = 1.0f/60.0f; float timeScale = 1.0f/60.0f;
float transScale = 1.0f/128.0f; float transScale = 1.0f/128.0f;
@ -105,8 +108,12 @@ CAnimBlendSequence::Uncompress(void)
} }
keyFrames = newKfs; keyFrames = newKfs;
} }
REGISTER_MEMPTR(&keyFrames);
RwFree(keyFramesCompressed); RwFree(keyFramesCompressed);
keyFramesCompressed = nil; keyFramesCompressed = nil;
POP_MEMID();
} }
void void
@ -117,6 +124,8 @@ CAnimBlendSequence::CompressKeyframes(void)
if(numFrames == 0) if(numFrames == 0)
return; return;
PUSH_MEMID(MEMID_ANIMATION);
float rotScale = 4096.0f; float rotScale = 4096.0f;
float timeScale = 60.0f; float timeScale = 60.0f;
float transScale = 128.0f; float transScale = 128.0f;
@ -152,6 +161,9 @@ CAnimBlendSequence::CompressKeyframes(void)
} }
keyFramesCompressed = newKfs; keyFramesCompressed = newKfs;
} }
REGISTER_MEMPTR(&keyFramesCompressed);
POP_MEMID();
} }
void void

View File

@ -1,6 +1,7 @@
#include "common.h" #include "common.h"
#include "ColModel.h" #include "ColModel.h"
#include "Game.h" #include "Game.h"
#include "MemoryHeap.h"
CColModel::CColModel(void) CColModel::CColModel(void)
{ {
@ -48,10 +49,15 @@ CColModel::RemoveCollisionVolumes(void)
void void
CColModel::CalculateTrianglePlanes(void) CColModel::CalculateTrianglePlanes(void)
{ {
PUSH_MEMID(MEMID_COLLISION);
// HACK: allocate space for one more element to stuff the link pointer into // HACK: allocate space for one more element to stuff the link pointer into
trianglePlanes = (CColTrianglePlane*)RwMalloc(sizeof(CColTrianglePlane) * (numTriangles+1)); trianglePlanes = (CColTrianglePlane*)RwMalloc(sizeof(CColTrianglePlane) * (numTriangles+1));
REGISTER_MEMPTR(&trianglePlanes);
for(int i = 0; i < numTriangles; i++) for(int i = 0; i < numTriangles; i++)
trianglePlanes[i].Set(vertices, triangles[i]); trianglePlanes[i].Set(vertices, triangles[i]);
POP_MEMID();
} }
void void

View File

@ -5,6 +5,7 @@
#include "CdStream.h" #include "CdStream.h"
#include "rwcore.h" #include "rwcore.h"
#include "RwHelper.h" #include "RwHelper.h"
#include "MemoryMgr.h"
#define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) #define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__)
#define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) #define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__)

View File

@ -16,7 +16,7 @@
#include "CdStream.h" #include "CdStream.h"
#include "rwcore.h" #include "rwcore.h"
#include "RwHelper.h" #include "MemoryMgr.h"
#define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) #define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__)
#define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) #define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__)

View File

@ -24,6 +24,7 @@
#include "ZoneCull.h" #include "ZoneCull.h"
#include "CdStream.h" #include "CdStream.h"
#include "FileLoader.h" #include "FileLoader.h"
#include "MemoryHeap.h"
char CFileLoader::ms_line[256]; char CFileLoader::ms_line[256];
@ -71,11 +72,13 @@ CFileLoader::LoadLevel(const char *filename)
if(strncmp(line, "IMAGEPATH", 9) == 0){ if(strncmp(line, "IMAGEPATH", 9) == 0){
RwImageSetPath(line + 10); RwImageSetPath(line + 10);
}else if(strncmp(line, "TEXDICTION", 10) == 0){ }else if(strncmp(line, "TEXDICTION", 10) == 0){
PUSH_MEMID(MEMID_TEXTURES);
strcpy(txdname, line+11); strcpy(txdname, line+11);
LoadingScreenLoadingFile(txdname); LoadingScreenLoadingFile(txdname);
RwTexDictionary *txd = LoadTexDictionary(txdname); RwTexDictionary *txd = LoadTexDictionary(txdname);
AddTexDictionaries(savedTxd, txd); AddTexDictionaries(savedTxd, txd);
RwTexDictionaryDestroy(txd); RwTexDictionaryDestroy(txd);
POP_MEMID();
}else if(strncmp(line, "COLFILE", 7) == 0){ }else if(strncmp(line, "COLFILE", 7) == 0){
int level; int level;
sscanf(line+8, "%d", &level); sscanf(line+8, "%d", &level);
@ -94,12 +97,16 @@ CFileLoader::LoadLevel(const char *filename)
LoadObjectTypes(line + 4); LoadObjectTypes(line + 4);
}else if(strncmp(line, "IPL", 3) == 0){ }else if(strncmp(line, "IPL", 3) == 0){
if(!objectsLoaded){ if(!objectsLoaded){
PUSH_MEMID(MEMID_DEF_MODELS);
CModelInfo::ConstructMloClumps(); CModelInfo::ConstructMloClumps();
POP_MEMID();
CObjectData::Initialise("DATA\\OBJECT.DAT"); CObjectData::Initialise("DATA\\OBJECT.DAT");
objectsLoaded = true; objectsLoaded = true;
} }
PUSH_MEMID(MEMID_WORLD);
LoadingScreenLoadingFile(line + 4); LoadingScreenLoadingFile(line + 4);
LoadScene(line + 4); LoadScene(line + 4);
POP_MEMID();
}else if(strncmp(line, "MAPZONE", 7) == 0){ }else if(strncmp(line, "MAPZONE", 7) == 0){
LoadingScreenLoadingFile(line + 8); LoadingScreenLoadingFile(line + 8);
LoadMapZones(line + 8); LoadMapZones(line + 8);
@ -188,6 +195,8 @@ CFileLoader::LoadCollisionFile(const char *filename)
CBaseModelInfo *mi; CBaseModelInfo *mi;
ColHeader header; ColHeader header;
PUSH_MEMID(MEMID_COLLISION);
debug("Loading collision file %s\n", filename); debug("Loading collision file %s\n", filename);
fd = CFileMgr::OpenFile(filename, "rb"); fd = CFileMgr::OpenFile(filename, "rb");
@ -211,6 +220,8 @@ CFileLoader::LoadCollisionFile(const char *filename)
} }
CFileMgr::CloseFile(fd); CFileMgr::CloseFile(fd);
POP_MEMID();
} }
void void

View File

@ -90,6 +90,7 @@
#include "custompipes.h" #include "custompipes.h"
#include "screendroplets.h" #include "screendroplets.h"
#include "crossplatform.h" #include "crossplatform.h"
#include "MemoryHeap.h"
eLevelName CGame::currLevel; eLevelName CGame::currLevel;
bool CGame::bDemoMode = true; bool CGame::bDemoMode = true;
@ -327,21 +328,35 @@ CGame::FinalShutdown(void)
bool CGame::Initialise(const char* datFile) bool CGame::Initialise(const char* datFile)
{ {
#ifdef GTA_PS2
// TODO: upload VU0 collision code here
#else
ResetLoadingScreenBar(); ResetLoadingScreenBar();
strcpy(aDatFile, datFile); strcpy(aDatFile, datFile);
CPools::Initialise(); CPools::Initialise(); // done in CWorld on PS2
CIniFile::LoadIniFile(); CIniFile::LoadIniFile();
#endif
currLevel = LEVEL_INDUSTRIAL; currLevel = LEVEL_INDUSTRIAL;
PUSH_MEMID(MEMID_TEXTURES);
LoadingScreen("Loading the Game", "Loading generic textures", GetRandomSplashScreen()); LoadingScreen("Loading the Game", "Loading generic textures", GetRandomSplashScreen());
gameTxdSlot = CTxdStore::AddTxdSlot("generic"); gameTxdSlot = CTxdStore::AddTxdSlot("generic");
CTxdStore::Create(gameTxdSlot); CTxdStore::Create(gameTxdSlot);
CTxdStore::AddRef(gameTxdSlot); CTxdStore::AddRef(gameTxdSlot);
LoadingScreen("Loading the Game", "Loading particles", nil); LoadingScreen("Loading the Game", "Loading particles", nil);
int particleTxdSlot = CTxdStore::AddTxdSlot("particle"); int particleTxdSlot = CTxdStore::AddTxdSlot("particle");
CTxdStore::LoadTxd(particleTxdSlot, "MODELS/PARTICLE.TXD"); CTxdStore::LoadTxd(particleTxdSlot, "MODELS/PARTICLE.TXD");
CTxdStore::AddRef(particleTxdSlot); CTxdStore::AddRef(particleTxdSlot);
CTxdStore::SetCurrentTxd(gameTxdSlot); CTxdStore::SetCurrentTxd(gameTxdSlot);
LoadingScreen("Loading the Game", "Setup game variables", nil); LoadingScreen("Loading the Game", "Setup game variables", nil);
POP_MEMID();
#ifdef GTA_PS2
CDma::SyncChannel(0, true);
#endif
CGameLogic::InitAtStartOfGame(); CGameLogic::InitAtStartOfGame();
CReferences::Init(); CReferences::Init();
TheCamera.Init(); TheCamera.Init();
@ -361,20 +376,41 @@ bool CGame::Initialise(const char* datFile)
CMessages::ClearAllMessagesDisplayedByGame(); CMessages::ClearAllMessagesDisplayedByGame();
CRecordDataForGame::Init(); CRecordDataForGame::Init();
CRestart::Initialise(); CRestart::Initialise();
PUSH_MEMID(MEMID_WORLD);
CWorld::Initialise(); CWorld::Initialise();
POP_MEMID();
PUSH_MEMID(MEMID_TEXTURES);
CParticle::Initialise(); CParticle::Initialise();
#ifdef PS2 POP_MEMID();
#ifdef GTA_PS2
gStartX = -180.0f; gStartX = -180.0f;
gStartY = 180.0f; gStartY = 180.0f;
gStartZ = 14.0f; gStartZ = 14.0f;
#endif #endif
PUSH_MEMID(MEMID_ANIMATION);
CAnimManager::Initialise(); CAnimManager::Initialise();
CCutsceneMgr::Initialise(); CCutsceneMgr::Initialise();
POP_MEMID();
PUSH_MEMID(MEMID_CARS);
CCarCtrl::Init(); CCarCtrl::Init();
POP_MEMID();
#ifndef GTA_PS2
InitModelIndices(); InitModelIndices();
#endif
PUSH_MEMID(MEMID_DEF_MODELS);
CModelInfo::Initialise(); CModelInfo::Initialise();
#ifndef GTA_PS2
// probably moved before LoadLevel for multiplayer maps?
CPickups::Init(); CPickups::Init();
CTheCarGenerators::Init(); CTheCarGenerators::Init();
#endif
CdStreamAddImage("MODELS\\GTA3.IMG"); CdStreamAddImage("MODELS\\GTA3.IMG");
CFileLoader::LoadLevel("DATA\\DEFAULT.DAT"); CFileLoader::LoadLevel("DATA\\DEFAULT.DAT");
CFileLoader::LoadLevel(datFile); CFileLoader::LoadLevel(datFile);
@ -386,17 +422,23 @@ bool CGame::Initialise(const char* datFile)
CVehicleModelInfo::LoadVehicleColours(); CVehicleModelInfo::LoadVehicleColours();
CVehicleModelInfo::LoadEnvironmentMaps(); CVehicleModelInfo::LoadEnvironmentMaps();
CTheZones::PostZoneCreation(); CTheZones::PostZoneCreation();
POP_MEMID();
LoadingScreen("Loading the Game", "Setup paths", GetRandomSplashScreen()); LoadingScreen("Loading the Game", "Setup paths", GetRandomSplashScreen());
ThePaths.PreparePathData(); ThePaths.PreparePathData();
// done elsewhere on PS2
for (int i = 0; i < NUMPLAYERS; i++) for (int i = 0; i < NUMPLAYERS; i++)
CWorld::Players[i].Clear(); CWorld::Players[i].Clear();
CWorld::Players[0].LoadPlayerSkin(); CWorld::Players[0].LoadPlayerSkin();
TestModelIndices(); TestModelIndices();
//
LoadingScreen("Loading the Game", "Setup water", nil); LoadingScreen("Loading the Game", "Setup water", nil);
CWaterLevel::Initialise("DATA\\WATER.DAT"); CWaterLevel::Initialise("DATA\\WATER.DAT");
TheConsole.Init(); TheConsole.Init();
CDraw::SetFOV(120.0f); CDraw::SetFOV(120.0f);
CDraw::ms_fLODDistance = 500.0f; CDraw::ms_fLODDistance = 500.0f;
LoadingScreen("Loading the Game", "Setup streaming", nil); LoadingScreen("Loading the Game", "Setup streaming", nil);
CStreaming::Init(); CStreaming::Init();
CStreaming::LoadInitialVehicles(); CStreaming::LoadInitialVehicles();
@ -404,8 +446,12 @@ bool CGame::Initialise(const char* datFile)
CStreaming::RequestBigBuildings(LEVEL_GENERIC); CStreaming::RequestBigBuildings(LEVEL_GENERIC);
CStreaming::LoadAllRequestedModels(false); CStreaming::LoadAllRequestedModels(false);
printf("Streaming uses %zuK of its memory", CStreaming::ms_memoryUsed / 1024); // original modifier was %d printf("Streaming uses %zuK of its memory", CStreaming::ms_memoryUsed / 1024); // original modifier was %d
LoadingScreen("Loading the Game", "Load animations", GetRandomSplashScreen()); LoadingScreen("Loading the Game", "Load animations", GetRandomSplashScreen());
PUSH_MEMID(MEMID_ANIMATION);
CAnimManager::LoadAnimFiles(); CAnimManager::LoadAnimFiles();
POP_MEMID();
CPed::Initialise(); CPed::Initialise();
CRouteNode::Initialise(); CRouteNode::Initialise();
CEventList::Initialise(); CEventList::Initialise();
@ -414,13 +460,16 @@ bool CGame::Initialise(const char* datFile)
#endif #endif
LoadingScreen("Loading the Game", "Find big buildings", nil); LoadingScreen("Loading the Game", "Find big buildings", nil);
CRenderer::Init(); CRenderer::Init();
LoadingScreen("Loading the Game", "Setup game variables", nil); LoadingScreen("Loading the Game", "Setup game variables", nil);
CRadar::Initialise(); CRadar::Initialise();
CRadar::LoadTextures(); CRadar::LoadTextures();
CWeapon::InitialiseWeapons(); CWeapon::InitialiseWeapons();
LoadingScreen("Loading the Game", "Setup traffic lights", nil); LoadingScreen("Loading the Game", "Setup traffic lights", nil);
CTrafficLights::ScanForLightsOnMap(); CTrafficLights::ScanForLightsOnMap();
CRoadBlocks::Init(); CRoadBlocks::Init();
LoadingScreen("Loading the Game", "Setup game variables", nil); LoadingScreen("Loading the Game", "Setup game variables", nil);
CPopulation::Initialise(); CPopulation::Initialise();
CWorld::PlayerInFocus = 0; CWorld::PlayerInFocus = 0;
@ -431,26 +480,48 @@ bool CGame::Initialise(const char* datFile)
CAntennas::Init(); CAntennas::Init();
CGlass::Init(); CGlass::Init();
gPhoneInfo.Initialise(); gPhoneInfo.Initialise();
#ifndef GTA_PS2
CSceneEdit::Initialise(); CSceneEdit::Initialise();
#endif
LoadingScreen("Loading the Game", "Load scripts", nil); LoadingScreen("Loading the Game", "Load scripts", nil);
PUSH_MEMID(MEMID_SCRIPT);
CTheScripts::Init(); CTheScripts::Init();
CGangs::Initialise(); CGangs::Initialise();
POP_MEMID();
LoadingScreen("Loading the Game", "Setup game variables", nil); LoadingScreen("Loading the Game", "Setup game variables", nil);
#ifdef GTA_PS2
CTimer::Initialise();
#endif
CClock::Initialise(1000); CClock::Initialise(1000);
#ifdef GTA_PS2
CTheCarGenerators::Init();
#endif
CHeli::InitHelis(); CHeli::InitHelis();
CCranes::InitCranes(); CCranes::InitCranes();
CMovingThings::Init(); CMovingThings::Init();
CDarkel::Init(); CDarkel::Init();
CStats::Init(); CStats::Init();
#ifdef GTA_PS2
CPickups::Init();
#endif
CPacManPickups::Init(); CPacManPickups::Init();
// CGarages::Init(); here on PS2 instead
CRubbish::Init(); CRubbish::Init();
CClouds::Init(); CClouds::Init();
#ifdef GTA_PS2
CRemote::Init();
#endif
CSpecialFX::Init(); CSpecialFX::Init();
CWaterCannons::Init(); CWaterCannons::Init();
CBridge::Init(); CBridge::Init();
CGarages::Init(); CGarages::Init();
LoadingScreen("Loading the Game", "Position dynamic objects", nil); LoadingScreen("Loading the Game", "Position dynamic objects", nil);
CWorld::RepositionCertainDynamicObjects(); CWorld::RepositionCertainDynamicObjects();
// CCullZones::ResolveVisibilities(); on PS2 here instead
LoadingScreen("Loading the Game", "Initialise vehicle paths", nil); LoadingScreen("Loading the Game", "Initialise vehicle paths", nil);
CCullZones::ResolveVisibilities(); CCullZones::ResolveVisibilities();
CTrain::InitTrains(); CTrain::InitTrains();
@ -458,6 +529,7 @@ bool CGame::Initialise(const char* datFile)
CCredits::Init(); CCredits::Init();
CRecordDataForChase::Init(); CRecordDataForChase::Init();
CReplay::Init(); CReplay::Init();
#ifdef PS2_MENU #ifdef PS2_MENU
if ( !TheMemoryCard.m_bWantToLoad ) if ( !TheMemoryCard.m_bWantToLoad )
{ {
@ -469,6 +541,7 @@ bool CGame::Initialise(const char* datFile)
#ifdef PS2_MENU #ifdef PS2_MENU
} }
#endif #endif
LoadingScreen("Loading the Game", "Load scene", nil); LoadingScreen("Loading the Game", "Load scene", nil);
CModelInfo::RemoveColModelsFromOtherLevels(currLevel); CModelInfo::RemoveColModelsFromOtherLevels(currLevel);
CCollision::ms_collisionInMemory = currLevel; CCollision::ms_collisionInMemory = currLevel;
@ -550,7 +623,7 @@ void CGame::ReInitGameObjectVariables(void)
CWorld::bDoingCarCollisions = false; CWorld::bDoingCarCollisions = false;
CHud::ReInitialise(); CHud::ReInitialise();
CRadar::Initialise(); CRadar::Initialise();
#ifdef PS2 #ifdef GTA_PS2
gStartX = -180.0f; gStartX = -180.0f;
gStartY = 180.0f; gStartY = 180.0f;
gStartZ = 14.0f; gStartZ = 14.0f;
@ -573,15 +646,19 @@ void CGame::ReInitGameObjectVariables(void)
CWorld::Players[i].Clear(); CWorld::Players[i].Clear();
CWorld::PlayerInFocus = 0; CWorld::PlayerInFocus = 0;
#ifdef PS2 #ifdef GTA_PS2
CWeaponEffects::Init(); CWeaponEffects::Init();
CSkidmarks::Init(); CSkidmarks::Init();
#endif #endif
CAntennas::Init(); CAntennas::Init();
CGlass::Init(); CGlass::Init();
gPhoneInfo.Initialise(); gPhoneInfo.Initialise();
PUSH_MEMID(MEMID_SCRIPT);
CTheScripts::Init(); CTheScripts::Init();
CGangs::Initialise(); CGangs::Initialise();
POP_MEMID();
CTimer::Initialise(); CTimer::Initialise();
CClock::Initialise(1000); CClock::Initialise(1000);
CTheCarGenerators::Init(); CTheCarGenerators::Init();
@ -592,7 +669,7 @@ void CGame::ReInitGameObjectVariables(void)
CPickups::Init(); CPickups::Init();
CPacManPickups::Init(); CPacManPickups::Init();
CGarages::Init(); CGarages::Init();
#ifdef PS2 #ifdef GTA_PS2
CClouds::Init(); CClouds::Init();
CRemote::Init(); CRemote::Init();
#endif #endif
@ -807,7 +884,7 @@ void CGame::InitialiseWhenRestarting(void)
void CGame::Process(void) void CGame::Process(void)
{ {
CPad::UpdatePads(); CPad::UpdatePads();
#ifdef GTA_PS2 #ifdef USE_CUSTOM_ALLOCATOR
ProcessTidyUpMemory(); ProcessTidyUpMemory();
#endif #endif
TheCamera.SetMotionBlurAlpha(0); TheCamera.SetMotionBlurAlpha(0);
@ -817,8 +894,12 @@ void CGame::Process(void)
DebugMenuProcess(); DebugMenuProcess();
#endif #endif
CCutsceneMgr::Update(); CCutsceneMgr::Update();
PUSH_MEMID(MEMID_FRONTEND);
if (!CCutsceneMgr::IsCutsceneProcessing() && !CTimer::GetIsCodePaused()) if (!CCutsceneMgr::IsCutsceneProcessing() && !CTimer::GetIsCodePaused())
FrontEndMenuManager.Process(); FrontEndMenuManager.Process();
POP_MEMID();
CStreaming::Update(); CStreaming::Update();
if (!CTimer::GetIsPaused()) if (!CTimer::GetIsPaused())
{ {
@ -831,7 +912,11 @@ void CGame::Process(void)
CPad::DoCheats(); CPad::DoCheats();
CClock::Update(); CClock::Update();
CWeather::Update(); CWeather::Update();
PUSH_MEMID(MEMID_SCRIPT);
CTheScripts::Process(); CTheScripts::Process();
POP_MEMID();
CCollision::Update(); CCollision::Update();
CTrain::UpdateTrains(); CTrain::UpdateTrains();
CPlane::UpdatePlanes(); CPlane::UpdatePlanes();
@ -855,7 +940,11 @@ void CGame::Process(void)
CWaterCannons::Update(); CWaterCannons::Update();
CUserDisplay::Process(); CUserDisplay::Process();
CReplay::Update(); CReplay::Update();
PUSH_MEMID(MEMID_WORLD);
CWorld::Process(); CWorld::Process();
POP_MEMID();
gAccidentManager.Update(); gAccidentManager.Update();
CPacManPickups::Update(); CPacManPickups::Update();
CPickups::Update(); CPickups::Update();
@ -876,33 +965,35 @@ void CGame::Process(void)
gPhoneInfo.Update(); gPhoneInfo.Update();
if (!CReplay::IsPlayingBack()) if (!CReplay::IsPlayingBack())
{ {
PUSH_MEMID(MEMID_CARS);
CCarCtrl::GenerateRandomCars(); CCarCtrl::GenerateRandomCars();
CRoadBlocks::GenerateRoadBlocks(); CRoadBlocks::GenerateRoadBlocks();
CCarCtrl::RemoveDistantCars(); CCarCtrl::RemoveDistantCars();
POP_MEMID();
} }
} }
#ifdef PS2 #ifdef GTA_PS2
CMemCheck::DoTest(); CMemCheck::DoTest();
#endif #endif
} }
void CGame::DrasticTidyUpMemory(bool) void CGame::DrasticTidyUpMemory(bool)
{ {
#ifdef PS2 #ifdef USE_CUSTOM_ALLOCATOR
// meow // meow
#endif #endif
} }
void CGame::TidyUpMemory(bool, bool) void CGame::TidyUpMemory(bool, bool)
{ {
#ifdef PS2 #ifdef USE_CUSTOM_ALLOCATOR
// meow // meow
#endif #endif
} }
void CGame::ProcessTidyUpMemory(void) void CGame::ProcessTidyUpMemory(void)
{ {
#ifdef PS2 #ifdef USE_CUSTOM_ALLOCATOR
// meow // meow
#endif #endif
} }

View File

@ -12,6 +12,7 @@
#include "Streaming.h" #include "Streaming.h"
#include "Wanted.h" #include "Wanted.h"
#include "World.h" #include "World.h"
#include "MemoryHeap.h"
CCPtrNodePool *CPools::ms_pPtrNodePool; CCPtrNodePool *CPools::ms_pPtrNodePool;
CEntryInfoNodePool *CPools::ms_pEntryInfoNodePool; CEntryInfoNodePool *CPools::ms_pEntryInfoNodePool;
@ -23,18 +24,36 @@ CObjectPool *CPools::ms_pObjectPool;
CDummyPool *CPools::ms_pDummyPool; CDummyPool *CPools::ms_pDummyPool;
CAudioScriptObjectPool *CPools::ms_pAudioScriptObjectPool; CAudioScriptObjectPool *CPools::ms_pAudioScriptObjectPool;
#ifdef GTA_PS2 // or USE_CUSTOM_ALLOCATOR
#define CHECKMEM(msg) CMemCheck::AllocateMemCheckBlock(msg)
#else
#define CHECKMEM(msg)
#endif
void void
CPools::Initialise(void) CPools::Initialise(void)
{ {
PUSH_MEMID(MEMID_POOLS);
CHECKMEM("before pools");
ms_pPtrNodePool = new CCPtrNodePool(NUMPTRNODES); ms_pPtrNodePool = new CCPtrNodePool(NUMPTRNODES);
CHECKMEM("after CPtrNodePool");
ms_pEntryInfoNodePool = new CEntryInfoNodePool(NUMENTRYINFOS); ms_pEntryInfoNodePool = new CEntryInfoNodePool(NUMENTRYINFOS);
CHECKMEM("after CEntryInfoNodePool");
ms_pPedPool = new CPedPool(NUMPEDS); ms_pPedPool = new CPedPool(NUMPEDS);
CHECKMEM("after CPedPool");
ms_pVehiclePool = new CVehiclePool(NUMVEHICLES); ms_pVehiclePool = new CVehiclePool(NUMVEHICLES);
CHECKMEM("after CVehiclePool");
ms_pBuildingPool = new CBuildingPool(NUMBUILDINGS); ms_pBuildingPool = new CBuildingPool(NUMBUILDINGS);
CHECKMEM("after CBuildingPool");
ms_pTreadablePool = new CTreadablePool(NUMTREADABLES); ms_pTreadablePool = new CTreadablePool(NUMTREADABLES);
CHECKMEM("after CTreadablePool");
ms_pObjectPool = new CObjectPool(NUMOBJECTS); ms_pObjectPool = new CObjectPool(NUMOBJECTS);
CHECKMEM("after CObjectPool");
ms_pDummyPool = new CDummyPool(NUMDUMMIES); ms_pDummyPool = new CDummyPool(NUMDUMMIES);
CHECKMEM("after CDummyPool");
ms_pAudioScriptObjectPool = new CAudioScriptObjectPool(NUMAUDIOSCRIPTOBJECTS); ms_pAudioScriptObjectPool = new CAudioScriptObjectPool(NUMAUDIOSCRIPTOBJECTS);
CHECKMEM("after pools");
POP_MEMID();
} }
void void

View File

@ -34,6 +34,8 @@
#include "main.h" #include "main.h"
#include "Frontend.h" #include "Frontend.h"
#include "Font.h" #include "Font.h"
#include "MemoryMgr.h"
#include "MemoryHeap.h"
bool CStreaming::ms_disableStreaming; bool CStreaming::ms_disableStreaming;
bool CStreaming::ms_bLoadingBigModel; bool CStreaming::ms_bLoadingBigModel;
@ -489,8 +491,10 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
// Set Txd to use // Set Txd to use
CTxdStore::AddRef(mi->GetTxdSlot()); CTxdStore::AddRef(mi->GetTxdSlot());
CTxdStore::SetCurrentTxd(mi->GetTxdSlot());
PUSH_MEMID(MEMID_STREAM_MODELS);
CTxdStore::SetCurrentTxd(mi->GetTxdSlot());
// TODO(USE_CUSTOM_ALLOCATOR): register mem pointers
if(mi->IsSimple()){ if(mi->IsSimple()){
success = CFileLoader::LoadAtomicFile(stream, streamId); success = CFileLoader::LoadAtomicFile(stream, streamId);
} else if (mi->GetModelType() == MITYPE_VEHICLE) { } else if (mi->GetModelType() == MITYPE_VEHICLE) {
@ -502,6 +506,7 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
}else{ }else{
success = CFileLoader::LoadClumpFile(stream, streamId); success = CFileLoader::LoadClumpFile(stream, streamId);
} }
POP_MEMID();
UpdateMemoryUsed(); UpdateMemoryUsed();
// Txd no longer needed unless we only read part of the file // Txd no longer needed unless we only read part of the file
@ -525,12 +530,14 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
return false; return false;
} }
PUSH_MEMID(MEMID_STREAM_TEXUTRES);
if(ms_bLoadingBigModel || cdsize > 200){ if(ms_bLoadingBigModel || cdsize > 200){
success = CTxdStore::StartLoadTxd(streamId - STREAM_OFFSET_TXD, stream); success = CTxdStore::StartLoadTxd(streamId - STREAM_OFFSET_TXD, stream);
if(success) if(success)
ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_STARTED; ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_STARTED;
}else }else
success = CTxdStore::LoadTxd(streamId - STREAM_OFFSET_TXD, stream); success = CTxdStore::LoadTxd(streamId - STREAM_OFFSET_TXD, stream);
POP_MEMID();
UpdateMemoryUsed(); UpdateMemoryUsed();
if(!success){ if(!success){
@ -580,7 +587,9 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
// Mark objects as loaded // Mark objects as loaded
if(ms_aInfoForModel[streamId].m_loadState != STREAMSTATE_STARTED){ if(ms_aInfoForModel[streamId].m_loadState != STREAMSTATE_STARTED){
ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_LOADED; ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_LOADED;
#ifndef USE_CUSTOM_ALLOCATOR
ms_memoryUsed += ms_aInfoForModel[streamId].GetCdSize() * CDSTREAM_SECTOR_SIZE; ms_memoryUsed += ms_aInfoForModel[streamId].GetCdSize() * CDSTREAM_SECTOR_SIZE;
#endif
} }
endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond(); endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond();
@ -619,32 +628,40 @@ CStreaming::FinishLoadingLargeFile(int8 *buf, int32 streamId)
if(streamId < STREAM_OFFSET_TXD){ if(streamId < STREAM_OFFSET_TXD){
// Model // Model
// TODO(USE_CUSTOM_ALLOCATOR): register pointers
mi = CModelInfo::GetModelInfo(streamId); mi = CModelInfo::GetModelInfo(streamId);
PUSH_MEMID(MEMID_STREAM_MODELS);
CTxdStore::SetCurrentTxd(mi->GetTxdSlot()); CTxdStore::SetCurrentTxd(mi->GetTxdSlot());
success = CFileLoader::FinishLoadClumpFile(stream, streamId); success = CFileLoader::FinishLoadClumpFile(stream, streamId);
if(success) if(success)
success = AddToLoadedVehiclesList(streamId); success = AddToLoadedVehiclesList(streamId);
POP_MEMID();
mi->RemoveRef(); mi->RemoveRef();
CTxdStore::RemoveRefWithoutDelete(mi->GetTxdSlot()); CTxdStore::RemoveRefWithoutDelete(mi->GetTxdSlot());
}else{ }else{
// Txd // Txd
CTxdStore::AddRef(streamId - STREAM_OFFSET_TXD); CTxdStore::AddRef(streamId - STREAM_OFFSET_TXD);
PUSH_MEMID(MEMID_STREAM_TEXUTRES);
success = CTxdStore::FinishLoadTxd(streamId - STREAM_OFFSET_TXD, stream); success = CTxdStore::FinishLoadTxd(streamId - STREAM_OFFSET_TXD, stream);
POP_MEMID();
CTxdStore::RemoveRefWithoutDelete(streamId - STREAM_OFFSET_TXD); CTxdStore::RemoveRefWithoutDelete(streamId - STREAM_OFFSET_TXD);
} }
RwStreamClose(stream, &mem); RwStreamClose(stream, &mem);
ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_LOADED;
ms_aInfoForModel[streamId].m_loadState = STREAMSTATE_LOADED; // only done if success on PS2
#ifndef USE_CUSTOM_ALLOCATOR
ms_memoryUsed += ms_aInfoForModel[streamId].GetCdSize() * CDSTREAM_SECTOR_SIZE; ms_memoryUsed += ms_aInfoForModel[streamId].GetCdSize() * CDSTREAM_SECTOR_SIZE;
#endif
if(!success){ if(!success){
RemoveModel(streamId); RemoveModel(streamId);
ReRequestModel(streamId); ReRequestModel(streamId);
UpdateMemoryUsed(); UpdateMemoryUsed(); // directly after pop on PS2
return false; return false;
} }
UpdateMemoryUsed(); UpdateMemoryUsed(); // directly after pop on PS2
endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond(); endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond();
timeDiff = endTime - startTime; timeDiff = endTime - startTime;
@ -877,7 +894,11 @@ CStreaming::RemoveModel(int32 id)
CModelInfo::GetModelInfo(id)->DeleteRwObject(); CModelInfo::GetModelInfo(id)->DeleteRwObject();
else else
CTxdStore::RemoveTxd(id - STREAM_OFFSET_TXD); CTxdStore::RemoveTxd(id - STREAM_OFFSET_TXD);
#ifdef USE_CUSTOM_ALLOCATOR
UpdateMemoryUsed();
#else
ms_memoryUsed -= ms_aInfoForModel[id].GetCdSize()*CDSTREAM_SECTOR_SIZE; ms_memoryUsed -= ms_aInfoForModel[id].GetCdSize()*CDSTREAM_SECTOR_SIZE;
#endif
} }
if(ms_aInfoForModel[id].m_next){ if(ms_aInfoForModel[id].m_next){
@ -899,6 +920,9 @@ CStreaming::RemoveModel(int32 id)
RpClumpGtaCancelStream(); RpClumpGtaCancelStream();
else else
CTxdStore::RemoveTxd(id - STREAM_OFFSET_TXD); CTxdStore::RemoveTxd(id - STREAM_OFFSET_TXD);
#ifdef USE_CUSTOM_ALLOCATOR
UpdateMemoryUsed();
#endif
} }
ms_aInfoForModel[id].m_loadState = STREAMSTATE_NOTLOADED; ms_aInfoForModel[id].m_loadState = STREAMSTATE_NOTLOADED;
@ -2063,19 +2087,25 @@ CStreaming::FlushRequestList(void)
void void
CStreaming::ImGonnaUseStreamingMemory(void) CStreaming::ImGonnaUseStreamingMemory(void)
{ {
// empty PUSH_MEMID(MEMID_STREAM);
} }
void void
CStreaming::IHaveUsedStreamingMemory(void) CStreaming::IHaveUsedStreamingMemory(void)
{ {
POP_MEMID();
UpdateMemoryUsed(); UpdateMemoryUsed();
} }
void void
CStreaming::UpdateMemoryUsed(void) CStreaming::UpdateMemoryUsed(void)
{ {
// empty #ifdef USE_CUSTOM_ALLOCATOR
ms_memoryUsed =
gMainHeap.GetMemoryUsed(MEMID_STREAM) +
gMainHeap.GetMemoryUsed(MEMID_STREAM_MODELS) +
gMainHeap.GetMemoryUsed(MEMID_STREAM_TEXUTRES);
#endif
} }
#define STREAM_DIST 80.0f #define STREAM_DIST 80.0f

View File

@ -53,6 +53,9 @@ bool CWorld::bIncludeCarTyres;
void void
CWorld::Initialise() CWorld::Initialise()
{ {
#ifdef GTA_PS2
CPools::Initialise();
#endif
pIgnoreEntity = nil; pIgnoreEntity = nil;
bDoingCarCollisions = false; bDoingCarCollisions = false;
bSecondShift = false; bSecondShift = false;

View File

@ -67,6 +67,7 @@
#include "custompipes.h" #include "custompipes.h"
#include "screendroplets.h" #include "screendroplets.h"
#include "frontendoption.h" #include "frontendoption.h"
#include "MemoryHeap.h"
GlobalScene Scene; GlobalScene Scene;
@ -109,6 +110,15 @@ void TheGame(void);
void DebugMenuPopulate(void); void DebugMenuPopulate(void);
#endif #endif
#ifdef GTA_PS2
#define WANT_TO_LOAD TheMemoryCard.m_bWantToLoad
#define FOUND_GAME_TO_LOAD TheMemoryCard.b_FoundRecentSavedGameWantToLoad
#else
#define WANT_TO_LOAD FrontEndMenuManager.m_bWantToLoad
#define FOUND_GAME_TO_LOAD b_FoundRecentSavedGameWantToLoad
#endif
void void
ValidateVersion() ValidateVersion()
{ {
@ -772,6 +782,170 @@ tZonePrint ZonePrint[] =
}; };
#ifndef MASTER #ifndef MASTER
void
PrintMemoryUsage(void)
{
// little hack
if(CPools::GetPtrNodePool() == nil)
return;
// Style taken from LCS, modified for III
// CFont::SetFontStyle(FONT_PAGER);
CFont::SetFontStyle(FONT_BANK);
CFont::SetBackgroundOff();
CFont::SetWrapx(640.0f);
// CFont::SetScale(0.5f, 0.75f);
CFont::SetScale(0.4f, 0.75f);
CFont::SetCentreOff();
CFont::SetCentreSize(640.0f);
CFont::SetJustifyOff();
CFont::SetPropOn();
CFont::SetColor(CRGBA(200, 200, 200, 200));
CFont::SetBackGroundOnlyTextOff();
CFont::SetDropShadowPosition(0);
float y;
#ifdef USE_CUSTOM_ALLOCATOR
y = 24.0f;
sprintf(gString, "Total: %d blocks, %d bytes", gMainHeap.m_totalBlocksUsed, gMainHeap.m_totalMemUsed);
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Game: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_GAME), gMainHeap.GetMemoryUsed(MEMID_GAME));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "World: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_WORLD), gMainHeap.GetMemoryUsed(MEMID_WORLD));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Render: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_RENDER), gMainHeap.GetMemoryUsed(MEMID_RENDER));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Render List: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_RENDERLIST), gMainHeap.GetMemoryUsed(MEMID_RENDERLIST));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Default Models: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_DEF_MODELS), gMainHeap.GetMemoryUsed(MEMID_DEF_MODELS));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Textures: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_TEXTURES), gMainHeap.GetMemoryUsed(MEMID_TEXTURES));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Streaming: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_STREAM), gMainHeap.GetMemoryUsed(MEMID_STREAM));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Streamed Models: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_STREAM_MODELS), gMainHeap.GetMemoryUsed(MEMID_STREAM_MODELS));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Streamed Textures: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_STREAM_TEXUTRES), gMainHeap.GetMemoryUsed(MEMID_STREAM_TEXUTRES));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Animation: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_ANIMATION), gMainHeap.GetMemoryUsed(MEMID_ANIMATION));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Pools: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_POOLS), gMainHeap.GetMemoryUsed(MEMID_POOLS));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Collision: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_COLLISION), gMainHeap.GetMemoryUsed(MEMID_COLLISION));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Game Process: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_GAME_PROCESS), gMainHeap.GetMemoryUsed(MEMID_GAME_PROCESS));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Script: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_SCRIPT), gMainHeap.GetMemoryUsed(MEMID_SCRIPT));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Cars: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_CARS), gMainHeap.GetMemoryUsed(MEMID_CARS));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Frontend: %d blocks, %d bytes", gMainHeap.GetBlocksUsed(MEMID_FRONTEND), gMainHeap.GetMemoryUsed(MEMID_FRONTEND));
AsciiToUnicode(gString, gUString);
CFont::PrintString(24.0f, y, gUString);
y += 12.0f;
#endif
y = 132.0f;
AsciiToUnicode("Pools usage:", gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "PtrNode: %d/%d", CPools::GetPtrNodePool()->GetNoOfUsedSpaces(), CPools::GetPtrNodePool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "EntryInfoNode: %d/%d", CPools::GetEntryInfoNodePool()->GetNoOfUsedSpaces(), CPools::GetEntryInfoNodePool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Ped: %d/%d", CPools::GetPedPool()->GetNoOfUsedSpaces(), CPools::GetPedPool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Vehicle: %d/%d", CPools::GetVehiclePool()->GetNoOfUsedSpaces(), CPools::GetVehiclePool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Building: %d/%d", CPools::GetBuildingPool()->GetNoOfUsedSpaces(), CPools::GetBuildingPool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Treadable: %d/%d", CPools::GetTreadablePool()->GetNoOfUsedSpaces(), CPools::GetTreadablePool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Object: %d/%d", CPools::GetObjectPool()->GetNoOfUsedSpaces(), CPools::GetObjectPool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "Dummy: %d/%d", CPools::GetDummyPool()->GetNoOfUsedSpaces(), CPools::GetDummyPool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
sprintf(gString, "AudioScriptObjects: %d/%d", CPools::GetAudioScriptObjectPool()->GetNoOfUsedSpaces(), CPools::GetAudioScriptObjectPool()->GetSize());
AsciiToUnicode(gString, gUString);
CFont::PrintString(400.0f, y, gUString);
y += 12.0f;
}
void void
DisplayGameDebugText() DisplayGameDebugText()
{ {
@ -785,6 +959,7 @@ DisplayGameDebugText()
} }
#endif #endif
// PrintMemoryUsage(); // TODO: put this somewhere else
char str[200]; char str[200];
wchar ustr[200]; wchar ustr[200];
@ -1001,13 +1176,9 @@ RenderMenus(void)
{ {
if (FrontEndMenuManager.m_bMenuActive) if (FrontEndMenuManager.m_bMenuActive)
{ {
#ifdef PS2 PUSH_MEMID(MEMID_FRONTEND);
gMainHeap.PushMemId(_TODOCONST(17));
#endif
FrontEndMenuManager.DrawFrontEnd(); FrontEndMenuManager.DrawFrontEnd();
#ifdef PS2 POP_MEMID();
gMainHeap.PopMemId();
#endif
} }
} }
@ -1046,24 +1217,29 @@ Idle(void *arg)
CPad::UpdatePads(); CPad::UpdatePads();
FrontEndMenuManager.Process(); FrontEndMenuManager.Process();
} else { } else {
PUSH_MEMID(MEMID_GAME_PROCESS);
CPointLights::InitPerFrame(); CPointLights::InitPerFrame();
tbStartTimer(0, "CGame::Process"); tbStartTimer(0, "CGame::Process");
CGame::Process(); CGame::Process();
tbEndTimer("CGame::Process"); tbEndTimer("CGame::Process");
POP_MEMID();
tbStartTimer(0, "DMAudio.Service"); tbStartTimer(0, "DMAudio.Service");
DMAudio.Service(); DMAudio.Service();
tbEndTimer("DMAudio.Service"); tbEndTimer("DMAudio.Service");
} }
if (RsGlobal.quit) if (RsGlobal.quit)
return; return;
#else #else
PUSH_MEMID(MEMID_GAME_PROCESS);
CPointLights::InitPerFrame(); CPointLights::InitPerFrame();
tbStartTimer(0, "CGame::Process"); tbStartTimer(0, "CGame::Process");
CGame::Process(); CGame::Process();
tbEndTimer("CGame::Process"); tbEndTimer("CGame::Process");
POP_MEMID();
tbStartTimer(0, "DMAudio.Service"); tbStartTimer(0, "DMAudio.Service");
DMAudio.Service(); DMAudio.Service();
@ -1071,21 +1247,12 @@ Idle(void *arg)
#endif #endif
if(CGame::bDemoMode && CTimer::GetTimeInMilliseconds() > (3*60 + 30)*1000 && !CCutsceneMgr::IsCutsceneProcessing()){ if(CGame::bDemoMode && CTimer::GetTimeInMilliseconds() > (3*60 + 30)*1000 && !CCutsceneMgr::IsCutsceneProcessing()){
#ifdef PS2_MENU WANT_TO_LOAD = false;
TheMemoryCard.m_bWantToLoad = false;
FrontEndMenuManager.m_bWantToRestart = true; FrontEndMenuManager.m_bWantToRestart = true;
#else
FrontEndMenuManager.m_bWantToRestart = true;
FrontEndMenuManager.m_bWantToLoad = false;
#endif
return; return;
} }
#ifdef PS2_MENU if(FrontEndMenuManager.m_bWantToRestart || FOUND_GAME_TO_LOAD)
if ( FrontEndMenuManager.m_bWantToRestart || TheMemoryCard.b_FoundRecentSavedGameWantToLoad )
#else
if(FrontEndMenuManager.m_bWantToRestart || b_FoundRecentSavedGameWantToLoad)
#endif
{ {
return; return;
} }
@ -1095,6 +1262,8 @@ Idle(void *arg)
if(arg == nil) if(arg == nil)
return; return;
PUSH_MEMID(MEMID_RENDER);
if((!FrontEndMenuManager.m_bMenuActive || FrontEndMenuManager.m_bRenderGameInMenu) && if((!FrontEndMenuManager.m_bMenuActive || FrontEndMenuManager.m_bRenderGameInMenu) &&
TheCamera.GetScreenFadeStatus() != FADE_2) TheCamera.GetScreenFadeStatus() != FADE_2)
{ {
@ -1107,6 +1276,8 @@ Idle(void *arg)
RsMouseSetPos(&pos); RsMouseSetPos(&pos);
} }
#endif #endif
PUSH_MEMID(MEMID_RENDERLIST);
tbStartTimer(0, "CnstrRenderList"); tbStartTimer(0, "CnstrRenderList");
CRenderer::ConstructRenderList(); CRenderer::ConstructRenderList();
tbEndTimer("CnstrRenderList"); tbEndTimer("CnstrRenderList");
@ -1114,6 +1285,7 @@ Idle(void *arg)
tbStartTimer(0, "PreRender"); tbStartTimer(0, "PreRender");
CRenderer::PreRender(); CRenderer::PreRender();
tbEndTimer("PreRender"); tbEndTimer("PreRender");
POP_MEMID();
#ifdef FIX_BUGS #ifdef FIX_BUGS
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); // TODO: temp? this fixes OpenGL render but there should be a better place for this RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); // TODO: temp? this fixes OpenGL render but there should be a better place for this
@ -1124,12 +1296,12 @@ Idle(void *arg)
if(CWeather::LightningFlash && !CCullZones::CamNoRain()){ if(CWeather::LightningFlash && !CCullZones::CamNoRain()){
if(!DoRWStuffStartOfFrame_Horizon(255, 255, 255, 255, 255, 255, 255)) if(!DoRWStuffStartOfFrame_Horizon(255, 255, 255, 255, 255, 255, 255))
return; goto popret;
}else{ }else{
if(!DoRWStuffStartOfFrame_Horizon(CTimeCycle::GetSkyTopRed(), CTimeCycle::GetSkyTopGreen(), CTimeCycle::GetSkyTopBlue(), if(!DoRWStuffStartOfFrame_Horizon(CTimeCycle::GetSkyTopRed(), CTimeCycle::GetSkyTopGreen(), CTimeCycle::GetSkyTopBlue(),
CTimeCycle::GetSkyBottomRed(), CTimeCycle::GetSkyBottomGreen(), CTimeCycle::GetSkyBottomBlue(), CTimeCycle::GetSkyBottomRed(), CTimeCycle::GetSkyBottomGreen(), CTimeCycle::GetSkyBottomBlue(),
255)) 255))
return; goto popret;
} }
DefinedState(); DefinedState();
@ -1176,7 +1348,7 @@ Idle(void *arg)
CVisibilityPlugins::SetRenderWareCamera(Scene.camera); CVisibilityPlugins::SetRenderWareCamera(Scene.camera);
RwCameraClear(Scene.camera, &gColourTop, rwCAMERACLEARZ); RwCameraClear(Scene.camera, &gColourTop, rwCAMERACLEARZ);
if(!RsCameraBeginUpdate(Scene.camera)) if(!RsCameraBeginUpdate(Scene.camera))
return; goto popret;
} }
#ifdef PS2_SAVE_DIALOG #ifdef PS2_SAVE_DIALOG
@ -1189,7 +1361,7 @@ Idle(void *arg)
#ifdef PS2_MENU #ifdef PS2_MENU
if ( TheMemoryCard.m_bWantToLoad ) if ( TheMemoryCard.m_bWantToLoad )
return; goto popret;
#endif #endif
tbStartTimer(0, "DoFade"); tbStartTimer(0, "DoFade");
@ -1208,8 +1380,13 @@ Idle(void *arg)
DoRWStuffEndOfFrame(); DoRWStuffEndOfFrame();
POP_MEMID(); // MEMID_RENDER
if(g_SlowMode) if(g_SlowMode)
ProcessSlowMode(); ProcessSlowMode();
return;
popret: POP_MEMID(); // MEMID_RENDER
} }
void void
@ -1375,14 +1552,13 @@ TheModelViewer(void)
} }
#endif #endif
#ifdef PS2
#ifdef GTA_PS2
void TheGame(void) void TheGame(void)
{ {
printf("Into TheGame!!!\n"); printf("Into TheGame!!!\n");
#ifdef GTA_PS2 PUSH_MEMID(MEMID_GAME); // NB: not popped
gMainHeap.PushMemId(_TODOCONST(1));
#endif
CTimer::Initialise(); CTimer::Initialise();
@ -1420,77 +1596,49 @@ void TheGame(void)
while (true) while (true)
{ {
#ifdef PS2 if (WANT_TO_LOAD)
if (TheMemoryCard.m_bWantToLoad)
#else
if (FrontEndMenuManager.m_bWantToLoad)
#endif
{ {
Const char *splash1 = GetLevelSplashScreen(CGame::currLevel); Const char *splash1 = GetLevelSplashScreen(CGame::currLevel);
LoadSplash(splash1); LoadSplash(splash1);
} }
#ifdef PS2 WANT_TO_LOAD = false;
TheMemoryCard.m_bWantToLoad = false;
#else
FrontEndMenuManager.m_bWantToLoad = false;
#endif
CTimer::Update(); CTimer::Update();
#ifdef PS2 while (!(FrontEndMenuManager.m_bWantToRestart || FOUND_GAME_TO_LOAD))
while (!(FrontEndMenuManager.m_bWantToRestart || TheMemoryCard.b_FoundRecentSavedGameWantToLoad))
#else
while (!(FrontEndMenuManager.m_bWantToRestart || b_FoundRecentSavedGameWantToLoad))
#endif
{ {
CSprite2d::InitPerFrame(); CSprite2d::InitPerFrame();
CFont::InitPerFrame(); CFont::InitPerFrame();
#ifdef GTA_PS2 PUSH_MEMID(MEMID_GAME_PROCESS)
gMainHeap.PushMemId(_TODOCONST(12)); CPointLights::InitPerFrame();
#endif
CPointLights::NumLights = 0;
CGame::Process(); CGame::Process();
#ifdef GTA_PS2 POP_MEMID();
gMainHeap.PopMemId();
#endif
DMAudio.Service(); DMAudio.Service();
if (CGame::bDemoMode && CTimer::GetTimeInMilliseconds() > (3*60 + 30)*1000 && !CCutsceneMgr::IsCutsceneProcessing()) if (CGame::bDemoMode && CTimer::GetTimeInMilliseconds() > (3*60 + 30)*1000 && !CCutsceneMgr::IsCutsceneProcessing())
{ {
#ifdef PS2 WANT_TO_LOAD = false;
TheMemoryCard.m_bWantToLoad = false;
#else
FrontEndMenuManager.m_bWantToLoad = false;
#endif
FrontEndMenuManager.m_bWantToRestart = true; FrontEndMenuManager.m_bWantToRestart = true;
break; break;
} }
#ifdef PS2 if (FrontEndMenuManager.m_bWantToRestart || FOUND_GAME_TO_LOAD)
if (FrontEndMenuManager.m_bWantToRestart || TheMemoryCard.b_FoundRecentSavedGameWantToLoad)
#else
if (FrontEndMenuManager.m_bWantToRestart || b_FoundRecentSavedGameWantToLoad)
#endif
break; break;
SetLightsWithTimeOfDayColour(Scene.world); SetLightsWithTimeOfDayColour(Scene.world);
#ifdef GTA_PS2
gMainHeap.PushMemId(_TODOCONST(15)); PUSH_MEMID(MEMID_RENDER);
#endif
if (!FrontEndMenuManager.m_bMenuActive || FrontEndMenuManager.m_bRenderGameInMenu == true && TheCamera.GetScreenFadeStatus() != FADE_2 ) if (!FrontEndMenuManager.m_bMenuActive || FrontEndMenuManager.m_bRenderGameInMenu == true && TheCamera.GetScreenFadeStatus() != FADE_2 )
{ {
#ifdef GTA_PS2
gMainHeap.PushMemId(_TODOCONST(11)); PUSH_MEMID(MEMID_RENDERLIST);
#endif
CRenderer::ConstructRenderList(); CRenderer::ConstructRenderList();
CRenderer::PreRender(); CRenderer::PreRender();
#ifdef GTA_PS2 POP_MEMID();
gMainHeap.PopMemId();
#endif
if (CWeather::LightningFlash && !CCullZones::CamNoRain()) if (CWeather::LightningFlash && !CCullZones::CamNoRain())
DoRWStuffStartOfFrame_Horizon(255, 255, 255, 255, 255, 255, 255); DoRWStuffStartOfFrame_Horizon(255, 255, 255, 255, 255, 255, 255);
@ -1522,15 +1670,9 @@ void TheGame(void)
RenderMenus(); RenderMenus();
#ifdef PS2 if (WANT_TO_LOAD)
if (TheMemoryCard.m_bWantToLoad)
#else
if (FrontEndMenuManager.m_bWantToLoad)
#endif
{ {
#ifdef GTA_PS2 POP_MEMID(); // MEMID_RENDER
gMainHeap.PopMemId();
#endif
break; break;
} }
@ -1547,9 +1689,7 @@ void TheGame(void)
CTimer::Update(); CTimer::Update();
#ifdef GTA_PS2 POP_MEMID(): // MEMID_RENDER
gMainHeap.PopMemId();
#endif
if (g_SlowMode) if (g_SlowMode)
ProcessSlowMode(); ProcessSlowMode();
@ -1561,24 +1701,12 @@ void TheGame(void)
CGame::ShutDownForRestart(); CGame::ShutDownForRestart();
CTimer::Stop(); CTimer::Stop();
#ifdef PS2 if (FrontEndMenuManager.m_bWantToRestart || FOUND_GAME_TO_LOAD)
if (FrontEndMenuManager.m_bWantToRestart || TheMemoryCard.b_FoundRecentSavedGameWantToLoad)
#else
if (FrontEndMenuManager.m_bWantToRestart || b_FoundRecentSavedGameWantToLoad)
#endif
{ {
#ifdef PS2 if (FOUND_GAME_TO_LOAD)
if (TheMemoryCard.b_FoundRecentSavedGameWantToLoad)
#else
if (b_FoundRecentSavedGameWantToLoad)
#endif
{ {
FrontEndMenuManager.m_bWantToRestart = true; FrontEndMenuManager.m_bWantToRestart = true;
#ifdef PS2 WANT_TO_LOAD = true;
TheMemoryCard.m_bWantToLoad = true;
#else
FrontEndMenuManager.m_bWantToLoad = true;
#endif
} }
CGame::InitialiseWhenRestarting(); CGame::InitialiseWhenRestarting();
@ -1718,7 +1846,7 @@ void SystemInit()
// //
#endif #endif
#ifdef PS2 #ifdef GTA_PS2
TheMemoryCard.Init(); TheMemoryCard.Init();
#endif #endif
} }
@ -1747,7 +1875,7 @@ void GameInit()
#endif #endif
CdStreamInit(MAX_CDCHANNELS); CdStreamInit(MAX_CDCHANNELS);
#ifdef PS2 #ifdef GTA_PS2
Initialise3D(); //no params Initialise3D(); //no params
#else #else
//TODO //TODO
@ -1861,14 +1989,11 @@ void GameInit()
CSprite2d::SetRecipNearClip(); CSprite2d::SetRecipNearClip();
CTxdStore::Initialise(); CTxdStore::Initialise();
#ifdef GTA_PS2
gMainHeap.PushMemId(_TODOCONST(9)); PUSH_MEMID(MEMID_TEXTURES);
#endif
CFont::Initialise(); CFont::Initialise();
CHud::Initialise(); CHud::Initialise();
#ifdef GTA_PS2 POP_MEMID();
gMainHeap.PopMemId();
#endif
ValidateVersion(); ValidateVersion();
@ -1896,7 +2021,7 @@ main(int argc, char *argv[])
SystemInit(); SystemInit();
#ifdef PS2 #ifdef GTA_PS2
int32 r = TheMemoryCard.CheckCardStateAtGameStartUp(CARD_ONE); int32 r = TheMemoryCard.CheckCardStateAtGameStartUp(CARD_ONE);
if ( r == CMemoryCard::ERR_DIRNOENTRY || r == CMemoryCard::ERR_NOFORMAT if ( r == CMemoryCard::ERR_DIRNOENTRY || r == CMemoryCard::ERR_NOFORMAT

View File

@ -46,8 +46,8 @@ class CPool
public: public:
CPool(int size){ CPool(int size){
// TODO: use new here // TODO: use new here
m_entries = (U*)malloc(sizeof(U)*size); m_entries = (U*)new uint8[sizeof(U)*size];
m_flags = (Flags*)malloc(sizeof(Flags)*size); m_flags = (Flags*)new uint8[sizeof(Flags)*size];
m_size = size; m_size = size;
m_allocPtr = 0; m_allocPtr = 0;
for(int i = 0; i < size; i++){ for(int i = 0; i < size; i++){
@ -61,8 +61,8 @@ public:
} }
void Flush() { void Flush() {
if (m_size > 0) { if (m_size > 0) {
free(m_entries); delete[] (uint8*)m_entries;
free(m_flags); delete[] (uint8*)m_flags;
m_entries = nil; m_entries = nil;
m_flags = nil; m_flags = nil;
m_size = 0; m_size = 0;
@ -141,8 +141,8 @@ public:
} }
bool IsFreeSlot(int i) { return !!m_flags[i].free; } bool IsFreeSlot(int i) { return !!m_flags[i].free; }
void ClearStorage(uint8 *&flags, U *&entries){ void ClearStorage(uint8 *&flags, U *&entries){
free(flags); delete[] (uint8*)flags;
free(entries); delete[] (uint8*)entries;
flags = nil; flags = nil;
entries = nil; entries = nil;
} }
@ -156,8 +156,8 @@ public:
debug("CopyBack:%d (/%d)\n", GetNoOfUsedSpaces(), m_size); /* Assumed inlining */ debug("CopyBack:%d (/%d)\n", GetNoOfUsedSpaces(), m_size); /* Assumed inlining */
} }
void Store(uint8 *&flags, U *&entries){ void Store(uint8 *&flags, U *&entries){
flags = (uint8*)malloc(sizeof(uint8)*m_size); flags = (uint8*)new uint8[sizeof(uint8)*m_size];
entries = (U*)malloc(sizeof(U)*m_size); entries = (U*)new uint8[sizeof(U)*m_size];
memcpy(flags, m_flags, sizeof(uint8)*m_size); memcpy(flags, m_flags, sizeof(uint8)*m_size);
memcpy(entries, m_entries, sizeof(U)*m_size); memcpy(entries, m_entries, sizeof(U)*m_size);
debug("Stored:%d (/%d)\n", GetNoOfUsedSpaces(), m_size); /* Assumed inlining */ debug("Stored:%d (/%d)\n", GetNoOfUsedSpaces(), m_size); /* Assumed inlining */

View File

@ -28,6 +28,7 @@
#include "Bones.h" #include "Bones.h"
#include "Debug.h" #include "Debug.h"
#include "Renderer.h" #include "Renderer.h"
#include "MemoryHeap.h"
int gBuildings; int gBuildings;
@ -274,7 +275,11 @@ CEntity::CreateRwObject(void)
CBaseModelInfo *mi; CBaseModelInfo *mi;
mi = CModelInfo::GetModelInfo(m_modelIndex); mi = CModelInfo::GetModelInfo(m_modelIndex);
PUSH_MEMID(MEMID_WORLD);
m_rwObject = mi->CreateInstance(); m_rwObject = mi->CreateInstance();
POP_MEMID();
if(m_rwObject){ if(m_rwObject){
if(IsBuilding()) if(IsBuilding())
gBuildings++; gBuildings++;

View File

@ -3,7 +3,7 @@
#include "General.h" #include "General.h"
#include "ModelIndices.h" #include "ModelIndices.h"
#define X(name, var) int16 var; #define X(name, var) int16 var = -1;
MODELINDICES MODELINDICES
#undef X #undef X

View File

@ -14,6 +14,7 @@
#include "RwHelper.h" #include "RwHelper.h"
#include "Timer.h" #include "Timer.h"
#include "Lights.h" #include "Lights.h"
#include "MemoryMgr.h"
RpClump *gpPlayerClump; RpClump *gpPlayerClump;
float gOldFov; float gOldFov;

View File

@ -21,6 +21,7 @@
#include "RenderBuffer.h" #include "RenderBuffer.h"
#include <rpworld.h> #include <rpworld.h>
#include "WaterLevel.h" #include "WaterLevel.h"
#include "MemoryHeap.h"
float TEXTURE_ADDU; float TEXTURE_ADDU;
@ -1157,6 +1158,8 @@ CWaterLevel::AllocateBoatWakeArray()
{ {
CStreaming::MakeSpaceFor(14 * CDSTREAM_SECTOR_SIZE); CStreaming::MakeSpaceFor(14 * CDSTREAM_SECTOR_SIZE);
PUSH_MEMID(MEMID_STREAM);
ASSERT(ms_pWavyAtomic != NULL ); ASSERT(ms_pWavyAtomic != NULL );
RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic);
@ -1230,6 +1233,8 @@ CWaterLevel::AllocateBoatWakeArray()
RpGeometryUnlock(apGeomArray[geom]); RpGeometryUnlock(apGeomArray[geom]);
} }
} }
POP_MEMID();
} }
void void

View File

@ -44,7 +44,7 @@ CMemoryHeap::Init(uint32 total)
m_end = (HeapBlockDesc*)(mem + total - sizeof(HeapBlockDesc)); m_end = (HeapBlockDesc*)(mem + total - sizeof(HeapBlockDesc));
m_start->m_memId = MEMID_FREE; m_start->m_memId = MEMID_FREE;
m_start->m_size = total - 2*sizeof(HeapBlockDesc); m_start->m_size = total - 2*sizeof(HeapBlockDesc);
m_end->m_memId = MEMID_ID1; m_end->m_memId = MEMID_GAME;
m_end->m_size = 0; m_end->m_size = 0;
m_freeList.m_last.m_size = INT_MAX; m_freeList.m_last.m_size = INT_MAX;
@ -65,7 +65,7 @@ CMemoryHeap::Init(uint32 total)
RegisterMalloc(GetDescFromHeapPointer(m_memUsed)); RegisterMalloc(GetDescFromHeapPointer(m_memUsed));
RegisterMalloc(GetDescFromHeapPointer(m_blocksUsed)); RegisterMalloc(GetDescFromHeapPointer(m_blocksUsed));
m_currentMemID = MEMID_ID1; m_currentMemID = MEMID_GAME;
for(int i = 0; i < NUM_MEMIDS; i++){ for(int i = 0; i < NUM_MEMIDS; i++){
m_memUsed[i] = 0; m_memUsed[i] = 0;
m_blocksUsed[i] = 0; m_blocksUsed[i] = 0;
@ -90,8 +90,8 @@ CMemoryHeap::RegisterFree(HeapBlockDesc *block)
if(block->m_memId == MEMID_FREE) if(block->m_memId == MEMID_FREE)
return; return;
m_totalMemUsed -= block->m_size + sizeof(HeapBlockDesc); m_totalMemUsed -= block->m_size + sizeof(HeapBlockDesc);
m_memUsed[m_currentMemID] -= block->m_size + sizeof(HeapBlockDesc); m_memUsed[block->m_memId] -= block->m_size + sizeof(HeapBlockDesc);
m_blocksUsed[m_currentMemID]--; m_blocksUsed[block->m_memId]--;
m_totalBlocksUsed--; m_totalBlocksUsed--;
} }
@ -433,13 +433,16 @@ CMemoryHeap::GetBlocksUsed(int32 id)
void void
CMemoryHeap::PopMemId(void) CMemoryHeap::PopMemId(void)
{ {
assert(m_idStack.sp > 0);
m_currentMemID = m_idStack.pop(); m_currentMemID = m_idStack.pop();
assert(m_currentMemID != MEMID_FREE);
} }
void void
CMemoryHeap::PushMemId(int32 id) CMemoryHeap::PushMemId(int32 id)
{ {
MEMORYHEAP_ASSERT(id != MEMID_FREE); MEMORYHEAP_ASSERT(id != MEMID_FREE);
assert(m_idStack.sp < 16);
m_idStack.push(m_currentMemID); m_idStack.push(m_currentMemID);
m_currentMemID = id; m_currentMemID = id;
} }
@ -457,7 +460,7 @@ CMemoryHeap::ParseHeap(void)
for(HeapBlockDesc *block = m_start; block < m_end; block = block->GetNextConsecutive()){ for(HeapBlockDesc *block = m_start; block < m_end; block = block->GetNextConsecutive()){
char chr = '*'; // free char chr = '*'; // free
if(block->m_memId != MEMID_FREE) if(block->m_memId != MEMID_FREE)
chr = block->m_memId-MEMID_ID1 + 'A'; chr = block->m_memId-1 + 'A';
int numQW = block->m_size>>4; int numQW = block->m_size>>4;
if((addrQW & 0x3F) == 0){ if((addrQW & 0x3F) == 0){
@ -491,66 +494,4 @@ CommonSize::Init(uint32 size)
m_remaining = 0; m_remaining = 0;
} }
void *pMemoryTop;
void
InitMemoryMgr(void)
{
#ifdef GTA_PS2
#error "finish this"
#else
// randomly allocate 128mb
gMainHeap.Init(128*1024*1024);
#endif
}
void*
MemoryMgrMalloc(uint32 size)
{
void *mem = gMainHeap.Malloc(size);
if(mem > pMemoryTop)
pMemoryTop = mem;
return mem;
}
void*
MemoryMgrRealloc(void *ptr, uint32 size)
{
void *mem = gMainHeap.Realloc(ptr, size);
if(mem > pMemoryTop)
pMemoryTop = mem;
return mem;
}
void*
MemoryMgrCalloc(uint32 num, uint32 size)
{
void *mem = gMainHeap.Malloc(num*size);
if(mem > pMemoryTop)
pMemoryTop = mem;
#ifdef FIX_BUGS
memset(mem, 0, num*size);
#endif
return mem;
}
void
MemoryMgrFree(void *ptr)
{
#ifdef FIX_BUGS
// i don't suppose this is handled by RW?
if(ptr == nil) return;
#endif
gMainHeap.Free(ptr);
}
RwMemoryFunctions memFuncs = {
MemoryMgrMalloc,
MemoryMgrFree,
MemoryMgrRealloc,
MemoryMgrCalloc
};
#endif #endif

View File

@ -5,8 +5,62 @@
#undef MoveMemory #undef MoveMemory
#endif #endif
extern RwMemoryFunctions memFuncs; #ifdef USE_CUSTOM_ALLOCATOR
void InitMemoryMgr(void); #define PUSH_MEMID(id) gMainHeap.PushMemId(id)
#define POP_MEMID() gMainHeap.PopMemId()
#define REGISTER_MEMPTR(ptr) gMainHeap.RegisterMemPointer(ptr)
#else
#define PUSH_MEMID(id)
#define POP_MEMID()
#define REGISTER_MEMPTR(ptr)
#endif
enum {
MEMID_FREE,
// IDs from LCS:
/*
MEMID_GAME = 1, // "Game"
MEMID_WORLD = 2, // "World"
MEMID_ANIMATION = 3, // "Animation"
MEMID_POOLS = 4, // "Pools"
MEMID_DEF_MODELS = 5, // "Default Models"
MEMID_STREAM = 6, // "Streaming"
MEMID_STREAM_MODELS = 7, // "Streamed Models"
MEMID_STREAM_LODS = 8, // "Streamed LODs"
MEMID_STREAM_TEXUTRES = 9, // "Streamed Textures"
MEMID_STREAM_COLLISION = 10, // "Streamed Collision"
MEMID_STREAM_ANIMATION = 11, // "Streamed Animation"
MEMID_TEXTURES = 12, // "Textures"
MEMID_COLLISION = 13, // "Collision"
MEMID_PRE_ALLOC = 14, // "PreAlloc"
MEMID_GAME_PROCESS = 15, // "Game Process"
MEMID_SCRIPT = 16, // "Script"
MEMID_CARS = 17, // "Cars"
MEMID_RENDER = 18, // "Render"
MEMID_PED_ATTR = 19, // "Ped Attr"
*/
// III:
MEMID_GAME = 1, // "Game"
MEMID_WORLD = 2, // "World"
MEMID_ANIMATION = 3, // "Animation"
MEMID_POOLS = 4, // "Pools"
MEMID_DEF_MODELS = 5, // "Default Models"
MEMID_STREAM = 6, // "Streaming"
MEMID_STREAM_MODELS = 7, // "Streamed Models" (instance)
MEMID_STREAM_TEXUTRES = 8, // "Streamed Textures"
MEMID_TEXTURES = 9, // "Textures"
MEMID_COLLISION = 10, // "Collision"
MEMID_RENDERLIST = 11, // ?
MEMID_GAME_PROCESS = 12, // "Game Process"
MEMID_SCRIPT = 13, // "Script"
MEMID_CARS = 14, // "Cars"
MEMID_RENDER = 15, // "Render"
MEMID_FRONTEND = 17, // ?
NUM_MEMIDS,
NUM_FIXED_MEMBLOCKS = 6
};
template<typename T, uint32 N> template<typename T, uint32 N>
class CStack class CStack
@ -17,7 +71,7 @@ public:
CStack() : sp(0) {} CStack() : sp(0) {}
void push(const T& val) { values[sp++] = val; } void push(const T& val) { values[sp++] = val; }
T& pop() { return values[sp--]; } T& pop() { return values[--sp]; }
}; };
@ -111,34 +165,6 @@ struct CommonSize
} }
}; };
enum {
MEMID_FREE,
// IDs from LCS:
MEMID_ID1, // "Game"
MEMID_ID2, // "World"
MEMID_ID3, // "Animation"
MEMID_ID4, // "Pools"
MEMID_ID5, // "Default Models"
MEMID_ID6, // "Streaming"
MEMID_ID7, // "Streamed Models"
MEMID_ID8, // "Streamed LODs"
MEMID_ID9, // "Streamed Textures"
MEMID_ID10, // "Streamed Collision"
MEMID_ID11, // "Streamed Animation"
MEMID_ID12, // "Textures"
MEMID_ID13, // "Collision"
MEMID_ID14, // "PreAlloc"
MEMID_ID15, // "Game Process"
MEMID_ID16, // "Script"
MEMID_ID17, // "Cars"
MEMID_ID18, // "Render"
MEMID_ID19, // "Ped Attr"
NUM_MEMIDS,
NUM_FIXED_MEMBLOCKS = 6
};
class CMemoryHeap class CMemoryHeap
{ {
public: public:
@ -194,3 +220,5 @@ public:
block->InsertHeapFreeBlock(b->m_prev); block->InsertHeapFreeBlock(b->m_prev);
} }
}; };
extern CMemoryHeap gMainHeap;

130
src/rw/MemoryMgr.cpp Normal file
View File

@ -0,0 +1,130 @@
#include "common.h"
#include "MemoryHeap.h"
#include "MemoryMgr.h"
void *pMemoryTop;
void
InitMemoryMgr(void)
{
#ifdef USE_CUSTOM_ALLOCATOR
#ifdef GTA_PS2
#error "finish this"
#else
// randomly allocate 128mb
gMainHeap.Init(128*1024*1024);
#endif
#endif
}
RwMemoryFunctions memFuncs = {
MemoryMgrMalloc,
MemoryMgrFree,
MemoryMgrRealloc,
MemoryMgrCalloc
};
#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); }
#endif
void*
MemoryMgrMalloc(size_t size)
{
#ifdef USE_CUSTOM_ALLOCATOR
void *mem = gMainHeap.Malloc(size);
#else
void *mem = malloc(size);
#endif
if(mem > pMemoryTop)
pMemoryTop = mem;
return mem;
}
void*
MemoryMgrRealloc(void *ptr, size_t size)
{
#ifdef USE_CUSTOM_ALLOCATOR
void *mem = gMainHeap.Realloc(ptr, size);
#else
void *mem = realloc(ptr, size);
#endif
if(mem > pMemoryTop)
pMemoryTop = mem;
return mem;
}
void*
MemoryMgrCalloc(size_t num, size_t size)
{
#ifdef USE_CUSTOM_ALLOCATOR
void *mem = gMainHeap.Malloc(num*size);
#else
void *mem = calloc(num, size);
#endif
if(mem > pMemoryTop)
pMemoryTop = mem;
#ifdef FIX_BUGS
memset(mem, 0, num*size);
#endif
return mem;
}
void
MemoryMgrFree(void *ptr)
{
#ifdef USE_CUSTOM_ALLOCATOR
#ifdef FIX_BUGS
// i don't suppose this is handled by RW?
if(ptr == nil) return;
#endif
gMainHeap.Free(ptr);
#else
free(ptr);
#endif
}
void *
RwMallocAlign(RwUInt32 size, RwUInt32 align)
{
#ifdef FIX_BUGS
uintptr ptralign = align-1;
void *mem = (void *)MemoryMgrMalloc(size + sizeof(uintptr) + ptralign);
ASSERT(mem != nil);
void *addr = (void *)((((uintptr)mem) + sizeof(uintptr) + ptralign) & ~ptralign);
ASSERT(addr != nil);
#else
void *mem = (void *)MemoryMgrMalloc(size + align);
ASSERT(mem != nil);
void *addr = (void *)((((uintptr)mem) + align) & ~(align - 1));
ASSERT(addr != nil);
#endif
*(((void **)addr) - 1) = mem;
return addr;
}
void
RwFreeAlign(void *mem)
{
ASSERT(mem != nil);
void *addr = *(((void **)mem) - 1);
ASSERT(addr != nil);
MemoryMgrFree(addr);
}

12
src/rw/MemoryMgr.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
extern RwMemoryFunctions memFuncs;
void InitMemoryMgr(void);
void *MemoryMgrMalloc(size_t size);
void *MemoryMgrRealloc(void *ptr, size_t size);
void *MemoryMgrCalloc(size_t num, size_t size);
void MemoryMgrFree(void *ptr);
void *RwMallocAlign(RwUInt32 size, RwUInt32 align);
void RwFreeAlign(void *mem);

View File

@ -64,45 +64,6 @@ void FlushObrsPrintfs()
#endif #endif
} }
void *
RwMallocAlign(RwUInt32 size, RwUInt32 align)
{
#ifdef FIX_BUGS
uintptr ptralign = align-1;
void *mem = (void *)malloc(size + sizeof(uintptr) + ptralign);
ASSERT(mem != nil);
void *addr = (void *)((((uintptr)mem) + sizeof(uintptr) + ptralign) & ~ptralign);
ASSERT(addr != nil);
#else
void *mem = (void *)malloc(size + align);
ASSERT(mem != nil);
void *addr = (void *)((((uintptr)mem) + align) & ~(align - 1));
ASSERT(addr != nil);
#endif
*(((void **)addr) - 1) = mem;
return addr;
}
void
RwFreeAlign(void *mem)
{
ASSERT(mem != nil);
void *addr = *(((void **)mem) - 1);
ASSERT(addr != nil);
free(addr);
}
void void
DefinedState(void) DefinedState(void)
{ {

View File

@ -2,9 +2,6 @@
extern bool gPS2alphaTest; extern bool gPS2alphaTest;
void *RwMallocAlign(RwUInt32 size, RwUInt32 align);
void RwFreeAlign(void *mem);
void OpenCharsetSafe(); void OpenCharsetSafe();
void CreateDebugFont(); void CreateDebugFont();
void DestroyDebugFont(); void DestroyDebugFont();

View File

@ -10,6 +10,7 @@
#include "VisibilityPlugins.h" #include "VisibilityPlugins.h"
#include "World.h" #include "World.h"
#include "custompipes.h" #include "custompipes.h"
#include "MemoryHeap.h"
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaList; CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaList;
CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaEntityList; CLinkList<CVisibilityPlugins::AlphaObjectInfo> CVisibilityPlugins::m_alphaEntityList;
@ -30,6 +31,41 @@ float CVisibilityPlugins::ms_pedLod0Dist;
float CVisibilityPlugins::ms_pedLod1Dist; float CVisibilityPlugins::ms_pedLod1Dist;
float CVisibilityPlugins::ms_pedFadeDist; float CVisibilityPlugins::ms_pedFadeDist;
#ifdef GTA_PS2
void
rpDefaultGeometryInstance(RpGeometry *geo, void *atomic, int unk)
{
// TODO
// this function seems to delete the original geometry data
// and only keep the instanced data
AtomicDefaultRenderCallBack((RpAtomic*)atomic);
}
RpAtomic*
PreInstanceRenderCB(RpAtomic *atomic)
{
RpGeometry *geo = RpAtomicGetGeometry(atomic);
if(RpGeometryGetTriangles(geo)){
PUSH_MEMID(MEMID_STREAM_MODELS);
rpDefaultGeometryInstance(geo, atomic, 1);
POP_MEMID();
}else
AtomicDefaultRenderCallBack(atomic);
return atomic;
}
#define RENDERCALLBACK PreInstanceRenderCB
#else
RpAtomic*
DefaultRenderCB_pushid(RpAtomic *atomic)
{
PUSH_MEMID(MEMID_STREAM_MODELS);
AtomicDefaultRenderCallBack(atomic);
POP_MEMID();
return atomic;
}
#define RENDERCALLBACK DefaultRenderCB_pushid
#endif
void void
CVisibilityPlugins::Initialise(void) CVisibilityPlugins::Initialise(void)
{ {
@ -132,7 +168,7 @@ CVisibilityPlugins::RenderAlphaAtomics(void)
for(node = m_alphaList.tail.prev; for(node = m_alphaList.tail.prev;
node != &m_alphaList.head; node != &m_alphaList.head;
node = node->prev) node = node->prev)
AtomicDefaultRenderCallBack(node->item.atomic); RENDERCALLBACK(node->item.atomic);
} }
void void
@ -201,7 +237,7 @@ CVisibilityPlugins::RenderWheelAtomicCB(RpAtomic *atomic)
if(lodatm){ if(lodatm){
if(RpAtomicGetGeometry(lodatm) != RpAtomicGetGeometry(atomic)) if(RpAtomicGetGeometry(lodatm) != RpAtomicGetGeometry(atomic))
RpAtomicSetGeometry(atomic, RpAtomicGetGeometry(lodatm), rpATOMICSAMEBOUNDINGSPHERE); RpAtomicSetGeometry(atomic, RpAtomicGetGeometry(lodatm), rpATOMICSAMEBOUNDINGSPHERE);
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
return atomic; return atomic;
} }
@ -218,7 +254,7 @@ CVisibilityPlugins::RenderObjNormalAtomic(RpAtomic *atomic)
len = RwV3dLength(&view); len = RwV3dLength(&view);
if(RwV3dDotProduct(&view, RwMatrixGetUp(m)) < -0.3f*len && len > 8.0f) if(RwV3dDotProduct(&view, RwMatrixGetUp(m)) < -0.3f*len && len > 8.0f)
return atomic; return atomic;
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
return atomic; return atomic;
} }
@ -232,7 +268,7 @@ CVisibilityPlugins::RenderAlphaAtomic(RpAtomic *atomic, int alpha)
flags = RpGeometryGetFlags(geo); flags = RpGeometryGetFlags(geo);
RpGeometrySetFlags(geo, flags | rpGEOMETRYMODULATEMATERIALCOLOR); RpGeometrySetFlags(geo, flags | rpGEOMETRYMODULATEMATERIALCOLOR);
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha); RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha);
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255); RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255);
RpGeometrySetFlags(geo, flags); RpGeometrySetFlags(geo, flags);
return atomic; return atomic;
@ -250,7 +286,7 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist)
lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE); lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE);
if(mi->m_additive){ if(mi->m_additive){
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE);
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA);
}else{ }else{
fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE; fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE;
@ -258,7 +294,7 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist)
fadefactor = 1.0f; fadefactor = 1.0f;
alpha = mi->m_alpha * fadefactor; alpha = mi->m_alpha * fadefactor;
if(alpha == 255) if(alpha == 255)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
else{ else{
RpGeometry *geo = RpAtomicGetGeometry(lodatm); RpGeometry *geo = RpAtomicGetGeometry(lodatm);
uint32 flags = RpGeometryGetFlags(geo); uint32 flags = RpGeometryGetFlags(geo);
@ -266,7 +302,7 @@ CVisibilityPlugins::RenderFadingAtomic(RpAtomic *atomic, float camdist)
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha); RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)alpha);
if(geo != RpAtomicGetGeometry(atomic)) if(geo != RpAtomicGetGeometry(atomic))
RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255); RpGeometryForAllMaterials(geo, SetAlphaCB, (void*)255);
RpGeometrySetFlags(geo, flags); RpGeometrySetFlags(geo, flags);
} }
@ -293,7 +329,7 @@ CVisibilityPlugins::RenderVehicleHiDetailCB(RpAtomic *atomic)
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot)) if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot))
return atomic; return atomic;
} }
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
return atomic; return atomic;
} }
@ -318,10 +354,10 @@ CVisibilityPlugins::RenderVehicleHiDetailAlphaCB(RpAtomic *atomic)
if(flags & ATOMIC_FLAG_DRAWLAST){ if(flags & ATOMIC_FLAG_DRAWLAST){
// sort before clump // sort before clump
if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f)) if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f))
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
}else{ }else{
if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
} }
return atomic; return atomic;
@ -344,7 +380,7 @@ CVisibilityPlugins::RenderVehicleHiDetailCB_BigVehicle(RpAtomic *atomic)
if(dot > 0.0f) if(dot > 0.0f)
return atomic; return atomic;
} }
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
return atomic; return atomic;
} }
@ -367,7 +403,7 @@ CVisibilityPlugins::RenderVehicleHiDetailAlphaCB_BigVehicle(RpAtomic *atomic)
return atomic; return atomic;
if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
return atomic; return atomic;
} }
@ -381,7 +417,7 @@ CVisibilityPlugins::RenderVehicleHiDetailCB_Boat(RpAtomic *atomic)
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
distsq = GetDistanceSquaredFromCamera(clumpframe); distsq = GetDistanceSquaredFromCamera(clumpframe);
if(distsq < ms_bigVehicleLod1Dist) if(distsq < ms_bigVehicleLod1Dist)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
return atomic; return atomic;
} }
@ -403,7 +439,7 @@ CVisibilityPlugins::RenderVehicleLowDetailCB_BigVehicle(RpAtomic *atomic)
if(dot > 0.0f) if(dot > 0.0f)
return atomic; return atomic;
} }
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
return atomic; return atomic;
} }
@ -427,7 +463,7 @@ CVisibilityPlugins::RenderVehicleLowDetailAlphaCB_BigVehicle(RpAtomic *atomic)
return atomic; return atomic;
if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
return atomic; return atomic;
} }
@ -444,7 +480,7 @@ CVisibilityPlugins::RenderVehicleReallyLowDetailCB(RpAtomic *atomic)
if(dist >= ms_vehicleLod0Dist){ if(dist >= ms_vehicleLod0Dist){
alpha = GetClumpAlpha(clump); alpha = GetClumpAlpha(clump);
if(alpha == 255) if(alpha == 255)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
else else
RenderAlphaAtomic(atomic, alpha); RenderAlphaAtomic(atomic, alpha);
} }
@ -461,7 +497,7 @@ CVisibilityPlugins::RenderVehicleReallyLowDetailCB_BigVehicle(RpAtomic *atomic)
clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic)); clumpframe = RpClumpGetFrame(RpAtomicGetClump(atomic));
distsq = GetDistanceSquaredFromCamera(clumpframe); distsq = GetDistanceSquaredFromCamera(clumpframe);
if(distsq >= ms_bigVehicleLod1Dist) if(distsq >= ms_bigVehicleLod1Dist)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
return atomic; return atomic;
} }
@ -482,7 +518,7 @@ CVisibilityPlugins::RenderTrainHiDetailCB(RpAtomic *atomic)
if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot)) if(dot > 0.0f && ((flags & ATOMIC_FLAG_ANGLECULL) || 0.1f*distsq < dot*dot))
return atomic; return atomic;
} }
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
return atomic; return atomic;
} }
@ -507,10 +543,10 @@ CVisibilityPlugins::RenderTrainHiDetailAlphaCB(RpAtomic *atomic)
if(flags & ATOMIC_FLAG_DRAWLAST){ if(flags & ATOMIC_FLAG_DRAWLAST){
// sort before clump // sort before clump
if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f)) if(!InsertAtomicIntoSortedList(atomic, distsq - 0.0001f))
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
}else{ }else{
if(!InsertAtomicIntoSortedList(atomic, distsq + dot)) if(!InsertAtomicIntoSortedList(atomic, distsq + dot))
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
} }
} }
return atomic; return atomic;
@ -521,7 +557,7 @@ CVisibilityPlugins::RenderPlayerCB(RpAtomic *atomic)
{ {
if(CWorld::Players[0].m_pSkinTexture) if(CWorld::Players[0].m_pSkinTexture)
RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), SetTextureCB, CWorld::Players[0].m_pSkinTexture); RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), SetTextureCB, CWorld::Players[0].m_pSkinTexture);
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
return atomic; return atomic;
} }
@ -537,7 +573,7 @@ CVisibilityPlugins::RenderPedLowDetailCB(RpAtomic *atomic)
if(dist >= ms_pedLod0Dist){ if(dist >= ms_pedLod0Dist){
alpha = GetClumpAlpha(clump); alpha = GetClumpAlpha(clump);
if(alpha == 255) if(alpha == 255)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
else else
RenderAlphaAtomic(atomic, alpha); RenderAlphaAtomic(atomic, alpha);
} }
@ -556,7 +592,7 @@ CVisibilityPlugins::RenderPedHiDetailCB(RpAtomic *atomic)
if(dist < ms_pedLod0Dist){ if(dist < ms_pedLod0Dist){
alpha = GetClumpAlpha(clump); alpha = GetClumpAlpha(clump);
if(alpha == 255) if(alpha == 255)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
else else
RenderAlphaAtomic(atomic, alpha); RenderAlphaAtomic(atomic, alpha);
} }
@ -575,7 +611,7 @@ CVisibilityPlugins::RenderPedCB(RpAtomic *atomic)
if(RwV3dDotProduct(&cam2atm, &cam2atm) < ms_pedLod1Dist){ if(RwV3dDotProduct(&cam2atm, &cam2atm) < ms_pedLod1Dist){
alpha = GetClumpAlpha(RpAtomicGetClump(atomic)); alpha = GetClumpAlpha(RpAtomicGetClump(atomic));
if(alpha == 255) if(alpha == 255)
AtomicDefaultRenderCallBack(atomic); RENDERCALLBACK(atomic);
else else
RenderAlphaAtomic(atomic, alpha); RenderAlphaAtomic(atomic, alpha);
} }
@ -775,12 +811,11 @@ CVisibilityPlugins::GetAtomicId(RpAtomic *atomic)
return ATOMICEXT(atomic)->flags; return ATOMICEXT(atomic)->flags;
} }
// This is rather useless, but whatever
void void
CVisibilityPlugins::SetAtomicRenderCallback(RpAtomic *atomic, RpAtomicCallBackRender cb) CVisibilityPlugins::SetAtomicRenderCallback(RpAtomic *atomic, RpAtomicCallBackRender cb)
{ {
if(cb == nil) if(cb == nil)
cb = AtomicDefaultRenderCallBack; // not necessary cb = RENDERCALLBACK;
RpAtomicSetRenderCallBack(atomic, cb); RpAtomicSetRenderCallBack(atomic, cb);
} }

View File

@ -40,7 +40,7 @@
#include "Sprite2d.h" #include "Sprite2d.h"
#include "AnimViewer.h" #include "AnimViewer.h"
#include "Font.h" #include "Font.h"
#include "MemoryHeap.h" #include "MemoryMgr.h"
#define MAX_SUBSYSTEMS (16) #define MAX_SUBSYSTEMS (16)

View File

@ -10,6 +10,7 @@
#include "skeleton.h" #include "skeleton.h"
#include "platform.h" #include "platform.h"
#include "MemoryHeap.h"
@ -307,6 +308,8 @@ RsRwInitialize(void *displayID)
{ {
RwEngineOpenParams openParams; RwEngineOpenParams openParams;
PUSH_MEMID(MEMID_RENDER); // NB: not popped on failed return
/* /*
* Start RenderWare... * Start RenderWare...
*/ */
@ -374,6 +377,8 @@ RsRwInitialize(void *displayID)
RwTextureSetMipmapping(FALSE); RwTextureSetMipmapping(FALSE);
RwTextureSetAutoMipmapping(FALSE); RwTextureSetAutoMipmapping(FALSE);
POP_MEMID();
return TRUE; return TRUE;
} }

View File

@ -97,7 +97,7 @@ static psGlobalType PsGlobal;
#include "Sprite2d.h" #include "Sprite2d.h"
#include "AnimViewer.h" #include "AnimViewer.h"
#include "Font.h" #include "Font.h"
#include "MemoryHeap.h" #include "MemoryMgr.h"
VALIDATE_SIZE(psGlobalType, 0x28); VALIDATE_SIZE(psGlobalType, 0x28);

View File

@ -15,6 +15,7 @@
#include "World.h" #include "World.h"
#include "HandlingMgr.h" #include "HandlingMgr.h"
#include "Plane.h" #include "Plane.h"
#include "MemoryHeap.h"
CPlaneNode *pPathNodes; CPlaneNode *pPathNodes;
CPlaneNode *pPath2Nodes; CPlaneNode *pPath2Nodes;
@ -551,9 +552,11 @@ CPlane::ProcessControl(void)
if(m_rwObject && RwObjectGetType(m_rwObject) == rpCLUMP){ if(m_rwObject && RwObjectGetType(m_rwObject) == rpCLUMP){
DeleteRwObject(); DeleteRwObject();
if(mi->m_planeLodId != -1){ if(mi->m_planeLodId != -1){
PUSH_MEMID(MEMID_WORLD);
m_rwObject = CModelInfo::GetModelInfo(mi->m_planeLodId)->CreateInstance(); m_rwObject = CModelInfo::GetModelInfo(mi->m_planeLodId)->CreateInstance();
POP_MEMID();
if(m_rwObject) if(m_rwObject)
m_matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject))); m_matrix.AttachRW(RwFrameGetMatrix(RpAtomicGetFrame((RpAtomic*)m_rwObject)));
} }
} }
}else if(CStreaming::HasModelLoaded(GetModelIndex())){ }else if(CStreaming::HasModelLoaded(GetModelIndex())){