Remove artifacts

This commit is contained in:
Ryan Dwyer 2022-11-04 23:45:37 +10:00
parent c22efafb9f
commit 03151c9a3e
7 changed files with 0 additions and 1249 deletions

View File

@ -56,7 +56,6 @@ s32 g_NumActiveRooms;
u16 g_BgUnloadDelay240;
u16 g_BgUnloadDelay240_2;
u32 var800a4bf4;
s16 g_GlareRooms[100];
u32 *g_BgPrimaryData2;
struct bgroom *g_BgRooms;
struct bgportal *g_BgPortals;
@ -81,7 +80,6 @@ u32 var80082474nb = 0;
s16 var8007fc0c = 0;
s16 var8007fc10 = 0;
s32 g_NumRoomsWithGlares = 0;
u32 var8007fc18 = 0x01000100;
u32 var8007fc1c = 0x00000000;
s32 g_CamRoom = 0x00000001;
@ -1350,8 +1348,6 @@ Gfx *bgRenderSceneInXray(Gfx *gdl)
}
}
gdl = skyRenderSuns(gdl, true);
return gdl;
}
@ -1372,8 +1368,6 @@ Gfx *bgRenderScene(Gfx *gdl)
s16 roomorder[60];
s16 roomnums[60];
g_NumRoomsWithGlares = 0;
if (g_Vars.currentplayer->visionmode == VISIONMODE_XRAY) {
gdl = bgRenderSceneInXray(gdl);
return gdl;
@ -1409,8 +1403,6 @@ Gfx *bgRenderScene(Gfx *gdl)
gdl = currentPlayerScissorToViewport(gdl);
gdl = skyRenderSuns(gdl, false);
// Build an array of room numbers per onscreen prop.
// For each onscreen prop there is exactly one entry in the roomnumsbyprop array.
roomnumptr = roomnumsbyprop; \
@ -1531,14 +1523,6 @@ Gfx *bgRenderScene(Gfx *gdl)
gdl = propsRender(gdl, thing->roomnum, RENDERPASS_XLU, roomnumsbyprop);
}
if (!g_Vars.mplayerisrunning) {
artifactsCalculateGlaresForRoom(thing->roomnum);
if (g_NumRoomsWithGlares < 100) {
g_GlareRooms[g_NumRoomsWithGlares++] = thing->roomnum;
}
}
}
return gdl;
@ -2257,25 +2241,6 @@ glabel bgRenderScene
);
#endif
Gfx *bgRenderArtifacts(Gfx *gdl)
{
s32 i;
if (g_Vars.mplayerisrunning == false && g_NumRoomsWithGlares > 0) {
gdl = artifactsConfigureForGlares(gdl);
for (i = 0; i < g_NumRoomsWithGlares; i++) {
gdl = artifactsRenderGlaresForRoom(gdl, g_GlareRooms[i]);
}
gdl = artifactsUnconfigureForGlares(gdl);
}
gdl = skyRenderArtifacts(gdl);
return gdl;
}
void bgLoadFile(void *memaddr, u32 offset, u32 len)
{
if (var8007fc04) {

View File

@ -22,22 +22,6 @@ u32 var800a41a4;
u32 var800a41a8;
u32 var800a41ac;
void artifactsClear(void)
{
struct artifact *artifacts = schedGetWriteArtifacts();
s32 i;
for (i = 0; i < MAX_ARTIFACTS; i++) {
artifacts[i].type = ARTIFACTTYPE_FREE;
}
}
void artifactsTick(void)
{
schedIncrementWriteArtifacts();
schedIncrementFrontArtifacts();
}
u16 func0f13c574(f32 arg0)
{
u32 value = arg0 * 8.0f;
@ -96,248 +80,6 @@ s32 func0f13c710(f32 arg0)
return arg0;
}
void artifactsCalculateGlaresForRoom(s32 roomnum)
{
s32 i;
s32 j;
s32 k;
s32 l;
f32 f0;
s32 numlights;
f32 viewwidth;
f32 viewheight;
f32 viewleft;
f32 viewtop;
u8 *s1;
f32 x;
f32 y;
f32 f16;
f32 f20;
s32 xi;
s32 yi;
f32 sp190;
f32 brightnessfrac;
f32 thisfrac;
f32 tmp;
f32 tmp2;
f32 tmp3;
f32 sp178;
Mtxf sp138;
Mtxf spf8;
struct coord spec;
f32 spdc[4];
struct coord origin;
struct coord spc4;
struct light *roomlights;
s32 index;
struct artifact *artifacts = schedGetWriteArtifacts();
struct coord *campos = &g_Vars.currentplayer->cam_pos;
struct artifact *artifact;
if (g_Rooms[roomnum].gfxdata != NULL && g_Rooms[roomnum].loaded240) {
numlights = g_Rooms[roomnum].gfxdata->numlights;
if (numlights != 0) {
roomlights = (struct light *)&g_BgLightsFileData[g_Rooms[roomnum].gfxdata->lightsindex * 0x22];
s1 = &var800a41a0[g_Rooms[roomnum].gfxdata->lightsindex * 3];
room0f166a6c(&sp138, roomnum);
mtx00015f88(currentPlayerGetScaleBg2Gfx(), &sp138);
mtx4MultMtx4(camGetMtxF006c(), &sp138, &spf8);
viewwidth = viGetViewWidth();
viewheight = viGetViewHeight();
viewleft = viGetViewLeft();
viewtop = viGetViewTop();
for (i = 0; i < numlights; i++) {
origin.x = 0.0f;
origin.y = 0.0f;
origin.z = 0.0f;
for (j = 0; j < 4; j++) {
origin.x += roomlights[i].bbox[j].x;
origin.y += roomlights[i].bbox[j].y;
origin.z += roomlights[i].bbox[j].z;
}
origin.x /= 4.0f;
origin.y /= 4.0f;
origin.z /= 4.0f;
for (j = 0; j != 3; j++) {
spc4.f[j] = origin.f[j] - (campos->f[j] - g_BgRooms[roomnum].pos.f[j]);
}
s1[i * 3 + 1] = 0;
s1[i * 3 + 2] = 0;
tmp = roomlights[i].unk07 * roomlights[i].unk07 + roomlights[i].unk08 * roomlights[i].unk08 + roomlights[i].unk09 * roomlights[i].unk09;
f16 = spc4.f[0] * spc4.f[0] + spc4.f[1] * spc4.f[1] + spc4.f[2] * spc4.f[2];
if (tmp > 0.0001f && f16 > 0.0001f) {
sp190 = -((roomlights[i].unk07 * spc4.f[0] + roomlights[i].unk08 * spc4.f[1] + roomlights[i].unk09 * spc4.f[2]) / sqrtf(tmp * f16));
if (sp190 > 0.4f) {
sp190 = 0.4f;
}
sp190 *= 2.5f;
} else {
sp190 = 0.0f;
}
if (sp190 > 0.0f) {
for (l = 3; l >= 0; l--) {
spdc[l] = origin.f[0] * spf8.m[0][l] + origin.f[1] * spf8.m[1][l] + origin.f[2] * spf8.m[2][l] + spf8.m[3][l];
if (l == 3 && spdc[l] <= 0.0f) {
break;
}
}
if (spdc[3] > 0.0001f) {
f20 = 1.0f / spdc[3];
x = func0f13c710(viewleft + (1.0f + spdc[0] * f20) * (viewwidth * 0.5f));
y = func0f13c710(viewtop + (1.0f - spdc[1] * f20) * (viewheight * 0.5f));
f0 = (spdc[2] * f20 * 511.0f + 511.0f) * 32.0f;
if (f0 < 32576.0f) {
brightnessfrac = 1.0f;
tmp2 = (brightnessfrac - 1.00f);
if (x <= 10.0f + viewleft) {
brightnessfrac = 0.0f;
} else if (y <= 30.0f + viewtop) {
brightnessfrac = 0.0f;
} else if (x >= -10.0f + viewleft + viewwidth) {
brightnessfrac = 0.0f;
} else if (y >= -30.0f + viewtop + viewheight) {
brightnessfrac = 0.0f;
}
sp178 = 1.0f - 2.0f * tmp2;
if (brightnessfrac != 0.0f) {
brightnessfrac = 1.0f;
if (x < viewleft + 90.0f) {
thisfrac = (x - (10.0f + viewleft)) / 80.0f;
if (thisfrac < brightnessfrac) {
brightnessfrac = thisfrac;
}
}
if (y < viewtop + 100.0f) {
thisfrac = (y - (viewtop + 30.0f)) / 70.0f;
if (thisfrac < brightnessfrac) {
brightnessfrac = thisfrac;
}
}
if (x > viewleft + viewwidth - 90.0f) {
thisfrac = (viewleft + viewwidth - 10.0f - x) / 80.0f;
if (thisfrac < brightnessfrac) {
brightnessfrac = thisfrac;
}
}
if (y > viewtop + viewheight - 100.0f) {
thisfrac = (viewtop + viewheight - 30.0f - y) / 70.0f;
if (thisfrac < brightnessfrac) {
brightnessfrac = thisfrac;
}
}
}
tmp3 = 32300.0f - f0;
if (tmp3 < 0.0f) {
tmp3 = 0.0f;
}
if (tmp3 > 1300.0f) {
tmp3 = 1300.0f;
}
tmp3 *= 1.0f / 1300.0f;
if (2.0f * tmp2 > 1.0f) {
sp178 = 0.0f;
}
s1[i * 3 + 1] = sp190 * 255.0f * sp178;
s1[i * 3 + 2] = brightnessfrac * tmp3 * sp190 * 64.0f * 1;
}
}
}
if (s1[i * 3 + 1] > 0) {
for (j = 0; j < 4; j++) {
spec.x = origin.x + (roomlights[i].bbox[j].x - origin.x) * 0.6f;
spec.y = origin.y + (roomlights[i].bbox[j].y - origin.y) * 0.6f;
spec.z = origin.z + (roomlights[i].bbox[j].z - origin.z) * 0.6f;
for (k = 3; k >= 0; k--) {
spdc[k] = spec.f[0] * spf8.m[0][k] + spec.f[1] * spf8.m[1][k] + spec.f[2] * spf8.m[2][k] + spf8.m[3][k];
if (k == 3 && spdc[k] <= 0.0f) {
break;
}
}
if (spdc[3] > 0.0f) {
f20 = 1.0f / spdc[3];
if (f20 > 9999.0f) {
f20 = 9999.0f;
}
if (f20 < -9999.0f) {
f20 = -9999.0f;
}
xi = func0f13c710(viewleft + (1.0f + spdc[0] * f20) * (viewwidth * 0.5f));
yi = func0f13c710(viewtop + (1.0f - spdc[1] * f20) * (viewheight * 0.5f));
f0 = (spdc[2] * f20 * 511.0f + 511.0f) * 32.0f;
if (var800844f0
&& xi >= (s32)viewleft
&& xi < (s32)(viewleft + viewwidth)
&& yi >= (s32)viewtop
&& yi < (s32)(viewtop + viewheight)
&& f0 < 32576.0f) {
index = envGetCurrent()->numsuns;
index *= 8;
artifact = artifacts;
artifact += index;
while (artifact->type != ARTIFACTTYPE_FREE) {
index++;
artifact++;
}
if (index < MAX_ARTIFACTS) {
artifact->unk04 = func0f13c574(f0) >> 2;
artifact->unk08 = &var800844f0[viGetWidth() * yi + xi];
artifact->light = &roomlights[i];
artifact->type = ARTIFACTTYPE_GLARE;
artifact->unk0c.u16_2 = xi;
artifact->unk0c.u16_1 = yi;
}
}
}
}
}
}
}
}
}
u8 func0f13d3c4(u8 arg0, u8 arg1)
{
if (arg1 >= arg0 + 7) {
@ -350,239 +92,3 @@ u8 func0f13d3c4(u8 arg0, u8 arg1)
return arg1;
}
Gfx *artifactsConfigureForGlares(Gfx *gdl)
{
struct stagetableentry *stage = stageGetCurrent();
texSelect(&gdl, &g_TexLightGlareConfigs[stage->light_type], 4, 0, 2, 1, NULL);
gDPSetCycleType(gdl++, G_CYC_1CYCLE);
gDPSetRenderMode(gdl++, G_RM_CLD_SURF, G_RM_CLD_SURF2);
gDPSetTextureFilter(gdl++, G_TF_BILERP);
gDPSetCombineLERP(gdl++,
0, 0, 0, ENVIRONMENT, TEXEL0, 0, ENVIRONMENT, 0,
0, 0, 0, ENVIRONMENT, TEXEL0, 0, ENVIRONMENT, 0);
gDPSetColorDither(gdl++, G_CD_BAYER);
gDPSetAlphaDither(gdl++, G_AD_PATTERN);
gDPSetTexturePersp(gdl++, G_TP_NONE);
return gdl;
}
Gfx *artifactsUnconfigureForGlares(Gfx *gdl)
{
gDPSetTexturePersp(gdl++, G_TP_PERSP);
return gdl;
}
Gfx *artifactsRenderGlaresForRoom(Gfx *gdl, s32 roomnum)
{
s32 i;
s32 j;
s32 lightindex;
struct artifact *artifacts;
u16 min;
u16 max;
f32 f30;
s32 t2;
struct light *light;
u8 *s3;
s32 k;
s32 count;
u16 t4;
f32 add;
s32 l;
f32 brightness;
s32 avg;
f32 f0;
s32 v1;
s32 r;
s32 g;
s32 b;
s32 stack;
u8 colour[4];
s16 lightroompos[3];
struct coord lightworldpos;
struct coord lightscreenpos;
f32 spdc[2];
f32 spd4[2];
f32 f24;
bool extra;
f32 f26;
artifacts = schedGetFrontArtifacts();
f30 = roomGetUnk5c(roomnum);
if (g_Rooms[roomnum].gfxdata == NULL || g_Rooms[roomnum].loaded240 == 0) {
return gdl;
}
for (i = envGetCurrent()->numsuns * 8; i < MAX_ARTIFACTS; i++) {
struct light *light2 = artifacts[i].light;
count = 0;
for (j = i; j < MAX_ARTIFACTS && artifacts[j].type == ARTIFACTTYPE_GLARE && artifacts[j].light == light2; j++) {
count++;
}
light = artifacts[i].light;
if (count > 0) {
if (roomnum == light->roomnum) {
lightindex = ((u32)light - (u32)g_BgLightsFileData) / sizeof(struct light);
s3 = &var800a41a0[lightindex * 3];
t2 = 0;
min = 0xffff;
max = 0;
for (k = i; k < i + count; k++) {
if (artifacts[k].unk04 > max) {
max = artifacts[k].unk04;
}
if (artifacts[k].unk04 < min) {
min = artifacts[k].unk04;
}
}
avg = (max - min) >> 1;
if (avg < 25) {
avg = 25;
}
for (k = i; k < i + count; k++) {
u16 tmp;
t4 = (artifacts[k].unk02 & 0xfffc) >> 2;
tmp = artifacts[k].unk04;
if (tmp < t4) {
v1 = t4 - tmp;
} else {
v1 = tmp - t4;
}
if (avg >= v1) {
t2++;
}
artifacts[k].type = ARTIFACTTYPE_FREE;
}
s3[0] = func0f13d3c4(s3[0], t2 * 2);
if (t2 > 0) {
brightness = viGetFovY() * 0.017453292f;
add = cosf(brightness) / sinf(brightness) * 14.6f;
if (lightIsHealthy(roomnum, lightindex - g_Rooms[roomnum].gfxdata->lightsindex)) {
if (!lightIsOn(roomnum, lightindex - g_Rooms[roomnum].gfxdata->lightsindex)) {
continue;
}
brightness = 1.0f;
} else if (lightTickBroken(roomnum, lightindex - g_Rooms[roomnum].gfxdata->lightsindex)) {
brightness = 0.4f;
} else {
continue;
}
r = ((light->colour >> 12) & 0xf) * 17;
g = ((light->colour >> 8) & 0xf) * 17;
b = ((light->colour >> 4) & 0xf) * 17;
if ((r == 0xff && g == 0xff && b == 0xff) || (r == 0xff && g + b < 35)) {
extra = false;
} else {
extra = true;
}
f0 = s3[2] * (1.0f / 255.0f);
sky0f127334((s32) ((f32)f0 * r), (s32) ((f32)f0 * g), (s32) ((f32)f0 * b));
for (l = 0; l < 3; l++) {
lightroompos[l] = (light->bbox[0].s[l] + light->bbox[1].s[l] + light->bbox[2].s[l] + light->bbox[3].s[l]) / 4;
lightworldpos.f[l] = lightroompos[l] + g_BgRooms[roomnum].pos.f[l];
lightscreenpos.f[l] = lightworldpos.f[l] - g_Vars.currentplayer->cam_pos.f[l];
}
mtx4RotateVecInPlace(camGetWorldToScreenMtxf(), &lightscreenpos);
cam0f0b4d04(&lightscreenpos, spdc);
brightness *= 27500.0f / (-lightscreenpos.z < 1.0f ? 1.0f : -lightscreenpos.z);
if (light->unk06 != 0) {
brightness *= light->unk06 * (1.0f / 32.0f);
}
brightness *= s3[1] * (1.0f / 255.0f);
brightness += add;
brightness *= 2.0f * func0f000dbc(roomnum);
if (brightness > 750.0f) {
brightness = 750.0f;
}
f24 = stageGetCurrent()->light_width * brightness * 0.01f;
f26 = stageGetCurrent()->light_height * brightness * 0.01f;
f24 *= viGetViewWidth() * (1.0f / 240.0f) / camGetPerspAspect();
f26 *= viGetViewHeight() * (1.0f / 240.0f);
if (brightness > 3.0f) {
f32 alpha = (light->colour & 0xf) * 17;
colour[0] = r;
colour[1] = g;
colour[2] = b;
alpha *= stageGetCurrent()->light_alpha / 255.0f;
alpha *= (s3[1] / 255.0f);
alpha *= (s3[0] / 8.0f);
if (alpha > 255.0f) {
alpha = 255.0f;
}
colour[3] = alpha;
gDPSetEnvColor(gdl++, colour[0], colour[1], colour[2], colour[3]);
spd4[0] = f24;
spd4[1] = f26;
func0f0b2740(&gdl, spdc, spd4, 64, 64, false, false, false, 1);
if (extra) {
colour[0] = 0xff;
colour[1] = 0xff;
colour[2] = 0xff;
colour[3] = stageGetCurrent()->light_alpha;
colour[3] = s3[0] * colour[3] / 8;
gDPSetEnvColor(gdl++, colour[0], colour[1], colour[2], colour[3]);
spd4[0] = f24 * 0.4f;
spd4[1] = f26 * 0.4f;
func0f0b2740(&gdl, spdc, spd4, 64, 64, false, false, false, 1);
}
}
}
s3[1] = 0;
s3[2] = 0;
}
// This is incrementing i past all the artifacts for this particular
// light, then subtracting 1 because the for loop will add 1.
i = i + count - 1;
}
}
return gdl;
}

View File

@ -119,30 +119,8 @@ Gfx *mblur0f1763f4(Gfx *gdl)
return gdl;
}
u16 *mblur0f176668(s32 arg0)
{
u16 *addr;
if (arg0 == 0) {
addr = var800ab7c8;
}
if (arg0 == 1) {
addr = var800abac8;
}
if (arg0 == 2) {
addr = var800abdc8;
}
addr = (u16 *)(((u32)addr + 0x3f) & ~0x3f);
return addr;
}
Gfx *mblurRender(Gfx *gdl)
{
struct artifact *artifacts = schedGetWriteArtifacts();
u32 stack;
u16 *sp4c = var800844f0;
u32 s4 = 0;
@ -151,10 +129,6 @@ Gfx *mblurRender(Gfx *gdl)
u16 *image;
s32 i;
viGetBackBuffer();
sp44 = mblur0f176668(g_SchedWriteArtifactsIndex);
g_SchedSpecialArtifactIndexes[g_SchedWriteArtifactsIndex] = 1;
gDPPipeSync(gdl++);
gDPSetColorImage(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, viGetBufWidth(), OS_PHYSICAL_TO_K0(sp44));
gDPSetScissor(gdl++, G_SC_NON_INTERLACE, 0, 0, 320, 240);
@ -179,31 +153,6 @@ Gfx *mblurRender(Gfx *gdl)
gSPClearGeometryMode(gdl++, G_ZBUFFER);
gDPTileSync(gdl++);
for (i = 0; i < MAX_ARTIFACTS; i++) {
if (1);
if (artifacts[i].type != ARTIFACTTYPE_FREE) {
s2 = &sp44[s4];
image = &sp4c[artifacts[i].unk0c.u16_1 * viGetWidth()];
gDPPipeSync(gdl++);
gDPSetTextureImage(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, image);
gDPLoadSync(gdl++);
gDPLoadBlock(gdl++, 5, 0, 0, viGetWidth() - 1, 0);
gDPPipeSync(gdl++);
gSPTextureRectangle(gdl++,
s4 << 2, 0,
(s4 + 3) << 2, 0,
G_TX_RENDERTILE, (artifacts[i].unk0c.u16_2 * 32) + 16, 0x0010, 0x1000, 0);
artifacts[i].unk0c.u16p = s2;
s4++;
if (s2);
}
}
gDPPipeSync(gdl++);
gDPLoadSync(gdl++);
gDPTileSync(gdl++);
@ -214,7 +163,5 @@ Gfx *mblurRender(Gfx *gdl)
gDPSetTexturePersp(gdl++, G_TP_PERSP);
gDPSetColorDither(gdl++, G_CD_BAYER);
if (sp44);
return gdl;
}

View File

@ -446,7 +446,6 @@ void lvReset(s32 stagenum)
modelmgrSetLvResetting(false);
var80084018 = 1;
schedResetArtifacts();
lvSetPaused(0);
#if PIRACYCHECKS
@ -1186,7 +1185,6 @@ Gfx *lvRender(Gfx *gdl)
gdl = vi0000b280(gdl);
gdl = vi0000b1d0(gdl);
gdl = currentPlayerScissorToViewport(gdl);
artifactsClear();
if ((g_Vars.stagenum != STAGE_CITRAINING || (var80087260 <= 0 && g_MenuData.root != MENUROOT_MPSETUP))
&& g_Vars.lvframenum <= 5
@ -1533,8 +1531,6 @@ Gfx *lvRender(Gfx *gdl)
}
}
artifactsTick();
if ((g_Vars.coopplayernum >= 0 || g_Vars.antiplayernum >= 0)
#if VERSION >= VERSION_NTSC_1_0
&& playerHasSharedViewport()

View File

@ -4378,7 +4378,6 @@ Gfx *playerRenderHud(Gfx *gdl)
{
if (g_Vars.currentplayer->cameramode == CAMERAMODE_THIRDPERSON) {
gdl = boltbeamsRender(gdl);
gdl = bgRenderArtifacts(gdl);
gdl = hudmsgsRender(gdl);
if (g_Vars.currentplayer->isdead == false) {
@ -4394,10 +4393,6 @@ Gfx *playerRenderHud(Gfx *gdl)
bgunRender(&gdl);
gdl = lasersightRenderDot(gdl);
if (g_Vars.currentplayer->visionmode != VISIONMODE_XRAY) {
gdl = bgRenderArtifacts(gdl);
}
if (g_NbombsActive) {
gdl = nbombRenderOverlay(gdl);
}

View File

@ -2365,558 +2365,6 @@ Gfx *sky0f123fd4(Gfx *gdl, struct skything38 *arg1, struct skything38 *arg2, str
return gdl;
}
void skyCreateArtifact(struct artifact *artifact, s32 x, s32 y)
{
s32 viewleft = viGetViewLeft();
s32 viewtop = viGetViewTop();
s32 viewwidth = viGetViewWidth();
s32 viewheight = viGetViewHeight();
if (x >= viewleft && x < viewleft + viewwidth && y >= viewtop && y < viewtop + viewheight) {
artifact->unk08 = &var800844f0[(s32)camGetScreenWidth() * y + x];
artifact->unk0c.u16_2 = x;
artifact->unk0c.u16_1 = y;
artifact->type = ARTIFACTTYPE_CIRCLE;
}
}
f32 sky0f125a1c(struct artifact *artifacts)
{
f32 sum = 0;
s32 i;
for (i = 0; i < 8; i++) {
if (artifacts[i].type == ARTIFACTTYPE_CIRCLE && artifacts[i].unk02 == 0xfffc) {
sum += 0.125f;
}
}
return sum;
}
Gfx *skyRenderSuns(Gfx *gdl, bool xray)
{
Mtxf *sp16c;
Mtxf *sp168;
s16 viewleft;
s16 viewtop;
s16 viewwidth;
s16 viewheight;
f32 viewleftf;
f32 viewtopf;
f32 viewwidthf;
f32 viewheightf;
struct artifact *artifacts;
u8 colour[3];
struct environment *env;
struct sun *sun;
s32 i;
f32 sp134[2];
f32 sp12c[2];
s32 xscale;
f32 sp124;
bool onscreen;
f32 radius;
sp16c = camGetWorldToScreenMtxf();
sp168 = camGetMtxF1754();
env = envGetCurrent();
xscale = 1;
if (env->numsuns <= 0 || !var800844f0 || g_Vars.mplayerisrunning) {
return gdl;
}
#if !PAL
if (g_ViRes == 1) {
xscale = 2;
}
#endif
viewleft = viGetViewLeft();
viewtop = viGetViewTop();
viewwidth = viGetViewWidth();
viewheight = viGetViewHeight();
viewleftf = viewleft;
viewtopf = viewtop;
viewwidthf = viewwidth;
viewheightf = viewheight;
sun = env->suns;
for (i = 0; i < env->numsuns; i++) {
g_SunPositions[i].f[0] = sun->pos[0];
g_SunPositions[i].f[1] = sun->pos[1];
g_SunPositions[i].f[2] = sun->pos[2];
colour[0] = sun->red;
colour[1] = sun->green;
colour[2] = sun->blue;
if (!xray) {
mtx4TransformVecInPlace(sp16c, &g_SunPositions[i]);
mtx4TransformVecInPlace(sp168, &g_SunPositions[i]);
if (g_SunPositions[i].f[2] > 1.0f) {
g_SunScreenXPositions[i] = (g_SunPositions[i].f[0] / g_SunPositions[i].f[2] + 1.0f) * 0.5f * viewwidthf + viewleftf;
g_SunScreenYPositions[i] = (-g_SunPositions[i].f[1] / g_SunPositions[i].f[2] + 1.0f) * 0.5f * viewheightf + viewtopf;
radius = 60.0f / viGetFovY() * sun->texture_size;
onscreen = false;
if (g_SunScreenXPositions[i] >= viewleftf - radius
&& g_SunScreenXPositions[i] < viewleftf + viewwidth + radius
&& g_SunScreenYPositions[i] >= viewtopf - radius
&& g_SunScreenYPositions[i] < viewtopf + viewheightf + radius) {
// Sun is at least partially on screen
if (g_SunScreenXPositions[i] >= viewleftf
&& g_SunScreenXPositions[i] < viewleftf + viewwidthf
&& g_SunScreenYPositions[i] >= viewtopf
&& g_SunScreenYPositions[i] < viewtopf + viewheightf) {
// Sun's centre point is on-screen
f32 distfromedge;
f32 mindistfromedge;
artifacts = schedGetWriteArtifacts();
onscreen = true;
mindistfromedge = 1000;
if ((s32)g_SunScreenXPositions[i] < viewleft + 15) {
distfromedge = g_SunScreenXPositions[i];
if (distfromedge < mindistfromedge) {
mindistfromedge = distfromedge;
}
}
if (1);
if ((s32)g_SunScreenYPositions[i] < viewtop + 15) {
distfromedge = g_SunScreenYPositions[i];
if (distfromedge < mindistfromedge) {
mindistfromedge = distfromedge;
}
}
if ((s32)g_SunScreenXPositions[i] > viewleft + viewwidth - 16) {
distfromedge = viewleft + viewwidth - 1 - g_SunScreenXPositions[i];
if (distfromedge < mindistfromedge) {
mindistfromedge = distfromedge;
}
}
if ((s32)g_SunScreenYPositions[i] > viewtop + viewheight - 16) {
distfromedge = viewtop + viewheight - 1 - g_SunScreenYPositions[i];
if (distfromedge < mindistfromedge) {
mindistfromedge = distfromedge;
}
}
mindistfromedge -= 1.0f;
if (mindistfromedge < 0.0f) {
mindistfromedge = 0.0f;
}
g_SunAlphaFracs[i] = mindistfromedge * (1.0f / 15.0f);
if (g_SunAlphaFracs[i] > 1.0f) {
g_SunAlphaFracs[i] = 1.0f;
}
skyCreateArtifact(&artifacts[i * 8 + 0], (s32)g_SunScreenXPositions[i] - 7, (s32)g_SunScreenYPositions[i] + 1);
skyCreateArtifact(&artifacts[i * 8 + 1], (s32)g_SunScreenXPositions[i] - 5, (s32)g_SunScreenYPositions[i] - 3);
skyCreateArtifact(&artifacts[i * 8 + 2], (s32)g_SunScreenXPositions[i] - 3, (s32)g_SunScreenYPositions[i] + 5);
skyCreateArtifact(&artifacts[i * 8 + 3], (s32)g_SunScreenXPositions[i] - 1, (s32)g_SunScreenYPositions[i] - 7);
skyCreateArtifact(&artifacts[i * 8 + 4], (s32)g_SunScreenXPositions[i] + 1, (s32)g_SunScreenYPositions[i] + 7);
skyCreateArtifact(&artifacts[i * 8 + 5], (s32)g_SunScreenXPositions[i] + 3, (s32)g_SunScreenYPositions[i] - 5);
skyCreateArtifact(&artifacts[i * 8 + 6], (s32)g_SunScreenXPositions[i] + 5, (s32)g_SunScreenYPositions[i] + 3);
skyCreateArtifact(&artifacts[i * 8 + 7], (s32)g_SunScreenXPositions[i] + 7, (s32)g_SunScreenYPositions[i] - 1);
}
if (1);
g_SunFlareTimers240[i] += g_Vars.lvupdate240;
texSelect(&gdl, &g_TexLightGlareConfigs[5], 4, 0, 2, 1, NULL);
gDPSetCycleType(gdl++, G_CYC_1CYCLE);
gDPSetColorDither(gdl++, G_CD_DISABLE);
gDPSetRenderMode(gdl++, G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2);
gDPSetTexturePersp(gdl++, G_TP_NONE);
gDPSetAlphaCompare(gdl++, G_AC_NONE);
gDPSetTextureLOD(gdl++, G_TL_TILE);
gDPSetTextureConvert(gdl++, G_TC_FILT);
gDPSetTextureLUT(gdl++, G_TT_NONE);
gDPSetTextureFilter(gdl++, G_TF_BILERP);
gDPSetCombineLERP(gdl++,
ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0,
ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0);
gDPSetEnvColor(gdl++, colour[0], colour[1], colour[2], (s32)(g_SunAlphaFracs[i] * 255.0f));
sp134[0] = g_SunScreenXPositions[i];
sp134[1] = g_SunScreenYPositions[i];
sp12c[0] = radius * 0.50f * xscale;
sp12c[1] = radius * 0.50f;
func0f0b2150(&gdl, sp134, sp12c, g_TexLightGlareConfigs[5].width, g_TexLightGlareConfigs[5].height, 0, 1, 1, 1, 0, 1);
gDPPipeSync(gdl++);
gDPSetColorDither(gdl++, G_CD_BAYER);
gDPSetTexturePersp(gdl++, G_TP_PERSP);
gDPSetTextureLOD(gdl++, G_TL_LOD);
sp124 = sky0f125a1c(&schedGetFrontArtifacts()[i * 8]);
}
if (onscreen && sp124 > 0.0f) {
g_SunFlareTimers240[i] += g_Vars.lvupdate240;
} else {
g_SunFlareTimers240[i] = 0;
}
}
}
sun++;
}
return gdl;
}
/**
* Render a sun and its artifacts.
*/
Gfx *sky0f126384(Gfx *gdl, f32 x, f32 y, f32 arg3, f32 size, s32 arg5, f32 arg6)
{
s32 i;
f32 f2;
f32 f12;
f32 sp17c[2];
f32 sp174[2];
s32 sp15c[] = { 16, 32, 12, 32, 24, 64 }; // diameters?
s32 sp144[] = { 60, 80, 225, 275, 470, 570 }; // distances from the sun?
u32 colours[] = {
0xff99ffff, // pinkish/purple
0x9999ffff, // blue
0x99ffffff, // very light blue
0x99ff99ff, // green
0xffff99ff, // yellow
0xff9999ff, // red
};
f32 sp128;
f32 sp124;
s32 scale;
f32 fovy;
scale = 1;
#if !PAL
if (g_ViRes == VIRES_HI) {
scale = 2;
}
#endif
sp128 = (x - viGetViewWidth() / 2.0f) * 0.01f;
sp124 = (y - viGetViewHeight() / 2.0f) * 0.01f;
// Render the sun
texSelect(&gdl, &g_TexLightGlareConfigs[6], 4, 0, 2, 1, NULL);
gDPSetCycleType(gdl++, G_CYC_1CYCLE);
gDPSetColorDither(gdl++, G_CD_BAYER);
gDPSetAlphaDither(gdl++, G_AD_PATTERN);
gDPSetRenderMode(gdl++, G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2);
gDPSetTexturePersp(gdl++, G_TP_NONE);
gDPSetAlphaCompare(gdl++, G_AC_NONE);
gDPSetTextureLOD(gdl++, G_TL_TILE);
gDPSetTextureConvert(gdl++, G_TC_FILT);
gDPSetTextureLUT(gdl++, G_TT_NONE);
gDPSetTextureFilter(gdl++, G_TF_BILERP);
gDPSetCombineLERP(gdl++,
0, 0, 0, ENVIRONMENT, TEXEL0, 0, ENVIRONMENT, 0,
0, 0, 0, ENVIRONMENT, TEXEL0, 0, ENVIRONMENT, 0);
fovy = viGetFovY();
gDPSetEnvColor(gdl++, 0xff, 0xff, 0xff, (s32) (arg6 * arg3 * 255.0f));
f2 = ((s32) ((60.0f / fovy) * (size * (0.5f + (0.5f * arg3)))));
sp17c[0] = x;
sp17c[1] = y;
sp174[1] = f2 * 0.5f;
sp174[0] = f2 * 0.5f * scale;
func0f0b2150(&gdl, sp17c, sp174, g_TexLightGlareConfigs[6].width, g_TexLightGlareConfigs[6].height, 0, 1, 1, 1, 0, 1);
// Render the artifacts
texSelect(&gdl, &g_TexLightGlareConfigs[1], 4, 0, 2, 1, NULL);
gDPSetCycleType(gdl++, G_CYC_1CYCLE);
gDPSetColorDither(gdl++, G_CD_BAYER);
gDPSetAlphaDither(gdl++, G_AD_PATTERN);
gDPSetRenderMode(gdl++, G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2);
gDPSetTexturePersp(gdl++, G_TP_NONE);
gDPSetAlphaCompare(gdl++, G_AC_NONE);
gDPSetTextureLOD(gdl++, G_TL_TILE);
gDPSetTextureConvert(gdl++, G_TC_FILT);
gDPSetTextureLUT(gdl++, G_TT_NONE);
gDPSetTextureFilter(gdl++, G_TF_BILERP);
gDPSetCombineLERP(gdl++,
0, 0, 0, ENVIRONMENT, TEXEL0, 0, ENVIRONMENT, 0,
0, 0, 0, ENVIRONMENT, TEXEL0, 0, ENVIRONMENT, 0);
for (i = 0; i < 6; i++) {
f32 f12;
f32 f14;
f32 tmp;
if (arg5 < TICKS(90)) {
if (arg5 < TICKS(30)) {
f2 = arg5 * (1.0f / TICKS(30.0f));
} else {
f2 = 1.0f;
}
} else {
f2 = (TICKS(180.0f) - (arg5 - TICKS(90))) * (1.0f / TICKS(180.0f)) * 0.5f;
if (f2 < 0.0f) {
f2 = 0.0f;
}
f2 += 0.5f;
}
f12 = x - sp144[i] * sp128;
f14 = y - sp144[i] * sp124;
tmp = sp15c[i];
gDPSetEnvColor(gdl++,
(colours[i] >> 24) & 0xff,
(colours[i] >> 16) & 0xff,
(colours[i] >> 8) & 0xff,
(s32) ((colours[i] & 0xff) * (arg6 * f2)));
sp17c[0] = f12;
sp17c[1] = f14;
sp174[1] = tmp * 0.5f;
sp174[0] = tmp * 0.5f * scale;
func0f0b2150(&gdl, sp17c, sp174, g_TexLightGlareConfigs[1].width, g_TexLightGlareConfigs[1].height, 0, 0, 0, 0, 0, 1);
}
sp128 = viGetViewWidth() / 2.0f - x;
sp124 = viGetViewHeight() / 2.0f - y;
f12 = (40.0f - sqrtf(sp128 * sp128 + sp124 * sp124)) * 0.0125f;
if (f12 < 0.0f) {
f12 = 0.0f;
}
f12 += 0.1f;
if (arg5 <= g_Vars.lvupdate240) {
f12 = 0.0f;
}
if (f12 > 0.0f) {
sky0f127334(arg6 * f12 * 255.0f, arg6 * f12 * 255.0f, arg6 * f12 * 255.0f);
}
gDPSetColorDither(gdl++, G_CD_BAYER);
gDPSetAlphaDither(gdl++, G_AD_PATTERN | G_CD_DISABLE);
gDPSetTexturePersp(gdl++, G_TP_PERSP);
gDPSetTextureLOD(gdl++, G_TL_LOD);
return gdl;
}
struct coord g_TeleportToPos = {0, 0, 0};
struct coord g_TeleportToUp = {0, 0, 1};
struct coord g_TeleportToLook = {0, 1, 0};
/**
* Render a sun and its artifacts if on screen.
*/
Gfx *sky0f126c3c(Gfx *gdl, f32 x, f32 y, f32 z, f32 arg4, f32 arg5)
{
struct coord sp64;
sp64.x = x;
sp64.y = y;
sp64.z = z;
mtx4TransformVecInPlace(camGetWorldToScreenMtxf(), &sp64);
mtx4TransformVecInPlace(camGetMtxF1754(), &sp64);
if (sp64.z > 1.0f) {
f32 xpos;
f32 ypos;
s16 viewlefti = viGetViewLeft();
s16 viewtopi = viGetViewTop();
s16 viewwidthi = viGetViewWidth();
s16 viewheighti = viGetViewHeight();
f32 viewleft = viewlefti;
f32 viewwidth = viewwidthi;
f32 viewtop = viewtopi;
f32 viewheight = viewheighti;
xpos = viewleft + (sp64.f[0] / sp64.f[2] + 1.0f) * 0.5f * viewwidth;
ypos = viewtop + (-sp64.f[1] / sp64.f[2] + 1.0f) * 0.5f * viewheight;
if (xpos >= viewleft && xpos < viewleft + viewwidth
&& ypos >= viewtop && ypos < viewtop + viewheight) {
gdl = sky0f126384(gdl, xpos, ypos, arg5, arg4, TICKS(90), 1.0f);
}
}
return gdl;
}
/**
* Render lens flares during teleport.
*/
Gfx *sky0f126de8(Gfx *gdl)
{
f32 sp154 = g_20SecIntervalFrac * M_BADTAU;
s32 i;
f32 f20 = 0.0f;
f32 f20_2;
f32 f22;
f32 f22_3;
struct pad pad;
struct coord spe0;
f32 spd0[4];
Mtxf mtx;
f32 f24;
f32 f30;
if (g_Vars.currentplayer->teleportstate == TELEPORTSTATE_PREENTER) {
f20 = g_Vars.currentplayer->teleporttime / 24.0f * 0.33f;
} else if (g_Vars.currentplayer->teleportstate == TELEPORTSTATE_ENTERING) {
f20 = g_Vars.currentplayer->teleporttime / 48.0f * 0.66f + 0.33f;
}
f30 = f20 * 6.0f;
f22 = f20 * 1.3f;
if (f22 > 1.0f) {
f22 = 1.0f;
}
if (f30 > 1.0f) {
f30 = 1.0f;
}
f20 *= 1.7f;
if (f20 > 1.0f) {
f20 = 1.0f;
}
padUnpack(g_Vars.currentplayer->teleportpad, PADFIELD_POS | PADFIELD_LOOK | PADFIELD_UP, &pad);
g_TeleportToPos.x = pad.pos.x;
g_TeleportToPos.y = pad.pos.y;
g_TeleportToPos.z = pad.pos.z;
g_TeleportToLook.x = pad.look.x;
g_TeleportToLook.y = pad.look.y;
g_TeleportToLook.z = pad.look.z;
g_TeleportToUp.x = pad.up.x;
g_TeleportToUp.y = pad.up.y;
g_TeleportToUp.z = pad.up.z;
f22 = -cosf(f22 * M_PI) * 0.5f + .5f;
f24 = 100 * f22;
for (i = 0; i < 5; i++) {
spe0.x = g_TeleportToLook.f[0] * f24;
spe0.y = g_TeleportToLook.f[1] * f24;
spe0.z = g_TeleportToLook.f[2] * f24;
f22_3 = sp154 + i * 1.2564370632172f;
f20_2 = sinf(f22_3);
spd0[0] = cosf(f22_3);
spd0[1] = g_TeleportToUp.f[0] * f20_2;
spd0[2] = g_TeleportToUp.f[1] * f20_2;
spd0[3] = g_TeleportToUp.f[2] * f20_2;
quaternionToMtx(spd0, &mtx);
mtx4RotateVecInPlace(&mtx, &spe0);
spe0.x += g_TeleportToPos.x;
spe0.y += g_TeleportToPos.y;
spe0.z += g_TeleportToPos.z;
gdl = sky0f126c3c(gdl, spe0.x, spe0.y, spe0.z, f20 * 200, f30);
}
return gdl;
}
/**
* Render teleport artifacts, and all suns and their artifacts.
*/
Gfx *skyRenderArtifacts(Gfx *gdl)
{
struct environment *env = envGetCurrent();
struct sun *sun;
s32 i;
if (g_Vars.currentplayer->teleportstate == TELEPORTSTATE_PREENTER
|| g_Vars.currentplayer->teleportstate == TELEPORTSTATE_ENTERING) {
gdl = sky0f126de8(gdl);
}
if (env->numsuns <= 0 || !var800844f0 || g_Vars.mplayerisrunning) {
return gdl;
}
sun = env->suns;
for (i = 0; i < env->numsuns; i++) {
if (sun->lens_flare && g_SunPositions[i].z > 1) {
struct artifact *artifact = schedGetFrontArtifacts() + i * 8;
f32 value = sky0f125a1c(artifact);
if (value > 0.0f) {
gdl = sky0f126384(gdl, g_SunScreenXPositions[i], g_SunScreenYPositions[i], value, sun->orb_size, g_SunFlareTimers240[i], g_SunAlphaFracs[i]);
}
}
sun++;
}
return gdl;
}
void sky0f127334(s32 arg0, s32 arg1, s32 arg2)
{
g_Vars.currentplayer->unk1c28 = sqrtf(g_Vars.currentplayer->unk1c28 * g_Vars.currentplayer->unk1c28 + arg0 * arg0);
g_Vars.currentplayer->unk1c2c = sqrtf(g_Vars.currentplayer->unk1c2c * g_Vars.currentplayer->unk1c2c + arg1 * arg1);
g_Vars.currentplayer->unk1c30 = sqrtf(g_Vars.currentplayer->unk1c30 * g_Vars.currentplayer->unk1c30 + arg2 * arg2);
if (g_Vars.currentplayer->unk1c28 > 0xcc) {
g_Vars.currentplayer->unk1c28 = 0xcc;
}
if (g_Vars.currentplayer->unk1c2c > 0xcc) {
g_Vars.currentplayer->unk1c2c = 0xcc;
}
if (g_Vars.currentplayer->unk1c30 > 0xcc) {
g_Vars.currentplayer->unk1c30 = 0xcc;
}
}
s32 sky0f127490(s32 arg0, s32 arg1)
{
if (arg1 >= arg0) {

View File

@ -69,11 +69,6 @@ s32 var8008de10;
u32 var8008de14;
OSTimer g_SchedRspTimer;
u32 g_SchedDpCounters[4];
struct artifact g_ArtifactLists[3][120];
u8 g_SchedSpecialArtifactIndexes[3];
s32 g_SchedWriteArtifactsIndex;
s32 g_SchedFrontArtifactsIndex;
s32 g_SchedPendingArtifactsIndex;
bool g_SchedCrashedUnexpectedly = false;
bool g_SchedCrashEnable1 = false;
@ -236,8 +231,6 @@ void __scMain(void *arg)
OSSched *sc = (OSSched *)arg;
int done = 0;
schedInitArtifacts();
while (!done) {
osRecvMesg(&sc->interruptQ, (OSMesg *)&msg, OS_MESG_BLOCK);
@ -443,103 +436,6 @@ u32 *schedGetDpCounters(void)
return g_SchedDpCounters;
}
void schedInitArtifacts(void)
{
s32 i;
s32 j;
for (i = 0; i < 3; i++) {
for (j = 0; j < MAX_ARTIFACTS; j++) {
g_ArtifactLists[i][j].type = ARTIFACTTYPE_FREE;
}
g_SchedSpecialArtifactIndexes[i] = 0;
}
}
/**
* The write list is an artifact list that is not currently being displayed on
* the screen. Update logic can write here to put artifacts on the next frame.
*/
struct artifact *schedGetWriteArtifacts(void)
{
return g_ArtifactLists[g_SchedWriteArtifactsIndex];
}
/**
* The front list is the artifact list that is currently being displayed on the
* screen. Rendering logic reads this list. The list may be re-used for multiple
* frames in a row during lag.
*/
struct artifact *schedGetFrontArtifacts(void)
{
return g_ArtifactLists[g_SchedFrontArtifactsIndex];
}
/**
* The pending list is possibly misnamed. I'm not sure how this list works.
*
* @TODO: Investigate.
*/
struct artifact *schedGetPendingArtifacts(void)
{
return g_ArtifactLists[g_SchedPendingArtifactsIndex];
}
void schedIncrementWriteArtifacts(void)
{
g_SchedWriteArtifactsIndex = (g_SchedWriteArtifactsIndex + 1) % 3;
}
void schedIncrementFrontArtifacts(void)
{
g_SchedFrontArtifactsIndex = (g_SchedFrontArtifactsIndex + 1) % 3;
}
void schedIncrementPendingArtifacts(void)
{
g_SchedPendingArtifactsIndex = (g_SchedPendingArtifactsIndex + 1) % 3;
}
void schedResetArtifacts(void)
{
g_SchedWriteArtifactsIndex = 0;
g_SchedFrontArtifactsIndex = 1;
g_SchedPendingArtifactsIndex = 0;
}
void schedUpdatePendingArtifacts(void)
{
struct artifact *artifacts = schedGetPendingArtifacts();
s32 i;
for (i = 0; i < MAX_ARTIFACTS; i++) {
struct artifact *artifact = &artifacts[i];
if (artifact->type != ARTIFACTTYPE_FREE) {
u16 *unk08 = artifact->unk08;
u16 value08 = unk08[0];
if (g_SchedSpecialArtifactIndexes[g_SchedPendingArtifactsIndex] == 1) {
u16 *unk0c = artifact->unk0c.u16p;
u16 value0c = unk0c[0];
if (value0c > value08) {
artifact->unk02 = value08;
} else {
artifact->unk02 = value0c;
}
} else {
artifact->unk02 = value08;
}
}
}
g_SchedSpecialArtifactIndexes[g_SchedPendingArtifactsIndex] = 0;
schedIncrementPendingArtifacts();
}
/**
* __scHandleRDP is called when an RDP task signals that it has finished.
*/
@ -549,8 +445,6 @@ void __scHandleRDP(OSSched *sc)
s32 state;
if (sc->curRDPTask != NULL) {
schedUpdatePendingArtifacts();
if (var8005dd18 == 0) {
schedConsiderScreenshot();
}