checked some of streaming for VC changes

This commit is contained in:
aap 2020-05-06 21:54:43 +02:00
parent 03cecb6f1c
commit 965ea93a61
8 changed files with 120 additions and 108 deletions

View File

@ -501,13 +501,13 @@ CPathFind::PreparePathData(void)
} }
for(i = 0; i < NUMDETACHED_CARS; i++) for(i = 0; i < NUMDETACHED_CARS; i++)
for(j = 0; j < 12; j++) for(j = 0; j < 12; j++)
if(DetachedInfoForTilePeds[i*12 + j].type == NodeTypeExtern){ if(DetachedInfoForTileCars[i*12 + j].type == NodeTypeExtern){
// MI:%d here but no argument for it // MI:%d here but no argument for it
if(DetachedInfoForTilePeds[i*12 + j].numLeftLanes < 0) if(DetachedInfoForTileCars[i*12 + j].numLeftLanes < 0)
printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i); printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i);
if(DetachedInfoForTilePeds[i*12 + j].numRightLanes < 0) if(DetachedInfoForTileCars[i*12 + j].numRightLanes < 0)
printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i); printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i);
if(DetachedInfoForTilePeds[i*12 + j].numLeftLanes + DetachedInfoForTilePeds[i*12 + j].numRightLanes <= 0) if(DetachedInfoForTileCars[i*12 + j].numLeftLanes + DetachedInfoForTileCars[i*12 + j].numRightLanes <= 0)
printf("ILLEGAL BLOCK. NO LANES IN NODE (Obj:%d)\n", i); printf("ILLEGAL BLOCK. NO LANES IN NODE (Obj:%d)\n", i);
} }

View File

