-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtitlescreen.c
More file actions
445 lines (356 loc) · 15.7 KB
/
Copy pathtitlescreen.c
File metadata and controls
445 lines (356 loc) · 15.7 KB
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#include "titlescreen.h"
#include <nusys.h>
#include "cutscene.h"
#include "displaytext.h"
#include "gamemath.h"
#include "backgroundbuffers.h"
#include "cutscene_backgrounds/backgroundlookup.h"
#include "nustdfuncs.h"
#include "main.h"
#include "gameaudio.h"
#include "graphic.h"
#include "segmentinfo.h"
#include "sixtwelve.h"
#include "sixtwelve_helpers.h"
#include "audio/bgm/sequence/tracknumbers.h"
#include "audio/sfx/sfx.h"
#include "opening/envtexture.h"
#include "opening/tower.h"
#include "opening/ground.h"
#include "opening/decor.h"
static float timePassed;
static u8 downPressed;
static u8 upPressed;
static u8 stickInDeadzone;
#define OVERTURE_DURATION_SECONDS 48
typedef struct {
float duration;
Vec3 camera;
Vec3 look;
const char* text;
int soundIndex;
} Spot;
static int spotIndex;
static float spotTimePassed;
static u8 hasPlayedSoundForTheSpot;
static u8 showingTitle;
static u8 menuIndex;
static u8 isTransitioningOut;
static float transitionOutTime;
#define NUMBER_OF_TITLE_MENU_ITEMS 3
static const char* menuItems[NUMBER_OF_TITLE_MENU_ITEMS] = {
"START GAME",
"LEVEL SELECT",
// TODO: Marathon mode?
"CREDITS"
};
static float menuItemHorizontalOffsets[NUMBER_OF_TITLE_MENU_ITEMS];
static Spot spots[] = {
// Sky start
{ 6.f, { -99.3196f, -120.643f, 67.314f }, { -59.3667f, -69.484f, 123.734f }, "It is a shitty time.", SFX_23_VO_LINE_0 },
// "comes down" to view
{ 6.f, { -59.3667f, -120.643f, 67.314f }, { -59.3667f, -69.484f, 67.314f }, "The harvests are poor, and\n monsters roam freely\n across the land.", SFX_24_VO_LINE_1 },
{ 6.0f, { 83.7952f, -115.326f, 37.987f }, { 6.07872f, 11.4772f, -9.87373f }, " Chosen by lot, warriors are\n trained from birth\n in the mystic artes.", SFX_25_VO_LINE_2 },
{ 5.0f, { 178.037f, 36.7114f, 76.2756f }, { 6.07872f, 19.6313f, 21.6789f }, "A warrior must be learned\n in cunning,\n strategy,\n and swiftness...", SFX_26_VO_LINE_3 },
{ 6.0f, { 76.7275f, 73.2299f, 76.2756f }, { 5.48971f, 23.1654f, 14.9429f }, "...for their final lonesome trial\n when they come of age.", SFX_27_VO_LINE_4},
// Midpoint
{ 7.5f, { 0.745361f, 44.7062f, 108.537f }, { 0.667588f, 4.2692f, 24.0872f }, "To prevail as a warrior is to\n scale the Demon's Spire,\n lair of the Shadow Queen.", SFX_28_VO_LINE_5 },
{ 5.f, { -103.509f, 22.3239f, 70.2484f }, { -0.489938f, 21.5849f, 22.4681f }, "Many have entered,\n but few have returned.", SFX_29_VO_LINE_6 },
{ 9.f, { -4.55552f, -93.9098f, 44.2122f }, { 1.36965f, 21.797f, 24.2866f }, "If one prevails over the trial,\n if one succeeds at their task,\n they shall be known as a...", SFX_30_VO_LINE_7 },
{ 8.f, { 0.156551f, 7.43251f, 25.1426f }, { 1.36965f, 21.797f, 24.2866f }, "", -1 },
{ 1.f, { 0.f, -5.f, 0.f }, { 0.f, 11.5f, 26.f }, "" },
};
#define NUMBER_OF_SPOTS 9
static int maxNumberOfTwoLineRowsToDo;
void initializeBackgrounds() {
struct backgroundMappingData* mapping = getBackgroundTextureOffset("stars", _nstrlen("stars"));
if (mapping != NULL) {
nuPiReadRom((u32)(_packedbackgroundsSegmentRomStart + mapping->offset), backgroundBuffers[0], 320 * 240 * 2);
} else {
bzero(backgroundBuffers[0], 320 * 240 * 2);
}
struct backgroundMappingData* titleMapping = getBackgroundTextureOffset("logotype", _nstrlen("logotype"));
if (titleMapping != NULL) {
nuPiReadRom((u32)(_packedbackgroundsSegmentRomStart + titleMapping->offset), backgroundBuffers[1], 320 * 240 * 2);
}
}
void initTitleScreen() {
timePassed = 0.f;
downPressed = 0;
upPressed = 0;
stickInDeadzone = 0;
initializeBackgrounds();
nuPiReadRom((u32)_opening_environmentSegmentRomStart, environmentTexture, TMEM_SIZE_BYTES);
spotIndex = 0;
spotTimePassed = 0.f;
hasPlayedSoundForTheSpot = 0;
maxNumberOfTwoLineRowsToDo = 0;
showingTitle = 0;
for (int i = 0; i < NUMBER_OF_TITLE_MENU_ITEMS; i++) {
menuItemHorizontalOffsets[i] = 0.f;
}
menuIndex = 0;
isTransitioningOut = 0;
transitionOutTime = 0.f;
playMusic(TRACK_05_OVERTURE);
}
void makeTitleScreenDL() {
Dynamic* dynamicp;
/* Specify the display list buffer */
dynamicp = &gfx_dynamic[gfx_gtask_no];
glistp = &gfx_glist[gfx_gtask_no][0];
/* Initialize RCP */
gfxRCPInit();
/* Clear the frame and Z-buffer */
gfxClearCfb();
// This is used for `gSPPerspNormalize`
u16 perspectiveNorm = 0;
guPerspective(&dynamicp->projection, &perspectiveNorm, ingameFOV, ((float)SCREEN_WD)/((float)SCREEN_HT), 0.1f, 100.f, 1.f);
if (spotIndex < (NUMBER_OF_SPOTS - 1)) {
const float t = spotTimePassed / spots[spotIndex].duration;
Vec3 camPos = {
lerp(spots[spotIndex].camera.x, spots[spotIndex + 1].camera.x, t),
lerp(spots[spotIndex].camera.y, spots[spotIndex + 1].camera.y, t),
lerp(spots[spotIndex].camera.z, spots[spotIndex + 1].camera.z, t),
};
Vec3 look = {
lerp(spots[spotIndex].look.x, spots[spotIndex + 1].look.x, t),
lerp(spots[spotIndex].look.y, spots[spotIndex + 1].look.y, t),
lerp(spots[spotIndex].look.z, spots[spotIndex + 1].look.z, t),
};
guLookAt(&dynamicp->camera, camPos.x, camPos.y, camPos.z, look.x, look.y, look.z, 0.f, 0.f, 1.f);
} else {
guLookAt(&dynamicp->camera, spots[NUMBER_OF_SPOTS - 1].camera.x, spots[NUMBER_OF_SPOTS - 1].camera.y, spots[NUMBER_OF_SPOTS - 1].camera.z, spots[NUMBER_OF_SPOTS - 1].look.x, spots[NUMBER_OF_SPOTS - 1].look.y, spots[NUMBER_OF_SPOTS - 1].look.z, 0.f, 0.f, 1.f);
}
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++,G_CYC_1CYCLE);
gDPSetTexturePersp(glistp++, G_TP_NONE);
gDPSetTextureFilter(glistp++, G_TF_POINT);
gDPSetCombineMode(glistp++,G_CC_DECALRGBA, G_CC_DECALRGBA);
gDPSetRenderMode(glistp++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
gSPTexture(glistp++, 0xffff, 0xffff, 0, G_TX_RENDERTILE, G_ON);
if ((spotIndex == 0) && (spotTimePassed < 1.f)) {
gDPPipeSync(glistp++);
float t = (spotTimePassed / 1.f);
int tVal = t * 255;
gDPSetPrimColor(glistp++, 0, 0, tVal, tVal, tVal, (tVal));
gDPSetCombineMode(glistp++,G_CC_MODULATERGBA_PRIM, G_CC_MODULATERGBA_PRIM);
}
for (int i = 0; i < (240 / 6); i++) {
gDPPipeSync(glistp++);
gDPLoadTextureTile(glistp++, backgroundBuffers[0], G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, 240, 0, (i * 6), 320 - 1, ((i + 1) * 6) - 1, 0, G_TX_WRAP, G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD );
gSPTextureRectangle(glistp++, 0 << 2, (0 + (i * 6)) << 2, (0 + 320) << 2, (0 + ((i + 1) * 6)) << 2, 0, 0 << 5, (i * 6) << 5, 1 << 10, 1 << 10);
}
gSPMatrix(glistp++,OS_K0_TO_PHYSICAL(&(dynamicp->projection)), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
gSPMatrix(glistp++,OS_K0_TO_PHYSICAL(&(dynamicp->camera)), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH );
gDPPipeSync(glistp++);
gDPSetTexturePersp(glistp++, G_TP_PERSP);
gDPSetCombineMode(glistp++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA);
gDPLoadTextureBlock(glistp++, environmentTexture, G_IM_FMT_IA, G_IM_SIZ_8b, 128, 32, 0, G_TX_MIRROR, G_TX_MIRROR, 7, 5, G_TX_NOLOD, G_TX_NOLOD);
gDPSetRenderMode(glistp++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
gSPClearGeometryMode(glistp++,0xFFFFFFFF);
gSPSetGeometryMode(glistp++,G_SHADE | G_SHADING_SMOOTH | G_CULL_BACK);
gSPPerspNormalize(glistp++, perspectiveNorm);
gSPClipRatio(glistp++, FRUSTRATIO_6);
gSPDisplayList(glistp++, OS_K0_TO_PHYSICAL(gfx_Ground_None));
gDPPipeSync(glistp++);
gDPSetRenderMode(glistp++, G_RM_ZB_XLU_SURF, G_RM_ZB_XLU_SURF);
gSPClearGeometryMode(glistp++,0xFFFFFFFF);
gSPSetGeometryMode(glistp++,G_SHADE | G_ZBUFFER | G_SHADING_SMOOTH | G_CULL_BACK);
gSPDisplayList(glistp++, OS_K0_TO_PHYSICAL(gfx_decorations_None));
gDPPipeSync(glistp++);
gDPSetRenderMode(glistp++, G_RM_ZB_OPA_SURF, G_RM_ZB_OPA_SURF2);
gSPDisplayList(glistp++, OS_K0_TO_PHYSICAL(gfx_Tower_None));
gDPPipeSync(glistp++);
gDPSetTexturePersp(glistp++, G_TP_NONE);
gDPSetCombineMode(glistp++,G_CC_DECALRGBA, G_CC_DECALRGBA);
gDPSetRenderMode(glistp++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
gDPLoadTextureBlock_4b(glistp++, sixtwelve_tex, G_IM_FMT_IA, SIXTWELVE_TEXTURE_WIDTH, SIXTWELVE_TEXTURE_HEIGHT, 0, G_TX_MIRROR | G_TX_WRAP, G_TX_MIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
const char* str = NULL;
if ((spotIndex < (NUMBER_OF_SPOTS)) && (spots[spotIndex].text != NULL) && (((spotIndex > 0) && (spotTimePassed > 1.f)) || ( spotTimePassed > 3.f) )) {
str = spots[spotIndex].text;
}
if ((str != NULL) && (maxNumberOfTwoLineRowsToDo == 0)) {
int i = 0;
int xInit = 32;
int xAdv = xInit;
int y = 128;
while (spots[spotIndex].text[i] != '\0') {
const sixtwelve_character_info* characterInfo = sixtwelve_get_character_info(spots[spotIndex].text[i]);
if (spots[spotIndex].text[i] == '\n') {
xAdv = xInit;
y += SIXTWELVE_LINE_HEIGHT;
i++;
continue;
}
const int xLoc = xAdv + characterInfo->x_offset;
const int yLoc = y + characterInfo->y_offset;
gSPScisTextureRectangle(glistp++, (xLoc) << 2, (yLoc) << 2, (xLoc + characterInfo->width) << 2, (yLoc + characterInfo->height) << 2, 0, (characterInfo->x) << 5, (characterInfo->y) << 5, 1 << 10, 1 << 10);
xAdv += characterInfo->x_advance;
i++;
}
}
if (showingTitle) {
gDPPipeSync(glistp++);
gDPSetCombineMode(glistp++, G_CC_MODULATEIDECALA_PRIM, G_CC_MODULATEIDECALA_PRIM);
gDPLoadTextureBlock_4b(glistp++, OS_K0_TO_PHYSICAL(displayTextTexture), G_IM_FMT_IA, 512, 16, 0, G_TX_NOMIRROR, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
for (int i = 0; i < NUMBER_OF_TITLE_MENU_ITEMS; i++) {
const char* item = menuItems[i];
if (i == menuIndex) {
gDPSetPrimColor(glistp++, 0, 0, N64_C_BUTTONS_RED, N64_C_BUTTONS_GREEN, N64_C_BUTTONS_BLUE, 0xff);
} else {
gDPSetPrimColor(glistp++, 0, 0, 0xff, 0xff, 0xff, 0xff);
}
renderDisplayText(112 + ((int)menuItemHorizontalOffsets[i]), 160 + (16 * i), item);
}
}
gDPPipeSync(glistp++);
gDPSetTexturePersp(glistp++, G_TP_NONE);
gDPSetTextureFilter(glistp++, G_TF_BILERP);
gDPSetCombineMode(glistp++,G_CC_DECALRGBA, G_CC_DECALRGBA);
gDPSetRenderMode(glistp++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
gSPTexture(glistp++, 0xffff, 0xffff, 0, G_TX_RENDERTILE, G_ON);
const int nudgeX = (guRandom() % 4);
const int nudgeY = (guRandom() % 4);
for (int i = 0; i < maxNumberOfTwoLineRowsToDo; i++) {
gDPPipeSync(glistp++);
gDPLoadTextureTile(glistp++, backgroundBuffers[1], G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, 240, 0, (i * 2), 320 - 1, ((i + 1) * 2) - 1, 0, G_TX_WRAP, G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD );
gSPTextureRectangle(glistp++, 0 << 2, (0 + (i * 2)) << 2, (0 + 320) << 2, (0 + ((i + 1) * 2)) << 2, 0, (0 << 5) | (nudgeX << 2), ((i * 2) << 5) | (nudgeY << 2), 1 << 10, 1 << 10);
}
#ifdef LINES_CAPTURE_MARKERS
if (spotIndex < (NUMBER_OF_SPOTS) && spotTimePassed) {
const float percentage = (spotTimePassed) / (spots[spotIndex].duration);
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++, G_CYC_FILL);
gDPSetFillColor(glistp++, GPACK_RGBA5551(0xc0,0,0,1) << 16 | GPACK_RGBA5551(0xc0,0,0,1));
gDPFillRectangle(glistp++, 0, SCREEN_HT - 8, SCREEN_WD - 1, SCREEN_HT);
gDPPipeSync(glistp++);
gDPSetFillColor(glistp++, GPACK_RGBA5551(0x5a,0,0,1) << 16 | GPACK_RGBA5551(0x5a,0,0,1));
gDPFillRectangle(glistp++, 0, SCREEN_HT - 8,(u32)((SCREEN_WD) * (1.f / spots[spotIndex].duration)), SCREEN_HT);
gDPPipeSync(glistp++);
gDPSetFillColor(glistp++, GPACK_RGBA5551(0,0xc0,0,1) << 16 | GPACK_RGBA5551(0,0xc0,0,1));
gDPFillRectangle(glistp++, 0, SCREEN_HT - 8, (u32)((SCREEN_WD) * percentage), SCREEN_HT);
}
#endif
if (isTransitioningOut) {
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++, G_CYC_FILL);
gDPSetFillColor(glistp++, GPACK_RGBA5551(0x0,0,0,1) << 16 | GPACK_RGBA5551(0x0,0,0,1));
gDPFillRectangle(glistp++, 0, 0, SCREEN_WD - 1, SCREEN_HT * MIN(1.f, transitionOutTime));
}
gDPFullSync(glistp++);
gSPEndDisplayList(glistp++);
nuGfxTaskStart(&gfx_glist[gfx_gtask_no][0], (s32)(glistp - gfx_glist[gfx_gtask_no]) * sizeof (Gfx), NU_GFX_UCODE_F3DLP_REJ , NU_SC_SWAPBUFFER);
// char conbuf[20];
// nuDebConClear(0);
// nuDebConTextPos(0,4,4);
// sprintf(conbuf,"title screen");
// nuDebConCPuts(0, conbuf);
// nuDebConTextPos(0,4,5);
// sprintf(conbuf," t: %2.2f/%2.2f", spotTimePassed, spots[spotIndex].duration);
// nuDebConCPuts(0, conbuf);
// nuDebConTextPos(0,4,6);
// sprintf(conbuf,"spotIndex: %02d", spotIndex);
// nuDebConCPuts(0, conbuf);
// nuDebConTextPos(0,4,7);
// sprintf(conbuf," time: %2.2f", timePassed);
// nuDebConCPuts(0, conbuf);
/* Display characters on the frame buffer */
// nuDebConDisp(NU_SC_SWAPBUFFER);
gfx_gtask_no = (gfx_gtask_no + 1) % BUFFER_COUNT;
}
void updateTitleScreen() {
nuContDataGetEx(contdata,0);
timePassed += deltaTimeSeconds;
if (spotIndex < (NUMBER_OF_SPOTS)) {
spotTimePassed += deltaTimeSeconds;
if ((!hasPlayedSoundForTheSpot) && (((spotIndex > 0) && (spotTimePassed > 1.f)) || ( spotTimePassed > 3.f)) ) {
hasPlayedSoundForTheSpot = 1;
if ((spots[spotIndex].soundIndex > -1) && (!showingTitle)) {
playSound((u32)(spots[spotIndex].soundIndex));
}
}
if (spotTimePassed > spots[spotIndex].duration) {
spotTimePassed = 0.f;
spotIndex++;
hasPlayedSoundForTheSpot = 0;
}
if (spotIndex == 7) {
if ((maxNumberOfTwoLineRowsToDo == 0) && (spotTimePassed > (6.015f + 1.f))) {
maxNumberOfTwoLineRowsToDo = (78 / 2);
} else if ((maxNumberOfTwoLineRowsToDo == (78 / 2)) && (spotTimePassed > (7.078f + 1.f))) {
maxNumberOfTwoLineRowsToDo = (106 / 2);
} else if ((maxNumberOfTwoLineRowsToDo == (106 / 2)) && (spotTimePassed > (7.501f + 1.f))) {
maxNumberOfTwoLineRowsToDo = (152 / 2);
}
} else if ((spotIndex > 7) && (!showingTitle)) {
showingTitle = 1;
}
}
if (showingTitle) {
for (int i = 0; i < NUMBER_OF_TITLE_MENU_ITEMS; i++) {
menuItemHorizontalOffsets[i] = lerp(menuItemHorizontalOffsets[i], (menuIndex == i) ? 16.f : 0.f, 0.13f);
}
}
if (!isTransitioningOut) {
if(contdata[0].trigger & U_JPAD) {
downPressed = 1;
} else if(contdata[0].trigger & D_JPAD) {
upPressed = 1;
} else {
upPressed = 0;
downPressed = 0;
}
if (!stickInDeadzone && (contdata[0].stick_y > -7) && (contdata[0].stick_y < 7)) {
stickInDeadzone = 1;
}
if (stickInDeadzone) {
if (contdata[0].stick_y < -7) {
upPressed = 1;
stickInDeadzone = 0;
} else if (contdata[0].stick_y > 7) {
downPressed = 1;
stickInDeadzone = 0;
}
}
if (upPressed) {
upPressed = 0;
menuIndex = (menuIndex + 1) % NUMBER_OF_TITLE_MENU_ITEMS;
playSound(SFX_02_NOBODY_BIP);
}
if (downPressed) {
downPressed = 1;
menuIndex = (menuIndex - 1 + NUMBER_OF_TITLE_MENU_ITEMS) % NUMBER_OF_TITLE_MENU_ITEMS;
playSound(SFX_02_NOBODY_BIP);
}
if (contdata[0].trigger & A_BUTTON) {
if (!showingTitle) {
showingTitle = 1;
maxNumberOfTwoLineRowsToDo = (152 / 2);
stopLastPlayedSound();
} else {
if (menuIndex == 0) {
playSound(SFX_11_MENU_CONFIRM);
cutsceneToLoad = "intro";
nextStage = &cutsceneStage;
currentLevel = 0;
isTransitioningOut = 1;
} else if (menuIndex == 1) {
playSound(SFX_11_MENU_CONFIRM);
nextStage = &levelSelectStage;
isTransitioningOut = 1;
} else if (menuIndex == 2) {
playSound(SFX_11_MENU_CONFIRM);
nextStage = &creditsStage;
isTransitioningOut = 1;
}
fadeOutMusic();
}
}
} else {
transitionOutTime += deltaTimeSeconds;
if (transitionOutTime > 1.5f) {
changeScreensFlag = 1;
}
}
}