summaryrefslogtreecommitdiff
path: root/src/animation/CutsceneMgr.cpp
blob: 088cb413ac27bc964fc7c2821b2c7acb69befb0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "common.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 "crossplatform.h"

static bool bModelsRemovedForCutscene;
static int32 NumberOfSavedWeapons;
static eWeaponType SavedWeaponIDs[TOTAL_WEAPON_SLOTS];
static int32 SavedWeaponAmmo[TOTAL_WEAPON_SLOTS];

char CCutsceneMgr::ms_cAppendAnimName[NUMCUTSCENEOBJECTS][NAMELENGTH];
char CCutsceneMgr::ms_cAppendObjectName[NUMCUTSCENEOBJECTS][NAMELENGTH];
int CCutsceneMgr::ms_numAppendObjectNames;
CDirectory *CCutsceneMgr::ms_pCutsceneDir;
bool CCutsceneMgr::ms_loaded;
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;

void
CCutsceneMgr::Initialise(void *dir)
{
	ms_cutsceneLoadStatus = CUTSCENE_NOT_LOADED;
	ms_running = false;
	ms_animLoaded = false;
	ms_cutsceneProcessing = false;
	ms_useLodMultiplier = false;
	ms_wasCutsceneSkipped = false;
	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;

	//numUncompressedAnims = 0;
	//uncompressedAnims[0][0] = '\0';
}

void CCutsceneMgr::Write(base::cRelocatableChunkWriter& writer)
{
	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::Shutdown(void)
{
	delete ms_pCutsceneDir;
}

void
CCutsceneMgr::LoadCutsceneData(const char *szCutsceneName)
{
	LoadCutsceneData_overlay(szCutsceneName);
}

void
CCutsceneMgr::DeleteCutsceneData(void)
{
	DeleteCutsceneData_overlay();
	if (bModelsRemovedForCutscene)
		LoadEverythingBecauseCutsceneDeletedAllOfIt();
}

void
CCutsceneMgr::RemoveEverythingBecauseCutsceneDoesntFitInMemory()
{
	//CStreaming::ms_disableStreaming = true;
	CWorld::ClearExcitingStuffFromArea(FindPlayerCoors(), 120.0f, true);
	CColStore::RemoveAllCollision();
	CWorld::bProcessCutsceneOnly = true;
	/*ms_cutsceneProcessing = true;

	for (int i = CPools::GetPedPool()->GetSize() - 1; i >= 0; i--) {
		CPed *pPed = CPools::GetPedPool()->GetSlot(i);
		if (pPed) {
			if (!pPed->IsPlayer() && pPed->CanBeDeleted()) {
				CWorld::Remove(pPed);
				delete pPed;
			}
		}
	}

	for (int i = CPools::GetVehiclePool()->GetSize() - 1; i >= 0; i--) {
		CVehicle *pVehicle = CPools::GetVehiclePool()->GetSlot(i);
		if (pVehicle) {
			if (pVehicle->CanBeDeleted()) {
				CWorld::Remove(pVehicle);
				delete pVehicle;
			}
		}
	}
	CWorld::bProcessCutsceneOnly = true;
	//bIsEverythingRemovedFromTheWorldForTheBiggestFuckoffCutsceneEver = true;*/
	CStreaming::RemoveCurrentZonesModels();
	while (CStreaming::RemoveLoadedVehicle());
	CRadar::RemoveRadarSections();
	CStreaming::SetModelIsDeletable(MI_MALE01);
	CStreaming::SetModelTxdIsDeletable(MI_MALE01);
	CStreaming::SetModelIsDeletable(MI_COLT45);
	CStreaming::SetModelTxdIsDeletable(MI_COLT45);
	CStreaming::SetModelIsDeletable(MI_NIGHTSTICK);
	CStreaming::SetModelTxdIsDeletable(MI_NIGHTSTICK);
	CStreaming::SetModelIsDeletable(MI_MISSILE);
	CStreaming::SetModelTxdIsDeletable(MI_MISSILE);

	/*for (int i = CPools::GetDummyPool()->GetSize() - 1; i >= 0; i--) {
		CDummy* pDummy = CPools::GetDummyPool()->GetSlot(i);
		if (pDummy)
			pDummy->DeleteRwObject();
	}

	for (int i = CPools::GetObjectPool()->GetSize() - 1; i >= 0; i--) {
		CObject* pObject = CPools::GetObjectPool()->GetSlot(i);
		if (pObject)
			pObject->DeleteRwObject();
	}

	for (int i = CPools::GetBuildingPool()->GetSize() - 1; i >= 0; i--) {
		CBuilding* pBuilding = CPools::GetBuildingPool()->GetSlot(i);
		if (pBuilding && pBuilding->m_rwObject != nil && pBuilding->bIsBIGBuilding && pBuilding->bStreamBIGBuilding) {
			if (pBuilding->bIsBIGBuilding)
				CStreaming::RequestModel(pBuilding->GetModelIndex(), 0);
			if (!pBuilding->bImBeingRendered)
				pBuilding->DeleteRwObject();
		}
	}*/

	CPlayerPed *pPlayerPed = FindPlayerPed();
	pPlayerPed->RemoveWeaponAnims(0, -1000.0f);
	NumberOfSavedWeapons = 0;

	for (int i = 0; i < TOTAL_WEAPON_SLOTS; i++) {
		if (pPlayerPed->m_weapons[i].m_eWeaponType != WEAPONTYPE_UNARMED) {
			SavedWeaponIDs[NumberOfSavedWeapons] = pPlayerPed->m_weapons[i].m_eWeaponType;
			SavedWeaponAmmo[NumberOfSavedWeapons] = pPlayerPed->m_weapons[i].m_nAmmoTotal;
			NumberOfSavedWeapons++;
		}
	}

	pPlayerPed->ClearWeapons();
	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++;
}