mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 10:02:08 -05:00
Optimise BlockInfo.IsLiquid to be simple lookup table instead
This commit is contained in:
parent
5b197dd874
commit
35219142cd
12 changed files with 58 additions and 53 deletions
|
@ -38,13 +38,13 @@ namespace ClassicalSharp {
|
|||
case Side.Right:
|
||||
min.X = bbMin.Z; min.Y = bbMin.Y;
|
||||
max.X = bbMax.Z; max.Y = bbMax.Y;
|
||||
if (IsLiquid(block)) max.Y -= 1.5f/16;
|
||||
if (IsLiquid[block]) max.Y -= 1.5f/16;
|
||||
break;
|
||||
case Side.Front:
|
||||
case Side.Back:
|
||||
min.X = bbMin.X; min.Y = bbMin.Y;
|
||||
max.X = bbMax.X; max.Y = bbMax.Y;
|
||||
if (IsLiquid(block)) max.Y -= 1.5f/16;
|
||||
if (IsLiquid[block]) max.Y -= 1.5f/16;
|
||||
break;
|
||||
case Side.Top:
|
||||
case Side.Bottom:
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace ClassicalSharp {
|
|||
internal static void CalcRenderBounds(BlockID block) {
|
||||
Vector3 min = MinBB[block], max = MaxBB[block];
|
||||
|
||||
if (IsLiquid(block)) {
|
||||
if (IsLiquid[block]) {
|
||||
min.X -= 0.1f/16f; max.X -= 0.1f/16f;
|
||||
min.Z -= 0.1f/16f; max.Z -= 0.1f/16f;
|
||||
min.Y -= 1.5f/16f; max.Y -= 1.5f/16f;
|
||||
|
|
|
@ -40,25 +40,25 @@ namespace ClassicalSharp {
|
|||
static void CalcCulling(BlockID block, BlockID other) {
|
||||
Vector3 bMin = MinBB[block], bMax = MaxBB[block];
|
||||
Vector3 oMin = MinBB[other], oMax = MaxBB[other];
|
||||
if (IsLiquid(block)) bMax.Y -= 1.5f/16;
|
||||
if (IsLiquid(other)) oMax.Y -= 1.5f/16;
|
||||
if (IsLiquid[block]) bMax.Y -= 1.5f/16;
|
||||
if (IsLiquid[other]) oMax.Y -= 1.5f/16;
|
||||
|
||||
if (Draw[block] == DrawType.Sprite) {
|
||||
SetHidden(block, other, Side.Left, true);
|
||||
SetHidden(block, other, Side.Left, true);
|
||||
SetHidden(block, other, Side.Right, true);
|
||||
SetHidden(block, other, Side.Front, true);
|
||||
SetHidden(block, other, Side.Back, true);
|
||||
SetHidden(block, other, Side.Back, true);
|
||||
SetHidden(block, other, Side.Bottom, oMax.Y == 1);
|
||||
SetHidden(block, other, Side.Top, bMax.Y == 1);
|
||||
SetHidden(block, other, Side.Top, bMax.Y == 1);
|
||||
} else {
|
||||
SetXStretch(block, bMin.X == 0 && bMax.X == 1);
|
||||
SetZStretch(block, bMin.Z == 0 && bMax.Z == 1);
|
||||
bool bothLiquid = IsLiquid(block) && IsLiquid(other);
|
||||
bool bothLiquid = IsLiquid[block] && IsLiquid[other];
|
||||
|
||||
SetHidden(block, other, Side.Left, oMax.X == 1 && bMin.X == 0);
|
||||
SetHidden(block, other, Side.Left, oMax.X == 1 && bMin.X == 0);
|
||||
SetHidden(block, other, Side.Right, oMin.X == 0 && bMax.X == 1);
|
||||
SetHidden(block, other, Side.Front, oMax.Z == 1 && bMin.Z == 0);
|
||||
SetHidden(block, other, Side.Back, oMin.Z == 0 && bMax.Z == 1);
|
||||
SetHidden(block, other, Side.Back, oMin.Z == 0 && bMax.Z == 1);
|
||||
SetHidden(block, other, Side.Bottom,
|
||||
bothLiquid || (oMax.Y == 1 && bMin.Y == 0));
|
||||
SetHidden(block, other, Side.Top,
|
||||
|
@ -79,7 +79,7 @@ namespace ClassicalSharp {
|
|||
if (block == other) return Draw[block] != DrawType.TransparentThick;
|
||||
|
||||
// An opaque neighbour (asides from lava) culls the face.
|
||||
if (Draw[other] == DrawType.Opaque && !IsLiquid(other)) return true;
|
||||
if (Draw[other] == DrawType.Opaque && !IsLiquid[other]) return true;
|
||||
if (Draw[block] != DrawType.Translucent || Draw[other] != DrawType.Translucent) return false;
|
||||
|
||||
// e.g. for water / ice, don't need to draw water.
|
||||
|
|
|
@ -67,13 +67,7 @@ namespace ClassicalSharp {
|
|||
/// <remarks> e.g. blocks light, height, texture IDs, etc. </remarks>
|
||||
public static partial class BlockInfo {
|
||||
|
||||
public static bool IsLiquid(BlockID block) {
|
||||
byte collide = ExtendedCollide[block];
|
||||
return
|
||||
(collide == CollideType.LiquidWater && Draw[block] == DrawType.Translucent) ||
|
||||
(collide == CollideType.LiquidLava && Draw[block] == DrawType.Transparent);
|
||||
}
|
||||
|
||||
public static bool[] IsLiquid = new bool[Block.Count];
|
||||
public static bool[] BlocksLight = new bool[Block.Count];
|
||||
public static bool[] FullBright = new bool[Block.Count];
|
||||
public static string[] Name = new string[Block.Count];
|
||||
|
@ -124,10 +118,18 @@ namespace ClassicalSharp {
|
|||
CanPlace[Block.Bedrock] = false; CanDelete[Block.Bedrock] = false;
|
||||
}
|
||||
|
||||
static void RecalcIsLiquid(BlockID block) {
|
||||
byte collide = ExtendedCollide[block];
|
||||
IsLiquid[block] =
|
||||
(collide == CollideType.LiquidWater && Draw[block] == DrawType.Translucent) ||
|
||||
(collide == CollideType.LiquidLava && Draw[block] == DrawType.Transparent);
|
||||
}
|
||||
|
||||
public static void SetCollide(BlockID block, byte collide) {
|
||||
// necessary for cases where servers redefined core blocks before extended types were introduced
|
||||
collide = DefaultSet.MapOldCollide(block, collide);
|
||||
ExtendedCollide[block] = collide;
|
||||
RecalcIsLiquid(block);
|
||||
|
||||
// Reduce extended collision types to their simpler forms
|
||||
if (collide == CollideType.Ice) collide = CollideType.Solid;
|
||||
|
@ -142,6 +144,7 @@ namespace ClassicalSharp {
|
|||
if (draw == DrawType.Opaque && Collide[block] != CollideType.Solid)
|
||||
draw = DrawType.Transparent;
|
||||
Draw[block] = draw;
|
||||
RecalcIsLiquid(block);
|
||||
|
||||
FullOpaque[block] = draw == DrawType.Opaque
|
||||
&& MinBB[block] == Vector3.Zero && MaxBB[block] == Vector3.One;
|
||||
|
|
|
@ -148,7 +148,7 @@ namespace ClassicalSharp.Entities {
|
|||
posY--;
|
||||
|
||||
byte draw = BlockInfo.Draw[block];
|
||||
if (draw == DrawType.Gas || draw == DrawType.Sprite || BlockInfo.IsLiquid(block)) continue;
|
||||
if (draw == DrawType.Gas || draw == DrawType.Sprite || BlockInfo.IsLiquid[block]) continue;
|
||||
float blockY = posY + 1 + BlockInfo.MaxBB[block].Y;
|
||||
if (blockY >= Position.Y + 0.01f) continue;
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ namespace ClassicalSharp {
|
|||
|
||||
static bool IsHackBlock(BlockID b) {
|
||||
return b == Block.DoubleSlab || b == Block.Bedrock ||
|
||||
b == Block.Grass || BlockInfo.IsLiquid(b);
|
||||
b == Block.Grass || BlockInfo.IsLiquid[b];
|
||||
}
|
||||
|
||||
public void AddDefault(BlockID block) {
|
||||
|
|
|
@ -104,7 +104,7 @@ namespace ClassicalSharp.Particles {
|
|||
bool CanPassThrough(Game game, BlockID block, bool throughLiquids) {
|
||||
byte draw = BlockInfo.Draw[block];
|
||||
return draw == DrawType.Gas || draw == DrawType.Sprite
|
||||
|| (throughLiquids && BlockInfo.IsLiquid(block));
|
||||
|| (throughLiquids && BlockInfo.IsLiquid[block]);
|
||||
}
|
||||
|
||||
bool CollideHor(Game game, BlockID block) {
|
||||
|
|
|
@ -53,10 +53,18 @@ void Block_SetDefaultPerms(void) {
|
|||
Block_CanPlace[BLOCK_BEDROCK] = false; Block_CanDelete[BLOCK_BEDROCK] = false;
|
||||
}
|
||||
|
||||
void Block_RecalcIsLiquid(BlockID b) {
|
||||
UInt8 collide = Block_ExtendedCollide[b];
|
||||
Block_IsLiquid[b] =
|
||||
(collide == COLLIDE_LIQUID_WATER && Block_Draw[b] == DRAW_TRANSLUCENT) ||
|
||||
(collide == COLLIDE_LIQUID_LAVA && Block_Draw[b] == DRAW_TRANSPARENT);
|
||||
}
|
||||
|
||||
void Block_SetCollide(BlockID block, UInt8 collide) {
|
||||
/* necessary for cases where servers redefined core blocks before extended types were introduced. */
|
||||
collide = DefaultSet_MapOldCollide(block, collide);
|
||||
Block_ExtendedCollide[block] = collide;
|
||||
Block_RecalcIsLiquid(block);
|
||||
|
||||
/* Reduce extended collision types to their simpler forms. */
|
||||
if (collide == COLLIDE_ICE) collide = COLLIDE_SOLID;
|
||||
|
@ -72,6 +80,7 @@ void Block_SetDrawType(BlockID block, UInt8 draw) {
|
|||
draw = DRAW_TRANSPARENT;
|
||||
}
|
||||
Block_Draw[block] = draw;
|
||||
Block_RecalcIsLiquid(block);
|
||||
|
||||
Vector3 zero = Vector3_Zero, one = Vector3_One;
|
||||
Block_FullOpaque[block] = draw == DRAW_OPAQUE
|
||||
|
@ -172,13 +181,6 @@ Int32 Block_FindID(STRING_PURE String* name) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool Block_IsLiquid(BlockID b) {
|
||||
UInt8 collide = Block_ExtendedCollide[b];
|
||||
return
|
||||
(collide == COLLIDE_LIQUID_WATER && Block_Draw[b] == DRAW_TRANSLUCENT) ||
|
||||
(collide == COLLIDE_LIQUID_LAVA && Block_Draw[b] == DRAW_TRANSPARENT);
|
||||
}
|
||||
|
||||
|
||||
void Block_SetSide(TextureLoc texLoc, BlockID blockId) {
|
||||
Int32 index = blockId * FACE_COUNT;
|
||||
|
@ -200,14 +202,14 @@ void Block_GetTextureRegion(BlockID block, Face face, Vector2* min, Vector2* max
|
|||
case FACE_XMAX:
|
||||
min->X = bbMin.Z; min->Y = bbMin.Y;
|
||||
max->X = bbMax.Z; max->Y = bbMax.Y;
|
||||
if (Block_IsLiquid(block)) max->Y -= 1.5f / 16.0f;
|
||||
if (Block_IsLiquid[block]) max->Y -= 1.5f / 16.0f;
|
||||
break;
|
||||
|
||||
case FACE_ZMIN:
|
||||
case FACE_ZMAX:
|
||||
min->X = bbMin.X; min->Y = bbMin.Y;
|
||||
max->X = bbMax.X; max->Y = bbMax.Y;
|
||||
if (Block_IsLiquid(block)) max->Y -= 1.5f / 16.0f;
|
||||
if (Block_IsLiquid[block]) max->Y -= 1.5f / 16.0f;
|
||||
break;
|
||||
|
||||
case FACE_YMAX:
|
||||
|
@ -232,7 +234,7 @@ bool Block_FaceOccluded(BlockID block, BlockID other, Face face) {
|
|||
void Block_CalcRenderBounds(BlockID block) {
|
||||
Vector3 min = Block_MinBB[block], max = Block_MaxBB[block];
|
||||
|
||||
if (Block_IsLiquid(block)) {
|
||||
if (Block_IsLiquid[block]) {
|
||||
min.X -= 0.1f / 16.0f; max.X -= 0.1f / 16.0f;
|
||||
min.Z -= 0.1f / 16.0f; max.Z -= 0.1f / 16.0f;
|
||||
min.Y -= 1.5f / 16.0f; max.Y -= 1.5f / 16.0f;
|
||||
|
@ -357,30 +359,30 @@ void Block_SetZStretch(BlockID block, bool stretch) {
|
|||
void Block_CalcCulling(BlockID block, BlockID other) {
|
||||
Vector3 bMin = Block_MinBB[block], bMax = Block_MaxBB[block];
|
||||
Vector3 oMin = Block_MinBB[other], oMax = Block_MaxBB[other];
|
||||
if (Block_IsLiquid(block)) bMax.Y -= 1.5f / 16;
|
||||
if (Block_IsLiquid(other)) oMax.Y -= 1.5f / 16;
|
||||
if (Block_IsLiquid[block]) bMax.Y -= 1.5f / 16.0f;
|
||||
if (Block_IsLiquid[other]) oMax.Y -= 1.5f / 16.0f;
|
||||
|
||||
if (Block_Draw[block] == DRAW_SPRITE) {
|
||||
Block_SetHidden(block, other, FACE_XMIN, true);
|
||||
Block_SetHidden(block, other, FACE_XMAX, true);
|
||||
Block_SetHidden(block, other, FACE_ZMIN, true);
|
||||
Block_SetHidden(block, other, FACE_ZMAX, true);
|
||||
Block_SetHidden(block, other, FACE_YMIN, oMax.Y == 1);
|
||||
Block_SetHidden(block, other, FACE_YMAX, bMax.Y == 1);
|
||||
Block_SetHidden(block, other, FACE_YMIN, oMax.Y == 1.0f);
|
||||
Block_SetHidden(block, other, FACE_YMAX, bMax.Y == 1.0f);
|
||||
} else {
|
||||
Block_SetXStretch(block, bMin.X == 0 && bMax.X == 1);
|
||||
Block_SetZStretch(block, bMin.Z == 0 && bMax.Z == 1);
|
||||
bool bothLiquid = Block_IsLiquid(block) && Block_IsLiquid(other);
|
||||
Block_SetXStretch(block, bMin.X == 0 && bMax.X == 1.0f);
|
||||
Block_SetZStretch(block, bMin.Z == 0 && bMax.Z == 1.0f);
|
||||
bool bothLiquid = Block_IsLiquid[block] && Block_IsLiquid[other];
|
||||
|
||||
Block_SetHidden(block, other, FACE_XMIN, oMax.X == 1 && bMin.X == 0);
|
||||
Block_SetHidden(block, other, FACE_XMAX, oMin.X == 0 && bMax.X == 1);
|
||||
Block_SetHidden(block, other, FACE_ZMIN, oMax.Z == 1 && bMin.Z == 0);
|
||||
Block_SetHidden(block, other, FACE_ZMAX, oMin.Z == 0 && bMax.Z == 1);
|
||||
Block_SetHidden(block, other, FACE_XMIN, oMax.X == 1.0f && bMin.X == 0.0f);
|
||||
Block_SetHidden(block, other, FACE_XMAX, oMin.X == 0.0f && bMax.X == 1.0f);
|
||||
Block_SetHidden(block, other, FACE_ZMIN, oMax.Z == 1.0f && bMin.Z == 0.0f);
|
||||
Block_SetHidden(block, other, FACE_ZMAX, oMin.Z == 0.0f && bMax.Z == 1.0f);
|
||||
|
||||
Block_SetHidden(block, other, FACE_YMIN,
|
||||
bothLiquid || (oMax.Y == 1 && bMin.Y == 0));
|
||||
bothLiquid || (oMax.Y == 1.0f && bMin.Y == 0.0f));
|
||||
Block_SetHidden(block, other, FACE_YMAX,
|
||||
bothLiquid || (oMin.Y == 0 && bMax.Y == 1));
|
||||
bothLiquid || (oMin.Y == 0.0f && bMax.Y == 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,7 +421,7 @@ bool Block_IsHidden(BlockID block, BlockID other) {
|
|||
if (block == other) return Block_Draw[block] != DRAW_TRANSPARENT_THICK;
|
||||
|
||||
/* An opaque neighbour (asides from lava) culls the face. */
|
||||
if (Block_Draw[other] == DRAW_OPAQUE && !Block_IsLiquid(other)) return true;
|
||||
if (Block_Draw[other] == DRAW_OPAQUE && !Block_IsLiquid[other]) return true;
|
||||
if (Block_Draw[block] != DRAW_TRANSLUCENT || Block_Draw[other] != DRAW_TRANSLUCENT) return false;
|
||||
|
||||
/* e.g. for water / ice, don't need to draw water. */
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
UInt8 Block_NamesBuffer[String_BufferSize(STRING_SIZE) * BLOCK_COUNT];
|
||||
#define Block_NamePtr(i) &Block_NamesBuffer[String_BufferSize(STRING_SIZE) * i]
|
||||
|
||||
bool Block_IsLiquid[BLOCK_COUNT];
|
||||
bool Block_BlocksLight[BLOCK_COUNT];
|
||||
bool Block_FullBright[BLOCK_COUNT];
|
||||
String Block_Name[BLOCK_COUNT];
|
||||
|
@ -96,7 +97,6 @@ void Block_SetDrawType(BlockID block, UInt8 draw);
|
|||
void Block_ResetProps(BlockID block);
|
||||
|
||||
Int32 Block_FindID(STRING_PURE String* name);
|
||||
bool Block_IsLiquid(BlockID b);
|
||||
|
||||
void Block_CalcRenderBounds(BlockID block);
|
||||
UInt8 Block_CalcLightOffset(BlockID block);
|
||||
|
|
|
@ -165,7 +165,7 @@ bool HacksComp_Floating(HacksComp* hacks) {
|
|||
return hacks->Noclip || hacks->Flying;
|
||||
}
|
||||
|
||||
String HacksComp_GetFlagValue(String* flag, HacksComp* hacks) {
|
||||
String HacksComp_UNSAFE_FlagValue(String* flag, HacksComp* hacks) {
|
||||
String* joined = &hacks->HacksFlags;
|
||||
Int32 start = String_IndexOfString(joined, flag);
|
||||
if (start < 0) return String_MakeNull();
|
||||
|
@ -179,7 +179,7 @@ String HacksComp_GetFlagValue(String* flag, HacksComp* hacks) {
|
|||
|
||||
void HacksComp_ParseHorizontalSpeed(HacksComp* hacks) {
|
||||
String horSpeedFlag = String_FromConst("horspeed=");
|
||||
String speedStr = HacksComp_GetFlagValue(&horSpeedFlag, hacks);
|
||||
String speedStr = HacksComp_UNSAFE_FlagValue(&horSpeedFlag, hacks);
|
||||
if (speedStr.length == 0) return;
|
||||
|
||||
Real32 speed = 0.0f;
|
||||
|
@ -189,7 +189,7 @@ void HacksComp_ParseHorizontalSpeed(HacksComp* hacks) {
|
|||
|
||||
void HacksComp_ParseMultiSpeed(HacksComp* hacks) {
|
||||
String jumpsFlag = String_FromConst("jumps=");
|
||||
String jumpsStr = HacksComp_GetFlagValue(&jumpsFlag, hacks);
|
||||
String jumpsStr = HacksComp_UNSAFE_FlagValue(&jumpsFlag, hacks);
|
||||
if (jumpsStr.length == 0 || Game_ClassicMode) return;
|
||||
|
||||
Int32 jumps = 0;
|
||||
|
@ -555,7 +555,7 @@ bool ShadowComponent_GetBlocks(Entity* entity, Vector3I* coords, Real32 x, Real3
|
|||
posY--;
|
||||
|
||||
UInt8 draw = Block_Draw[block];
|
||||
if (draw == DRAW_GAS || draw == DRAW_SPRITE || Block_IsLiquid(block)) continue;
|
||||
if (draw == DRAW_GAS || draw == DRAW_SPRITE || Block_IsLiquid[block]) continue;
|
||||
Real32 blockY = posY + 1.0f + Block_MaxBB[block].Y;
|
||||
if (blockY >= Position.Y + 0.01f) continue;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ void Inventory_SetSelectedBlock(BlockID block) {
|
|||
}
|
||||
|
||||
bool Inventory_IsHackBlock(BlockID b) {
|
||||
return b == BLOCK_DOUBLE_SLAB || b == BLOCK_BEDROCK || b == BLOCK_GRASS || Block_IsLiquid(b);
|
||||
return b == BLOCK_DOUBLE_SLAB || b == BLOCK_BEDROCK || b == BLOCK_GRASS || Block_IsLiquid[b];
|
||||
}
|
||||
|
||||
BlockID Inventory_DefaultMapping(Int32 i) {
|
||||
|
|
|
@ -44,7 +44,7 @@ void Particle_Reset(Particle* p, Vector3 pos, Vector3 velocity, Real32 lifetime)
|
|||
|
||||
bool Particle_CanPass(BlockID block, bool throughLiquids) {
|
||||
UInt8 draw = Block_Draw[block];
|
||||
return draw == DRAW_GAS || draw == DRAW_SPRITE || (throughLiquids && Block_IsLiquid(block));
|
||||
return draw == DRAW_GAS || draw == DRAW_SPRITE || (throughLiquids && Block_IsLiquid[block]);
|
||||
}
|
||||
|
||||
bool Particle_CollideHor(Vector3* nextPos, BlockID block) {
|
||||
|
|
Loading…
Add table
Reference in a new issue