From 047c390e704151e0b74113eb6aed8c9ef7adf54b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 26 Apr 2024 20:07:11 +1000 Subject: [PATCH] Fix respawn point not being set (oops) --- src/Entity.c | 4 ++++ src/EnvRenderer.c | 18 +++++++++++------- src/Picking.c | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Entity.c b/src/Entity.c index 30484c735..e2c1b252b 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -961,6 +961,10 @@ void LocalPlayers_MoveToSpawn(struct LocationUpdate* update) { { p = &LocalPlayer_Instances[i]; p->Base.VTABLE->SetLocation(&p->Base, update); + + if (update->flags & LU_HAS_POS) p->Spawn = update->pos; + if (update->flags & LU_HAS_YAW) p->SpawnYaw = update->yaw; + if (update->flags & LU_HAS_PITCH) p->SpawnPitch = update->pitch; } /* TODO: This needs to be before new map... */ diff --git a/src/EnvRenderer.c b/src/EnvRenderer.c index 2df9dc8a6..9121d4e24 100644 --- a/src/EnvRenderer.c +++ b/src/EnvRenderer.c @@ -41,21 +41,25 @@ static int CalcNumVertices(int axis1Len, int axis2Len) { /*########################################################################################################################* *------------------------------------------------------------Fog----------------------------------------------------------* *#########################################################################################################################*/ -static void CalcFog(float* density, PackedCol* color) { +static cc_bool CameraInsideBlock(BlockID block, IVec3* coords) { + struct AABB blockBB; Vec3 pos; + IVec3_ToVec3(&pos, coords); /* pos = coords; */ + + Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]); + Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]); + return AABB_ContainsPoint(&blockBB, &Camera.CurrentPos); +} + +static void CalcFog(float* density, PackedCol* color) { IVec3 coords; BlockID block; - struct AABB blockBB; float blend; IVec3_Floor(&coords, &Camera.CurrentPos); /* coords = floor(camera_pos); */ - IVec3_ToVec3(&pos, &coords); /* pos = coords; */ - block = World_SafeGetBlock(coords.x, coords.y, coords.z); - Vec3_Add(&blockBB.Min, &pos, &Blocks.MinBB[block]); - Vec3_Add(&blockBB.Max, &pos, &Blocks.MaxBB[block]); - if (AABB_ContainsPoint(&blockBB, &Camera.CurrentPos) && Blocks.FogDensity[block]) { + if (Blocks.FogDensity[block] && CameraInsideBlock(block, &coords)) { *density = Blocks.FogDensity[block]; *color = Blocks.FogCol[block]; } else { diff --git a/src/Picking.c b/src/Picking.c index fa4eda1ea..b2e1b8817 100644 --- a/src/Picking.c +++ b/src/Picking.c @@ -83,9 +83,9 @@ void RayTracer_Init(struct RayTracer* t, const Vec3* origin, const Vec3* dir) { t->tMax.z = RayTracer_Div(cellBoundary.z - origin->z, dir->z); /* Boundary is a plane on the XY axis. */ /* Determine how far we must travel along the ray before we have crossed a gridcell. */ - t->tDelta.x = RayTracer_Div((float)t->step.x, dir->x); - t->tDelta.y = RayTracer_Div((float)t->step.y, dir->y); - t->tDelta.z = RayTracer_Div((float)t->step.z, dir->z); + t->tDelta.x = (float)t->step.x * t->invDir.x; + t->tDelta.y = (float)t->step.y * t->invDir.y; + t->tDelta.z = (float)t->step.z * t->invDir.z; } void RayTracer_Step(struct RayTracer* t) {