summaryrefslogtreecommitdiff
path: root/src/manager/lightRayManager.c
diff options
context:
space:
mode:
authoroctorock <79596758+octorock@users.noreply.github.com>2022-05-01 11:43:19 +0200
committeroctorock <79596758+octorock@users.noreply.github.com>2022-05-18 13:07:06 +0200
commit60e33b636d7b9dca767b3833ee39affcc626f420 (patch)
tree51d7752fb76f5044028c56404f75c780783d8002 /src/manager/lightRayManager.c
parent3afbd0e9012be95e687ccb36eb62f6df08cded19 (diff)
Rename managers
Diffstat (limited to 'src/manager/lightRayManager.c')
-rw-r--r--src/manager/lightRayManager.c272
1 files changed, 272 insertions, 0 deletions
diff --git a/src/manager/lightRayManager.c b/src/manager/lightRayManager.c
new file mode 100644
index 00000000..a738f620
--- /dev/null
+++ b/src/manager/lightRayManager.c
@@ -0,0 +1,272 @@
+/**
+ * @file lightRayManager.c
+ * @ingroup Managers
+ *
+ * @brief Creates and updates light rays.
+ *
+ * Light rays at the left of minish woods
+ * Light rays in the barrel minish house
+ */
+#include "manager/lightRayManager.h"
+#include "common.h"
+#include "functions.h"
+#include "main.h"
+#include "screen.h"
+
+extern void sub_08056250(void);
+
+void (*const gUnk_08107C5C[])(LightRayManager*);
+void (*const gUnk_08107C48[])(LightRayManager*);
+const u16 gUnk_08107C1C[];
+const u16 gUnk_08107C30[];
+const u8 gLightRayManagerGfxGroups[];
+
+extern u16 gUnk_02017AA0[];
+extern u16 gUnk_085B4180[];
+
+typedef struct {
+ u8 unk0;
+ u8 unk1;
+ u8 unk2;
+ u8 unk3;
+ u8 unk4;
+} PACKED LightRayManagerProp;
+
+#define ZS(this) ((u8*)&this->speed)
+
+void LightRayManager_Main(LightRayManager* this) {
+ u8 bVar1;
+ u8* pbVar2;
+
+ gUnk_08107C5C[super->action](this);
+ gUnk_08107C48[this->unk_21](this);
+ bVar1 = gLightRayManagerGfxGroups[this->unk_21];
+ if ((bVar1 != 0) && (this->unk_20 != bVar1)) {
+ this->unk_20 = bVar1;
+ LoadGfxGroup(bVar1);
+ }
+}
+
+static void sub_080570B8(LightRayManager* this) {
+ u8* pbVar1;
+
+ LoadGfxGroup(this->unk_20);
+ this->unk_34 = NULL;
+ pbVar1 = &this->unk_21;
+ if (*pbVar1 == 3) {
+ gScreen.bg3.updated = 1;
+ } else {
+ gUnk_08107C48[*pbVar1](this);
+ }
+}
+
+static void sub_080570F8(void) {
+ gScreen.lcd.displayControl &= ~DISPCNT_BG3_ON;
+ gScreen.controls.layerFXControl = 0;
+ sub_08056250();
+}
+
+void sub_08057118(LightRayManager* this) {
+ super->timer = 0;
+ this->unk_20 = 0;
+ this->unk_21 = 0;
+ this->unk_22 = 0;
+ super->action = 1;
+ gScreen.bg3.control = 0x1e04;
+ gScreen.lcd.displayControl |= DISPCNT_BG3_ON;
+ gScreen.controls.layerFXControl = 0x3648;
+ gScreen.controls.alphaBlend = 0x1000;
+ RegisterTransitionManager(this, sub_080570B8, sub_080570F8);
+}
+
+// regalloc
+NONMATCH("asm/non_matching/lightRayManager/sub_08057174.inc", void sub_08057174(LightRayManager* this)) {
+ LightRayManagerProp* prop = GetCurrentRoomProperty(super->type);
+ s32 temp;
+ s32 x;
+ s32 y;
+
+ if (prop->unk0 == 0xff)
+ return;
+ temp = gPlayerEntity.x.HALF.HI;
+ if (temp < 0) {
+ temp += 0xf;
+ }
+
+ x = temp >> 4;
+ temp = gPlayerEntity.y.HALF.HI;
+ if (temp < 0) {
+ temp += 0xf;
+ }
+
+ y = temp >> 4;
+
+ for (; prop->unk0 != 0xff; prop++) {
+ if (prop->unk0 != this->unk_21) {
+ u32 x2 = (gRoomControls.origin_x >> 4) + prop->unk1;
+ u32 y2 = (gRoomControls.origin_y >> 4) + prop->unk2;
+
+ if (y - y2 < prop->unk4 && x - x2 < prop->unk3) {
+ switch (prop->unk0) {
+ case 1:
+ if (this->unk_21 == 2) {
+ super->action = 3;
+ super->timer = 9;
+ }
+ break;
+ case 5:
+ if (this->unk_21 == 6) {
+ super->action = 3;
+ super->timer = 9;
+ }
+ break;
+ case 2:
+ if (this->unk_21 == 0) {
+ super->action = 2;
+ super->timer = 0;
+ this->unk_20 = 0;
+ }
+ break;
+ case 6:
+ if (this->unk_21 == 0) {
+ super->action = 2;
+ super->timer = 0;
+ }
+ break;
+ case 4:
+ if (this->unk_21 == 0) {
+ super->action = 2;
+ super->timer = 0;
+ this->unk_34 = NULL;
+ }
+ break;
+ case 3:
+ if (this->unk_21 == 4) {
+ super->action = 3;
+ super->timer = 9;
+ }
+ break;
+ }
+
+ if (super->action != 1) {
+ super->subtimer = 8;
+ this->unk_21 = prop->unk0;
+ this->unk_22 = 1;
+ return;
+ }
+ }
+ }
+ }
+}
+END_NONMATCH
+
+void sub_0805728C(LightRayManager* this) {
+ if (--super->subtimer == 0) {
+ super->subtimer = 8;
+ gScreen.controls.alphaBlend = gUnk_08107C1C[super->timer++];
+
+ if (super->timer == 10) {
+ super->action = 1;
+ this->unk_22 = 0;
+ }
+ }
+}
+
+void sub_080572D4(LightRayManager* this) {
+ if (--super->subtimer == 0) {
+ super->subtimer = 8;
+ gScreen.controls.alphaBlend = gUnk_08107C1C[super->timer--];
+
+ if (super->timer == 0xff) {
+ super->action = 1;
+ this->unk_22 = 0;
+ this->unk_21 = 0;
+ gScreen._6c = 0;
+ }
+ }
+}
+
+void sub_0805732C(u32 param_1, u32 param_2) {
+ u32 index;
+ u16* ptr = &gUnk_02017AA0[gUnk_03003DE4[0] * 0x500];
+
+ for (index = 0; index < 0xa0; ptr++, index++) {
+ *ptr = gSineTable[(param_2 + index) & 0xff] * param_1 / 0x100 + gScreen.bg3.xOffset;
+ }
+
+ sub_0805622C((struct BgAffineDstData*)&gUnk_02017AA0[gUnk_03003DE4[0] * 0x500], REG_ADDR_BG3HOFS, 0xa2600001UL);
+}
+
+void nullsub_494() {
+}
+
+void sub_080573AC(LightRayManager* this) {
+ s32 sin, frameCount;
+ gRoomControls.bg3OffsetX.WORD -= 0x2000;
+ gRoomControls.bg3OffsetY.WORD -= 0x1000;
+ gScreen.bg3.xOffset = ((gRoomControls.scroll_x - gRoomControls.origin_x) >> 1) + gRoomControls.bg3OffsetX.HALF.HI;
+ gScreen.bg3.yOffset = ((gRoomControls.scroll_y - gRoomControls.origin_y) >> 1) + gRoomControls.bg3OffsetY.HALF.HI;
+ sin = gSineTable[(gRoomTransition.frameCount & 0xff) + 0x40];
+ sub_0805732C((sin >> 5) + 0x10, gRoomTransition.frameCount);
+ if (this->unk_22 == 0) {
+ if ((gRoomTransition.frameCount & 0x1f) == 0) {
+ this->unk_24 = (this->unk_24 + 1) & 7;
+ gScreen.controls.alphaBlend = gUnk_08107C30[this->unk_24];
+ }
+ }
+}
+
+void sub_08057450(LightRayManager* this) {
+ s32 y;
+ gScreen.bg3.xOffset = 0x10;
+ y = gRoomControls.scroll_y;
+ y -= gRoomControls.origin_y;
+ y >>= 2;
+
+ gScreen.bg3.yOffset = y & 0x3f;
+ gScreen.bg3.tilemap = &gBG3Buffer[(y / 0x40) << 8];
+ if (this->unk_34 != gScreen.bg3.tilemap) {
+ this->unk_34 = gScreen.bg3.tilemap;
+ gScreen.bg3.updated = 1;
+ }
+
+ if (this->unk_22 == 0 && (gRoomTransition.frameCount & 0x1f) == 0) {
+ this->unk_24 = (this->unk_24 + 1) & 7;
+ gScreen.controls.alphaBlend = gUnk_08107C30[this->unk_24];
+ }
+
+ if ((gRoomTransition.frameCount & 0x7) == 0) {
+ u32 index;
+ u16* ptr = &gUnk_085B4180[(this->unk_23 << 4)];
+
+ for (index = 0, ptr = ptr + 7; index <= 3; index++) {
+ SetColor(index + 0x87, *(ptr + index));
+ SetColor(index + 0x8c, *(ptr + index + 5));
+ }
+
+ this->unk_23 = (this->unk_23 + 1) & 3;
+ }
+}
+
+const u16 gUnk_08107C1C[] = {
+ 0x1000, 0xF01, 0xE02, 0xD03, 0xC04, 0xB05, 0xA06, 0x907, 0x908, 0x909,
+};
+
+const u16 gUnk_08107C30[] = {
+ 0x909, 0xA08, 0xB07, 0xC06, 0xD05, 0xC06, 0xB07, 0xA08,
+};
+
+const u8 gLightRayManagerGfxGroups[] = {
+ 0x25, 0x00, 0x24, 0x00, 0x25, 0x00, 0x00, 0x00,
+};
+
+void (*const gUnk_08107C48[])(LightRayManager*) = {
+ nullsub_494, nullsub_494, sub_080573AC, nullsub_494, sub_08057450,
+};
+
+void (*const gUnk_08107C5C[])(LightRayManager*) = {
+ sub_08057118,
+ sub_08057174,
+ sub_0805728C,
+ sub_080572D4,
+};