@ -222,6 +222,7 @@ CColStore::EnsureCollisionIsInMemory(const CVector2D &pos)
} }
} }
//--MIAMI: done
bool bool
CColStore::HasCollisionLoaded(const CVector2D &pos) CColStore::HasCollisionLoaded(const CVector2D &pos)
{ {

View File

@ -641,7 +641,7 @@ CFileLoader::LoadObjectTypes(const char *filename)
for(id = minID; id <= maxID; id++){ for(id = minID; id <= maxID; id++){
CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(id); CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(id);
if(mi && mi->IsSimple()) if(mi && mi->IsBuilding())
mi->SetupBigBuilding(); mi->SetupBigBuilding();
} }
} }
@ -1143,7 +1143,7 @@ CFileLoader::LoadObjectInstance(const char *line)
entity->GetMatrix() = CMatrix(xform); entity->GetMatrix() = CMatrix(xform);
entity->m_level = CTheZones::GetLevelFromPosition(&entity->GetPosition()); entity->m_level = CTheZones::GetLevelFromPosition(&entity->GetPosition());
entity->m_area = area; entity->m_area = area;
if(mi->IsSimple()){ if(mi->IsBuilding()){
if(mi->m_isBigBuilding) if(mi->m_isBigBuilding)
entity->SetupBigBuilding(); entity->SetupBigBuilding();
if(mi->m_isSubway) if(mi->m_isSubway)

View File

@ -50,6 +50,7 @@ int32 CStreaming::ms_channelError;
int32 CStreaming::ms_numVehiclesLoaded; int32 CStreaming::ms_numVehiclesLoaded;
int32 CStreaming::ms_vehiclesLoaded[MAXVEHICLESLOADED]; int32 CStreaming::ms_vehiclesLoaded[MAXVEHICLESLOADED];
int32 CStreaming::ms_lastVehicleDeleted; int32 CStreaming::ms_lastVehicleDeleted;
bool CStreaming::ms_bIsPedFromPedGroupLoaded[NUMMODELSPERPEDGROUP];
CDirectory *CStreaming::ms_pExtraObjectsDir; CDirectory *CStreaming::ms_pExtraObjectsDir;
int32 CStreaming::ms_numPriorityRequests; int32 CStreaming::ms_numPriorityRequests;
int32 CStreaming::ms_currentPedGrp; int32 CStreaming::ms_currentPedGrp;
@ -69,6 +70,7 @@ CEntity *pIslandLODbeachEntity;
int32 islandLODmainland; int32 islandLODmainland;
int32 islandLODbeach; int32 islandLODbeach;
//--MIAMI: done
bool bool
CStreamingInfo::GetCdPosnAndSize(uint32 &posn, uint32 &size) CStreamingInfo::GetCdPosnAndSize(uint32 &posn, uint32 &size)
{ {
@ -79,6 +81,7 @@ CStreamingInfo::GetCdPosnAndSize(uint32 &posn, uint32 &size)
return true; return true;
} }
//--MIAMI: done
void void
CStreamingInfo::SetCdPosnAndSize(uint32 posn, uint32 size) CStreamingInfo::SetCdPosnAndSize(uint32 posn, uint32 size)
{ {
@ -86,6 +89,7 @@ CStreamingInfo::SetCdPosnAndSize(uint32 posn, uint32 size)
m_size = size; m_size = size;
} }
//--MIAMI: done
void void
CStreamingInfo::AddToList(CStreamingInfo *link) CStreamingInfo::AddToList(CStreamingInfo *link)
{ {
@ -96,6 +100,7 @@ CStreamingInfo::AddToList(CStreamingInfo *link)
m_next->m_prev = this; m_next->m_prev = this;
} }
//--MIAMI: done
void void
CStreamingInfo::RemoveFromList(void) CStreamingInfo::RemoveFromList(void)
{ {
@ -105,6 +110,7 @@ CStreamingInfo::RemoveFromList(void)
m_prev = nil; m_prev = nil;
} }
//--MIAMI: done
void void
CStreaming::Init2(void) CStreaming::Init2(void)
{ {
@ -174,12 +180,15 @@ CStreaming::Init2(void)
ms_vehiclesLoaded[i] = -1; ms_vehiclesLoaded[i] = -1;
ms_numVehiclesLoaded = 0; ms_numVehiclesLoaded = 0;
for(i = 0; i < ARRAY_SIZE(ms_bIsPedFromPedGroupLoaded); i++)
ms_bIsPedFromPedGroupLoaded[i] = false;
ms_pExtraObjectsDir = new CDirectory(EXTRADIRSIZE); ms_pExtraObjectsDir = new CDirectory(EXTRADIRSIZE);
ms_numPriorityRequests = 0; ms_numPriorityRequests = 0;
ms_currentPedGrp = -1; ms_currentPedGrp = -1;
ms_lastCullZone = -1; // unused because RemoveModelsNotVisibleFromCullzone is gone ms_lastCullZone = -1; // unused because RemoveModelsNotVisibleFromCullzone is gone
ms_loadedGangs = 0; ms_loadedGangs = 0;
ms_currentPedLoading = 8; // unused, whatever it is ms_currentPedLoading = NUMMODELSPERPEDGROUP; // unused, whatever it is
LoadCdDirectory(); LoadCdDirectory();
@ -190,19 +199,11 @@ CStreaming::Init2(void)
ms_pStreamingBuffer[1] = ms_pStreamingBuffer[0] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE; ms_pStreamingBuffer[1] = ms_pStreamingBuffer[0] + ms_streamingBufferSize*CDSTREAM_SECTOR_SIZE;
debug("Streaming buffer size is %d sectors", ms_streamingBufferSize); debug("Streaming buffer size is %d sectors", ms_streamingBufferSize);
// PC only, figure out how much memory we got
#ifdef GTA_PC
#define MB (1024*1024) #define MB (1024*1024)
extern unsigned long _dwMemAvailPhys; ms_memoryAvailable = 65*MB;
ms_memoryAvailable = (_dwMemAvailPhys - 10*MB)/2; desiredNumVehiclesLoaded = 25;
if(ms_memoryAvailable < 50*MB)
ms_memoryAvailable = 50*MB;
desiredNumVehiclesLoaded = (ms_memoryAvailable/MB - 50)/3 + 12;
if(desiredNumVehiclesLoaded > MAXVEHICLESLOADED)
desiredNumVehiclesLoaded = MAXVEHICLESLOADED;
debug("Memory allocated to Streaming is %dMB", ms_memoryAvailable/MB); debug("Memory allocated to Streaming is %dMB", ms_memoryAvailable/MB);
#undef MB #undef MB
#endif
// find island LODs // find island LODs
@ -237,6 +238,7 @@ CStreaming::Init(void)
#endif #endif
} }
//--MIAMI: done
void void
CStreaming::Shutdown(void) CStreaming::Shutdown(void)
{ {
@ -246,6 +248,7 @@ CStreaming::Shutdown(void)
delete ms_pExtraObjectsDir; delete ms_pExtraObjectsDir;
} }
//--MIAMI: done
void void
CStreaming::Update(void) CStreaming::Update(void)
{ {
@ -272,7 +275,7 @@ CStreaming::Update(void)
!CCutsceneMgr::IsCutsceneProcessing() && !CCutsceneMgr::IsCutsceneProcessing() &&
ms_numModelsRequested < 5 && ms_numModelsRequested < 5 &&
!CRenderer::m_loadingPriority && !CRenderer::m_loadingPriority &&
CGame::currArea == 0 && CGame::currArea == AREA_MAIN_MAP &&
!CReplay::IsPlayingBack()){ !CReplay::IsPlayingBack()){
StreamVehiclesAndPeds(); StreamVehiclesAndPeds();
StreamZoneModels(FindPlayerCoors()); StreamZoneModels(FindPlayerCoors());
@ -296,6 +299,7 @@ CStreaming::Update(void)
} }
} }
//--MIAMI: done
void void
CStreaming::LoadCdDirectory(void) CStreaming::LoadCdDirectory(void)
{ {
@ -309,12 +313,6 @@ CStreaming::LoadCdDirectory(void)
ms_imageOffsets[3] = -1; ms_imageOffsets[3] = -1;
ms_imageOffsets[4] = -1; ms_imageOffsets[4] = -1;
ms_imageOffsets[5] = -1; ms_imageOffsets[5] = -1;
ms_imageOffsets[6] = -1;
ms_imageOffsets[7] = -1;
ms_imageOffsets[8] = -1;
ms_imageOffsets[9] = -1;
ms_imageOffsets[10] = -1;
ms_imageOffsets[11] = -1;
ms_imageSize = GetGTA3ImgSize(); ms_imageSize = GetGTA3ImgSize();
// PS2 uses CFileMgr::GetCdFile on all IMG files to fill the array // PS2 uses CFileMgr::GetCdFile on all IMG files to fill the array
#endif #endif
@ -330,6 +328,7 @@ CStreaming::LoadCdDirectory(void)
ms_imageSize /= CDSTREAM_SECTOR_SIZE; ms_imageSize /= CDSTREAM_SECTOR_SIZE;
} }
//--MIAMI: needs IFP
void void
CStreaming::LoadCdDirectory(const char *dirname, int n) CStreaming::LoadCdDirectory(const char *dirname, int n)
{ {
@ -406,6 +405,22 @@ CStreaming::LoadCdDirectory(const char *dirname, int n)
CFileMgr::CloseFile(fd); CFileMgr::CloseFile(fd);
} }
static char*
GetObjectName(int streamId)
{
static char objname[32];
if(streamId < STREAM_OFFSET_TXD)
sprintf(objname, "%s.dff", CModelInfo::GetModelInfo(streamId)->GetName());
else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL)
sprintf(objname, "%s.txd", CTxdStore::GetTxdName(streamId-STREAM_OFFSET_TXD));
else if(streamId >= STREAM_OFFSET_COL && streamId < NUMSTREAMINFO)
sprintf(objname, "%s.col", CColStore::GetColName(streamId-STREAM_OFFSET_COL));
// TODO(MIAMI): IFP
return objname;
}
//--MIAMI: needs IFP
bool bool
CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId) CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
{ {
@ -444,6 +459,7 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
if(mi->IsSimple()){ if(mi->IsSimple()){
success = CFileLoader::LoadAtomicFile(stream, streamId); success = CFileLoader::LoadAtomicFile(stream, streamId);
// TODO(MIAMI)? complain if file is not pre-instanced. we hardly are interested in that
} else if (mi->GetModelType() == MITYPE_VEHICLE) { } else if (mi->GetModelType() == MITYPE_VEHICLE) {
// load vehicles in two parts // load vehicles in two parts
CModelInfo::GetModelInfo(streamId)->AddRef(); CModelInfo::GetModelInfo(streamId)->AddRef();
@ -468,7 +484,6 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
} }
}else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL){ }else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL){
// Txd // Txd
assert(streamId < NUMSTREAMINFO);
if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_KEEP_IN_MEMORY) == 0 && if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_KEEP_IN_MEMORY) == 0 &&
!IsTxdUsedByRequestedModels(streamId - STREAM_OFFSET_TXD)){ !IsTxdUsedByRequestedModels(streamId - STREAM_OFFSET_TXD)){
RemoveModel(streamId); RemoveModel(streamId);
@ -518,12 +533,12 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
smi->m_alpha = 0; smi->m_alpha = 0;
} }
if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_CANT_REMOVE) == 0) if(CanRemoveModel(streamId))
ms_aInfoForModel[streamId].AddToList(&ms_startLoadedList); ms_aInfoForModel[streamId].AddToList(&ms_startLoadedList);
} }
}else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL){ }else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL){
// Txd // Txd
if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_CANT_REMOVE) == 0) if(CanRemoveModel(streamId))
ms_aInfoForModel[streamId].AddToList(&ms_startLoadedList); ms_aInfoForModel[streamId].AddToList(&ms_startLoadedList);
// TODO(MIAMI): animations // TODO(MIAMI): animations
} }
@ -536,23 +551,13 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId)
endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond(); endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond();
timeDiff = endTime - startTime; timeDiff = endTime - startTime;
if(timeDiff > 5){ if(timeDiff > 5)
// TODO: is this inlined? debug("%s took %d ms\n", GetObjectName(streamId), timeDiff);
static char objname[32];
if(streamId < STREAM_OFFSET_TXD)
sprintf(objname, "%s.dff", CModelInfo::GetModelInfo(streamId)->GetName());
else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL)
sprintf(objname, "%s.txd", CTxdStore::GetTxdName(streamId-STREAM_OFFSET_TXD));
else if(streamId >= STREAM_OFFSET_COL && streamId < NUMSTREAMINFO)
sprintf(objname, "%s.col", CColStore::GetColName(streamId-STREAM_OFFSET_COL));
// TODO(MIAMI): IFP
debug("%s took %d ms\n", objname, timeDiff);
}
return true; return true;
} }
//--MIAMI: TODO: anim
bool bool
CStreaming::FinishLoadingLargeFile(int8 *buf, int32 streamId) CStreaming::FinishLoadingLargeFile(int8 *buf, int32 streamId)
{ {
@ -583,7 +588,8 @@ CStreaming::FinishLoadingLargeFile(int8 *buf, int32 streamId)
success = AddToLoadedVehiclesList(streamId); success = AddToLoadedVehiclesList(streamId);
mi->RemoveRef(); mi->RemoveRef();
CTxdStore::RemoveRefWithoutDelete(mi->GetTxdSlot()); CTxdStore::RemoveRefWithoutDelete(mi->GetTxdSlot());
}else{ // TODO(MIAMI): animation
}else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL){
// Txd // Txd
CTxdStore::AddRef(streamId - STREAM_OFFSET_TXD); CTxdStore::AddRef(streamId - STREAM_OFFSET_TXD);
success = CTxdStore::FinishLoadTxd(streamId - STREAM_OFFSET_TXD, stream); success = CTxdStore::FinishLoadTxd(streamId - STREAM_OFFSET_TXD, stream);
@ -605,16 +611,13 @@ CStreaming::FinishLoadingLargeFile(int8 *buf, int32 streamId)
endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond(); endTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond();
timeDiff = endTime - startTime; timeDiff = endTime - startTime;
if(timeDiff > 5){ if(timeDiff > 5)
if(streamId < STREAM_OFFSET_TXD) debug("%s took %d ms\n", GetObjectName(streamId), timeDiff);
debug("finish model %s took %d ms\n", CModelInfo::GetModelInfo(streamId)->GetName(), timeDiff);
else
debug("finish txd %s took %d ms\n", CTxdStore::GetTxdName(streamId - STREAM_OFFSET_TXD), timeDiff);
}
return true; return true;
} }
//--MIAMI: TODO: anim
void void
CStreaming::RequestModel(int32 id, int32 flags) CStreaming::RequestModel(int32 id, int32 flags)
{ {
@ -643,7 +646,7 @@ CStreaming::RequestModel(int32 id, int32 flags)
// reinsert into list // reinsert into list
if(ms_aInfoForModel[id].m_next){ if(ms_aInfoForModel[id].m_next){
ms_aInfoForModel[id].RemoveFromList(); ms_aInfoForModel[id].RemoveFromList();
if((ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0) if(CanRemoveModel(id))
ms_aInfoForModel[id].AddToList(&ms_startLoadedList); ms_aInfoForModel[id].AddToList(&ms_startLoadedList);
} }
}else if(ms_aInfoForModel[id].m_loadState == STREAMSTATE_NOTLOADED || }else if(ms_aInfoForModel[id].m_loadState == STREAMSTATE_NOTLOADED ||
@ -652,6 +655,7 @@ CStreaming::RequestModel(int32 id, int32 flags)
if(ms_aInfoForModel[id].m_loadState == STREAMSTATE_NOTLOADED){ if(ms_aInfoForModel[id].m_loadState == STREAMSTATE_NOTLOADED){
if(id < STREAM_OFFSET_TXD) if(id < STREAM_OFFSET_TXD)
RequestTxd(CModelInfo::GetModelInfo(id)->GetTxdSlot(), flags); RequestTxd(CModelInfo::GetModelInfo(id)->GetTxdSlot(), flags);
// TODO(MIAMI): animation
ms_aInfoForModel[id].AddToList(&ms_startRequestedList); ms_aInfoForModel[id].AddToList(&ms_startRequestedList);
ms_numModelsRequested++; ms_numModelsRequested++;
if(flags & STREAMFLAGS_PRIORITY) if(flags & STREAMFLAGS_PRIORITY)
@ -665,6 +669,7 @@ CStreaming::RequestModel(int32 id, int32 flags)
#define BIGBUILDINGFLAGS STREAMFLAGS_DONT_REMOVE #define BIGBUILDINGFLAGS STREAMFLAGS_DONT_REMOVE
//--MIAMI: done
void void
CStreaming::RequestBigBuildings(eLevelName level) CStreaming::RequestBigBuildings(eLevelName level)
{ {
@ -681,6 +686,7 @@ CStreaming::RequestBigBuildings(eLevelName level)
RequestIslands(level); RequestIslands(level);
} }
//--MIAMI: done
void void
CStreaming::RequestBigBuildings(eLevelName level, const CVector &pos) CStreaming::RequestBigBuildings(eLevelName level, const CVector &pos)
{ {
@ -700,6 +706,7 @@ CStreaming::RequestBigBuildings(eLevelName level, const CVector &pos)
RequestIslands(level); RequestIslands(level);
} }
//--MIAMI: done
void void
CStreaming::InstanceBigBuildings(eLevelName level, const CVector &pos) CStreaming::InstanceBigBuildings(eLevelName level, const CVector &pos)
{ {
@ -716,6 +723,8 @@ CStreaming::InstanceBigBuildings(eLevelName level, const CVector &pos)
} }
} }
// TODO(MIAMI): InstanceLoadedModels
//--MIAMI: done //--MIAMI: done
void void
CStreaming::RequestIslands(eLevelName level) CStreaming::RequestIslands(eLevelName level)
@ -732,6 +741,7 @@ CStreaming::RequestIslands(eLevelName level)
} }
} }
//--MIAMI: TODO
void void
CStreaming::RequestSpecialModel(int32 modelId, const char *modelName, int32 flags) CStreaming::RequestSpecialModel(int32 modelId, const char *modelName, int32 flags)
{ {
@ -773,24 +783,28 @@ CStreaming::RequestSpecialModel(int32 modelId, const char *modelName, int32 flag
RequestModel(modelId, flags); RequestModel(modelId, flags);
} }
//--MIAMI: done
void void
CStreaming::RequestSpecialChar(int32 charId, const char *modelName, int32 flags) CStreaming::RequestSpecialChar(int32 charId, const char *modelName, int32 flags)
{ {
RequestSpecialModel(charId + MI_SPECIAL01, modelName, flags); RequestSpecialModel(charId + MI_SPECIAL01, modelName, flags);
} }
//--MIAMI: done
bool bool
CStreaming::HasSpecialCharLoaded(int32 id) CStreaming::HasSpecialCharLoaded(int32 id)
{ {
return HasModelLoaded(id + MI_SPECIAL01); return HasModelLoaded(id + MI_SPECIAL01);
} }
//--MIAMI: done
void void
CStreaming::SetMissionDoesntRequireSpecialChar(int32 id) CStreaming::SetMissionDoesntRequireSpecialChar(int32 id)
{ {
return SetMissionDoesntRequireModel(id + MI_SPECIAL01); return SetMissionDoesntRequireModel(id + MI_SPECIAL01);
} }
//--MIAMI: done
void void
CStreaming::DecrementRef(int32 id) CStreaming::DecrementRef(int32 id)
{ {
@ -801,6 +815,7 @@ CStreaming::DecrementRef(int32 id)
} }
} }
//--MIAMI: TODO: animation
void void
CStreaming::RemoveModel(int32 id) CStreaming::RemoveModel(int32 id)
{ {
@ -929,6 +944,7 @@ CStreaming::RemoveUnusedBigBuildings(eLevelName level)
RemoveIslandsNotUsed(level); RemoveIslandsNotUsed(level);
} }
//--MIAMI: done
void void
DeleteIsland(CEntity *island) DeleteIsland(CEntity *island)
{ {
@ -942,6 +958,7 @@ DeleteIsland(CEntity *island)
} }
} }
//--MIAMI: done
void void
CStreaming::RemoveIslandsNotUsed(eLevelName level) CStreaming::RemoveIslandsNotUsed(eLevelName level)
{ {
@ -999,8 +1016,7 @@ CStreaming::RemoveLoadedVehicle(void)
if(ms_lastVehicleDeleted == MAXVEHICLESLOADED) if(ms_lastVehicleDeleted == MAXVEHICLESLOADED)
ms_lastVehicleDeleted = 0; ms_lastVehicleDeleted = 0;
id = ms_vehiclesLoaded[ms_lastVehicleDeleted]; id = ms_vehiclesLoaded[ms_lastVehicleDeleted];
if(id != -1 && if(id != -1 && CanRemoveModel(id) && CModelInfo::GetModelInfo(id)->GetNumRefs() == 0 &&
(ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0 && CModelInfo::GetModelInfo(id)->GetNumRefs() == 0 &&
ms_aInfoForModel[id].m_loadState == STREAMSTATE_LOADED) ms_aInfoForModel[id].m_loadState == STREAMSTATE_LOADED)
goto found; goto found;
} }
@ -1009,33 +1025,39 @@ found:
RemoveModel(ms_vehiclesLoaded[ms_lastVehicleDeleted]); RemoveModel(ms_vehiclesLoaded[ms_lastVehicleDeleted]);
ms_numVehiclesLoaded--; ms_numVehiclesLoaded--;
ms_vehiclesLoaded[ms_lastVehicleDeleted] = -1; ms_vehiclesLoaded[ms_lastVehicleDeleted] = -1;
// TODO(MIAMI): CCarCtrl::RemoveFromLoadedVehicleArray
return true; return true;
} }
//--MIAMI: TODO: anim
bool bool
CStreaming::RemoveLeastUsedModel(void) CStreaming::RemoveLeastUsedModel(uint32 excludeMask)
{ {
CStreamingInfo *si; CStreamingInfo *si;
int streamId; int streamId;
for(si = ms_endLoadedList.m_prev; si != &ms_startLoadedList; si = si->m_prev){ for(si = ms_endLoadedList.m_prev; si != &ms_startLoadedList; si = si->m_prev){
if(si->m_flags & excludeMask)
continue;
streamId = si - ms_aInfoForModel; streamId = si - ms_aInfoForModel;
if(streamId < STREAM_OFFSET_TXD){ if(streamId < STREAM_OFFSET_TXD){
if (CModelInfo::GetModelInfo(streamId)->GetNumRefs() == 0) { if (CModelInfo::GetModelInfo(streamId)->GetNumRefs() == 0) {
RemoveModel(streamId); RemoveModel(streamId);
return true; return true;
} }
}else{ }else if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL){
if(CTxdStore::GetNumRefs(streamId - STREAM_OFFSET_TXD) == 0 && if(CTxdStore::GetNumRefs(streamId - STREAM_OFFSET_TXD) == 0 &&
!IsTxdUsedByRequestedModels(streamId - STREAM_OFFSET_TXD)){ !IsTxdUsedByRequestedModels(streamId - STREAM_OFFSET_TXD)){
RemoveModel(streamId); RemoveModel(streamId);
return true; return true;
} }
// TODO(MIAMI): IFP
} }
} }
return ms_numVehiclesLoaded > 7 && RemoveLoadedVehicle(); return (ms_numVehiclesLoaded > 7 || CGame::currArea != AREA_MAIN_MAP && ms_numVehiclesLoaded > 4) && RemoveLoadedVehicle();
} }
//--MIAMI: done
void void
CStreaming::RemoveAllUnusedModels(void) CStreaming::RemoveAllUnusedModels(void)
{ {
@ -1046,7 +1068,6 @@ CStreaming::RemoveAllUnusedModels(void)
for(i = NUM_DEFAULT_MODELS; i < MODELINFOSIZE; i++){ for(i = NUM_DEFAULT_MODELS; i < MODELINFOSIZE; i++){
if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED && if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED &&
ms_aInfoForModel[i].m_flags & STREAMFLAGS_DONT_REMOVE &&
CModelInfo::GetModelInfo(i)->GetNumRefs() == 0) { CModelInfo::GetModelInfo(i)->GetNumRefs() == 0) {
RemoveModel(i); RemoveModel(i);
ms_aInfoForModel[i].m_loadState = STREAMSTATE_NOTLOADED; ms_aInfoForModel[i].m_loadState = STREAMSTATE_NOTLOADED;
@ -1054,30 +1075,14 @@ CStreaming::RemoveAllUnusedModels(void)
} }
} }
bool //--MIAMI: done
CStreaming::RemoveReferencedTxds(int32 mem)
{
CStreamingInfo *si;
int streamId;
for(si = ms_endLoadedList.m_prev; si != &ms_startLoadedList; si = si->m_prev){
streamId = si - ms_aInfoForModel;
if(streamId >= STREAM_OFFSET_TXD &&
CTxdStore::GetNumRefs(streamId-STREAM_OFFSET_TXD) == 0){
RemoveModel(streamId);
if(ms_memoryUsed < mem)
return true;
}
}
return false;
}
void void
CStreaming::RemoveUnusedModelsInLoadedList(void) CStreaming::RemoveUnusedModelsInLoadedList(void)
{ {
// empty // empty
} }
//--MIAMI: done, but strangely not found in mobile?
bool bool
CStreaming::IsTxdUsedByRequestedModels(int32 txdId) CStreaming::IsTxdUsedByRequestedModels(int32 txdId)
{ {
@ -1137,8 +1142,8 @@ CStreaming::AddToLoadedVehiclesList(int32 modelId)
// find vehicle we can remove // find vehicle we can remove
for(i = 0; i < MAXVEHICLESLOADED; i++){ for(i = 0; i < MAXVEHICLESLOADED; i++){
id = ms_vehiclesLoaded[ms_lastVehicleDeleted]; id = ms_vehiclesLoaded[ms_lastVehicleDeleted];
if(id != -1 && if(id != -1 && CanRemoveModel(id) &&
(ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0 && CModelInfo::GetModelInfo(id)->GetNumRefs() == 0) CModelInfo::GetModelInfo(id)->GetNumRefs() == 0)
goto found; goto found;
ms_lastVehicleDeleted++; ms_lastVehicleDeleted++;
if(ms_lastVehicleDeleted == MAXVEHICLESLOADED) if(ms_lastVehicleDeleted == MAXVEHICLESLOADED)
@ -1190,6 +1195,7 @@ CStreaming::SetModelTxdIsDeletable(int32 id)
SetModelIsDeletable(CModelInfo::GetModelInfo(id)->GetTxdSlot() + STREAM_OFFSET_TXD); SetModelIsDeletable(CModelInfo::GetModelInfo(id)->GetTxdSlot() + STREAM_OFFSET_TXD);
} }
//--MIAMI: done
void void
CStreaming::SetMissionDoesntRequireModel(int32 id) CStreaming::SetMissionDoesntRequireModel(int32 id)
{ {
@ -1566,13 +1572,15 @@ CStreaming::RequestModelStream(int32 ch)
imgOffset = GetCdImageOffset(lastPosn); imgOffset = GetCdImageOffset(lastPosn);
streamId = GetNextFileOnCd(lastPosn - imgOffset, true); streamId = GetNextFileOnCd(lastPosn - imgOffset, true);
if(streamId == -1) // remove Txds and Anims that aren't requested anymore
return; while(streamId != -1){
if(ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_KEEP_IN_MEMORY)
// remove Txds that aren't requested anymore break;
while(streamId >= STREAM_OFFSET_TXD){ if(streamId >= STREAM_OFFSET_TXD && streamId < STREAM_OFFSET_COL){
if(ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_KEEP_IN_MEMORY || if(IsTxdUsedByRequestedModels(streamId - STREAM_OFFSET_TXD))
IsTxdUsedByRequestedModels(streamId - STREAM_OFFSET_TXD)) break;
// TODO(MIAMI): anims
}else
break; break;
RemoveModel(streamId); RemoveModel(streamId);
// so try next file // so try next file
@ -1610,6 +1618,7 @@ CStreaming::RequestModelStream(int32 ch)
if (havePed && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_PED || if (havePed && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_PED ||
haveBigFile && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_VEHICLE || haveBigFile && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_VEHICLE ||
!TxdAvailable(CModelInfo::GetModelInfo(streamId)->GetTxdSlot())) !TxdAvailable(CModelInfo::GetModelInfo(streamId)->GetTxdSlot()))
// TODO(MIAMI): anims
break; break;
}else{ }else{
if(haveBigFile && size > 200) if(haveBigFile && size > 200)
@ -1656,6 +1665,7 @@ CStreaming::RequestModelStream(int32 ch)
ms_channel[ch].numTries = 0; ms_channel[ch].numTries = 0;
} }
//--MIAMI: done
// Load data previously read from disc // Load data previously read from disc
bool bool
CStreaming::ProcessLoadingChannel(int32 ch) CStreaming::ProcessLoadingChannel(int32 ch)
@ -1690,10 +1700,10 @@ CStreaming::ProcessLoadingChannel(int32 ch)
if(id < STREAM_OFFSET_TXD && CModelInfo::GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE && if(id < STREAM_OFFSET_TXD && CModelInfo::GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE &&
ms_numVehiclesLoaded >= desiredNumVehiclesLoaded && ms_numVehiclesLoaded >= desiredNumVehiclesLoaded &&
!RemoveLoadedVehicle() && !RemoveLoadedVehicle() &&
((ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0 || GetAvailableVehicleSlot() == -1)){ (CanRemoveModel(id) || GetAvailableVehicleSlot() == -1)){
// can't load vehicle // can't load vehicle
RemoveModel(id); RemoveModel(id);
if(ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) if(!CanRemoveModel(id))
ReRequestModel(id); ReRequestModel(id);
else if(CTxdStore::GetNumRefs(CModelInfo::GetModelInfo(id)->GetTxdSlot()) == 0) else if(CTxdStore::GetNumRefs(CModelInfo::GetModelInfo(id)->GetTxdSlot()) == 0)
RemoveTxd(CModelInfo::GetModelInfo(id)->GetTxdSlot()); RemoveTxd(CModelInfo::GetModelInfo(id)->GetTxdSlot());
@ -1725,6 +1735,7 @@ CStreaming::ProcessLoadingChannel(int32 ch)
return true; return true;
} }
//--MIAMI: done
void void
CStreaming::RetryLoadFile(int32 ch) CStreaming::RetryLoadFile(int32 ch)
{ {
@ -1761,6 +1772,7 @@ CStreaming::RetryLoadFile(int32 ch)
} }
} }
//--MIAMI: done
void void
CStreaming::LoadRequestedModels(void) CStreaming::LoadRequestedModels(void)
{ {
@ -1785,6 +1797,7 @@ CStreaming::LoadRequestedModels(void)
} }
} }
//--MIAMI: done
void void
CStreaming::LoadAllRequestedModels(bool priority) CStreaming::LoadAllRequestedModels(bool priority)
{ {
@ -1838,6 +1851,7 @@ CStreaming::LoadAllRequestedModels(bool priority)
bInsideLoadAll = false; bInsideLoadAll = false;
} }
//--MIAMI: done
void void
CStreaming::FlushChannels(void) CStreaming::FlushChannels(void)
{ {
@ -1859,6 +1873,7 @@ CStreaming::FlushChannels(void)
ProcessLoadingChannel(1); ProcessLoadingChannel(1);
} }
//--MIAMI: done
void void
CStreaming::FlushRequestList(void) CStreaming::FlushRequestList(void)
{ {
@ -2228,9 +2243,6 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem)
} }
} }
if(RemoveReferencedTxds(mem))
return;
// As last resort, delete objects from the last step more aggressively // As last resort, delete objects from the last step more aggressively
for(y = ymin; y <= ymax; y++){ for(y = ymin; y <= ymax; y++){
for(x = xmax; x != xmin; x -= inc){ for(x = xmax; x != xmin; x -= inc){
@ -2292,9 +2304,6 @@ CStreaming::DeleteRwObjectsBehindCamera(int32 mem)
} }
} }
if(RemoveReferencedTxds(mem))
return;
// As last resort, delete objects from the last step more aggressively // As last resort, delete objects from the last step more aggressively
for(x = xmin; x <= xmax; x++){ for(x = xmin; x <= xmax; x++){
for(y = ymax; y != ymin; y -= inc){ for(y = ymax; y != ymin; y -= inc){
@ -2393,7 +2402,7 @@ CStreaming::MakeSpaceFor(int32 size)
// but it's not nice.... // but it's not nice....
while((uint32)ms_memoryUsed >= ms_memoryAvailable - size) while((uint32)ms_memoryUsed >= ms_memoryAvailable - size)
if(!RemoveLeastUsedModel()){ if(!RemoveLeastUsedModel(STREAMFLAGS_20)){
DeleteRwObjectsBehindCamera(ms_memoryAvailable - size); DeleteRwObjectsBehindCamera(ms_memoryAvailable - size);
return; return;
} }

View File

@ -94,6 +94,7 @@ public:
static int32 ms_numVehiclesLoaded; static int32 ms_numVehiclesLoaded;
static int32 ms_vehiclesLoaded[MAXVEHICLESLOADED]; static int32 ms_vehiclesLoaded[MAXVEHICLESLOADED];
static int32 ms_lastVehicleDeleted; static int32 ms_lastVehicleDeleted;
static bool ms_bIsPedFromPedGroupLoaded[NUMMODELSPERPEDGROUP];
static CDirectory *ms_pExtraObjectsDir; static CDirectory *ms_pExtraObjectsDir;
static int32 ms_numPriorityRequests; static int32 ms_numPriorityRequests;
static int32 ms_currentPedGrp; static int32 ms_currentPedGrp;
@ -145,7 +146,7 @@ public:
static void RemoveIslandsNotUsed(eLevelName level); static void RemoveIslandsNotUsed(eLevelName level);
static void RemoveBigBuildings(eLevelName level); static void RemoveBigBuildings(eLevelName level);
static bool RemoveLoadedVehicle(void); static bool RemoveLoadedVehicle(void);
static bool RemoveLeastUsedModel(void); static bool RemoveLeastUsedModel(uint32 excludeMask);
static void RemoveAllUnusedModels(void); static void RemoveAllUnusedModels(void);
static void RemoveUnusedModelsInLoadedList(void); static void RemoveUnusedModelsInLoadedList(void);
static bool RemoveReferencedTxds(int32 mem); static bool RemoveReferencedTxds(int32 mem);

View File

@ -3,14 +3,14 @@
enum Config { enum Config {
NUMPLAYERS = 1, NUMPLAYERS = 1,
NUMCDIMAGES = 12, // gta3.img duplicates (not used on PC) NUMCDIMAGES = 6, // gta3.img duplicates (not used on PC)
MAX_CDIMAGES = 8, // additional cdimages MAX_CDIMAGES = 8, // additional cdimages
MAX_CDCHANNELS = 5, MAX_CDCHANNELS = 5,
MODELINFOSIZE = 6500, MODELINFOSIZE = 6500,
TXDSTORESIZE = 1385, TXDSTORESIZE = 1385,
COLSTORESIZE = 31, COLSTORESIZE = 31,
EXTRADIRSIZE = 128, EXTRADIRSIZE = 256,
CUTSCENEDIRSIZE = 512, CUTSCENEDIRSIZE = 512,
SIMPLEMODELSIZE = 5000, // only 3885 in VC??? SIMPLEMODELSIZE = 5000, // only 3885 in VC???
@ -106,7 +106,7 @@ enum Config {
NUMPEDROUTES = 200, NUMPEDROUTES = 200,
NUMPHONES = 50, NUMPHONES = 50,
NUMPEDGROUPS = 31, NUMPEDGROUPS = 31,
NUMMODELSPERPEDGROUP = 8, NUMMODELSPERPEDGROUP = 8, // TODO(MIAMI): 16 once we have peds
NUMSHOTINFOS = 100, NUMSHOTINFOS = 100,
NUMROADBLOCKS = 300, NUMROADBLOCKS = 300,

View File

@ -6,14 +6,16 @@
enum ModelInfoType : uint8 enum ModelInfoType : uint8
{ {
MITYPE_NA = 0, MITYPE_NA,
MITYPE_SIMPLE = 1, MITYPE_SIMPLE,
MITYPE_MLO = 2, MITYPE_MLO, // unused but still in enum
MITYPE_TIME = 3, MITYPE_TIME,
MITYPE_CLUMP = 4, MITYPE_WEAPON,
MITYPE_VEHICLE = 5, MITYPE_CLUMP,
MITYPE_PED = 6, MITYPE_VEHICLE,
MITYPE_XTRACOMPS = 7, MITYPE_PED,
MITYPE_XTRACOMPS, // unused but still in enum
MITYPE_HAND // xbox and mobile
}; };
static_assert(sizeof(ModelInfoType) == 1, "ModeInfoType: error"); static_assert(sizeof(ModelInfoType) == 1, "ModeInfoType: error");
@ -43,10 +45,9 @@ public:
// one day it becomes virtual // one day it becomes virtual
ModelInfoType GetModelType() const { return m_type; } ModelInfoType GetModelType() const { return m_type; }
bool IsSimple(void) { return m_type == MITYPE_SIMPLE || m_type == MITYPE_TIME; } bool IsBuilding(void) { return m_type == MITYPE_SIMPLE || m_type == MITYPE_TIME; }
bool IsClump(void) { return m_type == MITYPE_CLUMP || m_type == MITYPE_PED || m_type == MITYPE_VEHICLE || bool IsSimple(void) { return m_type == MITYPE_SIMPLE || m_type == MITYPE_TIME || m_type == MITYPE_WEAPON; }
m_type == MITYPE_MLO || m_type == MITYPE_XTRACOMPS; // unused but what the heck bool IsClump(void) { return m_type == MITYPE_CLUMP || m_type == MITYPE_PED || m_type == MITYPE_VEHICLE; }
}
char *GetName(void) { return m_name; } char *GetName(void) { return m_name; }
void SetName(const char *name) { strncpy(m_name, name, 24); } void SetName(const char *name) { strncpy(m_name, name, 24); }
void SetColModel(CColModel *col, bool owns = false){ void SetColModel(CColModel *col, bool owns = false){

View File

@ -357,7 +357,7 @@ enum
MI_AIRTRAIN_VLO = 198, MI_AIRTRAIN_VLO = 198,
MI_LOPOLYGUY, MI_LOPOLYGUY,
NUM_DEFAULT_MODELS NUM_DEFAULT_MODELS = 300 // MIAMI
}; };
enum{ enum{
@ -373,7 +373,7 @@ inline bool
IsGlass(int16 id) IsGlass(int16 id)
{ {
CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(id); CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(id);
return mi->IsSimple() && (mi->m_isCodeGlass || mi->m_isArtistGlass); return mi->IsBuilding() && (mi->m_isCodeGlass || mi->m_isArtistGlass);
} }
inline bool inline bool