1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 05:19:36 +00:00
oot/src/code/z_lights.c

196 lines
5.9 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <ultra64.h>
#include <global.h>
extern LightsList sLightsList;
2020-03-22 21:19:43 +00:00
void Lights_InitPositionalLight(LightInfoPositional* info, s16 posX, s16 posY, s16 posZ, u8 red, u8 green, u8 blue,
s16 radius, u32 type) {
2020-03-17 04:31:30 +00:00
info->type = type;
info->params.posX = posX;
info->params.posY = posY;
info->params.posZ = posZ;
Lights_SetPositionalLightColorAndRadius(info, red, green, blue, radius);
}
2020-03-22 21:19:43 +00:00
void Lights_InitType0PositionalLight(LightInfoPositional* info, s16 posX, s16 posY, s16 posZ, u8 red, u8 green, u8 blue,
s16 radius) {
2020-03-17 04:31:30 +00:00
Lights_InitPositionalLight(info, posX, posY, posZ, red, green, blue, radius, 0);
}
2020-03-22 21:19:43 +00:00
void Lights_InitType2PositionalLight(LightInfoPositional* info, s16 posX, s16 posY, s16 posZ, u8 red, u8 green, u8 blue,
s16 radius) {
2020-03-17 04:31:30 +00:00
Lights_InitPositionalLight(info, posX, posY, posZ, red, green, blue, radius, 2);
}
2020-03-22 21:19:43 +00:00
void Lights_SetPositionalLightColorAndRadius(LightInfoPositional* info, u8 red, u8 green, u8 blue, s16 radius) {
2020-03-17 04:31:30 +00:00
info->params.red = red;
info->params.green = green;
info->params.blue = blue;
info->params.radius = radius;
}
2020-03-22 21:19:43 +00:00
void Lights_InitDirectional(LightInfoDirectional* info, s8 dirX, s8 dirY, s8 dirZ, u8 red, u8 green, u8 blue) {
2020-03-17 04:31:30 +00:00
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;
}
2020-03-22 21:19:43 +00:00
void Lights_MapperInit(LightMapper* mapper, u8 red, u8 green, u8 blue) {
2020-03-17 04:31:30 +00:00
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")
2020-03-22 21:19:43 +00:00
Light* Lights_MapperGetNextFreeSlot(LightMapper* mapper) {
if (6 < mapper->numLights) {
2020-03-17 04:31:30 +00:00
return NULL;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
return &mapper->lights[mapper->numLights++];
}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/func_8007A084.s")
2020-03-22 21:19:43 +00:00
void func_8007A40C(LightMapper* mapper, LightInfoDirectionalParams* params, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
Light* light = Lights_MapperGetNextFreeSlot(mapper);
2020-03-22 21:19:43 +00:00
if (light != NULL) {
2020-03-17 04:31:30 +00:00
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")
2020-03-22 21:19:43 +00:00
z_Light* Lights_FindFreeSlot() {
2020-03-17 04:31:30 +00:00
z_Light* ret;
2020-03-22 21:19:43 +00:00
if (0x1F < sLightsList.numOccupied) {
2020-03-17 04:31:30 +00:00
return NULL;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
ret = &sLightsList.lights[sLightsList.nextFree];
2020-03-22 21:19:43 +00:00
while (ret->info != NULL) {
2020-03-17 04:31:30 +00:00
sLightsList.nextFree++;
2020-03-22 21:19:43 +00:00
if (sLightsList.nextFree < 0x20) {
2020-03-17 04:31:30 +00:00
ret++;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
sLightsList.nextFree = 0;
ret = &sLightsList.lights[0];
}
}
sLightsList.numOccupied++;
return ret;
}
#ifdef NON_MATCHING
// single ordering difference
2020-03-22 21:19:43 +00:00
void Lights_Free(z_Light* light) {
if (light != NULL) {
2020-03-17 04:31:30 +00:00
sLightsList.numOccupied--;
light->info = NULL;
2020-03-22 21:19:43 +00:00
sLightsList.nextFree = (light - sLightsList.lights) /
sizeof(z_Light); //! @bug Due to pointer arithmetic, the division is unnecessary
2020-03-17 04:31:30 +00:00
}
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_lights/Lights_Free.s")
#endif
2020-03-22 21:19:43 +00:00
void func_8007A614(GlobalContext* globalCtx, LightingContext* lightCtx) {
2020-03-17 04:31:30 +00:00
Lights_ClearHead(globalCtx, lightCtx);
Lights_SetAmbientColor(lightCtx, 0x50, 0x50, 0x50);
func_8007A698(lightCtx, 0, 0, 0, 0x3e4, 0x3200);
bzero(&sLightsList, sizeof(sLightsList));
}
2020-03-22 21:19:43 +00:00
void Lights_SetAmbientColor(LightingContext* lightCtx, u8 red, u8 green, u8 blue) {
2020-03-17 04:31:30 +00:00
lightCtx->ambientRed = red;
lightCtx->ambientGreen = green;
lightCtx->ambientBlue = blue;
}
2020-03-22 21:19:43 +00:00
void func_8007A698(LightingContext* lightCtx, u8 arg1, u8 arg2, u8 arg3, s16 arg4, s16 arg5) {
2020-03-17 04:31:30 +00:00
lightCtx->unk_07 = arg1;
lightCtx->unk_08 = arg2;
lightCtx->unk_09 = arg3;
lightCtx->unk_0A = arg4;
lightCtx->unk_0C = arg5;
}
2020-03-22 21:19:43 +00:00
LightMapper* Lights_CreateMapper(LightingContext* lightCtx, GraphicsContext* gfxCtx) {
2020-03-17 04:31:30 +00:00
return func_8007A960(gfxCtx, lightCtx->ambientRed, lightCtx->ambientGreen, lightCtx->ambientBlue);
}
2020-03-22 21:19:43 +00:00
void Lights_ClearHead(GlobalContext* globalCtx, LightingContext* lightCtx) {
2020-03-17 04:31:30 +00:00
lightCtx->lightsHead = NULL;
}
2020-03-22 21:19:43 +00:00
void Lights_RemoveAll(GlobalContext* globalCtx, LightingContext* lightCtx) {
while (lightCtx->lightsHead != NULL) {
2020-03-17 04:31:30 +00:00
Lights_Remove(globalCtx, lightCtx, lightCtx->lightsHead);
lightCtx->lightsHead = lightCtx->lightsHead->next;
}
}
2020-03-22 21:19:43 +00:00
z_Light* Lights_Insert(GlobalContext* globalCtx, LightingContext* lightCtx, LightInfo* info) {
2020-03-17 04:31:30 +00:00
z_Light* light;
light = Lights_FindFreeSlot();
2020-03-22 21:19:43 +00:00
if (light != NULL) {
2020-03-17 04:31:30 +00:00
light->info = info;
light->prev = NULL;
light->next = lightCtx->lightsHead;
2020-03-22 21:19:43 +00:00
if (lightCtx->lightsHead != NULL) {
2020-03-17 04:31:30 +00:00
lightCtx->lightsHead->prev = light;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
lightCtx->lightsHead = light;
}
return light;
}
2020-03-22 21:19:43 +00:00
void Lights_Remove(GlobalContext* globalCtx, LightingContext* lightCtx, z_Light* light) {
if (light != NULL) {
if (light->prev != NULL) {
2020-03-17 04:31:30 +00:00
light->prev->next = light->next;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
lightCtx->lightsHead = light->next;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if (light->next != NULL) {
2020-03-17 04:31:30 +00:00
light->next->prev = light->prev;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
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")