summaryrefslogtreecommitdiff
path: root/src/cutScene.cpp
blob: cac1f1008001926065769b25b175e72d9bdb7b4a (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
#include "cutScene.h"

dScCutScene_c *dScCutScene_c::instance = 0;

dScCutScene_c *dScCutScene_c::build() {
	// return new dScCutScene_c;
	void *buffer = AllocFromGameHeap1(sizeof(dScCutScene_c));
	dScCutScene_c *c = new(buffer) dScCutScene_c;

	instance = c;
	return c;
}

dScCutScene_c::dScCutScene_c() {
	data = 0;
	layout = 0;
	sceneLoaders = 0;
}

dScCutScene_c::~dScCutScene_c() {
	if (layout)
		delete layout;

	if (sceneLoaders)
		delete[] sceneLoaders;
}


static const char *CutsceneNames[] = {
	"/CS/Opening.cs",
	"/CS/Kamek.cs",
	"/CS/Ending.cs"
};


int dScCutScene_c::onCreate() {
	*CurrentDrawFunc = CutSceneDrawFunc;

	currentScene = -1;

	int csNumber = settings >> 28;
	if (settingsLoader.load(CutsceneNames[csNumber])) {
		// only deal with this once!
		if (data) return 1;

		data = (dMovieData_s*)settingsLoader.buffer;

		// fix up the settings
		for (int i = 0; i < data->sceneCount; i++) {
			data->scenes[i] =
				(dMovieScene_s*)((u32)data + (u32)data->scenes[i]);

			data->scenes[i]->sceneName =
				(char*)((u32)data + (u32)data->scenes[i]->sceneName);
		}

		sceneLoaders = new dDvdLoader_c[data->sceneCount];

		nextScene = 0;

		return 1;
	}

	return 0;
}

int dScCutScene_c::onDelete() {
	if (layout)
		return layout->free();

	return true;
}

int dScCutScene_c::onExecute() {
	// deal with loading first
	
	// what do we want to load?
	if (currentScene >= 0 || nextScene >= 0) {
		int whatToLoad = (nextScene >= 0) ? nextScene : (currentScene + 1);

		sceneLoaders[whatToLoad].load(data->scenes[whatToLoad]->sceneName);
	}


	// now, do all other processing

	if (currentScene >= 0) {
		int nowPressed = Remocon_GetPressed(GetActiveRemocon());
		if (!layout->isAnyAnimOn() || nowPressed & WPAD_TWO) {
			// we're at the end
			// what now?

			if ((currentScene + 1) == data->sceneCount) {
				// we're TOTALLY done!
				OSReport("playback complete\n");
				int nsmbwMovieType = settings & 3;
				switch (nsmbwMovieType) {
					case 0:
						DoSceneChange(WORLD_MAP, 0x80000000, 0);
						break;
					case 1:
						StartTitleScreenStage(false, 0);
						break;
				}
			} else {
				nextScene = currentScene + 1;
				OSReport("switching to scene %d\n", nextScene);
			}

			sceneLoaders[currentScene].unload();
			currentScene = -1;
			layout->loader.buffer = 0;
			layout->free();
			delete layout;
			layout = 0;
			return true;
		}

		layout->execAnimations();
		layout->update();
	}
	
	if (nextScene >= 0) {
		// is this scene loaded yet?
		if (sceneLoaders[nextScene].buffer) {
			currentScene = nextScene;

			OSReport("Loading scene %d\n", currentScene);

			layout = new m2d::EmbedLayout_c;
			layout->loader.buffer = sceneLoaders[nextScene].buffer;
			layout->loader.attachArc(layout->loader.buffer, "arc");
			layout->resAccPtr = &layout->loader;

			bool result = layout->build("cutscene.brlyt");
			OSReport("Result: %d\n", result);
			layout->loadAnimations((const char *[1]){"cutscene.brlan"}, 1);
			layout->loadGroups((const char *[1]){"cutscene"}, (int[1]){0}, 1);
			layout->disableAllAnimations();
			layout->enableNonLoopAnim(0);

			if (data->scenes[nextScene]->widescreenFlag) {
				// Native on 16:9, letterboxed on 4:3
				if (!IsWideScreen()) {
					layout->clippingEnabled = true;
					layout->clipX = 0;
					layout->clipY = 52;
					layout->clipWidth = 640;
					layout->clipHeight = 352;
					layout->layout.rootPane->scale.x = 0.7711f;
					layout->layout.rootPane->scale.y = 0.7711f;
				}
			} else {
				// Native on 4:3, black bars on 16:9
				if (IsWideScreen()) {
					layout->clippingEnabled = true;
					layout->clipX = 66;
					layout->clipY = 0;
					layout->clipWidth = 508;
					layout->clipHeight = 456;
					layout->layout.rootPane->scale.x = 0.794f;
				}
			}

			layout->execAnimations();
			layout->update();

			OSReport("Loaded scene %d\n", currentScene);

			nextScene = -1;
		}
	}

	return true;
}

int dScCutScene_c::onDraw() {
	if (currentScene >= 0)
		layout->scheduleForDrawing();

	return true;
}

void CutSceneDrawFunc() {
	Reset3DState();
	SetupLYTDrawing();
	DrawAllLayoutsBeforeX(0x81);
	RenderEffects(0, 3);
	RenderEffects(0, 2);
	GXDrawDone();
	RemoveAllFromScnRoot();
	Reset3DState();
	SetCurrentCameraID(1);
	DoSpecialDrawing1();
	SetCurrentCameraID(0);
	for (int i = 0; i < 4; i++)
		RenderEffects(0, 0xB+i);
	for (int i = 0; i < 4; i++)
		RenderEffects(0, 7+i);
	GXDrawDone();
	// Leaving out some stuff here
	DrawAllLayoutsAfterX(0x80);
	ClearLayoutDrawList();
	SetCurrentCameraID(0);
}