Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Common/BGSwitch.c
413 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: BGSwitch Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectBGSwitch *BGSwitch;
11
12
void BGSwitch_Update(void)
13
{
14
RSDK_THIS(BGSwitch);
15
16
for (BGSwitch->screenID = 0; BGSwitch->screenID < SCREEN_COUNT; BGSwitch->screenID++) {
17
EntityCamera *camera = RSDK_GET_ENTITY(SLOT_CAMERA1 + BGSwitch->screenID, Camera);
18
if (!camera->classID)
19
break;
20
21
if (abs(camera->position.x - self->position.x) < self->size.x && abs(camera->position.y - self->position.y) < self->size.y) {
22
if (self->bgID < LAYER_COUNT)
23
BGSwitch->layerIDs[BGSwitch->screenID] = self->bgID;
24
}
25
26
int32 id = BGSwitch->layerIDs[BGSwitch->screenID];
27
if (id != BGSwitch->layerIDs[BGSwitch->screenID + 4]) {
28
BGSwitch->layerIDs[BGSwitch->screenID + 4] = id;
29
StateMachine_Run(BGSwitch->switchCallback[id]);
30
}
31
}
32
}
33
34
void BGSwitch_LateUpdate(void) {}
35
36
void BGSwitch_StaticUpdate(void) {}
37
38
void BGSwitch_Draw(void) {}
39
40
void BGSwitch_Create(void *data)
41
{
42
RSDK_THIS(BGSwitch);
43
44
if (!SceneInfo->inEditor) {
45
self->updateRange.x = self->size.x;
46
self->updateRange.y = self->size.y;
47
self->active = ACTIVE_BOUNDS;
48
}
49
}
50
51
void BGSwitch_StageLoad(void)
52
{
53
BGSwitch->layerIDs[4] = -1;
54
BGSwitch->layerIDs[5] = -1;
55
BGSwitch->layerIDs[6] = -1;
56
BGSwitch->layerIDs[7] = -1;
57
}
58
59
#if GAME_INCLUDE_EDITOR
60
void BGSwitch_EditorDraw(void)
61
{
62
RSDK_THIS(BGSwitch);
63
64
self->updateRange.x = self->size.x;
65
self->updateRange.y = self->size.y;
66
67
RSDK.SetSpriteAnimation(BGSwitch->aniFrames, 0, &self->animator, true, 5);
68
RSDK.DrawSprite(&self->animator, NULL, false);
69
70
if (showGizmos()) {
71
// Bounds
72
RSDK_DRAWING_OVERLAY(true);
73
// This is taken from Sonic 3 & Knuckles in Sonic Origins.
74
// Presumably, this is what the editor code actually was. Raw function calls.
75
// Note: I don't think we'd need to use updateRange here? It can be just size like it is in S3K...
76
RSDK.DrawLine(self->position.x - self->updateRange.x, self->position.y - self->updateRange.y, self->position.x + self->updateRange.x, self->position.y - self->updateRange.y, 0xFFFF00, 0xFF, INK_NONE, false);
77
RSDK.DrawLine(self->position.x - self->updateRange.x, self->position.y + self->updateRange.y, self->position.x + self->updateRange.x, self->position.y + self->updateRange.y, 0xFFFF00, 0xFF, INK_NONE, false);
78
RSDK.DrawLine(self->position.x - self->updateRange.x, self->position.y - self->updateRange.y, self->position.x - self->updateRange.x, self->position.y + self->updateRange.y, 0xFFFF00, 0xFF, INK_NONE, false);
79
RSDK.DrawLine(self->position.x + self->updateRange.x, self->position.y - self->updateRange.y, self->position.x + self->updateRange.x, self->position.y + self->updateRange.y, 0xFFFF00, 0xFF, INK_NONE, false);
80
RSDK_DRAWING_OVERLAY(false);
81
}
82
}
83
84
void BGSwitch_EditorLoad(void) { BGSwitch->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE); }
85
#endif
86
87
void BGSwitch_Serialize(void)
88
{
89
RSDK_EDITABLE_VAR(BGSwitch, VAR_VECTOR2, size);
90
RSDK_EDITABLE_VAR(BGSwitch, VAR_UINT8, bgID);
91
}
92
93