Style: Stop hardcoding 255 everywhere.

This commit is contained in:
UnknownShadow200 2016-09-17 09:47:43 +10:00
parent bce5a35948
commit 85ce30d0ca
10 changed files with 43 additions and 40 deletions

View File

@ -138,10 +138,11 @@ namespace MCGalaxy {
if ((C.data.Raw & mask) == 0 || ExtraInfoPhysics.DoDoorsOnly(this, ref C, null)) {
Block.HandlePhysics handler = Block.physicsDoorsHandlers[blocks[C.b]];
if (handler != null)
if (handler != null) {
handler(this, ref C);
else if ((C.data.Raw & mask) == 0 || !C.data.HasWait)
C.data.Data = 255;
} else if ((C.data.Raw & mask) == 0 || !C.data.HasWait) {
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
}
ListCheck.Items[i] = C;
} catch {
@ -160,10 +161,11 @@ namespace MCGalaxy {
if ((C.data.Raw & mask) == 0 || ExtraInfoPhysics.DoComplex(this, ref C)) {
Block.HandlePhysics handler = Block.physicsHandlers[blocks[C.b]];
if (handler != null)
if (handler != null) {
handler(this, ref C);
else if ((C.data.Raw & mask) == 0 || !C.data.HasWait)
C.data.Data = 255;
} else if ((C.data.Raw & mask) == 0 || !C.data.HasWait) {
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
}
ListCheck.Items[i] = C;
} catch {
@ -271,7 +273,7 @@ namespace MCGalaxy {
ushort x, y, z;
for (int i = 0; i < count; i++) {
if (items[i].data.Data == 255) {
if (items[i].data.Data == PhysicsArgs.RemoveFromChecks) {
IntToPos(items[i].b, out x, out y, out z);
listCheckExists.Set(x, y, z, false);
continue;
@ -326,7 +328,7 @@ namespace MCGalaxy {
}
try {
PhysicsArgs args = (PhysicsArgs)C.data;
PhysicsArgs args = C.data;
if (args.Type1 == PhysicsArgs.Revert)
Blockchange(x, y, z, args.Value1, true);
if (args.Type2 == PhysicsArgs.Revert)

View File

@ -39,14 +39,14 @@ namespace MCGalaxy.BlockPhysics {
if (x == 0 || x == lvl.Width - 1 || z == 0 || z == lvl.Length - 1)
lvl.AddUpdate(C.b, Block.water);
}
if (!C.data.HasWait) C.data.Data = 255;
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
}
public static void DoFlood(Level lvl, ref Check C, AirFlood mode, byte block) {
Random rand = lvl.physRandom;
if (C.data.Data >= 1) {
lvl.AddUpdate(C.b, Block.air);
C.data.Data = 255; return;
C.data.Data = PhysicsArgs.RemoveFromChecks; return;
}
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);

View File

@ -56,7 +56,7 @@ namespace MCGalaxy.BlockPhysics {
break;
}
lvl.AddUpdate(C.b, Block.air);
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
static void FlyTo(Level lvl, ref Check C, int x, int y, int z) {

View File

@ -22,15 +22,13 @@ namespace MCGalaxy.BlockPhysics {
public static class DoorPhysics {
public static void odoorPhysics(Level lvl, ref Check C) {
if (C.data.Data != 0) { C.data.Data = 255; return; }
odoorNeighbour(lvl, ref C, lvl.IntOffset(C.b, -1, 0, 0));
odoorNeighbour(lvl, ref C, lvl.IntOffset(C.b, +1, 0, 0));
odoorNeighbour(lvl, ref C, lvl.IntOffset(C.b, 0, -1, 0));
odoorNeighbour(lvl, ref C, lvl.IntOffset(C.b, 0, +1, 0));
odoorNeighbour(lvl, ref C, lvl.IntOffset(C.b, 0, 0, -1));
odoorNeighbour(lvl, ref C, lvl.IntOffset(C.b, 0, 0, +1));
C.data.Data++;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
static void odoorNeighbour(Level lvl, ref Check C, int index) {
@ -66,7 +64,7 @@ namespace MCGalaxy.BlockPhysics {
C.data.Data++;
} else {
lvl.AddUpdate(C.b, Block.Props[lvl.blocks[C.b]].DoorId);
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
}
}

View File

@ -106,7 +106,7 @@ namespace MCGalaxy.BlockPhysics {
{
case Block.air:
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.WaterDown);
if (!C.data.HasWait) C.data.Data = 255;
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
break;
case Block.air_flood_down:
case Block.lavastill:
@ -119,7 +119,7 @@ namespace MCGalaxy.BlockPhysics {
LiquidPhysics.PhysWater(lvl, (ushort)(x - 1), y, z, block);
LiquidPhysics.PhysWater(lvl, x, y, (ushort)(z + 1),block);
LiquidPhysics.PhysWater(lvl, x, y, (ushort)(z - 1), block);
if (!C.data.HasWait) C.data.Data = 255;
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
break;
}
}
@ -134,7 +134,7 @@ namespace MCGalaxy.BlockPhysics {
{
case Block.air:
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.LavaDown);
if (!C.data.HasWait) C.data.Data = 255;
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
break;
case Block.air_flood_down:
case Block.lavastill:
@ -147,7 +147,7 @@ namespace MCGalaxy.BlockPhysics {
LiquidPhysics.PhysLava(lvl, (ushort)(x - 1), y, z, block);
LiquidPhysics.PhysLava(lvl, x, y, (ushort)(z + 1),block);
LiquidPhysics.PhysLava(lvl, x, y, (ushort)(z - 1), block);
if (!C.data.HasWait) C.data.Data = 255;
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
break;
}
}

View File

@ -26,7 +26,7 @@ namespace MCGalaxy.BlockPhysics {
C.data.ResetTypes();
if (C.data.Type1 == PhysicsArgs.TntWars) return true;
bool wait = false, door = C.data.TDoor;
bool wait = false, tdoor = C.data.TDoor;
int waitTime = 0;
if (C.data.Type1 == PhysicsArgs.Wait) {
wait = true; waitTime = C.data.Value1;
@ -35,7 +35,7 @@ namespace MCGalaxy.BlockPhysics {
}
if (!wait) return false;
if (door && C.data.Data < 2) {
if (tdoor && C.data.Data < 2) {
// TODO: perhaps do proper bounds checking
Checktdoor(lvl, lvl.IntOffset(C.b, -1, 0, 0));
Checktdoor(lvl, lvl.IntOffset(C.b, 1, 0, 0));

View File

@ -35,14 +35,14 @@ namespace MCGalaxy.BlockPhysics {
if (!lvl.leafDecay) {
lvl.leaves.Clear();
C.data.Data = 255; return;
C.data.Data = PhysicsArgs.RemoveFromChecks; return;
}
if (C.data.Data < 5) {
if (rand.Next(10) == 0) C.data.Data++;
return;
}
if (DoLeafDecay(lvl, ref C)) lvl.AddUpdate(C.b, Block.air);
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
static bool DoLeafDecay(Level lvl, ref Check C) {

View File

@ -24,7 +24,6 @@ namespace MCGalaxy.BlockPhysics {
public static class OtherPhysics {
public static void DoFalling(Level lvl, ref Check C) {
if (lvl.physics == 0 || lvl.physics == 5) { C.data.Data = 255; return; }
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
int index = C.b;
@ -70,7 +69,7 @@ namespace MCGalaxy.BlockPhysics {
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, y, (ushort)(z - 1)));
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, (ushort)(y + 1), z));
}
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
public static void DoStairs(Level lvl, ref Check C) {
@ -84,7 +83,7 @@ namespace MCGalaxy.BlockPhysics {
lvl.AddUpdate(C.b, Block.air);
lvl.AddUpdate(bBelow, Block.stone);
}
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
public static void DoFloatwood(Level lvl, ref Check C) {
@ -99,7 +98,7 @@ namespace MCGalaxy.BlockPhysics {
lvl.AddUpdate(index, Block.wood_float);
}
}
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
public static void DoShrub(Level lvl, ref Check C) {
@ -114,7 +113,7 @@ namespace MCGalaxy.BlockPhysics {
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, (ushort)(y + 1), z));
}
if (!lvl.growTrees) { C.data.Data = 255; return; }
if (!lvl.growTrees) { C.data.Data = PhysicsArgs.RemoveFromChecks; return; }
if (C.data.Data < 20) {
if (rand.Next(20) == 0) C.data.Data++;
return;
@ -128,11 +127,11 @@ namespace MCGalaxy.BlockPhysics {
op.Perform(marks, null, lvl, null,
b => lvl.Blockchange(b.X, b.Y, b.Z, b.Block));
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
public static void DoDirt(Level lvl, ref Check C) {
if (!lvl.GrassGrow) { C.data.Data = 255; return; }
if (!lvl.GrassGrow) { C.data.Data = PhysicsArgs.RemoveFromChecks; return; }
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
@ -143,7 +142,7 @@ namespace MCGalaxy.BlockPhysics {
if (Block.LightPass(block, extBlock, lvl.CustomBlockDefs))
lvl.AddUpdate(C.b, Block.grass);
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
} else {
C.data.Data++;
}
@ -161,7 +160,7 @@ namespace MCGalaxy.BlockPhysics {
if ((!lava && Block.Convert(block) == Block.water) || (lava && Block.Convert(block) == Block.lava))
lvl.AddUpdate(index, Block.air);
}
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
public static void DoSpongeRemoved(Level lvl, int b, bool lava = false) {
@ -182,7 +181,7 @@ namespace MCGalaxy.BlockPhysics {
}
public static void DoOther(Level lvl, ref Check C) {
if (lvl.physics <= 1) { C.data.Data = 255; return; }
if (lvl.physics <= 1) { C.data.Data = PhysicsArgs.RemoveFromChecks; return; }
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
@ -192,7 +191,7 @@ namespace MCGalaxy.BlockPhysics {
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, y, (ushort)(z + 1)));
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, y, (ushort)(z - 1)));
AirPhysics.PhysAir(lvl, lvl.PosToInt(x, (ushort)(y + 1), z));
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
}
}

View File

@ -28,6 +28,10 @@ namespace MCGalaxy.BlockPhysics {
public const uint TypeBitsMask = 0x07;
public const uint ValueBitsMask = 0xFF;
/// <summary> Indicates that this physics entry should be removed from the list of
/// entries that are checked for physics, at the end of the current tick. </summary>
public const byte RemoveFromChecks = 255;
public byte Type1 {
get { return (byte)(Raw & TypeBitsMask); }
set { Raw &= ~TypeBitsMask;

View File

@ -112,14 +112,14 @@ namespace MCGalaxy.BlockPhysics {
} else { //was placed near sponge
lvl.liquids.TryGetValue(C.b, out blocked);
lvl.AddUpdate(C.b, Block.air);
if (!C.data.HasWait) C.data.Data = 255;
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
}
if (!C.data.HasWait && blocked != null)
if (blocked[0] && blocked[1] && blocked[2] && blocked[3] && blocked[4])
{
lvl.liquids.Remove(C.b);
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
}
@ -141,7 +141,7 @@ namespace MCGalaxy.BlockPhysics {
} else { //was placed near sponge
lvl.AddUpdate(C.b, Block.air);
}
if (!C.data.HasWait) C.data.Data = 255;
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
}
static bool WaterBlocked(Level lvl, ushort x, ushort y, ushort z) {
@ -224,14 +224,14 @@ namespace MCGalaxy.BlockPhysics {
lvl.liquids.TryGetValue(C.b, out blocked);
lvl.AddUpdate(C.b, Block.air);
if (!checkWait || !C.data.HasWait)
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
if (blocked != null && (!checkWait || !C.data.HasWait))
if (blocked[0] && blocked[1] && blocked[2] && blocked[3] && blocked[4])
{
lvl.liquids.Remove(C.b);
C.data.Data = 255;
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
}
@ -251,7 +251,7 @@ namespace MCGalaxy.BlockPhysics {
} else { //was placed near sponge
lvl.AddUpdate(C.b, Block.air);
}
if (!checkWait || !C.data.HasWait) C.data.Data = 255;
if (!checkWait || !C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
}
static bool LavaBlocked(Level lvl, ushort x, ushort y, ushort z) {