Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Helpers/DrawHelpers.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: DrawHelpers Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectDrawHelpers *DrawHelpers = NULL;
11
12
void DrawHelpers_Update(void) {}
13
14
void DrawHelpers_LateUpdate(void) {}
15
16
void DrawHelpers_StaticUpdate(void) {}
17
18
void DrawHelpers_Draw(void) {}
19
20
void DrawHelpers_Create(void *data) {}
21
22
void DrawHelpers_StageLoad(void) {}
23
24
void DrawHelpers_DrawHitboxOutline(int32 x, int32 y, Hitbox *hitbox, uint8 direction, uint32 color)
25
{
26
int16 left, top, right, bottom;
27
28
if (direction & FLIP_X) {
29
right = -hitbox->right;
30
left = -hitbox->left;
31
}
32
else {
33
left = hitbox->left;
34
right = hitbox->right;
35
}
36
37
if (direction & FLIP_Y) {
38
top = -hitbox->top;
39
bottom = -hitbox->bottom;
40
}
41
else {
42
top = hitbox->top;
43
bottom = hitbox->bottom;
44
}
45
46
RSDK.DrawLine(x + (left << 16), y + (top << 16), x + (right << 16), y + (top << 16), color, 0xFF, INK_NONE, false);
47
RSDK.DrawLine(x + (right << 16), y + (top << 16), x + (right << 16), y + (bottom << 16), color, 0xFF, INK_NONE, false);
48
RSDK.DrawLine(x + (right << 16), y + (bottom << 16), x + (left << 16), y + (bottom << 16), color, 0xFF, INK_NONE, false);
49
RSDK.DrawLine(x + (left << 16), y + (bottom << 16), x + (left << 16), y + (top << 16), color, 0xFF, INK_NONE, false);
50
}
51
52
void DrawHelpers_DrawArrowAdditive(int32 x1, int32 y1, int32 x2, int32 y2, uint32 color)
53
{
54
int32 angle = RSDK.ATan2(x1 - x2, y1 - y2);
55
RSDK.DrawLine(x1, y1, x2, y2, color, 0x7F, INK_ADD, false);
56
RSDK.DrawLine(x2, y2, x2 + (RSDK.Cos256(angle + 12) << 12), y2 + (RSDK.Sin256(angle + 12) << 12), color, 0x7F, INK_ADD, false);
57
RSDK.DrawLine(x2, y2, x2 + (RSDK.Cos256(angle - 12) << 12), y2 + (RSDK.Sin256(angle - 12) << 12), color, 0x7F, INK_ADD, false);
58
}
59
60
void DrawHelpers_DrawIsocelesTriangle(int32 x1, int32 y1, int32 x2, int32 y2, int32 edgeSize, uint32 color, uint32 inkEffect, uint32 alpha)
61
{
62
Vector2 verts[3];
63
64
int32 angle = RSDK.ATan2(x2 - x1, y2 - y1);
65
66
verts[0].x = x2;
67
verts[0].y = y2;
68
verts[1].x = x1 + (edgeSize << 7) * RSDK.Cos256(angle + 64);
69
verts[1].y = y1 + (edgeSize << 7) * RSDK.Sin256(angle + 64);
70
verts[2].x = x1 + (edgeSize << 7) * RSDK.Cos256(angle - 64);
71
verts[2].y = y1 + (edgeSize << 7) * RSDK.Sin256(angle - 64);
72
73
if (SceneInfo->inEditor) {
74
RSDK.DrawLine(x2, y2, verts[1].x, verts[1].y, color, 255, INK_NONE, false);
75
RSDK.DrawLine(verts[1].x, verts[1].y, verts[2].x, verts[2].y, color, 255, INK_NONE, false);
76
RSDK.DrawLine(verts[2].x, verts[2].y, x2, y2, color, 255, INK_NONE, false);
77
}
78
else {
79
int32 screenX = ScreenInfo->position.x << 16;
80
int32 screenY = ScreenInfo->position.y << 16;
81
verts[0].x -= screenX;
82
verts[0].y -= screenY;
83
verts[1].x -= screenX;
84
verts[1].y -= screenY;
85
verts[2].x -= screenX;
86
verts[2].y -= screenY;
87
RSDK.DrawFace(verts, 3, (color >> 16) & 0xFF, (color >> 8) & 0xFF, (color >> 0) & 0xFF, alpha, inkEffect);
88
}
89
}
90
91
void DrawHelpers_DrawCross(int32 x, int32 y, int32 sizeX, int32 sizeY, uint32 color)
92
{
93
if (x || y) {
94
RSDK.DrawLine(x - (sizeX >> 1), y - (sizeY >> 1), x + (sizeX >> 1), y + (sizeY >> 1), color, 0x7F, INK_NONE, false);
95
RSDK.DrawLine(x + (sizeX >> 1), y - (sizeY >> 1), x - (sizeX >> 1), y + (sizeY >> 1), color, 0x7F, INK_NONE, false);
96
}
97
}
98
99
// Custom ones!!
100
101
// Adds alpha & ink effect in params for extra customizability
102
void DrawHelpers_DrawArrow(int32 x1, int32 y1, int32 x2, int32 y2, uint32 color, uint32 inkEffect, uint32 alpha)
103
{
104
int32 angle = RSDK.ATan2(x1 - x2, y1 - y2);
105
RSDK.DrawLine(x1, y1, x2, y2, color, alpha, inkEffect, false);
106
RSDK.DrawLine(x2, y2, x2 + (RSDK.Cos256(angle + 12) << 12), y2 + (RSDK.Sin256(angle + 12) << 12), color, alpha, inkEffect, false);
107
RSDK.DrawLine(x2, y2, x2 + (RSDK.Cos256(angle - 12) << 12), y2 + (RSDK.Sin256(angle - 12) << 12), color, alpha, inkEffect, false);
108
}
109
110
void DrawHelpers_DrawRectOutline(int32 x, int32 y, int32 sizeX, int32 sizeY, uint32 color)
111
{
112
Vector2 drawPos;
113
114
drawPos.x = x - (sizeX >> 1);
115
drawPos.y = y - (sizeY >> 1);
116
RSDK.DrawLine(drawPos.x - TO_FIXED(1), drawPos.y - TO_FIXED(1), drawPos.x + sizeX, drawPos.y - TO_FIXED(1), color, 0x00, INK_NONE, false);
117
RSDK.DrawLine(drawPos.x - TO_FIXED(1), drawPos.y + sizeY, drawPos.x + sizeX, drawPos.y + sizeY, color, 0x00, INK_NONE, false);
118
RSDK.DrawLine(drawPos.x - TO_FIXED(1), drawPos.y - TO_FIXED(1), drawPos.x - TO_FIXED(1), drawPos.y + sizeY, color, 0x00, INK_NONE, false);
119
RSDK.DrawLine(drawPos.x + sizeX, drawPos.y - TO_FIXED(1), drawPos.x + sizeX, drawPos.y + sizeY, color, 0x00, INK_NONE, false);
120
}
121
122
void DrawHelpers_DrawArenaBounds(int32 left, int32 top, int32 right, int32 bottom, uint8 sideMasks, uint32 color)
123
{
124
RSDK_THIS_GEN();
125
126
left <<= 16;
127
top <<= 16;
128
right <<= 16;
129
bottom <<= 16;
130
131
// left
132
if (sideMasks & 1) {
133
RSDK.DrawLine(self->position.x + left, self->position.y + top, self->position.x + left, self->position.y + bottom, color, 0, INK_NONE, false);
134
}
135
136
// top
137
if (sideMasks & 2) {
138
RSDK.DrawLine(self->position.x + left, self->position.y + top, self->position.x + right, self->position.y + top, color, 0, INK_NONE, false);
139
}
140
141
// right
142
if (sideMasks & 4) {
143
RSDK.DrawLine(self->position.x + right, self->position.y + top, self->position.x + right, self->position.y + bottom, color, 0, INK_NONE,
144
false);
145
}
146
147
// bottom
148
if (sideMasks & 8) {
149
RSDK.DrawLine(self->position.x + left, self->position.y + bottom, self->position.x + right, self->position.y + bottom, color, 0, INK_NONE,
150
false);
151
}
152
}
153
154
#if GAME_INCLUDE_EDITOR
155
void DrawHelpers_EditorDraw(void) {}
156
157
void DrawHelpers_EditorLoad(void) {}
158
#endif
159
160
void DrawHelpers_Serialize(void) {}
161
162