mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 01:21:57 -05:00
Slightly less hardcoding
This commit is contained in:
parent
7949aba790
commit
d947ac6988
8 changed files with 28 additions and 34 deletions
|
@ -10,6 +10,24 @@ namespace ClassicalSharp {
|
|||
|
||||
public Vector3[] MinBB = new Vector3[Block.Count];
|
||||
public Vector3[] MaxBB = new Vector3[Block.Count];
|
||||
public Vector3[] RenderMinBB = new Vector3[Block.Count];
|
||||
public Vector3[] RenderMaxBB = new Vector3[Block.Count];
|
||||
|
||||
internal void CalcRenderBounds(byte id) {
|
||||
Vector3 min = MinBB[id], max = MaxBB[id];
|
||||
|
||||
if (id >= Block.Water && id <= Block.StillLava) {
|
||||
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;
|
||||
} else if (Draw[id] == DrawType.Translucent && Collide[id] != CollideType.Solid) {
|
||||
min.X += 0.1f/16f; max.X += 0.1f/16f;
|
||||
min.Z += 0.1f/16f; max.Z += 0.1f/16f;
|
||||
min.Y -= 0.1f/16f; max.Y -= 0.1f/16f;
|
||||
}
|
||||
|
||||
RenderMinBB[id] = min; RenderMaxBB[id] = max;
|
||||
}
|
||||
|
||||
internal byte CalcLightOffset(byte block) {
|
||||
int flags = 0xFF;
|
||||
|
|
|
@ -123,6 +123,8 @@ namespace ClassicalSharp {
|
|||
MaxBB[id] = Vector3.One;
|
||||
MaxBB[id].Y = DefaultSet.Height(id);
|
||||
}
|
||||
|
||||
CalcRenderBounds(id);
|
||||
LightOffset[id] = CalcLightOffset(id);
|
||||
|
||||
if (id >= Block.CpeCount) {
|
||||
|
|
|
@ -167,6 +167,7 @@ namespace ClassicalSharp.Map {
|
|||
info.MinBB[id] = new Vector3(data[0] / 16f, data[1] / 16f, data[2] / 16f);
|
||||
info.MaxBB[id] = new Vector3(data[3] / 16f, data[4] / 16f, data[5] / 16f);
|
||||
|
||||
info.CalcRenderBounds(id);
|
||||
info.UpdateCulling(id);
|
||||
info.LightOffset[id] = info.CalcLightOffset(id);
|
||||
game.Events.RaiseBlockDefinitionChanged();
|
||||
|
|
|
@ -74,9 +74,8 @@ namespace ClassicalSharp {
|
|||
for (int i = 0; i < 10000; i++) {
|
||||
int x = t.X, y = t.Y, z = t.Z;
|
||||
t.Block = GetBlock(game.World, x, y, z, pOrigin);
|
||||
Vector3 min = new Vector3(x, y, z) + info.MinBB[t.Block];
|
||||
Vector3 max = new Vector3(x, y, z) + info.MaxBB[t.Block];
|
||||
if (info.IsLiquid(t.Block)) { min.Y -= 1.5f/16; max.Y -= 1.5f/16; }
|
||||
Vector3 min = new Vector3(x, y, z) + info.RenderMinBB[t.Block];
|
||||
Vector3 max = new Vector3(x, y, z) + info.RenderMaxBB[t.Block];
|
||||
|
||||
float dx = Math.Min(Math.Abs(origin.X - min.X), Math.Abs(origin.X - max.X));
|
||||
float dy = Math.Min(Math.Abs(origin.Y - min.Y), Math.Abs(origin.Y - max.Y));
|
||||
|
|
|
@ -97,21 +97,11 @@ namespace ClassicalSharp {
|
|||
lightFlags = info.LightOffset[curBlock];
|
||||
tinted = info.Tinted[curBlock];
|
||||
|
||||
Vector3 min = info.MinBB[curBlock], max = info.MaxBB[curBlock];
|
||||
Vector3 min = info.RenderMinBB[curBlock], max = info.RenderMaxBB[curBlock];
|
||||
x1 = X + min.X; y1 = Y + min.Y; z1 = Z + min.Z;
|
||||
x2 = X + max.X; y2 = Y + max.Y; z2 = Z + max.Z;
|
||||
|
||||
if (curBlock >= Block.Water && curBlock <= Block.StillLava) {
|
||||
x1 -= 0.1f/16; x2 -= 0.1f/16f;
|
||||
z1 -= 0.1f/16f; z2 -= 0.1f/16f;
|
||||
y1 -= 1.5f/16; y2 -= 1.5f/16;
|
||||
} else if (isTranslucent && info.Collide[curBlock] != CollideType.Solid) {
|
||||
x1 += 0.1f/16; x2 += 0.1f/16f;
|
||||
z1 += 0.1f/16f; z2 += 0.1f/16f;
|
||||
y1 -= 0.1f/16; y2 -= 0.1f/16f;
|
||||
}
|
||||
|
||||
this.minBB = min; this.maxBB = max;
|
||||
this.minBB = info.MinBB[curBlock]; this.maxBB = info.MaxBB[curBlock];
|
||||
minBB.Y = 1 - minBB.Y; maxBB.Y = 1 - maxBB.Y;
|
||||
|
||||
if (leftCount != 0) DrawLeftFace(leftCount);
|
||||
|
|
|
@ -107,6 +107,7 @@ namespace ClassicalSharp.Network.Protocols {
|
|||
reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8());
|
||||
info.Tinted[id] = info.FogColour[id] != FastColour.Black && info.Name[id].IndexOf('#') >= 0;
|
||||
|
||||
info.CalcRenderBounds(id);
|
||||
info.UpdateCulling(id);
|
||||
game.Events.RaiseBlockDefinitionChanged();
|
||||
info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));
|
||||
|
|
|
@ -207,20 +207,12 @@ namespace ClassicalSharp.Renderers {
|
|||
|
||||
float HorOffset(byte block) {
|
||||
BlockInfo info = game.BlockInfo;
|
||||
if (info.IsLiquid(block)) return -0.1f/16;
|
||||
|
||||
if (info.Draw[block] == DrawType.Translucent
|
||||
&& info.Collide[block] != CollideType.Solid) return 0.1f/16;
|
||||
return 0;
|
||||
return info.RenderMinBB[block].X - info.RenderMinBB[block].X;
|
||||
}
|
||||
|
||||
float YOffset(byte block) {
|
||||
BlockInfo info = game.BlockInfo;
|
||||
if (info.IsLiquid(block)) return -1.5f/16;
|
||||
|
||||
if (info.Draw[block] == DrawType.Translucent
|
||||
&& info.Collide[block] != CollideType.Solid) return -0.1f/16;
|
||||
return 0;
|
||||
return info.RenderMinBB[block].Y - info.RenderMinBB[block].Y;
|
||||
}
|
||||
|
||||
void DrawX(int x, int z1, int z2, int y1, int y2, int axisSize,
|
||||
|
|
|
@ -46,15 +46,6 @@ namespace ClassicalSharp.Renderers {
|
|||
|
||||
Vector3 p1 = selected.Min - new Vector3(offset, offset, offset);
|
||||
Vector3 p2 = selected.Max + new Vector3(offset, offset, offset);
|
||||
BlockInfo info = game.BlockInfo;
|
||||
if (info.IsLiquid(selected.Block)) {
|
||||
p1.X -= 0.1f/16; p2.X -= 0.1f/16;
|
||||
p1.Z -= 0.1f/16; p2.Z -= 0.1f/16;
|
||||
} else if (info.Draw[selected.Block] == DrawType.Translucent
|
||||
&& info.Collide[selected.Block] != CollideType.Solid) {
|
||||
p1.X += 0.1f/16; p2.X += 0.1f/16;
|
||||
p1.Z += 0.1f/16; p2.Z += 0.1f/16;
|
||||
}
|
||||
|
||||
float size = 1/16f;
|
||||
if (dist < 32 * 32) size = 1/32f;
|
||||
|
|
Loading…
Reference in a new issue