From 6c75142051768b952f73971074d450b33f934784 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 8 Apr 2016 12:35:15 +1000 Subject: [PATCH] Reorganise PhysicsArgs to work properly with two or more types. --- Levels/PhysicsArgs.cs | 105 +++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 63 deletions(-) diff --git a/Levels/PhysicsArgs.cs b/Levels/PhysicsArgs.cs index a35bd7aa2..f49735306 100644 --- a/Levels/PhysicsArgs.cs +++ b/Levels/PhysicsArgs.cs @@ -24,78 +24,57 @@ namespace MCGalaxy.BlockPhysics { public struct PhysicsArgs { public uint Raw; - // Flags - /// Whether this physics item should wait before performing its other arguments. - public bool Wait { - get { return (Raw & (1u << 0)) != 0; } - set { Raw &= ~(1u << 0); - Raw |= (value ? 1u : 0u) << 0; } + public byte Type1 { + get { return (byte)(Raw & 0x7); } + set { Raw &= ~(0x7u << 0); + Raw |= (uint)value << 0; } } - /// Whether this physics item should randomly drop downards. - public bool Drop { - get { return (Raw & (1u << 1)) != 0; } - set { Raw &= ~(1u << 1); - Raw |= (value ? 1u : 0u) << 1; } - } - - /// Whether this physics item should randomly convert back into air. - public bool Dissipate { - get { return (Raw & (1u << 2)) != 0; } - set { Raw &= ~(1u << 2); - Raw |= (value ? 1u : 0u) << 2; } - } - - /// Whether this physics item should revert back into the given block id. - public bool Revert { - get { return (Raw & (1u << 3)) != 0; } - set { Raw &= ~(1u << 3); - Raw |= (value ? 1u : 0u) << 3; } - } - - /// Whether this physics item should check itself and its neighbours for tdoor activation. - public bool Door { - get { return (Raw & (1u << 4)) != 0; } - set { Raw &= ~(1u << 4); - Raw |= (value ? 1u : 0u) << 4; } - } - - /// Whether this physics item should randomly explode. - public bool Explode { - get { return (Raw & (1u << 5)) != 0; } - set { Raw &= ~(1u << 5); - Raw |= (value ? 1u : 0u) << 5; } - } - - /// Whether this physics update should have a rainbow affect applied. - public bool Rainbow { - get { return (Raw & (1u << 6)) != 0; } - set { Raw &= ~(1u << 6); - Raw |= (value ? 1u : 0u) << 6; } - } - - // Data - public bool RandomRainbow { - get { return (Raw & (1u << 7)) != 0; } - set { Raw |= (value ? 1u : 0u) << 7; } + public byte Type2 { + get { return (byte)((Raw >> 3) & 0x7); } + set { Raw &= ~(0x7u << 3); + Raw |= (uint)value << 3; } } public byte Value1 { - get { return (byte)(Raw >> 8); } - set { Raw &= ~(0xFFu << 8); - Raw |= (uint)value << 8; } + get { return (byte)(Raw >> 6); } + set { Raw &= ~(0xFFu << 6); + Raw |= (uint)value << 6; } } public byte Value2 { - get { return (byte)(Raw >> 16); } - set { Raw &= ~(0xFFu << 16); - Raw |= (uint)value << 16; } + get { return (byte)(Raw >> 14); } + set { Raw &= ~(0xFFu << 14); + Raw |= (uint)value << 14; } } - public byte Value3 { - get { return (byte)(Raw >> 24); } - set { Raw &= ~(0xFFu << 24); - Raw |= (uint)value << 24; } + public byte Time { + get { return (byte)(Raw >> 22); } + set { Raw &= ~(0xFFu << 22); + Raw |= (uint)value << 22; } } + + public bool Door { + get { return (Raw & (1u << 30)) != 0; } + set { Raw &= ~(1u << 30); + Raw |= (value ? 1u : 0u) << 30; } + } + // TODO: what to do with last bit + + /// No special action is performed. + public const byte None = 0; + /// A specified action will be delayed for a certain time. + public const byte Wait = 1; + /// Reverts the block in the map back into the specified block id. + public const byte Revert = 2; + /// Randomly converts this physics item back into air. + public const byte Dissipate = 3; + /// Randomly causes this physics item to move down one block. + public const byte Drop = 4; + /// Randomly causes this physics item to create an explosion. + public const byte Explode = 5; + /// Causes this physics item to iterate through the 'rainbow' wool + /// block ids in either sequential or random order. + public const byte Rainbow = 6; } -} +} \ No newline at end of file