-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbetweenstages.c
90 lines (68 loc) · 3.36 KB
/
betweenstages.c
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
#include "betweenstages.h"
#include "cutscene.h"
#include "graphic.h"
#include "displaytext.h"
#include "main.h"
#include "segmentinfo.h"
#include "stagekeys.h"
#define BETWEEN_STAGES_TIME 2.5f
#define BUFFER_TIME 0.3f
static u8 walkingAnimTexture[TMEM_SIZE_BYTES * 2] __attribute__((aligned(8)));
#define NUMBER_OF_ANIMATION_FRAMES 16
static float betweenTimePassed;
static u32 animationFrame;
void initBetweenStages() {
nuPiReadRom((u32)(_stairs_animSegmentRomStart), (void*)(walkingAnimTexture), TMEM_SIZE_BYTES * 2);
betweenTimePassed = 0.f;
animationFrame = 0;
}
void makeBetweenStagesDisplaylist() {
Dynamic* dynamicp;
char conbuf[20];
/* 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();
guOrtho(&dynamicp->ortho, 0.f, SCREEN_WD, SCREEN_HT, 0.f, 1.0F, 10.0F, 1.0F);
guMtxIdent(&dynamicp->modelling);
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++,G_CYC_1CYCLE);
gDPSetTexturePersp(glistp++, G_TP_NONE);
gDPSetTextureFilter(glistp++, G_TF_POINT);
gDPSetRenderMode(glistp++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2);
gSPClearGeometryMode(glistp++,0xFFFFFFFF);
gSPSetGeometryMode(glistp++,G_SHADE | G_SHADING_SMOOTH | G_CULL_BACK);
gSPTexture(glistp++, 0xffff, 0xffff, 0, G_TX_RENDERTILE, G_ON);
gSPClipRatio(glistp++, FRUSTRATIO_2);
if ((betweenTimePassed > BUFFER_TIME) && (betweenTimePassed < (BETWEEN_STAGES_TIME - BUFFER_TIME))) {
gDPPipeSync(glistp++);
gDPSetCombineMode(glistp++, G_CC_MODULATEIDECALA_PRIM, G_CC_MODULATEIDECALA_PRIM);
gDPSetPrimColor(glistp++, 0, 0, 0xff, 0xff, 0xff, 0xff);
gDPLoadTextureBlock_4b(glistp++, OS_K0_TO_PHYSICAL(walkingAnimTexture), G_IM_FMT_I, 512, 16, 0, G_TX_NOMIRROR, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gSPScisTextureRectangle(glistp++, (((SCREEN_WD - 32) / 2)) << 2, (((SCREEN_HT - 32) / 2 ) + 16 - 16) << 2, (((SCREEN_WD - 32) / 2) + 32) << 2, (((SCREEN_HT - 32) / 2 ) + 16 + 16 - 16) << 2, 0, (animationFrame * 32) << 5, 0 << 5, 1 << 10, 1 << 10);
gDPPipeSync(glistp++);
gDPLoadTextureBlock_4b(glistp++, OS_K0_TO_PHYSICAL(walkingAnimTexture + TMEM_SIZE_BYTES), G_IM_FMT_I, 512, 16, 0, G_TX_NOMIRROR, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gSPScisTextureRectangle(glistp++, (((SCREEN_WD - 32) / 2)) << 2, (((SCREEN_HT - 32) / 2 ) + 32 - 16) << 2, (((SCREEN_WD - 32) / 2) + 32) << 2, (((SCREEN_HT - 32) / 2 ) + 32 + 16 - 16) << 2, 0, (animationFrame * 32) << 5, 0 << 5, 1 << 10, 1 << 10);
}
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);
gfx_gtask_no = (gfx_gtask_no + 1) % BUFFER_COUNT;
}
void updateBetweenStages() {
betweenTimePassed += deltaTimeSeconds;
animationFrame = ((int)(betweenTimePassed * 24.f)) % NUMBER_OF_ANIMATION_FRAMES;
if (betweenTimePassed > BETWEEN_STAGES_TIME) {
if (levels[currentLevel].completionCutsceneKey != 0x0) {
cutsceneToLoad = levels[currentLevel].completionCutsceneKey;
nextStage = &cutsceneStage;
} else {
nextStage = &gameplayStage;
}
currentLevel = (currentLevel + 1) % NUMBER_OF_LEVELS; // TODO: finish the game if we top out
changeScreensFlag = 1;
}
}