Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Common/BGSwitch.c
338 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
DrawHelpers_DrawRectOutline(self->position.x, self->position.y, self->size.x, self->size.y, 0xFFFF00);
74
RSDK_DRAWING_OVERLAY(false);
75
}
76
}
77
78
void BGSwitch_EditorLoad(void) { BGSwitch->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE); }
79
#endif
80
81
void BGSwitch_Serialize(void)
82
{
83
RSDK_EDITABLE_VAR(BGSwitch, VAR_VECTOR2, size);
84
RSDK_EDITABLE_VAR(BGSwitch, VAR_UINT8, bgID);
85
}
86
87