From a9254a03201aba00a4e52237eec05c3b423b3958 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 7 Apr 2016 20:45:59 +1000 Subject: [PATCH] Start work on packed uint32 physics args, fix checkpoint blocks. (Thanks goodlyay) --- Blocks/Behaviour/WalkthroughBehaviour.cs | 3 +- Levels/Physics/ExtraInfoPhysics.cs | 3 +- Levels/PhysicsArgs.cs | 101 +++++++++++++++++++++++ MCGalaxy_.csproj | 1 + 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 Levels/PhysicsArgs.cs diff --git a/Blocks/Behaviour/WalkthroughBehaviour.cs b/Blocks/Behaviour/WalkthroughBehaviour.cs index bc83d9eaf..744c94b7e 100644 --- a/Blocks/Behaviour/WalkthroughBehaviour.cs +++ b/Blocks/Behaviour/WalkthroughBehaviour.cs @@ -85,7 +85,8 @@ namespace MCGalaxy.BlockBehaviour { p.checkpointX = x; p.checkpointY = y; p.checkpointZ = z; int index = p.level.PosToInt(x, y, z); if (index != p.lastCheckpointIndex) { - p.SpawnEntity(p, 0xFF, p.pos[0], (ushort)((y - 1) * 32 + 51), p.pos[2], p.rot[0], p.rot[1]); + int sendY = (p.pos[1] / 32) * 32 + 10; + p.SpawnEntity(p, 0xFF, p.pos[0], (ushort)sendY, p.pos[2], p.rot[0], p.rot[1]); p.lastCheckpointIndex = index; } return true; diff --git a/Levels/Physics/ExtraInfoPhysics.cs b/Levels/Physics/ExtraInfoPhysics.cs index 6f378ae40..cf76ba1d0 100644 --- a/Levels/Physics/ExtraInfoPhysics.cs +++ b/Levels/Physics/ExtraInfoPhysics.cs @@ -41,8 +41,7 @@ namespace MCGalaxy.BlockPhysics { door = true; break; } } - if (!wait) - return false; + if (!wait) return false; if (door && C.time < 2) { // TODO: perhaps do proper bounds checking diff --git a/Levels/PhysicsArgs.cs b/Levels/PhysicsArgs.cs new file mode 100644 index 000000000..a35bd7aa2 --- /dev/null +++ b/Levels/PhysicsArgs.cs @@ -0,0 +1,101 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Runtime.InteropServices; + +namespace MCGalaxy.BlockPhysics { + + [StructLayout(LayoutKind.Sequential, Pack = 4)] + 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; } + } + + /// 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 Value1 { + get { return (byte)(Raw >> 8); } + set { Raw &= ~(0xFFu << 8); + Raw |= (uint)value << 8; } + } + + public byte Value2 { + get { return (byte)(Raw >> 16); } + set { Raw &= ~(0xFFu << 16); + Raw |= (uint)value << 16; } + } + + public byte Value3 { + get { return (byte)(Raw >> 24); } + set { Raw &= ~(0xFFu << 24); + Raw |= (uint)value << 24; } + } + } +} diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 1f8578e12..3dd855792 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -470,6 +470,7 @@ +