1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
#include <ultra64.h>
#include <global.h>
extern LightsList sLightsList;
void Lights_InitPositionalLight(LightInfoPositional* info, s16 posX, s16 posY, s16 posZ, u8 red, u8 green, u8 blue,
s16 radius, u32 type) {
info->type = type;
info->params.posX = posX;
info->params.posY = posY;
info->params.posZ = posZ;
Lights_SetPositionalLightColorAndRadius(info, red, green, blue, radius);
}
void Lights_InitType0PositionalLight(LightInfoPositional* info, s16 posX, s16 posY, s16 posZ, u8 red, u8 green, u8 blue,
s16 radius) {
Lights_InitPositionalLight(info, posX, posY, posZ, red, green, blue, radius, 0);
}
void Lights_InitType2PositionalLight(LightInfoPositional* info, s16 posX, s16 posY, s16 posZ, u8 red, u8 green, u8 blue,
s16 radius) {
Lights_InitPositionalLight(info, posX, posY, posZ, red, green, blue, radius, 2);
}
void Lights_SetPositionalLightColorAndRadius(LightInfoPositional* info, u8 red, u8 green, u8 blue, s16 radius) {
info->params.red = red;
info->params.green = green;
info->params.blue = blue;
info->params.radius = radius;
}
void Lights_InitDirectional(LightInfoDirectional* info, s8 dirX, s8 dirY, s8 dirZ, u8 red, u8 green, u8 blue) {
info->type = 1;
info->params.dirX = dirX;
info->params.dirY = dirY;
info->params.dirZ = dirZ;
info->params.red = red;
info->params.green = green;
info->params.blue = blue;
}
void Lights_MapperInit(LightMapper* mapper, u8 red, u8 green, u8 blue) {
mapper->ambient.l.col[0] = red;
mapper->ambient.l.colc[0] = red;
mapper->ambient.l.col[1] = green;
mapper->ambient.l.colc[1] = green;
mapper->ambient.l.col[2] = blue;
mapper->ambient.l.colc[2] = blue;
mapper->numLights = 0;
}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_80079EFC.s")
Light* Lights_MapperGetNextFreeSlot(LightMapper* mapper) {
if (6 < mapper->numLights) {
return NULL;
}
return &mapper->lights[mapper->numLights++];
}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_8007A084.s")
void func_8007A40C(LightMapper* mapper, LightInfoDirectionalParams* params, GlobalContext* globalCtx) {
Light* light = Lights_MapperGetNextFreeSlot(mapper);
if (light != NULL) {
light->l.col[0] = light->l.colc[0] = params->red;
light->l.col[1] = light->l.colc[1] = params->green;
light->l.col[2] = light->l.colc[2] = params->blue;
light->l.dir[0] = params->dirX;
light->l.dir[1] = params->dirY;
light->l.dir[2] = params->dirZ;
}
}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_8007A474.s")
z_Light* Lights_FindFreeSlot() {
z_Light* ret;
if (0x1F < sLightsList.numOccupied) {
return NULL;
}
ret = &sLightsList.lights[sLightsList.nextFree];
while (ret->info != NULL) {
sLightsList.nextFree++;
if (sLightsList.nextFree < 0x20) {
ret++;
} else {
sLightsList.nextFree = 0;
ret = &sLightsList.lights[0];
}
}
sLightsList.numOccupied++;
return ret;
}
#ifdef NON_MATCHING
// single ordering difference
void Lights_Free(z_Light* light) {
if (light != NULL) {
sLightsList.numOccupied--;
light->info = NULL;
sLightsList.nextFree = (light - sLightsList.lights) /
sizeof(z_Light); //! @bug Due to pointer arithmetic, the division is unnecessary
}
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/Lights_Free.s")
#endif
void func_8007A614(GlobalContext* globalCtx, LightingContext* lightCtx) {
Lights_ClearHead(globalCtx, lightCtx);
Lights_SetAmbientColor(lightCtx, 0x50, 0x50, 0x50);
func_8007A698(lightCtx, 0, 0, 0, 0x3e4, 0x3200);
bzero(&sLightsList, sizeof(sLightsList));
}
void Lights_SetAmbientColor(LightingContext* lightCtx, u8 red, u8 green, u8 blue) {
lightCtx->ambientRed = red;
lightCtx->ambientGreen = green;
lightCtx->ambientBlue = blue;
}
void func_8007A698(LightingContext* lightCtx, u8 arg1, u8 arg2, u8 arg3, s16 arg4, s16 arg5) {
lightCtx->unk_07 = arg1;
lightCtx->unk_08 = arg2;
lightCtx->unk_09 = arg3;
lightCtx->unk_0A = arg4;
lightCtx->unk_0C = arg5;
}
LightMapper* Lights_CreateMapper(LightingContext* lightCtx, GraphicsContext* gfxCtx) {
return func_8007A960(gfxCtx, lightCtx->ambientRed, lightCtx->ambientGreen, lightCtx->ambientBlue);
}
void Lights_ClearHead(GlobalContext* globalCtx, LightingContext* lightCtx) {
lightCtx->lightsHead = NULL;
}
void Lights_RemoveAll(GlobalContext* globalCtx, LightingContext* lightCtx) {
while (lightCtx->lightsHead != NULL) {
Lights_Remove(globalCtx, lightCtx, lightCtx->lightsHead);
lightCtx->lightsHead = lightCtx->lightsHead->next;
}
}
z_Light* Lights_Insert(GlobalContext* globalCtx, LightingContext* lightCtx, LightInfo* info) {
z_Light* light;
light = Lights_FindFreeSlot();
if (light != NULL) {
light->info = info;
light->prev = NULL;
light->next = lightCtx->lightsHead;
if (lightCtx->lightsHead != NULL) {
lightCtx->lightsHead->prev = light;
}
lightCtx->lightsHead = light;
}
return light;
}
void Lights_Remove(GlobalContext* globalCtx, LightingContext* lightCtx, z_Light* light) {
if (light != NULL) {
if (light->prev != NULL) {
light->prev->next = light->next;
} else {
lightCtx->lightsHead = light->next;
}
if (light->next != NULL) {
light->next->prev = light->prev;
}
Lights_Free(light);
}
}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_8007A824.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_8007A960.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_8007A9B4.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_8007ABBC.s")
|