From 0b4dc84271eac845e7066e39b9e8d9cc9ef7a63a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 16 Jun 2021 20:16:52 +1000 Subject: [PATCH] Move World_Contains checks to within Lighting_Col, rename Lighting_Col_XYZ to Lighting_Color_XYZ --- src/Builder.c | 26 +++++++++++++------------- src/Chat.h | 3 ++- src/Entity.c | 2 +- src/Lighting.c | 16 +++++++++------- src/Lighting.h | 20 +++++++++----------- src/Particle.c | 6 +++--- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/Builder.c b/src/Builder.c index 5a9d1d507..7c28aeece 100644 --- a/src/Builder.c +++ b/src/Builder.c @@ -501,7 +501,7 @@ static void Builder_DrawSprite(int x, int y, int z) { bright = Blocks.FullBright[Builder_Block]; part = &Builder_Parts[Atlas1D_Index(loc)]; - v.Col = bright ? PACKEDCOL_WHITE : Lighting_Col_Sprite_Fast(x, y, z); + v.Col = bright ? PACKEDCOL_WHITE : Lighting_Color_Sprite_Fast(x, y, z); Block_Tint(v.Col, Builder_Block); /* Draw Z axis */ @@ -544,17 +544,17 @@ static PackedCol Normal_LightCol(int x, int y, int z, Face face, BlockID block) switch (face) { case FACE_XMIN: - return x < offset ? Env.SunXSide : Lighting_Col_XSide_Fast(x - offset, y, z); + return x < offset ? Env.SunXSide : Lighting_Color_XSide_Fast(x - offset, y, z); case FACE_XMAX: - return x > (World.MaxX - offset) ? Env.SunXSide : Lighting_Col_XSide_Fast(x + offset, y, z); + return x > (World.MaxX - offset) ? Env.SunXSide : Lighting_Color_XSide_Fast(x + offset, y, z); case FACE_ZMIN: - return z < offset ? Env.SunZSide : Lighting_Col_ZSide_Fast(x, y, z - offset); + return z < offset ? Env.SunZSide : Lighting_Color_ZSide_Fast(x, y, z - offset); case FACE_ZMAX: - return z > (World.MaxZ - offset) ? Env.SunZSide : Lighting_Col_ZSide_Fast(x, y, z + offset); + return z > (World.MaxZ - offset) ? Env.SunZSide : Lighting_Color_ZSide_Fast(x, y, z + offset); case FACE_YMIN: - return y <= 0 ? Env.SunYMin : Lighting_Col_YMin_Fast(x, y - offset, z); + return y <= 0 ? Env.SunYMin : Lighting_Color_YMin_Fast(x, y - offset, z); case FACE_YMAX: - return y >= World.MaxY ? Env.SunCol : Lighting_Col_YMax_Fast(x, (y + 1) - offset, z); + return y >= World.MaxY ? Env.SunCol : Lighting_Color_YMax_Fast(x, (y + 1) - offset, z); } return 0; /* should never happen */ } @@ -674,7 +674,7 @@ static void NormalBuilder_RenderBlock(int index, int x, int y, int z) { part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)]; col = fullBright ? PACKEDCOL_WHITE : - x >= offset ? Lighting_Col_XSide_Fast(x - offset, y, z) : Env.SunXSide; + x >= offset ? Lighting_Color_XSide_Fast(x - offset, y, z) : Env.SunXSide; Drawer_XMin(count_XMin, col, loc, &part->fVertices[FACE_XMIN]); } @@ -684,7 +684,7 @@ static void NormalBuilder_RenderBlock(int index, int x, int y, int z) { part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)]; col = fullBright ? PACKEDCOL_WHITE : - x <= (World.MaxX - offset) ? Lighting_Col_XSide_Fast(x + offset, y, z) : Env.SunXSide; + x <= (World.MaxX - offset) ? Lighting_Color_XSide_Fast(x + offset, y, z) : Env.SunXSide; Drawer_XMax(count_XMax, col, loc, &part->fVertices[FACE_XMAX]); } @@ -694,7 +694,7 @@ static void NormalBuilder_RenderBlock(int index, int x, int y, int z) { part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)]; col = fullBright ? PACKEDCOL_WHITE : - z >= offset ? Lighting_Col_ZSide_Fast(x, y, z - offset) : Env.SunZSide; + z >= offset ? Lighting_Color_ZSide_Fast(x, y, z - offset) : Env.SunZSide; Drawer_ZMin(count_ZMin, col, loc, &part->fVertices[FACE_ZMIN]); } @@ -704,7 +704,7 @@ static void NormalBuilder_RenderBlock(int index, int x, int y, int z) { part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)]; col = fullBright ? PACKEDCOL_WHITE : - z <= (World.MaxZ - offset) ? Lighting_Col_ZSide_Fast(x, y, z + offset) : Env.SunZSide; + z <= (World.MaxZ - offset) ? Lighting_Color_ZSide_Fast(x, y, z + offset) : Env.SunZSide; Drawer_ZMax(count_ZMax, col, loc, &part->fVertices[FACE_ZMAX]); } @@ -713,7 +713,7 @@ static void NormalBuilder_RenderBlock(int index, int x, int y, int z) { offset = (lightFlags >> FACE_YMIN) & 1; part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)]; - col = fullBright ? PACKEDCOL_WHITE : Lighting_Col_YMin_Fast(x, y - offset, z); + col = fullBright ? PACKEDCOL_WHITE : Lighting_Color_YMin_Fast(x, y - offset, z); Drawer_YMin(count_YMin, col, loc, &part->fVertices[FACE_YMIN]); } @@ -722,7 +722,7 @@ static void NormalBuilder_RenderBlock(int index, int x, int y, int z) { offset = (lightFlags >> FACE_YMAX) & 1; part = &Builder_Parts[baseOffset + Atlas1D_Index(loc)]; - col = fullBright ? PACKEDCOL_WHITE : Lighting_Col_YMax_Fast(x, (y + 1) - offset, z); + col = fullBright ? PACKEDCOL_WHITE : Lighting_Color_YMax_Fast(x, (y + 1) - offset, z); Drawer_YMax(count_YMax, col, loc, &part->fVertices[FACE_YMAX]); } } diff --git a/src/Chat.h b/src/Chat.h index 0e8af2c43..01663d363 100644 --- a/src/Chat.h +++ b/src/Chat.h @@ -23,7 +23,8 @@ enum MsgType { MSG_TYPE_CLIENTSTATUS_2 = 257 /* Tab list matching names */ }; -extern cc_string Chat_Status[4], Chat_BottomRight[3], Chat_ClientStatus[2], Chat_Announcement, Chat_BigAnnouncement, Chat_SmallAnnouncement; +extern cc_string Chat_Status[4], Chat_BottomRight[3], Chat_ClientStatus[2]; +extern cc_string Chat_Announcement, Chat_BigAnnouncement, Chat_SmallAnnouncement; /* All chat messages received. */ extern struct StringsBuffer Chat_Log; /* Time each chat message was received at. */ diff --git a/src/Entity.c b/src/Entity.c index 6880fa142..b6a24f5ef 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -66,7 +66,7 @@ void LocationUpdate_MakePosAndOri(struct LocationUpdate* update, Vec3 pos, float static PackedCol Entity_GetCol(struct Entity* e) { Vec3 eyePos = Entity_GetEyePosition(e); IVec3 pos; IVec3_Floor(&pos, &eyePos); - return World_Contains(pos.X, pos.Y, pos.Z) ? Lighting_Col(pos.X, pos.Y, pos.Z) : Env.SunCol; + return Lighting_Color(pos.X, pos.Y, pos.Z); } void Entity_Init(struct Entity* e) { diff --git a/src/Lighting.c b/src/Lighting.c index 7029ac291..79b63416a 100644 --- a/src/Lighting.c +++ b/src/Lighting.c @@ -52,31 +52,33 @@ cc_bool Lighting_IsLit(int x, int y, int z) { return y > Lighting_GetLightHeight(x, z); } -PackedCol Lighting_Col(int x, int y, int z) { +PackedCol Lighting_Color(int x, int y, int z) { + if (!World_Contains(x, y, z)) return Env.SunCol; return y > Lighting_GetLightHeight(x, z) ? Env.SunCol : Env.ShadowCol; } -PackedCol Lighting_Col_XSide(int x, int y, int z) { +PackedCol Lighting_Color_XSide(int x, int y, int z) { + if (!World_Contains(x, y, z)) return Env.SunXSide; return y > Lighting_GetLightHeight(x, z) ? Env.SunXSide : Env.ShadowXSide; } -PackedCol Lighting_Col_Sprite_Fast(int x, int y, int z) { +PackedCol Lighting_Color_Sprite_Fast(int x, int y, int z) { return y > Lighting_Heightmap[Lighting_Pack(x, z)] ? Env.SunCol : Env.ShadowCol; } -PackedCol Lighting_Col_YMax_Fast(int x, int y, int z) { +PackedCol Lighting_Color_YMax_Fast(int x, int y, int z) { return y > Lighting_Heightmap[Lighting_Pack(x, z)] ? Env.SunCol : Env.ShadowCol; } -PackedCol Lighting_Col_YMin_Fast(int x, int y, int z) { +PackedCol Lighting_Color_YMin_Fast(int x, int y, int z) { return y > Lighting_Heightmap[Lighting_Pack(x, z)] ? Env.SunYMin : Env.ShadowYMin; } -PackedCol Lighting_Col_XSide_Fast(int x, int y, int z) { +PackedCol Lighting_Color_XSide_Fast(int x, int y, int z) { return y > Lighting_Heightmap[Lighting_Pack(x, z)] ? Env.SunXSide : Env.ShadowXSide; } -PackedCol Lighting_Col_ZSide_Fast(int x, int y, int z) { +PackedCol Lighting_Color_ZSide_Fast(int x, int y, int z) { return y > Lighting_Heightmap[Lighting_Pack(x, z)] ? Env.SunZSide : Env.ShadowZSide; } diff --git a/src/Lighting.h b/src/Lighting.h index e9fda74e2..4f16a8d59 100644 --- a/src/Lighting.h +++ b/src/Lighting.h @@ -25,16 +25,14 @@ void Lighting_Refresh(void); /* Returns whether the block at the given coordinates is fully in sunlight. */ /* NOTE: Does ***NOT*** check that the coordinates are inside the map. */ cc_bool Lighting_IsLit(int x, int y, int z); -/* Returns the light colour of the block at the given coordinates. */ -/* NOTE: Does ***NOT*** check that the coordinates are inside the map. */ -PackedCol Lighting_Col(int x, int y, int z); -/* Returns the light colour of the block at the given coordinates. */ -/* NOTE: Does ***NOT*** check that the coordinates are inside the map. */ -PackedCol Lighting_Col_XSide(int x, int y, int z); +/* Returns the light colour at the given coordinates. */ +PackedCol Lighting_Color(int x, int y, int z); +/* Returns the light colour at the given coordinates. */ +PackedCol Lighting_Color_XSide(int x, int y, int z); -PackedCol Lighting_Col_Sprite_Fast(int x, int y, int z); -PackedCol Lighting_Col_YMax_Fast(int x, int y, int z); -PackedCol Lighting_Col_YMin_Fast(int x, int y, int z); -PackedCol Lighting_Col_XSide_Fast(int x, int y, int z); -PackedCol Lighting_Col_ZSide_Fast(int x, int y, int z); +PackedCol Lighting_Color_Sprite_Fast(int x, int y, int z); +PackedCol Lighting_Color_YMax_Fast(int x, int y, int z); +PackedCol Lighting_Color_YMin_Fast(int x, int y, int z); +PackedCol Lighting_Color_XSide_Fast(int x, int y, int z); +PackedCol Lighting_Color_ZSide_Fast(int x, int y, int z); #endif diff --git a/src/Particle.c b/src/Particle.c index adbc58222..5877fbbc5 100644 --- a/src/Particle.c +++ b/src/Particle.c @@ -150,7 +150,7 @@ static void RainParticle_Render(struct Particle* p, float t, struct VertexTextur size.X = p->size * 0.015625f; size.Y = size.X; x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z); - col = World_Contains(x, y, z) ? Lighting_Col(x, y, z) : Env.SunCol; + col = Lighting_Color(x, y, z); Particle_DoRender(&size, &pos, &rain_rec, col, vertices); } @@ -223,7 +223,7 @@ static void TerrainParticle_Render(struct TerrainParticle* p, float t, struct Ve if (!Blocks.FullBright[p->block]) { x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z); - col = World_Contains(x, y, z) ? Lighting_Col_XSide(x, y, z) : Env.SunXSide; + col = Lighting_Color_XSide(x, y, z); } Block_Tint(col, p->block); @@ -349,7 +349,7 @@ static void CustomParticle_Render(struct CustomParticle* p, float t, struct Vert size.X = p->base.size; size.Y = size.X; x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z); - col = e->fullBright ? PACKEDCOL_WHITE : (World_Contains(x, y, z) ? Lighting_Col(x, y, z) : Env.SunCol); + col = e->fullBright ? PACKEDCOL_WHITE : Lighting_Color(x, y, z); col = PackedCol_Tint(col, e->tintCol); Particle_DoRender(&size, &pos, &rec, col, vertices);