Skip to content

Commit

Permalink
fix most of special stage in widescreen
Browse files Browse the repository at this point in the history
  • Loading branch information
freshollie committed Jan 18, 2025
1 parent 8c85ad0 commit 28f5f0f
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 217 deletions.
2 changes: 1 addition & 1 deletion include/game/special_stage/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct UNK_8C87904 {
struct UNK_80DF670 {
/* 0x00 */ AnimId anim;
/* 0x02 */ u16 variant;
u16 unk4;
u16 size;
u8 animSpeed;
u8 unk7;
} /* size 0x8 */;
Expand Down
18 changes: 9 additions & 9 deletions include/game/special_stage/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ struct SpecialStage {
Background unk48;
ScreenFade fade;
s32 unk94[DISPLAY_HEIGHT][2];
s32 qCameraX;
s32 qCameraY;
s32 q16CameraX;
s32 q16CameraY;
s32 unk59C;

u16 cameraBearing;
u16 cameraRotX;
s16 animFrame;

s16 rings;
Expand Down Expand Up @@ -75,12 +75,12 @@ struct SpecialStage {
s8 unk5C7;
s8 unk5C8;

s16 unk5CA;
s16 unk5CC;
u16 unk5CE;
u8 unk5D0;
u8 unk5D1;
u8 unk5D2;
s16 cameraOriginX;
s16 cameraHeight;
u16 worldScale;
u8 cameraPitch;
u8 horizonHeight;
u8 viewDistance;
u8 unk5D3;
void *screenVram;
}; /* size 0x5D8 */
Expand Down
8 changes: 4 additions & 4 deletions include/game/special_stage/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ struct SpecialStageUI {
Sprite timeTens;
Sprite timeUnits;
Sprite ringsHundredsDigit;
Sprite ringsTENS_DIGIT;
Sprite ringsUNITS_DIGIT;
Sprite ringsTensDigit;
Sprite ringsUnitsDigit;
Sprite unk154;
Sprite ringsTargetHundredsDigit;
Sprite ringsTargetTENS_DIGIT;
Sprite ringsTargetUNITS_DIGIT;
Sprite ringsTargetTensDigit;
Sprite ringsTargetUnitsDigit;
Sprite multiplier;
Sprite unk244;
Sprite pauseMenu;
Expand Down
5 changes: 3 additions & 2 deletions include/game/special_stage/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ extern void *gUnknown_03005B5C;
#define RENDER_TARGET_SUB_MENU 1

void sub_806CA88(Sprite *obj, s8 target, u32 size, u16 c, u32 assetId, s16 xPos, s16 yPos, u16 g, u8 h, u8 palId);
void sub_806CEC4(Background *background, u32 a, u32 b, u8 assetId, u16 d, u16 e, u16 f, u8 g, u16 scrollX, u16 scrollY);
bool16 sub_806CB84(struct UNK_806CB84 *a, struct SpecialStageCollectables_UNK874_2 *unk874, struct SpecialStage *stage);
void SpecialStageDrawBackground(Background *background, u32 a, u32 b, u8 assetId, u16 d, u16 e, u16 f, u8 g, u16 scrollX, u16 scrollY);
bool16 SpecialStageCalcEntityScreenPosition(struct UNK_806CB84 *a, struct SpecialStageCollectables_UNK874_2 *unk874,
struct SpecialStage *stage);
void sub_806CD68(Sprite *element);
void InitSpecialStageScreenVram(void);
s16 MaxSpriteSize(const struct UNK_80DF670 *spriteConfig);
Expand Down
11 changes: 7 additions & 4 deletions include/game/special_stage/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

struct SpecialStageWorld {
struct SpecialStage *stage;
void *unk4; // size 0xA00
void *bgTransforms; // size 0xA00

// unused
void *unk8; // size 0x280
s32 *unkC; // size 0x280
Background unk10;
Background unk50;

s32 *qPerspectiveTable; // size 0x280
Background background;
Background floor;
Sprite unk90[11];
}; /* size 0x2A0 */

Expand Down
12 changes: 6 additions & 6 deletions src/game/special_stage/collectables.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ s16 sub_806E038(s16 acc, const struct UNK_8C878E8 *unk78E8, struct UNK_806DEA4 *
new_unk874.unkE = 8;
new_unk874.unk10 = 0;
new_unk874.unk12 = 5;
if (sub_806CB84(&new_unkCB84, &new_unk874, collectables->stage)) {
if (SpecialStageCalcEntityScreenPosition(&new_unkCB84, &new_unk874, collectables->stage)) {
if (result < 16) {
memcpy(&unkDEA4Arr[result], &new_unkCB84, sizeof(new_unkCB84));

Expand Down Expand Up @@ -394,7 +394,7 @@ void sub_806E1AC(s16 index, struct UNK_806DEA4 *unkDEA4)
element1->frameFlags = index | 0x1060 | 0xC0000;
element1->x = unkDEA4->unk2;
element1->y = unkDEA4->unk4 - unkDEA4->unk6;
element1->oamFlags = (unkDEA4->unk4 < (stage->unk5CC - 15)) ? SPRITE_OAM_ORDER(13) : SPRITE_OAM_ORDER(6);
element1->oamFlags = (unkDEA4->unk4 < (stage->cameraHeight - 15)) ? SPRITE_OAM_ORDER(13) : SPRITE_OAM_ORDER(6);
} else {
s16 x, y;
Sprite *reference;
Expand All @@ -407,7 +407,7 @@ void sub_806E1AC(s16 index, struct UNK_806DEA4 *unkDEA4)
element2->frameFlags = index | 0x1060 | 0xC0000;
element2->x = unkDEA4->unk2;
element2->y = ((13 - ((120 - unkDEA4->unk4) >> 5)) >> 1) + unkDEA4->unk4;
element2->oamFlags = (unkDEA4->unk4 < (stage->unk5CC - 15)) ? SPRITE_OAM_ORDER(14) : SPRITE_OAM_ORDER(7);
element2->oamFlags = (unkDEA4->unk4 < (stage->cameraHeight - 15)) ? SPRITE_OAM_ORDER(14) : SPRITE_OAM_ORDER(7);
sub_806CD68(element2);

reference = unkDEA4->unk0 == 1 ? &collectables->unk34 : &collectables->unkC4;
Expand All @@ -418,7 +418,7 @@ void sub_806E1AC(s16 index, struct UNK_806DEA4 *unkDEA4)
element1->frameFlags = index | 0x1060 | 0xC0000;
element1->x = x;
element1->y = y;
element1->oamFlags = (unkDEA4->unk4 < (stage->unk5CC - 15)) ? SPRITE_OAM_ORDER(13) : SPRITE_OAM_ORDER(6);
element1->oamFlags = (unkDEA4->unk4 < (stage->cameraHeight - 15)) ? SPRITE_OAM_ORDER(13) : SPRITE_OAM_ORDER(6);
}

sub_806CD68(element1);
Expand Down Expand Up @@ -530,7 +530,7 @@ void sub_806E584(s16 index, struct SpecialStageCollectables_UNK874 *unk874)
new_unk874.unk10 = 0;
new_unk874.unk12 = 5;

visible = sub_806CB84(&new_unkCB84, &new_unk874, collectables->stage);
visible = SpecialStageCalcEntityScreenPosition(&new_unkCB84, &new_unk874, collectables->stage);
if (visible) {
s32 screenX = new_unkCB84.screenX;
s32 unk4 = new_unkCB84.screenY;
Expand All @@ -541,7 +541,7 @@ void sub_806E584(s16 index, struct SpecialStageCollectables_UNK874 *unk874)
unk7B4->frameFlags = (index + 16) | 0x1060 | 0xC0000;
unk7B4->x = screenX;
unk7B4->y = screenY;
unk7B4->oamFlags = (new_unkCB84.screenY < (stage->unk5CC - 15)) ? SPRITE_OAM_ORDER(13) : SPRITE_OAM_ORDER(6);
unk7B4->oamFlags = (new_unkCB84.screenY < (stage->cameraHeight - 15)) ? SPRITE_OAM_ORDER(13) : SPRITE_OAM_ORDER(6);
sub_806CD68(unk7B4);

affine = &gOamBuffer[(index + 16) * 4].all.affineParam;
Expand Down
31 changes: 18 additions & 13 deletions src/game/special_stage/guard_robo.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void Task_GuardRoboMain(void)
{
struct SpecialStageCollectables_UNK874_2 unk874;
struct UNK_806CB84 unkCBB4;
u8 temp;
u8 order;
u16 *oam;
bool16 visible;

Expand All @@ -85,7 +85,7 @@ void Task_GuardRoboMain(void)
unk874.unk10 = 0;
unk874.unk12 = 0x1D;

visible = sub_806CB84(&unkCBB4, &unk874, guardRobo->stage);
visible = SpecialStageCalcEntityScreenPosition(&unkCBB4, &unk874, guardRobo->stage);
if (visible) {
u16 angle;

Expand All @@ -97,15 +97,16 @@ void Task_GuardRoboMain(void)
oam += 4;
*oam = unkCBB4.unk12;

angle = ((guardRobo->bearing - stage->cameraBearing) + 64) & 0x3FF;
if (unkCBB4.screenY < (stage->unk5CC - 0x3C)) {
temp = 0xC;
angle = ((guardRobo->bearing - stage->cameraRotX) + 64) & ONE_CYCLE;
// Is behind player
if (unkCBB4.screenY < (stage->cameraHeight - 60)) {
order = 12;
} else {
temp = 5;
order = 5;
}

if (stage->paused == FALSE) {
RenderGuardRobo(&guardRobo->sprite, unkCBB4.screenX, unkCBB4.screenY, temp, &guardRobo->sprites[angle >> 7]);
RenderGuardRobo(&guardRobo->sprite, unkCBB4.screenX, unkCBB4.screenY, order, &guardRobo->sprites[angle >> 7]);
}

if (guardRobo->state != 2 || !(guardRobo->animFrame & 2) || stage->paused != 0) {
Expand All @@ -124,7 +125,7 @@ void sub_80710B0(void)

s32 temp3, bearingToPlayer;

u16 angle = (-guardRobo->bearing & 0x3FF);
u16 angle = (-guardRobo->bearing & ONE_CYCLE);
s32 sin = SIN(angle) * 4;
s32 cos = COS(angle);

Expand All @@ -138,11 +139,11 @@ void sub_80710B0(void)
temp3 = (-sin >> 8) * sin4 + (cos >> 6) * (dY >> 8);

if (bearingToPlayer > 0) {
guardRobo->bearing = (guardRobo->bearing - guardRobo->rotateSpeed) & 0x3FF;
guardRobo->bearing = (guardRobo->bearing - guardRobo->rotateSpeed) & ONE_CYCLE;
} else if (bearingToPlayer < 0) {
guardRobo->bearing = (guardRobo->bearing + guardRobo->rotateSpeed) & 0x3FF;
guardRobo->bearing = (guardRobo->bearing + guardRobo->rotateSpeed) & ONE_CYCLE;
} else if (temp3 < 0) {
guardRobo->bearing = (guardRobo->bearing - guardRobo->rotateSpeed) & 0x3FF;
guardRobo->bearing = (guardRobo->bearing - guardRobo->rotateSpeed) & ONE_CYCLE;
}

angle = guardRobo->bearing;
Expand Down Expand Up @@ -186,6 +187,10 @@ void sub_807120C(struct SpecialStageGuardRobo *guardRobo)
return;
}

#ifdef NON_MATCHING
return;
#endif

if ((guardRoboX - 5) < playerX && (guardRoboX + 5) > playerX) {
if (((guardRoboY)-5) < playerY && (guardRoboY + 5) > playerY) {
#ifndef NON_MATCHING
Expand Down Expand Up @@ -320,7 +325,7 @@ void sub_80714F4(struct SpecialStageGuardRobo *guardRobo)
}
}

static void RenderGuardRobo(Sprite *s, s16 x, s16 y, u8 b, const struct UNK_80DF670 *spriteConfig)
static void RenderGuardRobo(Sprite *s, s16 x, s16 y, u8 order, const struct UNK_80DF670 *spriteConfig)
{
u32 flags = 0x107F;
if (spriteConfig->unk7 & 1) {
Expand All @@ -335,7 +340,7 @@ static void RenderGuardRobo(Sprite *s, s16 x, s16 y, u8 b, const struct UNK_80DF
s->frameFlags = flags;
s->x = x;
s->y = y;
s->oamFlags = SPRITE_OAM_ORDER(b);
s->oamFlags = SPRITE_OAM_ORDER(order);
s->variant = spriteConfig->variant;
s->animSpeed = spriteConfig->animSpeed;
UpdateSpriteAnimation(s);
Expand Down
35 changes: 19 additions & 16 deletions src/game/special_stage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "constants/zones.h"

#include "constants/songs.h"
#include "constants/tilemaps.h"

#define MAX_POINTS 99900

Expand Down Expand Up @@ -46,7 +47,7 @@ void CreateSpecialStage(s16 selectedCharacter, s16 level)
struct Task *t;
struct SpecialStage *stage;

s16 zone, character, temp, i, target;
s16 zone, character, temp, i, viewDistance;

m4aMPlayAllStop();

Expand All @@ -67,11 +68,11 @@ void CreateSpecialStage(s16 selectedCharacter, s16 level)

t = TaskCreate(Task_ShowIntroScreen, sizeof(struct SpecialStage), 0x2000, 0, SpecialStageOnDestroy);
stage = TASK_DATA(t);
stage->qCameraX = Q_16_16(256);
stage->qCameraY = Q_16_16(256);
stage->q16CameraX = Q_16_16(256);
stage->q16CameraY = Q_16_16(256);
stage->unk59C = 0;

stage->cameraBearing = 512;
stage->cameraRotX = 512;

if (character <= CHARACTER_AMY) {
stage->character = character;
Expand Down Expand Up @@ -110,23 +111,25 @@ void CreateSpecialStage(s16 selectedCharacter, s16 level)
stage->unk5C7 = 0;
stage->unk5C8 = 0;

stage->unk5CA = DISPLAY_WIDTH / 2; // originX
stage->unk5CC = 140; // camera height?
stage->unk5CE = 64; // scale
stage->cameraOriginX = DISPLAY_WIDTH / 2;
stage->cameraHeight = 140;
stage->worldScale = 64; // scale

stage->unk5D0 = 40; // perspective scale?
stage->cameraPitch = 40; // lower = towards the ground, higher = towards the horizon

stage->unk5D1 = 60; // horizon (pixels)
stage->horizonHeight = 60; // horizon (pixels)

// wtf, all this stuff is const
target = 49;
stage->unk5D2 = target;
// This value is 49 on the GBA
// - (horizonHeight / 2) - 1 is just a guess
viewDistance = (DISPLAY_HEIGHT / 2) - (60 / 2) - 1;
stage->viewDistance = viewDistance;

for (i = 1; i < stage->unk5D2; i *= 2)
// Round up to the nearest power of 2
for (i = 1; i < stage->viewDistance; i *= 2)
;

stage->unk5D2 = i;
stage->unk5D3 = (((DISPLAY_HEIGHT - 1) - stage->unk5D1) >> 1) + stage->unk5D1;
stage->viewDistance = i;
stage->unk5D3 = (((DISPLAY_HEIGHT - 1) - stage->horizonHeight) >> 1) + stage->horizonHeight;
}

static void SetupIntroScreenRegisters(void)
Expand Down Expand Up @@ -347,7 +350,7 @@ void Task_FadeToResultScreen(void)
stage->uiTask = NULL;
}

sub_806CEC4(&stage->unk48, 0, 7, 0x8B, 0x20, 0x20, 0, 1, 0, 0);
SpecialStageDrawBackground(&stage->unk48, 0, 7, TM_TILEMAP_139, 0x20, 0x20, 0, 1, 0, 0);
gBgScrollRegs[1][0] = 0;
gBgScrollRegs[1][1] = 0;
gDispCnt = 0x1240;
Expand Down
8 changes: 4 additions & 4 deletions src/game/special_stage/physics.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ static void Task_PhysicsMain(void)
}

sub_806FAA0();
stage->qCameraX = player->q16WorldX;
stage->qCameraY = player->q16WorldY;
stage->cameraBearing = player->bearing;
stage->q16CameraX = player->q16WorldX;
stage->q16CameraY = player->q16WorldY;
stage->cameraRotX = player->bearing;

gBgScrollRegs[2][1] = -Q_16_16_TO_INT(player->q16WorldY);
gBgScrollRegs[2][0] = -Q_16_16_TO_INT(player->q16WorldX);
Expand Down Expand Up @@ -218,7 +218,7 @@ void HandleRotationControls(void)
}

player->bearing = bearing;
player->bearing &= 0x3FF;
player->bearing &= ONE_CYCLE;
}
}

Expand Down
Loading

0 comments on commit 28f5f0f

Please sign in to comment.