diff options
Diffstat (limited to 'src/core/Streaming.cpp')
-rw-r--r-- | src/core/Streaming.cpp | 131 |
1 files changed, 80 insertions, 51 deletions
diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index a76e9038..f24192ef 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -114,7 +114,7 @@ CStreamingInfo::RemoveFromList(void) } void -CStreaming::Init(void) +CStreaming::Init2(void) { int i; @@ -244,6 +244,29 @@ CStreaming::Init(void) } void +CStreaming::Init(void) +{ +#ifdef USE_TXD_CDIMAGE + int txdHandle = CFileMgr::OpenFile("MODELS\\TXD.IMG", "r"); + if (txdHandle) + CFileMgr::CloseFile(txdHandle); + if (!CheckVideoCardCaps() && txdHandle) { + CdStreamAddImage("MODELS\\TXD.IMG"); + CStreaming::Init2(); + } else { + CStreaming::Init2(); + if (CreateTxdImageForVideoCard()) { + CStreaming::Shutdown(); + CdStreamAddImage("MODELS\\TXD.IMG"); + CStreaming::Init2(); + } + } +#else + CStreaming::Init(); +#endif +} + +void CStreaming::Shutdown(void) { RwFreeAlign(ms_pStreamingBuffer[0]); @@ -294,6 +317,7 @@ CStreaming::Update(void) LoadRequestedModels(); + for(si = ms_endRequestedList.m_prev; si != &ms_startRequestedList; si = prev){ prev = si->m_prev; if((si->m_flags & (STREAMFLAGS_KEEP_IN_MEMORY|STREAMFLAGS_PRIORITY)) == 0) @@ -435,7 +459,7 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId) if(mi->IsSimple()){ success = CFileLoader::LoadAtomicFile(stream, streamId); - }else if(mi->m_type == MITYPE_VEHICLE){ + } else if (mi->GetModelType() == MITYPE_VEHICLE) { // load vehicles in two parts CModelInfo::GetModelInfo(streamId)->AddRef(); success = CFileLoader::StartLoadClumpFile(stream, streamId); @@ -499,7 +523,7 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId) if(streamId < STREAM_OFFSET_TXD){ // Model // Vehicles and Peds not in loaded list - if(mi->m_type != MITYPE_VEHICLE && mi->m_type != MITYPE_PED){ + if (mi->GetModelType() != MITYPE_VEHICLE && mi->GetModelType() != MITYPE_PED) { CSimpleModelInfo *smi = (CSimpleModelInfo*)mi; // Set fading for some objects @@ -510,12 +534,12 @@ CStreaming::ConvertBufferToObject(int8 *buf, int32 streamId) smi->m_alpha = 0; } - if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_NOT_IN_LIST) == 0) + if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_CANT_REMOVE) == 0) ms_aInfoForModel[streamId].AddToList(&ms_startLoadedList); } }else{ // Txd - if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_NOT_IN_LIST) == 0) + if((ms_aInfoForModel[streamId].m_flags & STREAMFLAGS_CANT_REMOVE) == 0) ms_aInfoForModel[streamId].AddToList(&ms_startLoadedList); } @@ -628,7 +652,7 @@ CStreaming::RequestModel(int32 id, int32 flags) // reinsert into list if(ms_aInfoForModel[id].m_next){ ms_aInfoForModel[id].RemoveFromList(); - if((ms_aInfoForModel[id].m_flags & STREAMFLAGS_NOT_IN_LIST) == 0) + if((ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0) ms_aInfoForModel[id].AddToList(&ms_startLoadedList); } }else if(ms_aInfoForModel[id].m_loadState == STREAMSTATE_NOTLOADED || @@ -689,6 +713,8 @@ CStreaming::RequestSubway(void) } } +#define BIGBUILDINGFLAGS STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY + void CStreaming::RequestBigBuildings(eLevelName level) { @@ -699,7 +725,7 @@ CStreaming::RequestBigBuildings(eLevelName level) for(i = n; i >= 0; i--){ b = CPools::GetBuildingPool()->GetSlot(i); if(b && b->bIsBIGBuilding && b->m_level == level) - RequestModel(b->GetModelIndex(), STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY); + RequestModel(b->GetModelIndex(), BIGBUILDINGFLAGS); } RequestIslands(level); ms_hasLoadedLODs = false; @@ -710,16 +736,16 @@ CStreaming::RequestIslands(eLevelName level) { switch(level){ case LEVEL_INDUSTRIAL: - RequestModel(islandLODcomInd, STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY); - RequestModel(islandLODsubInd, STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY); + RequestModel(islandLODcomInd, BIGBUILDINGFLAGS); + RequestModel(islandLODsubInd, BIGBUILDINGFLAGS); break; case LEVEL_COMMERCIAL: - RequestModel(islandLODindust, STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY); - RequestModel(islandLODsubCom, STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY); + RequestModel(islandLODindust, BIGBUILDINGFLAGS); + RequestModel(islandLODsubCom, BIGBUILDINGFLAGS); break; case LEVEL_SUBURBAN: - RequestModel(islandLODindust, STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY); - RequestModel(islandLODcomSub, STREAMFLAGS_DONT_REMOVE|STREAMFLAGS_PRIORITY); + RequestModel(islandLODindust, BIGBUILDINGFLAGS); + RequestModel(islandLODcomSub, BIGBUILDINGFLAGS); break; } } @@ -858,7 +884,7 @@ CStreaming::RemoveBuildings(eLevelName level) mi = CModelInfo::GetModelInfo(e->GetModelIndex()); if(!e->bImBeingRendered){ e->DeleteRwObject(); - if(mi->m_refCount == 0) + if (mi->GetNumRefs() == 0) RemoveModel(e->GetModelIndex()); } } @@ -871,7 +897,7 @@ CStreaming::RemoveBuildings(eLevelName level) mi = CModelInfo::GetModelInfo(e->GetModelIndex()); if(!e->bImBeingRendered){ e->DeleteRwObject(); - if(mi->m_refCount == 0) + if (mi->GetNumRefs() == 0) RemoveModel(e->GetModelIndex()); } } @@ -884,7 +910,7 @@ CStreaming::RemoveBuildings(eLevelName level) mi = CModelInfo::GetModelInfo(e->GetModelIndex()); if(!e->bImBeingRendered && ((CObject*)e)->ObjectCreatedBy == GAME_OBJECT){ e->DeleteRwObject(); - if(mi->m_refCount == 0) + if (mi->GetNumRefs() == 0) RemoveModel(e->GetModelIndex()); } } @@ -897,7 +923,7 @@ CStreaming::RemoveBuildings(eLevelName level) mi = CModelInfo::GetModelInfo(e->GetModelIndex()); if(!e->bImBeingRendered){ e->DeleteRwObject(); - if(mi->m_refCount == 0) + if (mi->GetNumRefs() == 0) RemoveModel(e->GetModelIndex()); } } @@ -972,7 +998,7 @@ CStreaming::RemoveBigBuildings(eLevelName level) mi = CModelInfo::GetModelInfo(e->GetModelIndex()); if(!e->bImBeingRendered){ e->DeleteRwObject(); - if(mi->m_refCount == 0) + if (mi->GetNumRefs() == 0) RemoveModel(e->GetModelIndex()); } } @@ -990,8 +1016,7 @@ CStreaming::RemoveLoadedVehicle(void) ms_lastVehicleDeleted = 0; id = ms_vehiclesLoaded[ms_lastVehicleDeleted]; if(id != -1 && - (ms_aInfoForModel[id].m_flags & STREAMFLAGS_NOT_IN_LIST) == 0 && - CModelInfo::GetModelInfo(id)->m_refCount == 0 && + (ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0 && CModelInfo::GetModelInfo(id)->GetNumRefs() == 0 && ms_aInfoForModel[id].m_loadState == STREAMSTATE_LOADED) goto found; } @@ -1012,7 +1037,7 @@ CStreaming::RemoveLeastUsedModel(void) for(si = ms_endLoadedList.m_prev; si != &ms_startLoadedList; si = si->m_prev){ streamId = si - ms_aInfoForModel; if(streamId < STREAM_OFFSET_TXD){ - if(CModelInfo::GetModelInfo(streamId)->m_refCount == 0){ + if (CModelInfo::GetModelInfo(streamId)->GetNumRefs() == 0) { RemoveModel(streamId); return true; } @@ -1038,7 +1063,7 @@ CStreaming::RemoveAllUnusedModels(void) for(i = NUM_DEFAULT_MODELS; i < MODELINFOSIZE; i++){ if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED && ms_aInfoForModel[i].m_flags & STREAMFLAGS_DONT_REMOVE && - CModelInfo::GetModelInfo(i)->m_refCount == 0){ + CModelInfo::GetModelInfo(i)->GetNumRefs() == 0) { RemoveModel(i); ms_aInfoForModel[i].m_loadState = STREAMSTATE_NOTLOADED; } @@ -1129,8 +1154,7 @@ CStreaming::AddToLoadedVehiclesList(int32 modelId) for(i = 0; i < MAXVEHICLESLOADED; i++){ id = ms_vehiclesLoaded[ms_lastVehicleDeleted]; if(id != -1 && - (ms_aInfoForModel[id].m_flags & STREAMFLAGS_NOT_IN_LIST) == 0 && - CModelInfo::GetModelInfo(id)->m_refCount == 0) + (ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0 && CModelInfo::GetModelInfo(id)->GetNumRefs() == 0) goto found; ms_lastVehicleDeleted++; if(ms_lastVehicleDeleted == MAXVEHICLESLOADED) @@ -1202,7 +1226,7 @@ void CStreaming::SetModelIsDeletable(int32 id) { ms_aInfoForModel[id].m_flags &= ~STREAMFLAGS_DONT_REMOVE; - if((id >= STREAM_OFFSET_TXD || CModelInfo::GetModelInfo(id)->m_type != MITYPE_VEHICLE) && + if ((id >= STREAM_OFFSET_TXD || CModelInfo::GetModelInfo(id)->GetModelType() != MITYPE_VEHICLE) && (ms_aInfoForModel[id].m_flags & STREAMFLAGS_SCRIPTOWNED) == 0){ if(ms_aInfoForModel[id].m_loadState != STREAMSTATE_LOADED) RemoveModel(id); @@ -1221,7 +1245,7 @@ void CStreaming::SetMissionDoesntRequireModel(int32 id) { ms_aInfoForModel[id].m_flags &= ~STREAMFLAGS_SCRIPTOWNED; - if((id >= STREAM_OFFSET_TXD || CModelInfo::GetModelInfo(id)->m_type != MITYPE_VEHICLE) && + if ((id >= STREAM_OFFSET_TXD || CModelInfo::GetModelInfo(id)->GetModelType() != MITYPE_VEHICLE) && (ms_aInfoForModel[id].m_flags & STREAMFLAGS_DONT_REMOVE) == 0){ if(ms_aInfoForModel[id].m_loadState != STREAMSTATE_LOADED) RemoveModel(id); @@ -1307,7 +1331,7 @@ CStreaming::StreamVehiclesAndPeds(void) for(i = 1; i <= 10; i++){ model = CCarCtrl::ChooseCarModel(modelQualityClass); modelQualityClass++; - if(modelQualityClass >= NUM_VEHICLE_CLASSES) + if(modelQualityClass >= CCarCtrl::TOTAL_CUSTOM_CLASSES) modelQualityClass = 0; // check if we want to load this model @@ -1336,7 +1360,7 @@ CStreaming::StreamZoneModels(const CVector &pos) // unload pevious group if(ms_currentPedGrp != -1) - for(i = 0; i < 8; i++){ + for(i = 0; i < NUMMODELSPERPEDGROUP; i++){ if(CPopulation::ms_pPedGroups[ms_currentPedGrp].models[i] == -1) break; SetModelIsDeletable(CPopulation::ms_pPedGroups[ms_currentPedGrp].models[i]); @@ -1345,7 +1369,7 @@ CStreaming::StreamZoneModels(const CVector &pos) ms_currentPedGrp = info.pedGroup; - for(i = 0; i < 8; i++){ + for(i = 0; i < NUMMODELSPERPEDGROUP; i++){ if(CPopulation::ms_pPedGroups[ms_currentPedGrp].models[i] == -1) break; RequestModel(CPopulation::ms_pPedGroups[ms_currentPedGrp].models[i], STREAMFLAGS_DONT_REMOVE); @@ -1431,7 +1455,6 @@ CStreaming::RemoveCurrentZonesModels(void) } - // Find starting offset of the cdimage we next want to read // Not useful at all on PC... int32 @@ -1470,12 +1493,14 @@ CStreaming::GetCdImageOffset(int32 lastPosn) } inline bool -TxdAvailable(int32 txdId) +ModelNotLoaded(int32 modelId) { - CStreamingInfo *si = &CStreaming::ms_aInfoForModel[txdId + STREAM_OFFSET_TXD]; - return si->m_loadState == STREAMSTATE_LOADED || si->m_loadState == STREAMSTATE_READING; + CStreamingInfo *si = &CStreaming::ms_aInfoForModel[modelId]; + return si->m_loadState != STREAMSTATE_LOADED && si->m_loadState != STREAMSTATE_READING; } +inline bool TxdNotLoaded(int32 txdId) { return ModelNotLoaded(txdId + STREAM_OFFSET_TXD); } + // Find stream id of next requested file in cdimage int32 CStreaming::GetNextFileOnCd(int32 lastPosn, bool priority) @@ -1500,10 +1525,15 @@ CStreaming::GetNextFileOnCd(int32 lastPosn, bool priority) continue; // request Txd if necessary - if(streamId < STREAM_OFFSET_TXD && - !TxdAvailable(CModelInfo::GetModelInfo(streamId)->GetTxdSlot())){ - ReRequestTxd(CModelInfo::GetModelInfo(streamId)->GetTxdSlot()); - }else if(ms_aInfoForModel[streamId].GetCdPosnAndSize(posn, size)){ + if(streamId < STREAM_OFFSET_TXD){ + int txdId = CModelInfo::GetModelInfo(streamId)->GetTxdSlot(); + if(TxdNotLoaded(txdId)){ + ReRequestTxd(txdId); + continue; + } + } + + if(ms_aInfoForModel[streamId].GetCdPosnAndSize(posn, size)){ if(posn < posnFirst){ // find first requested file in image streamIdFirst = streamId; @@ -1599,9 +1629,9 @@ CStreaming::RequestModelStream(int32 ch) // Can't load certain combinations of files together if(streamId < STREAM_OFFSET_TXD){ - if(havePed && CModelInfo::GetModelInfo(streamId)->m_type == MITYPE_PED || - haveBigFile && CModelInfo::GetModelInfo(streamId)->m_type == MITYPE_VEHICLE || - !TxdAvailable(CModelInfo::GetModelInfo(streamId)->GetTxdSlot())) + if (havePed && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_PED || + haveBigFile && CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_VEHICLE || + TxdNotLoaded(CModelInfo::GetModelInfo(streamId)->GetTxdSlot())) break; }else{ if(haveBigFile && size > 200) @@ -1619,9 +1649,9 @@ CStreaming::RequestModelStream(int32 ch) break; } if(streamId < STREAM_OFFSET_TXD){ - if(CModelInfo::GetModelInfo(streamId)->m_type == MITYPE_PED) + if (CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_PED) havePed = 1; - if(CModelInfo::GetModelInfo(streamId)->m_type == MITYPE_VEHICLE) + if (CModelInfo::GetModelInfo(streamId)->GetModelType() == MITYPE_VEHICLE) haveBigFile = 1; }else{ if(size > 200) @@ -1679,14 +1709,13 @@ CStreaming::ProcessLoadingChannel(int32 ch) continue; cdsize = ms_aInfoForModel[id].GetCdSize(); - if(id < STREAM_OFFSET_TXD && - CModelInfo::GetModelInfo(id)->m_type == MITYPE_VEHICLE && + if(id < STREAM_OFFSET_TXD && CModelInfo::GetModelInfo(id)->GetModelType() == MITYPE_VEHICLE && ms_numVehiclesLoaded >= desiredNumVehiclesLoaded && !RemoveLoadedVehicle() && - ((ms_aInfoForModel[id].m_flags & STREAMFLAGS_NOT_IN_LIST) == 0 || GetAvailableVehicleSlot() == -1)){ + ((ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) == 0 || GetAvailableVehicleSlot() == -1)){ // can't load vehicle RemoveModel(id); - if(ms_aInfoForModel[id].m_flags & STREAMFLAGS_NOT_IN_LIST) + if(ms_aInfoForModel[id].m_flags & STREAMFLAGS_CANT_REMOVE) ReRequestModel(id); else if(CTxdStore::GetNumRefs(CModelInfo::GetModelInfo(id)->GetTxdSlot()) == 0) RemoveTxd(CModelInfo::GetModelInfo(id)->GetTxdSlot()); @@ -1953,7 +1982,7 @@ CStreaming::ProcessEntitiesInSectorList(CPtrList &list, float x, float y, float if(!e->bStreamingDontDelete && !e->bIsSubway && (!e->IsObject() || ((CObject*)e)->ObjectCreatedBy != TEMP_OBJECT)){ CTimeModelInfo *mi = (CTimeModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()); - if(mi->m_type != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())){ + if (mi->GetModelType() != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())) { lodDistSq = sq(mi->GetLargestLodDistance()); lodDistSq = Min(lodDistSq, sq(STREAM_DIST)); pos = CVector2D(e->GetPosition()); @@ -1983,7 +2012,7 @@ CStreaming::ProcessEntitiesInSectorList(CPtrList &list) if(!e->bStreamingDontDelete && !e->bIsSubway && (!e->IsObject() || ((CObject*)e)->ObjectCreatedBy != TEMP_OBJECT)){ CTimeModelInfo *mi = (CTimeModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()); - if(mi->m_type != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())) + if (mi->GetModelType() != MITYPE_TIME || CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())) if(CRenderer::IsEntityCullZoneVisible(e)) RequestModel(e->GetModelIndex(), 0); } @@ -2349,7 +2378,7 @@ CStreaming::DeleteRwObjectsBehindCameraInSectorList(CPtrList &list, int32 mem) if(!e->bStreamingDontDelete && !e->bImBeingRendered && e->m_rwObject && ms_aInfoForModel[e->GetModelIndex()].m_next){ e->DeleteRwObject(); - if(CModelInfo::GetModelInfo(e->GetModelIndex())->m_refCount == 0){ + if (CModelInfo::GetModelInfo(e->GetModelIndex())->GetNumRefs() == 0) { RemoveModel(e->GetModelIndex()); if(ms_memoryUsed < mem) return true; @@ -2370,7 +2399,7 @@ CStreaming::DeleteRwObjectsNotInFrustumInSectorList(CPtrList &list, int32 mem) if(!e->bStreamingDontDelete && !e->bImBeingRendered && e->m_rwObject && !e->IsVisible() && ms_aInfoForModel[e->GetModelIndex()].m_next){ e->DeleteRwObject(); - if(CModelInfo::GetModelInfo(e->GetModelIndex())->m_refCount == 0){ + if (CModelInfo::GetModelInfo(e->GetModelIndex())->GetNumRefs() == 0) { RemoveModel(e->GetModelIndex()); if(ms_memoryUsed < mem) return true; @@ -2400,7 +2429,7 @@ CStreaming::LoadScene(const CVector &pos) CStreamingInfo *si, *prev; eLevelName level; - level = CTheZones::GetLevelFromPosition(pos); + level = CTheZones::GetLevelFromPosition(&pos); debug("Start load scene\n"); for(si = ms_endRequestedList.m_prev; si != &ms_startRequestedList; si = prev){ prev = si->m_prev; |