diff --git a/port/src/pdsched.c b/port/src/pdsched.c index 4b15a2574..12c01d7cf 100644 --- a/port/src/pdsched.c +++ b/port/src/pdsched.c @@ -361,33 +361,7 @@ void schedResetArtifacts(void) 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(); } diff --git a/src/game/game_13c510.c b/src/game/game_13c510.c index 1360b5ed6..c081ecbf7 100644 --- a/src/game/game_13c510.c +++ b/src/game/game_13c510.c @@ -16,6 +16,12 @@ #include "lib/mtx.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 +#include "lib/collision.h" +#include "lib/lib_17ce0.h" +#include "game/player.h" +f32 fabsf(f32 value); +#endif u8 *var800a41a0; u32 var800a41a4; @@ -96,6 +102,52 @@ s32 func0f13c710(f32 arg0) return arg0; } +#ifndef PLATFORM_N64 + +bool artifactTestLos(struct coord *spec, struct coord *roompos) +{ + if (!g_Vars.currentplayer) { + return false; + } + + struct coord endpos; + endpos.x = roompos->x + spec->x; + endpos.y = roompos->y + spec->y; + endpos.z = roompos->z + spec->z; + + // get what rooms the LOS goes through + RoomNum outrooms[17], tmprooms[8], srcrooms[2]; + srcrooms[0] = g_Vars.currentplayer->cam_room; + srcrooms[1] = -1; + outrooms[16] = -1; + portal00018148(&g_Vars.currentplayer->cam_pos, &endpos, srcrooms, tmprooms, outrooms, 16); + + // cheaper LOS test against props first + const u32 cdtype = CDTYPE_OBJS | CDTYPE_DOORS | CDTYPE_PLAYERS | CDTYPE_CHRS; + const u16 geoflags = GEOFLAG_BLOCK_SIGHT | GEOFLAG_BLOCK_SHOOT; + if (!cdTestAToB(&g_Vars.currentplayer->cam_pos, &endpos, outrooms, cdtype, geoflags, true, 1, 0, 0)) { + return false; + } + + // no prop was hit; check for bg hits + struct hitthing hit; + for (s32 i = 0; outrooms[i] != -1; ++i) { + if (bgTestHitInRoom(&g_Vars.currentplayer->cam_pos, &endpos, outrooms[i], &hit)) { + // check if it's far enough away from the end point + if (fabsf(hit.unk00.x - endpos.x) >= 0.1f || + fabsf(hit.unk00.y - endpos.y) >= 0.1f || + fabsf(hit.unk00.z - endpos.z) >= 0.1f) { + return false; + } + } + } + + // nothing hit + return true; +} + +#endif + void artifactsCalculateGlaresForRoom(s32 roomnum) { s32 i; @@ -134,6 +186,11 @@ void artifactsCalculateGlaresForRoom(s32 roomnum) struct coord *campos = &g_Vars.currentplayer->cam_pos; struct artifact *artifact; +#ifndef PLATFORM_N64 + const bool prevperim = g_Vars.currentplayer->bondperimenabled; + playerSetPerimEnabled(g_Vars.currentplayer->prop, false); +#endif + if (g_Rooms[roomnum].gfxdata != NULL && g_Rooms[roomnum].loaded240) { numlights = g_Rooms[roomnum].gfxdata->numlights; @@ -322,6 +379,9 @@ void artifactsCalculateGlaresForRoom(s32 roomnum) } if (index < MAX_ARTIFACTS) { +#ifndef PLATFORM_N64 + artifact->unk02 = artifactTestLos(&spec, &g_BgRooms[roomnum].pos); +#endif artifact->unk04 = func0f13c574(f0) >> 2; artifact->unk08 = &g_ZbufPtr1[viGetWidth() * yi + xi]; artifact->light = &roomlights[i]; @@ -336,6 +396,10 @@ void artifactsCalculateGlaresForRoom(s32 roomnum) } } } + +#ifndef PLATFORM_N64 + playerSetPerimEnabled(g_Vars.currentplayer->prop, prevperim); +#endif } u8 func0f13d3c4(u8 arg0, u8 arg1) @@ -454,6 +518,7 @@ Gfx *artifactsRenderGlaresForRoom(Gfx *gdl, s32 roomnum) } for (k = i; k < i + count; k++) { +#ifdef PLATFORM_N64 u16 tmp; t4 = (artifacts[k].unk02 & 0xfffc) >> 2; tmp = artifacts[k].unk04; @@ -467,6 +532,9 @@ Gfx *artifactsRenderGlaresForRoom(Gfx *gdl, s32 roomnum) if (avg >= v1) { t2++; } +#else + t2 += artifacts[k].unk02; +#endif artifacts[k].type = ARTIFACTTYPE_FREE; } diff --git a/src/game/sky.c b/src/game/sky.c index e28832fe5..77f443941 100644 --- a/src/game/sky.c +++ b/src/game/sky.c @@ -14,6 +14,10 @@ #include "lib/sched.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 +#include "game/game_13c510.h" +#include "game/player.h" +#endif #define SKYABS(val) (val >= 0.0f ? (val) : -(val)) @@ -2423,6 +2427,16 @@ void skyCreateSunArtifact(struct artifact *artifact, s32 x, s32 y) s32 viewheight = viGetViewHeight(); if (x >= viewleft && x < viewleft + viewwidth && y >= viewtop && y < viewtop + viewheight) { +#ifndef PLATFORM_N64 + const s32 i = (artifact - schedGetWriteArtifacts()) >> 3; + struct coord zero = { 0.f }; + struct environment *env = envGetCurrent(); + struct coord sunpos; + sunpos.x = env->suns[i].pos[0]; + sunpos.y = env->suns[i].pos[1]; + sunpos.z = env->suns[i].pos[2]; + artifact->unk02 = artifactTestLos(&sunpos, &zero) * 0xfffc; +#endif artifact->unk08 = &g_ZbufPtr1[(s32)camGetScreenWidth() * y + x]; artifact->unk0c.u16_2 = x; artifact->unk0c.u16_1 = y; @@ -2577,6 +2591,11 @@ Gfx *skyRenderSuns(Gfx *gdl, bool xray) g_SunAlphaFracs[i] = 1.0f; } +#ifndef PLATFORM_N64 + const bool prevperim = g_Vars.currentplayer->bondperimenabled; + playerSetPerimEnabled(g_Vars.currentplayer->prop, false); +#endif + skyCreateSunArtifact(&artifacts[i * 8 + 0], (s32)g_SunScreenXPositions[i] - 7, (s32)g_SunScreenYPositions[i] + 1); skyCreateSunArtifact(&artifacts[i * 8 + 1], (s32)g_SunScreenXPositions[i] - 5, (s32)g_SunScreenYPositions[i] - 3); skyCreateSunArtifact(&artifacts[i * 8 + 2], (s32)g_SunScreenXPositions[i] - 3, (s32)g_SunScreenYPositions[i] + 5); @@ -2585,6 +2604,10 @@ Gfx *skyRenderSuns(Gfx *gdl, bool xray) skyCreateSunArtifact(&artifacts[i * 8 + 5], (s32)g_SunScreenXPositions[i] + 3, (s32)g_SunScreenYPositions[i] - 5); skyCreateSunArtifact(&artifacts[i * 8 + 6], (s32)g_SunScreenXPositions[i] + 5, (s32)g_SunScreenYPositions[i] + 3); skyCreateSunArtifact(&artifacts[i * 8 + 7], (s32)g_SunScreenXPositions[i] + 7, (s32)g_SunScreenYPositions[i] - 1); + +#ifndef PLATFORM_N64 + playerSetPerimEnabled(g_Vars.currentplayer->prop, prevperim); +#endif } if (1); diff --git a/src/include/game/game_13c510.h b/src/include/game/game_13c510.h index 0f5102260..187cbc6ce 100644 --- a/src/include/game/game_13c510.h +++ b/src/include/game/game_13c510.h @@ -13,5 +13,8 @@ u8 func0f13d3c4(u8 arg0, u8 arg1); Gfx *artifactsConfigureForGlares(Gfx *gdl); Gfx *artifactsUnconfigureForGlares(Gfx *gdl); Gfx *artifactsRenderGlaresForRoom(Gfx *gdl, s32 roomnum); +#ifndef PLATFORM_N64 +bool artifactTestLos(struct coord *spec, struct coord *roompos); +#endif #endif diff --git a/src/include/lib/collision.h b/src/include/lib/collision.h index a227b2331..8850948cc 100644 --- a/src/include/lib/collision.h +++ b/src/include/lib/collision.h @@ -67,5 +67,6 @@ bool cd0002ded8(struct coord *arg0, struct coord *arg1, struct prop *prop); s32 cdTestBlockOverlapsAnyProp(struct geoblock *geo, RoomNum *rooms, u32 types); s32 cd0002f02c(struct geoblock *block, RoomNum *rooms, s32 types); bool cdIsNearlyInSight(struct coord *viewpos, RoomNum *rooms, struct coord *targetpos, f32 distance, s32 arg4); +bool cdTestAToB(struct coord *pos, struct coord *coord2, RoomNum *rooms, u32 types, u16 geoflags, bool checkvertical, s32 arg6, f32 ymax, f32 ymin); #endif