diff options
author | Sergeanur <s.anureev@yandex.ua> | 2021-01-12 12:22:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-12 12:22:44 +0100 |
commit | 8888ee3974587cfb6172e420210df75e5c5de3f7 (patch) | |
tree | 10294da8d82bcdedaaf64cee35897a7fe08b64ea /src/animation | |
parent | Merge branch 'miami' into lcs (diff) | |
parent | More fix (diff) | |
download | re3-8888ee3974587cfb6172e420210df75e5c5de3f7.tar re3-8888ee3974587cfb6172e420210df75e5c5de3f7.tar.gz re3-8888ee3974587cfb6172e420210df75e5c5de3f7.tar.bz2 re3-8888ee3974587cfb6172e420210df75e5c5de3f7.tar.lz re3-8888ee3974587cfb6172e420210df75e5c5de3f7.tar.xz re3-8888ee3974587cfb6172e420210df75e5c5de3f7.tar.zst re3-8888ee3974587cfb6172e420210df75e5c5de3f7.zip |
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/AnimBlendAssocGroup.cpp | 74 | ||||
-rw-r--r-- | src/animation/AnimBlendAssocGroup.h | 1 | ||||
-rw-r--r-- | src/animation/CutsceneMgr.cpp | 676 | ||||
-rw-r--r-- | src/animation/CutsceneMgr.h | 128 | ||||
-rw-r--r-- | src/animation/CutsceneMgr_overlay.cpp | 1030 |
5 files changed, 1330 insertions, 579 deletions
diff --git a/src/animation/AnimBlendAssocGroup.cpp b/src/animation/AnimBlendAssocGroup.cpp index df47e9b5..ea6dea3e 100644 --- a/src/animation/AnimBlendAssocGroup.cpp +++ b/src/animation/AnimBlendAssocGroup.cpp @@ -14,6 +14,7 @@ #include "RpAnimBlend.h" #include "AnimBlendAssociation.h" #include "AnimBlendAssocGroup.h" +#include "KeyGen.h" //--MIAMI: file done @@ -109,27 +110,34 @@ strcmpIgnoringDigits(const char *s1, const char *s2) } } +extern const char* csPlayerNames[]; +extern const char* playerNames[]; + CBaseModelInfo* GetModelFromName(const char *name) { int i; - CBaseModelInfo *mi; - char playername[32]; - - if(strncasecmp(name, "CSplay", 6) == 0 && - strncasecmp(CModelInfo::GetModelInfo(MI_PLAYER)->GetModelName(), "ig", 2) == 0){ - strcpy(playername, CModelInfo::GetModelInfo(MI_PLAYER)->GetModelName()); - playername[0] = 'C'; - playername[1] = 'S'; - name = playername; + CBaseModelInfo* mi; + if (CKeyGen::GetUppercaseKey(name) == CKeyGen::GetUppercaseKey("cstoni_a")) { + i = 0; + while (csPlayerNames[i][0] != '\0') { + if (CModelInfo::GetModelInfo(0)->GetNameHashKey() == CKeyGen::GetUppercaseKey(playerNames[i])) { + name = csPlayerNames[i]; + break; + } + i++; + } } - for(i = 0; i < MODELINFOSIZE; i++){ + uint32 hashKey = CKeyGen::GetUppercaseKey(name); + for (i = 0; i < MODELINFOSIZE; i++) { mi = CModelInfo::GetModelInfo(i); - if(mi && mi->GetRwObject() && RwObjectGetType(mi->GetRwObject()) == rpCLUMP && - strcmpIgnoringDigits(mi->GetModelName(), name)) + if (mi && mi->GetRwObject() + && RwObjectGetType(mi->GetRwObject()) == rpCLUMP && + hashKey == mi->GetNameHashKey()) return mi; } + return nil; } @@ -183,3 +191,45 @@ CAnimBlendAssocGroup::CreateAssociations(const char *blockName, RpClump *clump, } numAssociations = numAssocs; } + +void +CAnimBlendAssocGroup::CreateAssociations(const char *blockName, const char *animNames, const char *objectNames, int numChars) +{ + if (!objectNames) { + CreateAssociations(blockName); + return; + } + + if (assocList) + DestroyAssociations(); + + animBlock = CAnimManager::GetAnimationBlock(blockName); + assocList = new CAnimBlendAssociation[animBlock->numAnims]; + + numAssociations = 0; + if (animBlock->numAnims > 0) + { + int i, j; + for (i = 0; i < animBlock->numAnims; i++) { + int animId = -1; + for (j = 0; j != animBlock->numAnims; j++) + if (strcmp(CAnimManager::GetAnimation(i + animBlock->firstIndex)->name, animNames + numChars * j) == 0) + animId = j; + + if (animId != -1) { + CBaseModelInfo* minfo = GetModelFromName(objectNames + numChars * animId); + if (minfo) + { + RpClump* clump = (RpClump*)minfo->CreateInstance(); + RpAnimBlendClumpInit(clump); + assocList[numAssociations].Init(clump, CAnimManager::GetAnimation(i + animBlock->firstIndex)); + if (IsClumpSkinned(clump)) + RpClumpForAllAtomics(clump, AtomicRemoveAnimFromSkinCB, nil); + RpClumpDestroy(clump); + assocList[numAssociations].animId = i + numAssociations; + assocList[numAssociations++].groupId = groupId; + } + } + } + } +}
\ No newline at end of file diff --git a/src/animation/AnimBlendAssocGroup.h b/src/animation/AnimBlendAssocGroup.h index 86f0ca18..e264787e 100644 --- a/src/animation/AnimBlendAssocGroup.h +++ b/src/animation/AnimBlendAssocGroup.h @@ -21,4 +21,5 @@ public: CAnimBlendAssociation *CopyAnimation(const char *name); void CreateAssociations(const char *name); void CreateAssociations(const char *blockName, RpClump *clump, const char **animNames, int numAssocs); + void CreateAssociations(const char *blockName, const char *animNames, const char *objectNames, int numChars); }; diff --git a/src/animation/CutsceneMgr.cpp b/src/animation/CutsceneMgr.cpp index 88c73661..bbbd9aa3 100644 --- a/src/animation/CutsceneMgr.cpp +++ b/src/animation/CutsceneMgr.cpp @@ -22,594 +22,86 @@ #include "ColStore.h" #include "Radar.h" #include "Pools.h" +#include "crossplatform.h" //--MIAMI: file done -const struct { - const char *szTrackName; - int iTrackId; -} musicNameIdAssoc[] = { - { "ASS_1", STREAMED_SOUND_CUTSCENE_ASS_1 }, - { "ASS_2", STREAMED_SOUND_CUTSCENE_ASS_2 }, - { "BANK_1", STREAMED_SOUND_CUTSCENE_BANK_1 }, - { "BANK_2A", STREAMED_SOUND_CUTSCENE_BANK_2A }, - { "BANK_2B", STREAMED_SOUND_CUTSCENE_BANK_2B }, - { "BANK_3A", STREAMED_SOUND_CUTSCENE_BANK_3A }, - { "BANK_3B", STREAMED_SOUND_CUTSCENE_BANK_3B }, - { "BANK_4", STREAMED_SOUND_CUTSCENE_BANK_4 }, - { "BIKE_1", STREAMED_SOUND_CUTSCENE_BIKE_1 }, - { "BIKE_2", STREAMED_SOUND_CUTSCENE_BIKE_2 }, - { "BIKE_3", STREAMED_SOUND_CUTSCENE_BIKE_3 }, - { "BUD_1", STREAMED_SOUND_CUTSCENE_BUD_1 }, - { "BUD_2", STREAMED_SOUND_CUTSCENE_BUD_2 }, - { "BUD_3", STREAMED_SOUND_CUTSCENE_BUD_3 }, - { "CAP_1", STREAMED_SOUND_CUTSCENE_CAP_1 }, - { "CAR_1", STREAMED_SOUND_CUTSCENE_CAR_1 }, - { "CNT_1A", STREAMED_SOUND_CUTSCENE_CNT_1A }, - { "CNT_1B", STREAMED_SOUND_CUTSCENE_CNT_1B }, - { "CNT_2", STREAMED_SOUND_CUTSCENE_CNT_2 }, - { "COK_1", STREAMED_SOUND_CUTSCENE_COK_1 }, - { "COK_2A", STREAMED_SOUND_CUTSCENE_COK_2A }, - { "COK_2B", STREAMED_SOUND_CUTSCENE_COK_2B }, - { "COK_3", STREAMED_SOUND_CUTSCENE_COK_3 }, - { "COK_4A", STREAMED_SOUND_CUTSCENE_COK_4A }, - { "COK_4A2", STREAMED_SOUND_CUTSCENE_COK_4A2 }, - { "COK_4B", STREAMED_SOUND_CUTSCENE_COK_4B }, - { "COL_1", STREAMED_SOUND_CUTSCENE_COL_1 }, - { "COL_2", STREAMED_SOUND_CUTSCENE_COL_2 }, - { "COL_3A", STREAMED_SOUND_CUTSCENE_COL_3A }, - { "COL_4A", STREAMED_SOUND_CUTSCENE_COL_4A }, - { "COL_5A", STREAMED_SOUND_CUTSCENE_COL_5A }, - { "COL_5B", STREAMED_SOUND_CUTSCENE_COL_5B }, - { "CUB_1", STREAMED_SOUND_CUTSCENE_CUB_1 }, - { "CUB_2", STREAMED_SOUND_CUTSCENE_CUB_2 }, - { "CUB_3", STREAMED_SOUND_CUTSCENE_CUB_3 }, - { "CUB_4", STREAMED_SOUND_CUTSCENE_CUB_4 }, - { "DRUG_1", STREAMED_SOUND_CUTSCENE_DRUG_1 }, - { "FIN", STREAMED_SOUND_CUTSCENE_FIN }, - { "FIN_2", STREAMED_SOUND_CUTSCENE_FIN2 }, - { "FINALE", STREAMED_SOUND_CUTSCENE_FINALE }, - { "HAT_1", STREAMED_SOUND_CUTSCENE_HAT_1 }, - { "HAT_2", STREAMED_SOUND_CUTSCENE_HAT_2 }, - { "HAT_3", STREAMED_SOUND_CUTSCENE_HAT_3 }, - { "ICE_1", STREAMED_SOUND_CUTSCENE_ICE_1 }, - { "INT_A", STREAMED_SOUND_CUTSCENE_INT_A }, - { "INT_B", STREAMED_SOUND_CUTSCENE_INT_B }, - { "INT_D", STREAMED_SOUND_CUTSCENE_INT_D }, - { "INT_M", STREAMED_SOUND_CUTSCENE_INT_M }, - { "LAW_1A", STREAMED_SOUND_CUTSCENE_LAW_1A }, - { "LAW_1B", STREAMED_SOUND_CUTSCENE_LAW_1B }, - { "LAW_2A", STREAMED_SOUND_CUTSCENE_LAW_2A }, - { "LAW_2B", STREAMED_SOUND_CUTSCENE_LAW_2B }, - { "LAW_2C", STREAMED_SOUND_CUTSCENE_LAW_2C }, - { "LAW_3", STREAMED_SOUND_CUTSCENE_LAW_3 }, - { "LAW_4", STREAMED_SOUND_CUTSCENE_LAW_4 }, - { "PHIL_1", STREAMED_SOUND_CUTSCENE_PHIL_1 }, - { "PHIL_2", STREAMED_SOUND_CUTSCENE_PHIL_2 }, - { "PORN_1", STREAMED_SOUND_CUTSCENE_PORN_1 }, - { "PORN_2", STREAMED_SOUND_CUTSCENE_PORN_2 }, - { "PORN_3", STREAMED_SOUND_CUTSCENE_PORN_3 }, - { "PORN_4", STREAMED_SOUND_CUTSCENE_PORN_4 }, - { "RESC_1A", STREAMED_SOUND_CUTSCENE_RESC_1A }, - { "ROK_1", STREAMED_SOUND_CUTSCENE_ROK_1 }, - { "ROK_2", STREAMED_SOUND_CUTSCENE_ROK_2 }, - { "ROK_3A", STREAMED_SOUND_CUTSCENE_ROK_3A }, - { "STRIPA", STREAMED_SOUND_CUTSCENE_STRIPA }, - { "TAX_1", STREAMED_SOUND_CUTSCENE_TAX_1 }, - { "TEX_1", STREAMED_SOUND_CUTSCENE_TEX_1 }, - { "TEX_2", STREAMED_SOUND_CUTSCENE_TEX_2 }, - { "TEX_3", STREAMED_SOUND_CUTSCENE_TEX_3 }, - { "GSPOT", STREAMED_SOUND_CUTSCENE_GLIGHT }, - { "FIST", STREAMED_SOUND_CUTSCENE_FIST }, - { "EL_PH1", STREAMED_SOUND_CUTSCENE_ELBURRO1_PH1 }, - { "EL_PH2", STREAMED_SOUND_CUTSCENE_ELBURRO2_PH2 }, - { NULL, 0 } -}; +static bool bModelsRemovedForCutscene; +static int32 NumberOfSavedWeapons; +static eWeaponType SavedWeaponIDs[TOTAL_WEAPON_SLOTS]; +static int32 SavedWeaponAmmo[TOTAL_WEAPON_SLOTS]; -int -FindCutsceneAudioTrackId(const char *szCutsceneName) -{ - for (int i = 0; musicNameIdAssoc[i].szTrackName; i++) { - if (!CGeneral::faststricmp(musicNameIdAssoc[i].szTrackName, szCutsceneName)) - return musicNameIdAssoc[i].iTrackId; - } - return -1; -} - -bool CCutsceneMgr::ms_running; -bool CCutsceneMgr::ms_cutsceneProcessing; +char CCutsceneMgr::ms_cAppendAnimName[NUMCUTSCENEOBJECTS][NAMELENGTH]; +char CCutsceneMgr::ms_cAppendObjectName[NUMCUTSCENEOBJECTS][NAMELENGTH]; +int CCutsceneMgr::ms_numAppendObjectNames; CDirectory *CCutsceneMgr::ms_pCutsceneDir; -CCutsceneObject *CCutsceneMgr::ms_pCutsceneObjects[NUMCUTSCENEOBJECTS]; -int32 CCutsceneMgr::ms_numCutsceneObjs; bool CCutsceneMgr::ms_loaded; -bool CCutsceneMgr::ms_animLoaded; -bool CCutsceneMgr::ms_useLodMultiplier; -char CCutsceneMgr::ms_cutsceneName[CUTSCENENAMESIZE]; -CAnimBlendAssocGroup CCutsceneMgr::ms_cutsceneAssociations; -CVector CCutsceneMgr::ms_cutsceneOffset; -float CCutsceneMgr::ms_cutsceneTimer; +bool CCutsceneMgr::ms_hasFileInfo; bool CCutsceneMgr::ms_wasCutsceneSkipped; +bool CCutsceneMgr::ms_useLodMultiplier; +bool CCutsceneMgr::ms_cutsceneProcessing; +bool CCutsceneMgr::ms_running; +bool CCutsceneMgr::ms_animLoaded; uint32 CCutsceneMgr::ms_cutsceneLoadStatus; -bool CCutsceneMgr::ms_useCutsceneShadows = true; - -bool bCamLoaded; -bool bIsEverythingRemovedFromTheWorldForTheBiggestFuckoffCutsceneEver; // pls don't shrink the name :P -int32 NumberOfSavedWeapons; -eWeaponType SavedWeaponIDs[TOTAL_WEAPON_SLOTS]; -int32 SavedWeaponAmmo[TOTAL_WEAPON_SLOTS]; -char uncompressedAnims[8][32]; -uint32 numUncompressedAnims; - - -RpAtomic * -CalculateBoundingSphereRadiusCB(RpAtomic *atomic, void *data) -{ - float radius = RpAtomicGetBoundingSphere(atomic)->radius; - RwV3d center = RpAtomicGetBoundingSphere(atomic)->center; - - for (RwFrame *frame = RpAtomicGetFrame(atomic); RwFrameGetParent(frame); frame = RwFrameGetParent(frame)) - RwV3dTransformPoints(¢er, ¢er, 1, RwFrameGetMatrix(frame)); - - float size = RwV3dLength(¢er) + radius; - if (size > *(float *)data) - *(float *)data = size; - return atomic; -} void -CCutsceneMgr::Initialise(void) +CCutsceneMgr::Initialise(void *dir) { - ms_numCutsceneObjs = 0; - ms_loaded = false; - ms_wasCutsceneSkipped = false; + ms_cutsceneLoadStatus = CUTSCENE_NOT_LOADED; ms_running = false; - ms_useLodMultiplier = false; ms_animLoaded = false; ms_cutsceneProcessing = false; - - ms_pCutsceneDir = new CDirectory(CUTSCENEDIRSIZE); - ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR"); - - numUncompressedAnims = 0; - uncompressedAnims[0][0] = '\0'; -} - -void -CCutsceneMgr::Shutdown(void) -{ - delete ms_pCutsceneDir; -} - -void -CCutsceneMgr::LoadCutsceneData(const char *szCutsceneName) -{ - int file; - uint32 size; - uint32 offset; - CPlayerPed *pPlayerPed; - - ms_cutsceneProcessing = true; + ms_useLodMultiplier = false; ms_wasCutsceneSkipped = false; - CTimer::Suspend(); - if (!bIsEverythingRemovedFromTheWorldForTheBiggestFuckoffCutsceneEver) - CStreaming::RemoveCurrentZonesModels(); - - ms_pCutsceneDir->numEntries = 0; - ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR"); - - CStreaming::RemoveUnusedModelsInLoadedList(); - CGame::DrasticTidyUpMemory(true); - - strcpy(ms_cutsceneName, szCutsceneName); - - RwStream *stream; - stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, "ANIM\\CUTS.IMG"); - assert(stream); - - // Load animations - sprintf(gString, "%s.IFP", szCutsceneName); - if (ms_pCutsceneDir->FindItem(gString, offset, size)) { - CStreaming::MakeSpaceFor(size << 11); - CStreaming::ImGonnaUseStreamingMemory(); - RwStreamSkip(stream, offset << 11); - CAnimManager::LoadAnimFile(stream, true, uncompressedAnims); - ms_cutsceneAssociations.CreateAssociations(szCutsceneName); - CStreaming::IHaveUsedStreamingMemory(); - ms_animLoaded = true; - } else { - ms_animLoaded = false; - } - RwStreamClose(stream, nil); - - // Load camera data - file = CFileMgr::OpenFile("ANIM\\CUTS.IMG", "rb"); - sprintf(gString, "%s.DAT", szCutsceneName); - if (ms_pCutsceneDir->FindItem(gString, offset, size)) { - CStreaming::ImGonnaUseStreamingMemory(); - CFileMgr::Seek(file, offset << 11, SEEK_SET); - TheCamera.LoadPathSplines(file); - CStreaming::IHaveUsedStreamingMemory(); - bCamLoaded = true; - } else { - bCamLoaded = false; - } - - CFileMgr::CloseFile(file); - - if (CGeneral::faststricmp(ms_cutsceneName, "finale")) { - DMAudio.ChangeMusicMode(MUSICMODE_CUTSCENE); - int trackId = FindCutsceneAudioTrackId(szCutsceneName); - if (trackId != -1) { - printf("Start preload audio %s\n", szCutsceneName); - DMAudio.PreloadCutSceneMusic(trackId); - printf("End preload audio %s\n", szCutsceneName); - } + ms_hasFileInfo = false; + //ms_numCutsceneObjs = 0; + //ms_loaded = false; + if (gMakeResources) { + ms_pCutsceneDir = new CDirectory(CUTSCENEDIRSIZE); + ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR"); } + else + ms_pCutsceneDir = (CDirectory*)dir; - ms_cutsceneTimer = 0.0f; - ms_loaded = true; - ms_cutsceneOffset = CVector(0.0f, 0.0f, 0.0f); - - pPlayerPed = FindPlayerPed(); - pPlayerPed->m_pWanted->ClearQdCrimes(); - pPlayerPed->bIsVisible = false; - pPlayerPed->m_fCurrentStamina = pPlayerPed->m_fMaxStamina; - CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_CUTSCENE); - CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(true); - - CTimer::Resume(); -} - -void -CCutsceneMgr::FinishCutscene() -{ - ms_wasCutsceneSkipped = true; - if (bCamLoaded) { - CCutsceneMgr::ms_cutsceneTimer = TheCamera.GetCutSceneFinishTime() * 0.001f; - TheCamera.FinishCutscene(); - } - - FindPlayerPed()->bIsVisible = true; - CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(false); + //numUncompressedAnims = 0; + //uncompressedAnims[0][0] = '\0'; } -void -CCutsceneMgr::SetupCutsceneToStart(void) +void CCutsceneMgr::Write(base::cRelocatableChunkWriter& writer) { - if (bCamLoaded) { - TheCamera.SetCamCutSceneOffSet(ms_cutsceneOffset); - TheCamera.TakeControlWithSpline(JUMP_CUT); - TheCamera.SetWideScreenOn(); - } - - ms_cutsceneOffset.z++; - - for (int i = ms_numCutsceneObjs - 1; i >= 0; i--) { - assert(RwObjectGetType(ms_pCutsceneObjects[i]->m_rwObject) == rpCLUMP); - if (CAnimBlendAssociation *pAnimBlendAssoc = RpAnimBlendClumpGetFirstAssociation((RpClump*)ms_pCutsceneObjects[i]->m_rwObject)) { - assert(pAnimBlendAssoc->hierarchy->sequences[0].HasTranslation()); - if (ms_pCutsceneObjects[i]->m_pAttachTo != nil) { - pAnimBlendAssoc->flags &= (~ASSOC_HAS_TRANSLATION); - } else { - if (pAnimBlendAssoc->hierarchy->IsCompressed()){ - KeyFrameTransCompressed *keyFrames = ((KeyFrameTransCompressed*)pAnimBlendAssoc->hierarchy->sequences[0].GetKeyFrameCompressed(0)); - CVector trans; - keyFrames->GetTranslation(&trans); - ms_pCutsceneObjects[i]->SetPosition(ms_cutsceneOffset + trans); - }else{ - KeyFrameTrans *keyFrames = ((KeyFrameTrans*)pAnimBlendAssoc->hierarchy->sequences[0].GetKeyFrame(0)); - ms_pCutsceneObjects[i]->SetPosition(ms_cutsceneOffset + keyFrames->translation); - } - } - pAnimBlendAssoc->SetRun(); - } else { - ms_pCutsceneObjects[i]->SetPosition(ms_cutsceneOffset); - } - CWorld::Add(ms_pCutsceneObjects[i]); - if (RwObjectGetType(ms_pCutsceneObjects[i]->m_rwObject) == rpCLUMP) { - ms_pCutsceneObjects[i]->UpdateRpHAnim(); - } - } - - CTimer::Update(); - CTimer::Update(); - ms_running = true; - ms_cutsceneTimer = 0.0f; + writer.AllocateRaw(ms_pCutsceneDir, sizeof(*ms_pCutsceneDir), 4, false, true); + writer.AllocateRaw(ms_pCutsceneDir->entries, sizeof(CDirectory::DirectoryInfo) * ms_pCutsceneDir->numEntries, 4, false, true); + writer.AddPatch(ms_pCutsceneDir); } void -CCutsceneMgr::SetCutsceneAnim(const char *animName, CObject *pObject) +CCutsceneMgr::Shutdown(void) { - CAnimBlendAssociation *pNewAnim; - CAnimBlendClumpData *pAnimBlendClumpData; - - assert(RwObjectGetType(pObject->m_rwObject) == rpCLUMP); - debug("Give cutscene anim %s\n", animName); - RpAnimBlendClumpRemoveAllAssociations((RpClump*)pObject->m_rwObject); - - pNewAnim = ms_cutsceneAssociations.GetAnimation(animName); - if (!pNewAnim) { - debug("\n\nHaven't I told you I can't find the fucking animation %s\n\n\n", animName); - return; - } - - if (pNewAnim->hierarchy->IsCompressed()) - pNewAnim->hierarchy->keepCompressed = true; - - CStreaming::ImGonnaUseStreamingMemory(); - pNewAnim = ms_cutsceneAssociations.CopyAnimation(animName); - CStreaming::IHaveUsedStreamingMemory(); - - pNewAnim->SetCurrentTime(0.0f); - pNewAnim->flags |= ASSOC_HAS_TRANSLATION; - pNewAnim->flags &= ~ASSOC_RUNNING; - - pAnimBlendClumpData = *RPANIMBLENDCLUMPDATA(pObject->m_rwObject); - pAnimBlendClumpData->link.Prepend(&pNewAnim->link); - - if (pNewAnim->hierarchy->keepCompressed) - pAnimBlendClumpData->frames->flag |= AnimBlendFrameData::COMPRESSED; + delete ms_pCutsceneDir; } void -CCutsceneMgr::SetCutsceneAnimToLoop(const char* animName) -{ - ms_cutsceneAssociations.GetAnimation(animName)->flags |= ASSOC_REPEAT; -} - -CCutsceneHead * -CCutsceneMgr::AddCutsceneHead(CObject *pObject, int modelId) -{ - return nil; -} - -void UpdateCutsceneObjectBoundingBox(RpClump* clump, int modelId) -{ - if (modelId >= MI_CUTOBJ01 && modelId <= MI_CUTOBJ05) { - CColModel* pColModel = &CTempColModels::ms_colModelCutObj[modelId - MI_CUTOBJ01]; - float radius = 0.0f; - RpClumpForAllAtomics(clump, CalculateBoundingSphereRadiusCB, &radius); - pColModel->boundingSphere.radius = radius; - pColModel->boundingBox.min = CVector(-radius, -radius, -radius); - pColModel->boundingBox.max = CVector(radius, radius, radius); - } -} - -CCutsceneObject * -CCutsceneMgr::CreateCutsceneObject(int modelId) +CCutsceneMgr::LoadCutsceneData(const char *szCutsceneName) { - CBaseModelInfo *pModelInfo; - CColModel *pColModel; - CCutsceneObject *pCutsceneObject; - - CStreaming::ImGonnaUseStreamingMemory(); - debug("Created cutscene object %s\n", CModelInfo::GetModelInfo(modelId)->GetModelName()); - if (modelId >= MI_CUTOBJ01 && modelId <= MI_CUTOBJ05) { - pModelInfo = CModelInfo::GetModelInfo(modelId); - pColModel = &CTempColModels::ms_colModelCutObj[modelId - MI_CUTOBJ01]; - pModelInfo->SetColModel(pColModel); - UpdateCutsceneObjectBoundingBox((RpClump*)pModelInfo->GetRwObject(), modelId); - } else if (modelId >= MI_SPECIAL01 && modelId <= MI_SPECIAL21) { - pModelInfo = CModelInfo::GetModelInfo(modelId); - if (pModelInfo->GetColModel() == &CTempColModels::ms_colModelPed1) { - CColModel *colModel = new CColModel(); - colModel->boundingSphere.radius = 2.0f; - colModel->boundingSphere.center = CVector(0.0f, 0.0f, 0.0f); - pModelInfo->SetColModel(colModel, true); - } - pColModel = pModelInfo->GetColModel(); - float radius = 2.0f; - pColModel->boundingSphere.radius = radius; - pColModel->boundingBox.min = CVector(-radius, -radius, -radius); - pColModel->boundingBox.max = CVector(radius, radius, radius); - } - - pCutsceneObject = new CCutsceneObject(); - pCutsceneObject->SetModelIndex(modelId); - if (ms_useCutsceneShadows) - pCutsceneObject->CreateShadow(); - ms_pCutsceneObjects[ms_numCutsceneObjs++] = pCutsceneObject; - CStreaming::IHaveUsedStreamingMemory(); - return pCutsceneObject; + LoadCutsceneData_overlay(szCutsceneName); } void CCutsceneMgr::DeleteCutsceneData(void) { - if (!ms_loaded) return; - CTimer::Suspend(); - - ms_cutsceneProcessing = false; - ms_useLodMultiplier = false; - ms_useCutsceneShadows = true; - - for (--ms_numCutsceneObjs; ms_numCutsceneObjs >= 0; ms_numCutsceneObjs--) { - CWorld::Remove(ms_pCutsceneObjects[ms_numCutsceneObjs]); - ms_pCutsceneObjects[ms_numCutsceneObjs]->DeleteRwObject(); - delete ms_pCutsceneObjects[ms_numCutsceneObjs]; - ms_pCutsceneObjects[ms_numCutsceneObjs] = nil; - } - ms_numCutsceneObjs = 0; - - /* TODO!!! tmp hack - for (int i = MI_SPECIAL01; i < MI_SPECIAL21; i++) { - CBaseModelInfo *minfo = CModelInfo::GetModelInfo(i); - CColModel *colModel = minfo->GetColModel(); - if (colModel != &CTempColModels::ms_colModelPed1) { - delete colModel; - minfo->SetColModel(&CTempColModels::ms_colModelPed1); - } - } - */ - - if (ms_animLoaded) - CAnimManager::RemoveLastAnimFile(); - - ms_animLoaded = false; - numUncompressedAnims = 0; - uncompressedAnims[0][0] = '\0'; - - if (bCamLoaded) { - TheCamera.RestoreWithJumpCut(); - TheCamera.SetWideScreenOff(); - TheCamera.DeleteCutSceneCamDataMemory(); - } - ms_running = false; - ms_loaded = false; - - FindPlayerPed()->bIsVisible = true; - CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_CUTSCENE); - CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(false); - - if (CGeneral::faststricmp(ms_cutsceneName, "finale")) { - DMAudio.StopCutSceneMusic(); - DMAudio.ChangeMusicMode(MUSICMODE_GAME); - } - - CStreaming::ms_disableStreaming = false; - CWorld::bProcessCutsceneOnly = false; - - if(bCamLoaded) - CGame::DrasticTidyUpMemory(TheCamera.GetScreenFadeStatus() == FADE_2); - - CPad::GetPad(0)->Clear(false); - if (bIsEverythingRemovedFromTheWorldForTheBiggestFuckoffCutsceneEver) { - CStreaming::LoadInitialPeds(); - CStreaming::LoadInitialWeapons(); - CStreaming::LoadInitialVehicles(); - bIsEverythingRemovedFromTheWorldForTheBiggestFuckoffCutsceneEver = false; - - CPlayerPed *pPlayerPed = FindPlayerPed(); - for (int i = 0; i < NumberOfSavedWeapons; i++) { - int32 weaponModelId = CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModelId; - uint8 flags = CStreaming::ms_aInfoForModel[weaponModelId].m_flags; - CStreaming::RequestModel(weaponModelId, STREAMFLAGS_DONT_REMOVE); - CStreaming::LoadAllRequestedModels(false); - if (CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModel2Id != -1) { - CStreaming::RequestModel(CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModel2Id, 0); - CStreaming::LoadAllRequestedModels(false); - } - if (!(flags & STREAMFLAGS_DONT_REMOVE)) - CStreaming::SetModelIsDeletable(weaponModelId); - pPlayerPed->GiveWeapon(SavedWeaponIDs[i], SavedWeaponAmmo[i], true); - } - NumberOfSavedWeapons = 0; - } - - CTimer::Resume(); -} - -void -CCutsceneMgr::Update(void) -{ - enum { - CUTSCENE_LOADING_0 = 0, - CUTSCENE_LOADING_AUDIO, - CUTSCENE_LOADING_2, - CUTSCENE_LOADING_3, - CUTSCENE_LOADING_4 - }; - - switch (ms_cutsceneLoadStatus) { - case CUTSCENE_LOADING_AUDIO: - SetupCutsceneToStart(); - if (CGeneral::faststricmp(ms_cutsceneName, "finale")) - DMAudio.PlayPreloadedCutSceneMusic(); - ms_cutsceneLoadStatus++; - break; - case CUTSCENE_LOADING_2: - case CUTSCENE_LOADING_3: - ms_cutsceneLoadStatus++; - break; - case CUTSCENE_LOADING_4: - ms_cutsceneLoadStatus = CUTSCENE_LOADING_0; - break; - default: - break; - } - - if (!ms_running) return; - - ms_cutsceneTimer += CTimer::GetTimeStepNonClippedInSeconds(); - - for (int i = 0; i < ms_numCutsceneObjs; i++) { - int modelId = ms_pCutsceneObjects[i]->GetModelIndex(); - if (modelId >= MI_CUTOBJ01 && modelId <= MI_CUTOBJ05) - UpdateCutsceneObjectBoundingBox(ms_pCutsceneObjects[i]->GetClump(), modelId); - - if (ms_pCutsceneObjects[i]->m_pAttachTo != nil && modelId >= MI_SPECIAL01 && modelId <= MI_SPECIAL21) - UpdateCutsceneObjectBoundingBox(ms_pCutsceneObjects[i]->GetClump(), modelId); - } - - if (bCamLoaded) - if (CGeneral::faststricmp(ms_cutsceneName, "finale") && TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FLYBY && ms_cutsceneLoadStatus == CUTSCENE_LOADING_0) { - if (CPad::GetPad(0)->GetCrossJustDown() - || (CGame::playingIntro && CPad::GetPad(0)->GetStartJustDown()) - || CPad::GetPad(0)->GetLeftMouseJustDown() - || CPad::GetPad(0)->GetEnterJustDown() - || CPad::GetPad(0)->GetCharJustDown(' ')) - FinishCutscene(); - } -} - -bool CCutsceneMgr::HasCutsceneFinished(void) { return !bCamLoaded || TheCamera.GetPositionAlongSpline() == 1.0f; } - -void -CCutsceneMgr::LoadAnimationUncompressed(char const* name) -{ - strcpy(uncompressedAnims[numUncompressedAnims], name); - - // Because that's how CAnimManager knows the end of array - ++numUncompressedAnims; - assert(numUncompressedAnims < ARRAY_SIZE(uncompressedAnims)); - uncompressedAnims[numUncompressedAnims][0] = '\0'; -} - -void -CCutsceneMgr::AttachObjectToParent(CObject *pObject, CEntity *pAttachTo) -{ - ((CCutsceneObject*)pObject)->m_pAttachmentObject = nil; - ((CCutsceneObject*)pObject)->m_pAttachTo = RpClumpGetFrame(pAttachTo->GetClump()); - - debug("Attach %s to %s\n", CModelInfo::GetModelInfo(pObject->GetModelIndex())->GetModelName(), CModelInfo::GetModelInfo(pAttachTo->GetModelIndex())->GetModelName()); -} - -void -CCutsceneMgr::AttachObjectToFrame(CObject *pObject, CEntity *pAttachTo, const char *frame) -{ - ((CCutsceneObject*)pObject)->m_pAttachmentObject = nil; - ((CCutsceneObject*)pObject)->m_pAttachTo = RpAnimBlendClumpFindFrame(pAttachTo->GetClump(), frame)->frame; - debug("Attach %s to component %s of %s\n", - CModelInfo::GetModelInfo(pObject->GetModelIndex())->GetModelName(), - frame, - CModelInfo::GetModelInfo(pAttachTo->GetModelIndex())->GetModelName()); - if (RwObjectGetType(pObject->m_rwObject) == rpCLUMP) { - RpClump *clump = (RpClump*)pObject->m_rwObject; - if (IsClumpSkinned(clump)) - RpAtomicGetBoundingSphere(GetFirstAtomic(clump))->radius *= 1.1f; - } + DeleteCutsceneData_overlay(); + if (bModelsRemovedForCutscene) + LoadEverythingBecauseCutsceneDeletedAllOfIt(); } void -CCutsceneMgr::AttachObjectToBone(CObject *pObject, CObject *pAttachTo, int bone) +CCutsceneMgr::RemoveEverythingBecauseCutsceneDoesntFitInMemory() { - RpHAnimHierarchy *hanim = GetAnimHierarchyFromSkinClump(pAttachTo->GetClump()); - RwInt32 id = RpHAnimIDGetIndex(hanim, bone); - RwMatrix *matrixArray = RpHAnimHierarchyGetMatrixArray(hanim); - ((CCutsceneObject*)pObject)->m_pAttachmentObject = pAttachTo; - ((CCutsceneObject*)pObject)->m_pAttachTo = &matrixArray[id]; - debug("Attach %s to %s\n", - CModelInfo::GetModelInfo(pObject->GetModelIndex())->GetModelName(), - CModelInfo::GetModelInfo(pAttachTo->GetModelIndex())->GetModelName()); -} - -void -CCutsceneMgr::RemoveEverythingFromTheWorldForTheBiggestFuckoffCutsceneEver() -{ - CStreaming::ms_disableStreaming = true; + //CStreaming::ms_disableStreaming = true; + CWorld::ClearExcitingStuffFromArea(FindPlayerCoors(), 120.0f, true); CColStore::RemoveAllCollision(); CWorld::bProcessCutsceneOnly = true; - ms_cutsceneProcessing = true; + /*ms_cutsceneProcessing = true; for (int i = CPools::GetPedPool()->GetSize() - 1; i >= 0; i--) { CPed *pPed = CPools::GetPedPool()->GetSlot(i); @@ -630,25 +122,21 @@ CCutsceneMgr::RemoveEverythingFromTheWorldForTheBiggestFuckoffCutsceneEver() } } } - - bIsEverythingRemovedFromTheWorldForTheBiggestFuckoffCutsceneEver = true; + CWorld::bProcessCutsceneOnly = true; + //bIsEverythingRemovedFromTheWorldForTheBiggestFuckoffCutsceneEver = true;*/ CStreaming::RemoveCurrentZonesModels(); + while (CStreaming::RemoveLoadedVehicle()); + CRadar::RemoveRadarSections(); CStreaming::SetModelIsDeletable(MI_MALE01); CStreaming::SetModelTxdIsDeletable(MI_MALE01); - CStreaming::SetModelIsDeletable(MI_TAXI_D); - CStreaming::SetModelTxdIsDeletable(MI_TAXI_D); + CStreaming::SetModelIsDeletable(MI_COLT45); + CStreaming::SetModelTxdIsDeletable(MI_COLT45); CStreaming::SetModelIsDeletable(MI_NIGHTSTICK); CStreaming::SetModelTxdIsDeletable(MI_NIGHTSTICK); CStreaming::SetModelIsDeletable(MI_MISSILE); CStreaming::SetModelTxdIsDeletable(MI_MISSILE); - CStreaming::SetModelIsDeletable(MI_POLICE); - CStreaming::SetModelTxdIsDeletable(MI_POLICE); - - while (CStreaming::RemoveLoadedVehicle()) ; - - CRadar::RemoveRadarSections(); - for (int i = CPools::GetDummyPool()->GetSize() - 1; i >= 0; i--) { + /*for (int i = CPools::GetDummyPool()->GetSize() - 1; i >= 0; i--) { CDummy* pDummy = CPools::GetDummyPool()->GetSlot(i); if (pDummy) pDummy->DeleteRwObject(); @@ -668,7 +156,7 @@ CCutsceneMgr::RemoveEverythingFromTheWorldForTheBiggestFuckoffCutsceneEver() if (!pBuilding->bImBeingRendered) pBuilding->DeleteRwObject(); } - } + }*/ CPlayerPed *pPlayerPed = FindPlayerPed(); pPlayerPed->RemoveWeaponAnims(0, -1000.0f); @@ -683,5 +171,69 @@ CCutsceneMgr::RemoveEverythingFromTheWorldForTheBiggestFuckoffCutsceneEver() } pPlayerPed->ClearWeapons(); - CGame::DrasticTidyUpMemory(true); + bModelsRemovedForCutscene = true; + //CGame::DrasticTidyUpMemory(true); +} + +void +CCutsceneMgr::LoadEverythingBecauseCutsceneDeletedAllOfIt() +{ + bModelsRemovedForCutscene = false; + CStreaming::LoadInitialPeds(); + CStreaming::LoadInitialWeapons(); + //CStreaming::LoadInitialVehicles(); + + CPlayerPed *pPlayerPed = FindPlayerPed(); + for (int i = 0; i < NumberOfSavedWeapons; i++) { + int32 weaponModelId = CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModelId; + uint8 flags = CStreaming::ms_aInfoForModel[weaponModelId].m_flags; + CStreaming::RequestModel(weaponModelId, STREAMFLAGS_DONT_REMOVE); + CStreaming::LoadAllRequestedModels(false); + if (CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModel2Id != -1) { + CStreaming::RequestModel(CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModel2Id, 0); + CStreaming::LoadAllRequestedModels(false); + } + if (!(flags & STREAMFLAGS_DONT_REMOVE)) + CStreaming::SetModelIsDeletable(weaponModelId); + pPlayerPed->GiveWeapon(SavedWeaponIDs[i], SavedWeaponAmmo[i], true); + } + NumberOfSavedWeapons = 0; +} + +void +CCutsceneMgr::Update(void) +{ + if (ms_cutsceneLoadStatus != CUTSCENE_NOT_LOADED) + Update_overlay(); +} + +void +CCutsceneMgr::LoadAnimationUncompressed(char const* name) +{ + strcpy(ms_aUncompressedCutsceneAnims[ms_numUncompressedCutsceneAnims], name); + + // Because that's how CAnimManager knows the end of array + ++ms_numUncompressedCutsceneAnims; + assert(ms_numUncompressedCutsceneAnims < ARRAY_SIZE(ms_aUncompressedCutsceneAnims)); + ms_aUncompressedCutsceneAnims[ms_numUncompressedCutsceneAnims][0] = '\0'; +} + + +bool +CCutsceneMgr::IsCutsceneSkipButtonBeingPressed() +{ + return (CPad::GetPad(0)->GetCrossJustDown() + || CPad::GetPad(0)->GetLeftMouseJustDown() + || CPad::GetPad(0)->GetEnterJustDown() + || CPad::GetPad(0)->GetCharJustDown(' ')); +} + +void +CCutsceneMgr::AppendToNextCutscene(const char *object, const char *anim) +{ + strcpy(ms_cAppendObjectName[ms_numAppendObjectNames], object); + strlwr(ms_cAppendObjectName[ms_numAppendObjectNames]); + strcpy(ms_cAppendAnimName[ms_numAppendObjectNames], anim); + strlwr(ms_cAppendAnimName[ms_numAppendObjectNames]); + ms_numAppendObjectNames++; }
\ No newline at end of file diff --git a/src/animation/CutsceneMgr.h b/src/animation/CutsceneMgr.h index 51ef6c04..7c749d4b 100644 --- a/src/animation/CutsceneMgr.h +++ b/src/animation/CutsceneMgr.h @@ -1,14 +1,69 @@ #pragma once #include "CutsceneObject.h" -#define CUTSCENENAMESIZE 8 class CDirectory; class CAnimBlendAssocGroup; class CCutsceneHead; +enum { + CUTSCENE_NOT_LOADED = 0, + CUTSCENE_LOADING, + CUTSCENE_LOADED, +}; + +enum { + CUTSCENE_PLAYING_0 = 0, + CUTSCENE_STARTED, + CUTSCENE_PLAYING_2, + CUTSCENE_PLAYING_3, + CUTSCENE_PLAYING_4, +}; + +enum +{ + NAMELENGTH = 32, + NUM_CUTS_PARTICLE_EFFECTS = 8, + NUM_CUTS_MAX_TEXTS = 64, + NUM_CUTS_UNCOMPRESSED_ANIMS = 8, + TEXT_KEY_SIZE = 8, + CUTSCENENAMESIZE = 8 +}; + +struct sToHideItem +{ + float x, y, z; + char name[NAMELENGTH]; +}; + +// TODO: figure out from SA +// this is unused in LCS anyway +struct sParticleEffect +{ + char name[NAMELENGTH]; + bool bPlayed; // ?? + int iTime; + int unk1; + int unk2; + char name2[NAMELENGTH]; + float x; + float y; + float z; + float unkX; + float unkY; + float unkZ; + bool unk10; + bool unk11; +}; + +struct sAttachInfo +{ + int attachToId, objectId, boneId; +}; + class CCutsceneMgr { + static bool ms_running; static CCutsceneObject *ms_pCutsceneObjects[NUMCUTSCENEOBJECTS]; @@ -24,10 +79,55 @@ class CCutsceneMgr static bool ms_wasCutsceneSkipped; static bool ms_cutsceneProcessing; static bool ms_useCutsceneShadows; + static bool ms_hasFileInfo; + static int ms_numLoadObjectNames; + + static char ms_cAppendAnimName[NUMCUTSCENEOBJECTS][NAMELENGTH]; + static char ms_cAppendObjectName[NUMCUTSCENEOBJECTS][NAMELENGTH]; + static int ms_numAppendObjectNames; public: static CDirectory *ms_pCutsceneDir; static uint32 ms_cutsceneLoadStatus; + static bool mCutsceneSkipFading; + static int mCutsceneSkipFadeTime; + + static float m_fPrevCarDensity; + static float m_fPrevPedDensity; + + static bool m_PrevExtraColourOn; + static uint32 m_PrevExtraColour; + + static uint32 ms_iNumParticleEffects; + static sParticleEffect ms_pParticleEffects[NUM_CUTS_PARTICLE_EFFECTS]; + + static sToHideItem ms_crToHideItems[NUMCUTSCENEOBJECTS]; + static uint32 ms_iNumHiddenEntities; + static CEntity *ms_pHiddenEntities[NUMCUTSCENEOBJECTS]; + + static int ms_numAttachObjectToBones; + static bool ms_bRepeatObject[NUMCUTSCENEOBJECTS]; + + static sAttachInfo ms_iAttachObjectToBone[NUMCUTSCENEOBJECTS]; + + static uint32 ms_numUncompressedCutsceneAnims; + + static char ms_aUncompressedCutsceneAnims[NUM_CUTS_UNCOMPRESSED_ANIMS][NAMELENGTH]; + + static uint32 ms_iTextDuration[NUM_CUTS_MAX_TEXTS]; + static uint32 ms_iTextStartTime[NUM_CUTS_MAX_TEXTS]; + static char ms_cTextOutput[NUM_CUTS_MAX_TEXTS][TEXT_KEY_SIZE]; + + static uint32 ms_currTextOutput; + static uint32 ms_numTextOutput; + static uint32 ms_iModelIndex[NUMCUTSCENEOBJECTS]; + + static char ms_cLoadAnimName[NUMCUTSCENEOBJECTS][NAMELENGTH]; + static char ms_cLoadObjectName[NUMCUTSCENEOBJECTS][NAMELENGTH]; + + static uint32 ms_cutscenePlayStatus; + + static void StartCutscene(); static void StartCutsceneProcessing() { ms_cutsceneProcessing = true; } static bool IsRunning(void) { return ms_running; } static bool HasLoaded(void) { return ms_loaded; } @@ -35,19 +135,19 @@ public: static bool WasCutsceneSkipped(void) { return ms_wasCutsceneSkipped; } static bool UseLodMultiplier(void) { return ms_useLodMultiplier; } static CCutsceneObject* GetCutsceneObject(int id) { return ms_pCutsceneObjects[id]; } - static int GetCutsceneTimeInMilleseconds(void) { return 1000.0f * ms_cutsceneTimer; } + static uint32 GetCutsceneTimeInMilleseconds(void); static char *GetCutsceneName(void) { return ms_cutsceneName; } static void SetCutsceneOffset(const CVector& vec) { ms_cutsceneOffset = vec; } static bool HasCutsceneFinished(void); - static void Initialise(void); + static void Initialise(void *dir = nil); static void Shutdown(void); static void LoadCutsceneData(const char *szCutsceneName); static void FinishCutscene(void); static void SetupCutsceneToStart(void); static void SetCutsceneAnim(const char *animName, CObject *pObject); static void SetCutsceneAnimToLoop(const char *animName); - static CCutsceneHead *AddCutsceneHead(CObject *pObject, int modelId); + static CCutsceneHead *SetHeadAnim(const char*, CObject *pObject); static CCutsceneObject *CreateCutsceneObject(int modelId); static void DeleteCutsceneData(void); static void LoadAnimationUncompressed(char const*); @@ -56,6 +156,24 @@ public: static void AttachObjectToParent(CObject *pObject, CEntity *pAttachTo); static void AttachObjectToFrame(CObject *pObject, CEntity *pAttachTo, const char *frame); static void AttachObjectToBone(CObject *pObject, CObject *pAttachTo, int frame); - static void RemoveEverythingFromTheWorldForTheBiggestFuckoffCutsceneEver(); + static void RemoveEverythingBecauseCutsceneDoesntFitInMemory(); + static void LoadEverythingBecauseCutsceneDeletedAllOfIt(); static void DisableCutsceneShadows() { ms_useCutsceneShadows = false; } + + + static void LoadCutsceneData_overlay(const char* szCutsceneName); + static bool LoadCutsceneData_postload(bool b = false); + static void Update_overlay(void); + static void DeleteCutsceneData_overlay(void); + + static bool IsCutsceneSkipButtonBeingPressed(); + static void AppendToNextCutscene(const char *object, const char *anim); + + static void LoadCutsceneData_preload(); + static void LoadCutsceneData_loading(); + static void HideRequestedObjects(); + + static bool PresubBodge(); + + static void Write(base::cRelocatableChunkWriter& writer); }; diff --git a/src/animation/CutsceneMgr_overlay.cpp b/src/animation/CutsceneMgr_overlay.cpp new file mode 100644 index 00000000..5fcb752d --- /dev/null +++ b/src/animation/CutsceneMgr_overlay.cpp @@ -0,0 +1,1030 @@ +#include "common.h" +#include "relocatableChunk.h" + +#include "General.h" +#include "CutsceneMgr.h" +#include "Directory.h" +#include "Camera.h" +#include "Streaming.h" +#include "FileMgr.h" +#include "main.h" +#include "AnimManager.h" +#include "AnimBlendAssociation.h" +#include "AnimBlendAssocGroup.h" +#include "AnimBlendClumpData.h" +#include "Pad.h" +#include "DMAudio.h" +#include "World.h" +#include "PlayerPed.h" +#include "Wanted.h" +#include "RpAnimBlend.h" +#include "ModelIndices.h" +#include "TempColModels.h" +#include "ColStore.h" +#include "Radar.h" +#include "Pools.h" +#include "Messages.h" +#include "Population.h" +#include "CarCtrl.h" +#include "Timecycle.h" +#include "Rubbish.h" +#include "Text.h" +#include "Hud.h" +#include "crossplatform.h" + +const struct { + const char *szTrackName; + int iTrackId; +} musicNameIdAssoc[] = { + { "BIKER", STREAMED_SOUND_CUTSCENE_BIKER }, + { "BONEVOY", STREAMED_SOUND_CUTSCENE_BONEVOY }, + { "CAMPAIN", STREAMED_SOUND_CUTSCENE_CAMPAIN }, + { "CASHCHP", STREAMED_SOUND_CUTSCENE_CASHCHP }, + { "CONTBAN", STREAMED_SOUND_CUTSCENE_CONTBAN }, + { "CRAZY69", STREAMED_SOUND_CUTSCENE_CRAZY69 }, + { "CUTTEST", STREAMED_SOUND_CUTSCENE_CUTTEST }, + { "DEADLY", STREAMED_SOUND_CUTSCENE_DEADLY }, + { "DONPROB", STREAMED_SOUND_CUTSCENE_DONPROB }, + { "DRIVNMR", STREAMED_SOUND_CUTSCENE_DRIVNMR }, + { "ELECTON", STREAMED_SOUND_CUTSCENE_ELECTON }, + { "FINAL", STREAMED_SOUND_CUTSCENE_FINAL }, + { "FINAL_2", STREAMED_SOUND_CUTSCENE_FINAL_2 }, + { "HOMSWET", STREAMED_SOUND_CUTSCENE_HOMSWET }, + { "HOTWHEL", STREAMED_SOUND_CUTSCENE_HOTWHEL }, + { "KIDNAPP", STREAMED_SOUND_CUTSCENE_KIDNAPP }, + { "LANDGRB", STREAMED_SOUND_CUTSCENE_LANDGRB }, + { "MORGUE", STREAMED_SOUND_CUTSCENE_MORGUE }, + { "OVERDOS", STREAMED_SOUND_CUTSCENE_OVERDOS }, + { "RUFJUST", STREAMED_SOUND_CUTSCENE_RUFJUST }, + { "SAYONAR", STREAMED_SOUND_CUTSCENE_SAYONAR }, + { "SICILAN", STREAMED_SOUND_CUTSCENE_SICILAN }, + { "THEOFER", STREAMED_SOUND_CUTSCENE_THEOFER }, + { "INTRO", STREAMED_SOUND_CUTSCENE_INTRO }, + { "FINALE", STREAMED_SOUND_CUTSCENE_FINALE }, + { NULL, 0 } +}; + +int +FindCutsceneAudioTrackId(const char *szCutsceneName) +{ + debug("looking for cutscene music track\n"); + for (int i = 0; musicNameIdAssoc[i].szTrackName; i++) { + if (!CGeneral::faststricmp(musicNameIdAssoc[i].szTrackName, szCutsceneName)) { + debug("HUZZA! FOUND cutscene music track\n"); + return musicNameIdAssoc[i].iTrackId; + } + } + debug("NOT FOUND cutscene music track\n"); + return -1; +} + +const char * +GetNextLine(const char *buf, char *line, uint32 lineSize) +{ + while (*buf == '\n' || *buf == '\r') + buf++; + + if (*buf == '\0') + return nil; + + // size check never happened, eh? + while (*buf != '\n' && *buf != '\r') { + if (*buf == '\0') + break; + *(line++) = *(buf++); + } + *(line++) = '\0'; + return buf; +} + +RpAtomic* +CalculateBoundingSphereRadiusCB(RpAtomic* atomic, void* data) +{ + float radius = RpAtomicGetBoundingSphere(atomic)->radius; + RwV3d center = RpAtomicGetBoundingSphere(atomic)->center; + + for (RwFrame* frame = RpAtomicGetFrame(atomic); RwFrameGetParent(frame); frame = RwFrameGetParent(frame)) + RwV3dTransformPoints(¢er, ¢er, 1, RwFrameGetMatrix(frame)); + + float size = RwV3dLength(¢er) + radius; + if (size > *(float*)data) + *(float*)data = size; + return atomic; +} + +void UpdateCutsceneObjectBoundingBox(RpClump* clump, int modelId) +{ + if (modelId >= MI_CUTOBJ01 && modelId <= MI_CUTOBJ10) { + CColModel* pColModel = &CTempColModels::ms_colModelCutObj[modelId - MI_CUTOBJ01]; + float oldRadius = pColModel->boundingSphere.radius; + float radius = 0.0f; + RpClumpForAllAtomics(clump, CalculateBoundingSphereRadiusCB, &radius); + if (oldRadius < 20.0f) oldRadius = 20.0f; + if (oldRadius < radius) { + debug("Limiting cutscene object radius %f\n", oldRadius); + radius = oldRadius; + } + radius = oldRadius; + pColModel->boundingSphere.radius = radius; + pColModel->boundingBox.min = CVector(-radius, -radius, -radius); + pColModel->boundingBox.max = CVector(radius, radius, radius); + } +} + +bool bCamLoaded; +bool bCamFading; + +// yes, they've actually doubled this thing here, thus this one is unused +static bool bModelsRemovedForCutscene; +static int32 NumberOfSavedWeapons; +static eWeaponType SavedWeaponIDs[TOTAL_WEAPON_SLOTS]; +static int32 SavedWeaponAmmo[TOTAL_WEAPON_SLOTS]; + +enum +{ + CUTMODEL_PLAYER = 1, + CUTMODEL_SIMPLE, + CUTMODEL_REPEATED, +}; + +bool CCutsceneMgr::ms_useCutsceneShadows = true; +bool CCutsceneMgr::mCutsceneSkipFading; +int CCutsceneMgr::mCutsceneSkipFadeTime; +float CCutsceneMgr::m_fPrevCarDensity; +float CCutsceneMgr::m_fPrevPedDensity; +bool CCutsceneMgr::m_PrevExtraColourOn; +uint32 CCutsceneMgr::m_PrevExtraColour; +uint32 CCutsceneMgr::ms_iNumParticleEffects; +sParticleEffect CCutsceneMgr::ms_pParticleEffects[NUM_CUTS_PARTICLE_EFFECTS]; +sToHideItem CCutsceneMgr::ms_crToHideItems[NUMCUTSCENEOBJECTS]; +uint32 CCutsceneMgr::ms_iNumHiddenEntities; +CEntity *CCutsceneMgr::ms_pHiddenEntities[NUMCUTSCENEOBJECTS]; +int CCutsceneMgr::ms_numAttachObjectToBones; +bool CCutsceneMgr::ms_bRepeatObject[NUMCUTSCENEOBJECTS]; +sAttachInfo CCutsceneMgr::ms_iAttachObjectToBone[NUMCUTSCENEOBJECTS]; +uint32 CCutsceneMgr::ms_numUncompressedCutsceneAnims; +char CCutsceneMgr::ms_aUncompressedCutsceneAnims[NUM_CUTS_UNCOMPRESSED_ANIMS][NAMELENGTH]; +uint32 CCutsceneMgr::ms_iTextDuration[NUM_CUTS_MAX_TEXTS]; +uint32 CCutsceneMgr::ms_iTextStartTime[NUM_CUTS_MAX_TEXTS]; +char CCutsceneMgr::ms_cTextOutput[NUM_CUTS_MAX_TEXTS][TEXT_KEY_SIZE]; +uint32 CCutsceneMgr::ms_currTextOutput; +uint32 CCutsceneMgr::ms_numTextOutput; +uint32 CCutsceneMgr::ms_iModelIndex[NUMCUTSCENEOBJECTS]; +char CCutsceneMgr::ms_cLoadAnimName[NUMCUTSCENEOBJECTS][NAMELENGTH]; +char CCutsceneMgr::ms_cLoadObjectName[NUMCUTSCENEOBJECTS][NAMELENGTH]; +int CCutsceneMgr::ms_numLoadObjectNames; +CCutsceneObject *CCutsceneMgr::ms_pCutsceneObjects[NUMCUTSCENEOBJECTS]; +int32 CCutsceneMgr::ms_numCutsceneObjs; +CVector CCutsceneMgr::ms_cutsceneOffset; +float CCutsceneMgr::ms_cutsceneTimer; +uint32 CCutsceneMgr::ms_cutscenePlayStatus; +CAnimBlendAssocGroup CCutsceneMgr::ms_cutsceneAssociations; +char CCutsceneMgr::ms_cutsceneName[CUTSCENENAMESIZE]; + +CCutsceneObject * +CCutsceneMgr::CreateCutsceneObject(int modelId) +{ + CBaseModelInfo *pModelInfo; + CColModel *pColModel; + CCutsceneObject *pCutsceneObject; + + CStreaming::ImGonnaUseStreamingMemory(); + debug("Created cutscene object %s\n", CModelInfo::GetModelInfo(modelId)->GetModelName()); + if (modelId >= MI_CUTOBJ01 && modelId <= MI_CUTOBJ10) { + pModelInfo = CModelInfo::GetModelInfo(modelId); + pColModel = &CTempColModels::ms_colModelCutObj[modelId - MI_CUTOBJ01]; + pModelInfo->SetColModel(pColModel); + UpdateCutsceneObjectBoundingBox((RpClump*)pModelInfo->GetRwObject(), modelId); + } + + pCutsceneObject = new CCutsceneObject(); + pCutsceneObject->SetModelIndex(modelId); + if (ms_useCutsceneShadows) + pCutsceneObject->CreateShadow(); + ms_pCutsceneObjects[ms_numCutsceneObjs++] = pCutsceneObject; + CStreaming::IHaveUsedStreamingMemory(); + return pCutsceneObject; +} + +void +CCutsceneMgr::SetCutsceneAnim(const char *animName, CObject *pObject) +{ + CAnimBlendAssociation *pNewAnim; + CAnimBlendClumpData *pAnimBlendClumpData; + + debug("Give cutscene anim %s\n", animName); + /*assert(RwObjectGetType(pObject->m_rwObject) == rpCLUMP); + debug("Give cutscene anim %s\n", animName); + RpAnimBlendClumpRemoveAllAssociations((RpClump*)pObject->m_rwObject); + + pNewAnim = ms_cutsceneAssociations.GetAnimation(animName); + if (!pNewAnim) { + debug("\n\nHaven't I told you I can't find the fucking animation %s\n\n\n", animName); + return; + } + + if (pNewAnim->hierarchy->IsCompressed()) + pNewAnim->hierarchy->keepCompressed = true;*/ + + CStreaming::ImGonnaUseStreamingMemory(); + pNewAnim = ms_cutsceneAssociations.CopyAnimation(animName); + CStreaming::IHaveUsedStreamingMemory(); + + pNewAnim->SetCurrentTime(0.0f); + pNewAnim->flags |= ASSOC_HAS_TRANSLATION; + pNewAnim->flags &= ~ASSOC_RUNNING; + + pAnimBlendClumpData = *RPANIMBLENDCLUMPDATA(pObject->m_rwObject); + pAnimBlendClumpData->link.Prepend(&pNewAnim->link); + + //if (pNewAnim->hierarchy->keepCompressed) + // pAnimBlendClumpData->frames->flag |= AnimBlendFrameData::COMPRESSED; +} + +void +CCutsceneMgr::SetCutsceneAnimToLoop(const char* animName) +{ + ms_cutsceneAssociations.GetAnimation(animName)->flags |= ASSOC_REPEAT; +} + +CCutsceneHead* +CCutsceneMgr::SetHeadAnim(const char*, CObject* pObject) +{ + return nil; +} + +void +CCutsceneMgr::StartCutscene() +{ + ms_cutscenePlayStatus = CUTSCENE_STARTED; + if (bCamLoaded) { + TheCamera.SetWideScreenOn(); + CHud::SetHelpMessage(nil, true); + } +} + +void +CCutsceneMgr::SetupCutsceneToStart(void) +{ + if (bCamLoaded) { + TheCamera.SetCamCutSceneOffSet(ms_cutsceneOffset); + TheCamera.TakeControlWithSpline(JUMP_CUT); + TheCamera.SetWideScreenOn(); + CHud::SetHelpMessage(nil, true); + } + + ms_cutsceneOffset.z += 1.0f; + + for (int i = ms_numCutsceneObjs - 1; i >= 0; i--) { + assert(RwObjectGetType(ms_pCutsceneObjects[i]->m_rwObject) == rpCLUMP); + if (CAnimBlendAssociation *pAnimBlendAssoc = RpAnimBlendClumpGetFirstAssociation((RpClump*)ms_pCutsceneObjects[i]->m_rwObject)) { + assert(pAnimBlendAssoc->hierarchy->sequences[0].HasTranslation()); + if (ms_pCutsceneObjects[i]->m_pAttachTo != nil) { + pAnimBlendAssoc->flags &= (~ASSOC_HAS_TRANSLATION); + } else { + if (pAnimBlendAssoc->hierarchy->IsCompressed()){ + KeyFrameTransCompressed *keyFrames = ((KeyFrameTransCompressed*)pAnimBlendAssoc->hierarchy->sequences[0].GetKeyFrameCompressed(0)); + CVector trans; + keyFrames->GetTranslation(&trans); + ms_pCutsceneObjects[i]->SetPosition(ms_cutsceneOffset + trans); + }else{ + KeyFrameTrans *keyFrames = ((KeyFrameTrans*)pAnimBlendAssoc->hierarchy->sequences[0].GetKeyFrame(0)); + ms_pCutsceneObjects[i]->SetPosition(ms_cutsceneOffset + keyFrames->translation); + } + } + pAnimBlendAssoc->SetRun(); + } else { + ms_pCutsceneObjects[i]->SetPosition(ms_cutsceneOffset); + } + CWorld::Add(ms_pCutsceneObjects[i]); + if (RwObjectGetType(ms_pCutsceneObjects[i]->m_rwObject) == rpCLUMP) { + ms_pCutsceneObjects[i]->UpdateRpHAnim(); + } + } + + CTimer::Update(); + CTimer::Update(); + ms_cutsceneTimer = 0.0f; + ms_running = true; + mCutsceneSkipFadeTime = 0; + mCutsceneSkipFading = 0; +} + +void +CCutsceneMgr::FinishCutscene() +{ + if (bCamLoaded) { + ms_cutsceneTimer = TheCamera.GetCutSceneFinishTime() * 0.001f; + TheCamera.FinishCutscene(); + } + + FindPlayerPed()->bIsVisible = true; + CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(false); +} + +uint32 +CCutsceneMgr::GetCutsceneTimeInMilleseconds(void) +{ + return 1000.0f * ms_cutsceneTimer; +} + +bool CCutsceneMgr::HasCutsceneFinished(void) +{ + return !bCamLoaded || TheCamera.GetPositionAlongSpline() == 1.0f; +} + +void +CCutsceneMgr::AttachObjectToBone(CObject *pObject, CObject *pAttachTo, int bone) +{ + RpHAnimHierarchy *hanim = GetAnimHierarchyFromSkinClump(pAttachTo->GetClump()); + RwInt32 id = RpHAnimIDGetIndex(hanim, bone); + RwMatrix *matrixArray = RpHAnimHierarchyGetMatrixArray(hanim); + ((CCutsceneObject*)pObject)->m_pAttachmentObject = pAttachTo; + ((CCutsceneObject*)pObject)->m_pAttachTo = &matrixArray[id]; + //debug("Attach %s to %s\n", + // CModelInfo::GetModelInfo(pObject->GetModelIndex())->GetModelName(), + // CModelInfo::GetModelInfo(pAttachTo->GetModelIndex())->GetModelName()); +} + +void +CCutsceneMgr::AttachObjectToFrame(CObject *pObject, CEntity *pAttachTo, const char *frame) +{ + ((CCutsceneObject*)pObject)->m_pAttachmentObject = nil; + ((CCutsceneObject*)pObject)->m_pAttachTo = RpAnimBlendClumpFindFrame(pAttachTo->GetClump(), frame)->frame; + //debug("Attach %s to component %s of %s\n", + // CModelInfo::GetModelInfo(pObject->GetModelIndex())->GetModelName(), + // frame, + // CModelInfo::GetModelInfo(pAttachTo->GetModelIndex())->GetModelName()); + if (RwObjectGetType(pObject->m_rwObject) == rpCLUMP) { + RpClump *clump = (RpClump*)pObject->m_rwObject; + if (IsClumpSkinned(clump)) + RpAtomicGetBoundingSphere(GetFirstAtomic(clump))->radius *= 1.1f; + } +} + +void +CCutsceneMgr::AttachObjectToParent(CObject *pObject, CEntity *pAttachTo) +{ + ((CCutsceneObject*)pObject)->m_pAttachmentObject = nil; + ((CCutsceneObject*)pObject)->m_pAttachTo = RpClumpGetFrame(pAttachTo->GetClump()); + + //debug("Attach %s to %s\n", CModelInfo::GetModelInfo(pObject->GetModelIndex())->GetModelName(), CModelInfo::GetModelInfo(pAttachTo->GetModelIndex())->GetModelName()); +} + +void +CCutsceneMgr::HideRequestedObjects(void) +{ + int num = ms_iNumHiddenEntities; + ms_iNumHiddenEntities = 0; + + for (int i = 0; i < num; i++) { + int id; + if (CModelInfo::GetModelInfo(ms_crToHideItems[i].name, &id)) { + CVector pos(ms_crToHideItems[i].x, ms_crToHideItems[i].y, ms_crToHideItems[i].z); + int16 foundEntities; + CEntity* pEntities[32]; + CWorld::FindObjectsOfTypeInRange(id, pos, 1.5f, true, &foundEntities, 32, pEntities, true, false, false, true, true); + for (int j = 0; i < foundEntities; j++) { + if (pEntities[j]->bIsVisible) { + ms_pHiddenEntities[ms_iNumHiddenEntities] = pEntities[j]; + ms_pHiddenEntities[ms_iNumHiddenEntities]->RegisterReference(&ms_pHiddenEntities[ms_iNumHiddenEntities]); + ms_pHiddenEntities[ms_iNumHiddenEntities]->bIsVisible = false; + ms_iNumHiddenEntities++; + } + } + } + } +} + +bool +CCutsceneMgr::PresubBodge() +{ + return true; +} + +void +CCutsceneMgr::LoadCutsceneData_loading() +{ + for (int i = 0; i < ms_numLoadObjectNames; i++) { + int mi = ms_iModelIndex[i]; + if (mi >= MI_CUTOBJ01 && mi <= MI_CUTOBJ10) { + if (CStreaming::ms_aInfoForModel[mi].m_loadState != STREAMSTATE_LOADED) + return; + } + } + + if (!LoadCutsceneData_postload()) + return; + + CCutsceneObject* cutsceneObject; + for (int i = 0; i < ms_numLoadObjectNames; i++) { + if (!ms_bRepeatObject[i]) + cutsceneObject = CreateCutsceneObject(ms_iModelIndex[i]); + if (ms_cLoadAnimName[i][0] != '\0') + SetCutsceneAnim(ms_cLoadAnimName[i], cutsceneObject); + } + + for (int i = 0; i < ms_numAttachObjectToBones; i++) { + int objectId = ms_iAttachObjectToBone[i].objectId; + int attachToId = ms_iAttachObjectToBone[i].attachToId; + int bone = ms_iAttachObjectToBone[i].boneId; + AttachObjectToBone(ms_pCutsceneObjects[objectId], ms_pCutsceneObjects[attachToId], bone); + } +} + +bool +CCutsceneMgr::LoadCutsceneData_postload(bool b) +{ + RwStream *stream = nil; + uint32 size; + uint32 offset; + + bool result; + + CMessages::ClearThisBigPrintNow(0); + CPopulation::PedDensityMultiplier = 0.0f; + CCarCtrl::CarDensityMultiplier = 0.0f; + CStreaming::ms_disableStreaming = false; + if (b) + { + sprintf(gString, "%s.IFP", ms_cutsceneName); + result = false; + ms_animLoaded = false; + RwStreamClose(stream, nil); // umm... + sprintf(gString, "%s.DAT", ms_cutsceneName); + bCamLoaded = false; + } else { + + stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, "ANIM\\CUTS.IMG"); + sprintf(gString, "%s.IFP", ms_cutsceneName); + if (stream) { + if (ms_pCutsceneDir->FindItem(gString, offset, size)) + { + CStreaming::MakeSpaceFor(size << 11); + CStreaming::ImGonnaUseStreamingMemory(); + RwStreamSkip(stream, offset << 11); + CAnimManager::LoadAnimFile(stream, true, ms_aUncompressedCutsceneAnims); + ms_cutsceneAssociations.CreateAssociations(ms_cutsceneName, ms_cLoadAnimName[0], ms_cLoadObjectName[0], NAMELENGTH); + CStreaming::IHaveUsedStreamingMemory(); + ms_animLoaded = true; + } + else + { + ms_animLoaded = false; + } + RwStreamClose(stream, nil); + + int file = CFileMgr::OpenFile("ANIM\\CUTS.IMG", "rb"); + sprintf(gString, "%s.DAT", ms_cutsceneName); + if (file) { + if (ms_pCutsceneDir->FindItem(gString, offset, size)) + { + CStreaming::ImGonnaUseStreamingMemory(); + CFileMgr::Seek(file, offset << 11, 0); + TheCamera.LoadPathSplines(file); + CStreaming::IHaveUsedStreamingMemory(); + bCamLoaded = true; + } + else + { + bCamLoaded = false; + } + result = true; + CFileMgr::CloseFile(file); + } + else + { + bCamLoaded = false; + result = true; + } + } + else + { + result = false; + ms_animLoaded = false; + RwStreamClose(stream, nil); + sprintf(gString, "%s.DAT", ms_cutsceneName); + bCamLoaded = false; + } + } + ms_cutsceneLoadStatus = CUTSCENE_LOADED; + ms_cutsceneTimer = 0.0f; + FindPlayerPed()->m_pWanted->ClearQdCrimes(); + return result; +} + +void +CCutsceneMgr::LoadCutsceneData_overlay(const char *szCutsceneName) +{ + CTimer::Suspend(); + ms_cutsceneProcessing = true; + ms_wasCutsceneSkipped = false; + if (!bModelsRemovedForCutscene) + CStreaming::RemoveCurrentZonesModels(); + + ms_pCutsceneDir->numEntries = 0; + ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR"); + + CStreaming::RemoveUnusedModelsInLoadedList(); + CGame::DrasticTidyUpMemory(true); + + strcpy(ms_cutsceneName, szCutsceneName); + + LoadCutsceneData_preload(); + CTimer::Resume(); +} + +void +CCutsceneMgr::LoadCutsceneData_preload(void) +{ + uint32 size; + uint32 offset; + CPlayerPed* pPlayerPed; + if (CGeneral::faststricmp(ms_cutsceneName, "finale")) { + DMAudio.ChangeMusicMode(MUSICMODE_CUTSCENE); + int trackId = FindCutsceneAudioTrackId(ms_cutsceneName); + if (trackId != -1) { + printf("Start preload audio %s\n", ms_cutsceneName); + DMAudio.PreloadCutSceneMusic(trackId); + printf("End preload audio %s\n", ms_cutsceneName); + } + } + + for (int i = MI_CUTOBJ01; i <= MI_CUTOBJ10; i++) { + if (CModelInfo::GetModelInfo(i)->GetNumRefs() <= 0) { + if (CStreaming::ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED) { + CStreaming::RemoveModel(i); + CModelInfo::GetModelInfo(i)->SetModelName("&*%"); + } + } + } + + m_PrevExtraColour = CTimeCycle::m_ExtraColour; + m_PrevExtraColourOn = CTimeCycle::m_bExtraColourOn != 0; + m_fPrevPedDensity = CPopulation::PedDensityMultiplier; + m_fPrevCarDensity = CCarCtrl::CarDensityMultiplier; + ms_cutsceneOffset = CVector(0.0f, 0.0f, 0.0f); + ms_numTextOutput = 0; + ms_currTextOutput = 0; + ms_numLoadObjectNames = 0; + ms_numUncompressedCutsceneAnims = 0; + ms_numAttachObjectToBones = 0; + ms_iNumHiddenEntities = 0; + bCamFading = false; + ms_iNumParticleEffects = 0; + + for (int i = 0; i < NUM_CUTS_UNCOMPRESSED_ANIMS; i++) + ms_aUncompressedCutsceneAnims[i][0] = '\0'; + + memset(ms_iModelIndex, 0, sizeof(ms_iModelIndex)); + CRubbish::SetVisibility(false); + + pPlayerPed = FindPlayerPed(); + pPlayerPed->m_pWanted->ClearQdCrimes(); + pPlayerPed->bIsVisible = false; + pPlayerPed->m_fCurrentStamina = pPlayerPed->m_fMaxStamina; + CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_CUTSCENE); + CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(true); + + sprintf(gString, "%s.CUT", ms_cutsceneName); + if (!ms_pCutsceneDir->FindItem(gString, offset, size)) { + LoadCutsceneData_postload(); + return; + } + + size <<= 11; + offset <<= 11; + + char *cutsBuf = new char[size]; + + RwStream* stream = RwStreamOpen(rwSTREAMFILENAME, rwSTREAMREAD, "ANIM\\CUTS.IMG"); + + if (stream) { + RwStreamSkip(stream, offset); + RwStreamRead(stream, cutsBuf, size); + RwStreamClose(stream, nil); + } + + enum + { + CUT_NONE = 0, + CUT_INFO, + CUT_MODEL, + CUT_TEXT, + CUT_UNCOMPRESS, + CUT_ATTACH, + CUT_REMOVE, + CUT_PARTICLE_EFFECT, + CUT_EXTRA_COLOR, + }; + + int cutSection = CUT_NONE; + bool bExtraColSet = false; + + char line[1024]; + const char *pCurLine = cutsBuf; + + while (true) + { + pCurLine = GetNextLine(pCurLine, line, sizeof(line)); + if (pCurLine) { + if (line[0] == '\0') + break; + + if (strcmp(line, "end") == 0) { + cutSection = CUT_NONE; + continue; + } + + switch (cutSection) + { + case CUT_NONE: + if (strcmp(line, "info") == 0) + cutSection = CUT_INFO; + if (strcmp(line, "model") == 0) + cutSection = CUT_MODEL; + if (strcmp(line, "text") == 0) + cutSection = CUT_TEXT; + if (strcmp(line, "uncompress") == 0) + cutSection = CUT_UNCOMPRESS; + if (strcmp(line, "attach") == 0) + cutSection = CUT_ATTACH; + if (strcmp(line, "remove") == 0) + cutSection = CUT_REMOVE; + if (strcmp(line, "peffect") == 0) + cutSection = CUT_PARTICLE_EFFECT; + if (strcmp(line, "extracol") == 0) + cutSection = CUT_EXTRA_COLOR; + break; + case CUT_INFO: + { + if (strncmp(line, "offset", 6) == 0) { + float x, y, z; + sscanf(line+7, "%f %f %f", &x, &y, &z); + FindPlayerPed(); // called for some sa check in here + ms_cutsceneOffset = CVector(x, y, z); + } + break; + } + case CUT_MODEL: + { + char objectName[NAMELENGTH]; + char animName[NAMELENGTH]; + + int num; // unused + sscanf(strtok(line, " ,"), "%d", &num); + strcpy(objectName, strtok(nil, " ,")); + char* pAnimName = strtok(0, " ,"); + strlwr(objectName); + + bool bUsedFirstTime = true; + if (pAnimName) { + do { + strcpy(animName, pAnimName); + strlwr(animName); + strcpy(ms_cLoadObjectName[ms_numLoadObjectNames], objectName); + strcpy(ms_cLoadAnimName[ms_numLoadObjectNames], animName); + if (bUsedFirstTime) { + bUsedFirstTime = false; + ms_iModelIndex[ms_numLoadObjectNames] = CUTMODEL_SIMPLE; + ms_bRepeatObject[ms_numLoadObjectNames] = false; + } else { + ms_bRepeatObject[ms_numLoadObjectNames] = true; + ms_iModelIndex[ms_numLoadObjectNames] = CUTMODEL_REPEATED; + } + ms_numLoadObjectNames++; + pAnimName = strtok(0, " ,"); + } while (pAnimName); + } + break; + } + case CUT_TEXT: + { + int iTextStartTime, iTextDuration; + char cTextOutput[8]; + sscanf(line, "%d,%d,%s", &iTextStartTime, &iTextDuration, cTextOutput); + for (size_t i = 0; i < strlen(cTextOutput); i++) + cTextOutput[i] = toupper(cTextOutput[i]); + + memcpy(ms_cTextOutput[ms_numTextOutput], cTextOutput, strlen(cTextOutput)+1); + ms_iTextStartTime[ms_numTextOutput] = iTextStartTime; + ms_iTextDuration[ms_numTextOutput] = iTextDuration; + ms_numTextOutput++; + break; + } + case CUT_UNCOMPRESS: + LoadAnimationUncompressed(strtok(line, " ,")); + break; + case CUT_ATTACH: + { + int attachToId, objectId, bone; + sscanf(line, "%d,%d,%d", &attachToId, &objectId, &bone); + ms_iAttachObjectToBone[ms_numAttachObjectToBones].attachToId = attachToId; + ms_iAttachObjectToBone[ms_numAttachObjectToBones].objectId = objectId; + ms_iAttachObjectToBone[ms_numAttachObjectToBones].boneId = bone; + ms_numAttachObjectToBones++; + break; + } + case CUT_REMOVE: + { + float x, y, z; + char name[NAMELENGTH]; + sscanf(line, "%f,%f,%f,%s", &x, &y, &z, name); + ms_crToHideItems[ms_iNumHiddenEntities].x = x; + ms_crToHideItems[ms_iNumHiddenEntities].y = y; + ms_crToHideItems[ms_iNumHiddenEntities].z = z; + strcpy(ms_crToHideItems[ms_iNumHiddenEntities].name, name); + ms_iNumHiddenEntities++; + break; + } + case CUT_PARTICLE_EFFECT: + { + char name[NAMELENGTH]; + char name2[NAMELENGTH]; + + int iTime; + int unk1; + int unk2; + float x; + float y; + float z; + float unkX; + float unkY; + float unkZ; + + memset(name, 0, NAMELENGTH); + memset(name2, 0, NAMELENGTH); + + strncpy(name, strtok(line, ","), NAMELENGTH-1); + iTime = atoi(strtok(0, ",")); + unk1 = atoi(strtok(0, ",")); + unk2 = atoi(strtok(0, ",")); + strncpy(name, strtok(line, ","), NAMELENGTH-1); + x = strtod(strtok(0, ","), nil); + y = strtod(strtok(0, ","), nil); + z = strtod(strtok(0, ","), nil); + unkX = strtod(strtok(0, ","), nil); + unkY = strtod(strtok(0, ","), nil); + unkZ = strtod(strtok(0, ","), nil); + + ms_pParticleEffects[ms_iNumParticleEffects].bPlayed = false; + ms_pParticleEffects[ms_iNumParticleEffects].iTime = iTime; + ms_pParticleEffects[ms_iNumParticleEffects].unk1 = unk1; + ms_pParticleEffects[ms_iNumParticleEffects].unk2 = unk2; + strcpy(CCutsceneMgr::ms_pParticleEffects[ms_iNumParticleEffects].name2, name2); + ms_pParticleEffects[ms_iNumParticleEffects].unk10 = false; + ms_pParticleEffects[ms_iNumParticleEffects].x = x; + ms_pParticleEffects[ms_iNumParticleEffects].y = y; + ms_pParticleEffects[ms_iNumParticleEffects].z = z; + ms_pParticleEffects[ms_iNumParticleEffects].unkX = unkX; + ms_pParticleEffects[ms_iNumParticleEffects].unkY = unkY; + ms_pParticleEffects[ms_iNumParticleEffects].unkZ = unkZ; + ms_pParticleEffects[ms_iNumParticleEffects].unk11 = false; + strcpy(CCutsceneMgr::ms_pParticleEffects[ms_iNumParticleEffects].name, name); + ms_iNumParticleEffects++; + break; + } + case CUT_EXTRA_COLOR: + if (!bExtraColSet) { + int colorId; + sscanf(line, "%d", &colorId); + if (colorId == 0) + bExtraColSet = false; + else { + CTimeCycle::StartExtraColour(colorId - 1, false); + bExtraColSet = true; + } + } + break; + default: + break; + }; + + } + else + { + delete[]cutsBuf; + + // add manually inserted objects + for (int i = 0; i < ms_numAppendObjectNames; i++) { + strcpy(ms_cLoadObjectName[ms_numLoadObjectNames], ms_cAppendObjectName[i]); + strcpy(ms_cLoadAnimName[ms_numLoadObjectNames], ms_cAppendAnimName[i]); + ms_iModelIndex[ms_numLoadObjectNames] = CUTMODEL_SIMPLE; + ms_numLoadObjectNames++; + } + ms_numAppendObjectNames = 0; + + int specialId = 0; + for (int i = 0; i < ms_numLoadObjectNames; i++) + { + if (strcasecmp(ms_cLoadObjectName[i], "csplay") == 0) { + ms_iModelIndex[i] = CUTMODEL_PLAYER; + continue; + } else if (ms_iModelIndex[i] == CUTMODEL_SIMPLE) { + int id; + if (CModelInfo::GetModelInfo(ms_cLoadObjectName[i], &id)) { + ms_iModelIndex[i] = id; + CStreaming::RequestModel(id, STREAMFLAGS_SCRIPTOWNED | STREAMFLAGS_DEPENDENCY | STREAMFLAGS_PRIORITY); + } else { + CStreaming::RequestSpecialModel(specialId + MI_CUTOBJ01, ms_cLoadObjectName[i], STREAMFLAGS_SCRIPTOWNED | STREAMFLAGS_DEPENDENCY | STREAMFLAGS_PRIORITY); + ms_iModelIndex[i] = specialId + MI_CUTOBJ01; + specialId++; + // skip if id is busy + while (CStreaming::ms_aInfoForModel[specialId + MI_CUTOBJ01].m_loadState == STREAMSTATE_LOADED) + specialId++; + } + } + else if (ms_iModelIndex[i] == CUTMODEL_REPEATED && i != 0) + ms_iModelIndex[i] = ms_iModelIndex[i - 1]; + } + + CStreaming::LoadAllRequestedModels(true); + ms_cutsceneLoadStatus = CUTSCENE_LOADING; + return; + } + } + + delete[]cutsBuf; + LoadCutsceneData_postload(true); +} + +void +CCutsceneMgr::DeleteCutsceneData_overlay(void) +{ + if (ms_cutsceneLoadStatus == CUTSCENE_NOT_LOADED) return; + CTimer::Suspend(); + CPopulation::PedDensityMultiplier = m_fPrevPedDensity; + CCarCtrl::CarDensityMultiplier = m_fPrevCarDensity; + if (m_PrevExtraColourOn) + CTimeCycle::StartExtraColour(m_PrevExtraColour, false); + else + CTimeCycle::StopExtraColour(m_PrevExtraColourOn); + + for (uint32 i = 0; i < ms_iNumHiddenEntities; i++) { + if (ms_pHiddenEntities[i]) { + ms_pHiddenEntities[i]->CleanUpOldReference(&ms_pHiddenEntities[i]); + ms_pHiddenEntities[i]->bIsVisible = true; + } + } + + ms_iNumHiddenEntities = 0; + ms_iNumParticleEffects = 0; + CMessages::ClearMessages(); + CRubbish::SetVisibility(true); + + ms_cutsceneProcessing = false; + ms_useLodMultiplier = false; + ms_useCutsceneShadows = false; + + ms_numCutsceneObjs--; + while (ms_numCutsceneObjs >= 0) { + CWorld::Remove(ms_pCutsceneObjects[ms_numCutsceneObjs]); + ms_pCutsceneObjects[ms_numCutsceneObjs]->DeleteRwObject(); + delete ms_pCutsceneObjects[ms_numCutsceneObjs]; + ms_pCutsceneObjects[ms_numCutsceneObjs] = nil; + ms_numCutsceneObjs--; + } + ms_numCutsceneObjs = 0; + + if (ms_animLoaded) + CAnimManager::RemoveLastAnimFile(); + + ms_animLoaded = false; + ms_cutsceneAssociations.DestroyAssociations(); + + ms_aUncompressedCutsceneAnims[0][0] = '\0'; + ms_numUncompressedCutsceneAnims = 0; + + if (bCamLoaded) { + TheCamera.RestoreWithJumpCut(); + TheCamera.SetWideScreenOff(); + TheCamera.DeleteCutSceneCamDataMemory(); + } + ms_cutsceneLoadStatus = CUTSCENE_NOT_LOADED; + ms_running = false; + + FindPlayerPed()->bIsVisible = true; + CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_CUTSCENE); + CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(false); + + if (CGeneral::faststricmp(ms_cutsceneName, "finale")) { + DMAudio.StopCutSceneMusic(); + DMAudio.ChangeMusicMode(MUSICMODE_GAME); + } + + CStreaming::ms_disableStreaming = false; + CWorld::bProcessCutsceneOnly = false; + + //if(bCamLoaded) + // CGame::DrasticTidyUpMemory(TheCamera.GetScreenFadeStatus() == FADE_2); + + CPad::GetPad(0)->Clear(false); + + if (bModelsRemovedForCutscene) { + CStreaming::LoadInitialPeds(); + CStreaming::LoadInitialWeapons(); + CStreaming::LoadInitialVehicles(); + bModelsRemovedForCutscene = false; + + CPlayerPed *pPlayerPed = FindPlayerPed(); + for (int i = 0; i < NumberOfSavedWeapons; i++) { + int32 weaponModelId = CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModelId; + uint8 flags = CStreaming::ms_aInfoForModel[weaponModelId].m_flags; + CStreaming::RequestModel(weaponModelId, STREAMFLAGS_DONT_REMOVE); + CStreaming::LoadAllRequestedModels(false); + if (CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModel2Id != -1) { + CStreaming::RequestModel(CWeaponInfo::GetWeaponInfo(SavedWeaponIDs[i])->m_nModel2Id, 0); + CStreaming::LoadAllRequestedModels(false); + } + if (!(flags & STREAMFLAGS_DONT_REMOVE)) + CStreaming::SetModelIsDeletable(weaponModelId); + pPlayerPed->GiveWeapon(SavedWeaponIDs[i], SavedWeaponAmmo[i], true); + } + NumberOfSavedWeapons = 0; + } + + for (int i = 0; i < ms_numLoadObjectNames; i++) + CStreaming::SetMissionDoesntRequireModel(ms_iModelIndex[i]); + + CStreaming::SetMissionDoesntRequireModel(MI_COP); + CStreaming::StreamZoneModels(FindPlayerCoors()); + CTimer::Resume(); +} + +void +CCutsceneMgr::Update_overlay(void) +{ + if (ms_cutsceneLoadStatus == CUTSCENE_LOADING) { + debug("Loading Cutscene...\n"); + CTimer::Suspend(); + LoadCutsceneData_loading(); + CTimer::Resume(); + return; + } + + if (ms_cutsceneLoadStatus != CUTSCENE_LOADED) { + debug("Cutscene Not Loaded!\n"); + return; + } + + switch (ms_cutscenePlayStatus) { + case CUTSCENE_STARTED: + SetupCutsceneToStart(); + HideRequestedObjects(); + ms_cutscenePlayStatus++; + break; + case CUTSCENE_PLAYING_2: + case CUTSCENE_PLAYING_3: + ms_cutscenePlayStatus++; + break; + case CUTSCENE_PLAYING_4: + ms_cutscenePlayStatus = CUTSCENE_PLAYING_0; + if (CGeneral::faststricmp(ms_cutsceneName, "finale")) + DMAudio.PlayPreloadedCutSceneMusic(); + break; + default: + break; + } + + if (!ms_running) return; + + ms_cutsceneTimer += CTimer::GetTimeStepNonClippedInSeconds(); + uint32 cutsceneTimeInMS = GetCutsceneTimeInMilleseconds(); + + if (ms_currTextOutput < ms_numTextOutput && cutsceneTimeInMS > ms_iTextStartTime[ms_currTextOutput]) { + CMessages::AddMessageJumpQ(TheText.Get(ms_cTextOutput[ms_currTextOutput]), ms_iTextDuration[ms_currTextOutput], 1); + ms_currTextOutput++; + } + + for (int i = 0; i < ms_numCutsceneObjs; i++) { + int modelId = ms_pCutsceneObjects[i]->GetModelIndex(); + if (modelId >= MI_CUTOBJ01 && modelId <= MI_CUTOBJ10) + UpdateCutsceneObjectBoundingBox(ms_pCutsceneObjects[i]->GetClump(), modelId); + } + + if (!bCamLoaded) return; + + if (CGeneral::faststricmp(ms_cutsceneName, "finale") && TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FLYBY && ms_cutsceneLoadStatus == CUTSCENE_LOADED) { + if (TheCamera.GetCutSceneFinishTime() < cutsceneTimeInMS + 1000) { + if (!bCamFading) { + bCamFading = true; + TheCamera.Fade(1.0f, FADE_OUT); + } + } + if (mCutsceneSkipFading) { + mCutsceneSkipFadeTime -= CTimer::GetTimeStepInMilliseconds(); + if (mCutsceneSkipFadeTime < 0) { + CHud::m_BigMessage[1][0] = '\0'; + ms_wasCutsceneSkipped = true; + FinishCutscene(); + mCutsceneSkipFading = false; + mCutsceneSkipFadeTime = 0; + } + } + else if (IsCutsceneSkipButtonBeingPressed() && PresubBodge()){ + mCutsceneSkipFading = true; + mCutsceneSkipFadeTime = 1000; + TheCamera.Fade(1.0f, FADE_OUT); + } + } +}
\ No newline at end of file |