mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Extend PhysicsArgs ExtBlock to two bits
This commit is contained in:
parent
4f4427b357
commit
4cecface9c
@ -331,5 +331,6 @@ namespace MCGalaxy
|
||||
public const byte Invalid = 0xff;
|
||||
|
||||
public const ushort Extended = 256;
|
||||
public const int ExtendedShift = 8;
|
||||
}
|
||||
}
|
@ -86,7 +86,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.Type1 = PhysicsArgs.Custom; args.Value1 = 16 - 1;
|
||||
args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)block;
|
||||
args.ExtBlock = block >= Block.Extended;
|
||||
args.ExtBlock = (byte)(block >> Block.ExtendedShift);
|
||||
|
||||
physForm = Block.Door_Log_air; // air
|
||||
if (block == Block.Door_Air || block == Block.Door_AirActivatable) {
|
||||
@ -103,7 +103,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.Type1 = PhysicsArgs.Custom; args.Value1 = 16;
|
||||
args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)block;
|
||||
args.ExtBlock = block >= Block.Extended;
|
||||
args.ExtBlock = (byte)(block >> Block.ExtendedShift);
|
||||
return args;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
public static void Do(Level lvl, ref PhysInfo C) {
|
||||
if (C.Data.Type1 != PhysicsArgs.Custom) return;
|
||||
if (C.Data.Data == 0) {
|
||||
BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock ? Block.Extended : 0));
|
||||
BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock << Block.ExtendedShift));
|
||||
bool tdoor = lvl.Props[block].IsTDoor;
|
||||
|
||||
if (tdoor) tDoor(lvl, ref C);
|
||||
@ -44,7 +44,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
// Change anys door blocks nearby into air forms
|
||||
static void Door(Level lvl, ref PhysInfo C) {
|
||||
ushort x = C.X, y = C.Y, z = C.Z;
|
||||
BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock ? Block.Extended : 0));
|
||||
BlockID block = (BlockID)(C.Data.Value2 | (C.Data.ExtBlock << Block.ExtendedShift));
|
||||
bool instant = block == Block.Door_Air || block == Block.Door_AirActivatable;
|
||||
|
||||
ActivateablePhysics.DoDoors(lvl, (ushort)(x + 1), y, z, instant);
|
||||
|
@ -85,7 +85,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
|
||||
if (args.Revert) {
|
||||
PhysicsArgs revertArgs = default(PhysicsArgs);
|
||||
if (args.ExtBlock) revertArgs.Raw |= PhysicsArgs.ExtBit;
|
||||
revertArgs.ExtBlock = args.ExtBlock;
|
||||
lvl.AddUpdate(C.Index, args.RevertType, revertArgs);
|
||||
|
||||
C.Data.ResetTypes();
|
||||
@ -141,9 +141,9 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
}
|
||||
|
||||
struct ExtraInfoArgs {
|
||||
public bool Wait, Drop, Dissipate, Revert, Explode, Rainbow, ExtBlock;
|
||||
public bool Wait, Drop, Dissipate, Revert, Explode, Rainbow;
|
||||
public int WaitTime, DropNum, DissipateNum, ExplodeNum, RainbowNum;
|
||||
public byte RevertType;
|
||||
public byte RevertType, ExtBlock;
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
public const uint TypeBitsMask = 0x07;
|
||||
public const uint ValueBitsMask = 0xFF;
|
||||
public const uint ExtBit = 1u << 30;
|
||||
public const uint ExtBits = (1u << 30) | (1u << 31);
|
||||
|
||||
/// <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>
|
||||
@ -58,9 +59,9 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
set { Raw &= ~(ValueBitsMask << 22); Raw |= (uint)value << 22; }
|
||||
}
|
||||
|
||||
public bool ExtBlock {
|
||||
get { return (Raw & ExtBit) != 0; }
|
||||
set { Raw &= ~ExtBit; Raw |= value ? ExtBit : 0u; }
|
||||
public byte ExtBlock {
|
||||
get { return (byte)(Raw >> 30); }
|
||||
set { Raw &= ~ExtBits; Raw |= (uint)value << 30; }
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,7 +49,7 @@ namespace MCGalaxy.Blocks.Physics {
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
|
||||
args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)below;
|
||||
args.ExtBlock = below >= Block.Extended;
|
||||
args.ExtBlock = (byte)(below >> Block.ExtendedShift);
|
||||
|
||||
lvl.AddUpdate(belowIndex, newBlock, args, true);
|
||||
return;
|
||||
|
@ -54,7 +54,7 @@ namespace MCGalaxy {
|
||||
/// <summary> Returns whether the given color code is defined. </summary>
|
||||
/// <remarks> NOTE: This returns false for A to F, be warned! </remarks>
|
||||
public static bool IsDefined(char c) {
|
||||
if (c >= '~' && c <= '~') return List[c].Fallback != '\0';
|
||||
if (c >= ' ' && c <= '~') return List[c].Fallback != '\0';
|
||||
return List[c.UnicodeToCp437()].Fallback != '\0';
|
||||
}
|
||||
|
||||
|
@ -47,31 +47,31 @@ namespace MCGalaxy.Commands.Building {
|
||||
Help(p); return false;
|
||||
}
|
||||
byte type = 0, value = 0;
|
||||
bool isExt = false;
|
||||
byte extBits = 0;
|
||||
|
||||
if (parts.Length >= 2) {
|
||||
if (!Parse(p, parts[0], parts[1], ref type, ref value, ref isExt)) return false;
|
||||
if (!Parse(p, parts[0], parts[1], ref type, ref value, ref extBits)) return false;
|
||||
args.Type1 = type; args.Value1 = value;
|
||||
}
|
||||
if (parts.Length >= 4) {
|
||||
if (!Parse(p, parts[2], parts[3], ref type, ref value, ref isExt)) return false;
|
||||
if (!Parse(p, parts[2], parts[3], ref type, ref value, ref extBits)) return false;
|
||||
args.Type2 = type; args.Value2 = value;
|
||||
}
|
||||
if (parts.Length >= 6) {
|
||||
Player.Message(p, "You can only use up to two types of physics."); return false;
|
||||
}
|
||||
|
||||
args.ExtBlock = isExt;
|
||||
args.ExtBlock = extBits;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parse(Player p, string name, string arg, ref byte type, ref byte value, ref bool isExt) {
|
||||
bool Parse(Player p, string name, string arg, ref byte type, ref byte value, ref byte isExt) {
|
||||
if (name == "revert") {
|
||||
BlockID block;
|
||||
if (!CommandParser.GetBlock(p, arg, out block)) return false;
|
||||
|
||||
type = PhysicsArgs.Revert; value = (BlockRaw)block;
|
||||
isExt = block >= Block.Extended;
|
||||
isExt = (byte)(block >> Block.ExtendedShift);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -175,13 +175,16 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
// Check to make sure the block is actually different and that we can change it
|
||||
if (old == b.Block || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block)) return;
|
||||
|
||||
// Set the block (inlined)
|
||||
lvl.blocks[index] = b.Block >= Block.Extended ? Block.custom_block : (BlockRaw)b.Block;
|
||||
// Set the block (inlined)
|
||||
lvl.Changed = true;
|
||||
if (b.Block >= Block.Extended) {
|
||||
lvl.blocks[index] = Block.custom_block;
|
||||
lvl.SetExtTileNoCheck(b.X, b.Y, b.Z, (BlockRaw)b.Block);
|
||||
} else if (old >= Block.Extended) {
|
||||
lvl.RevertExtTileNoCheck(b.X, b.Y, b.Z);
|
||||
} else {
|
||||
lvl.blocks[index] = (BlockRaw)b.Block;
|
||||
if (old >= Block.Extended) {
|
||||
lvl.RevertExtTileNoCheck(b.X, b.Y, b.Z);
|
||||
}
|
||||
}
|
||||
|
||||
if (p != null) {
|
||||
|
@ -247,12 +247,14 @@ namespace MCGalaxy {
|
||||
else p.TotalPlaced++;
|
||||
|
||||
errorLocation = "Setting tile";
|
||||
BlockRaw raw = block >= Block.Extended ? Block.custom_block : (BlockRaw)block;
|
||||
SetTile(x, y, z, raw);
|
||||
if (block >= Block.Extended) {
|
||||
SetTile(x, y, z, Block.custom_block);
|
||||
SetExtTileNoCheck(x, y, z, (BlockRaw)block);
|
||||
} else if (old >= Block.Extended) {
|
||||
RevertExtTileNoCheck(x, y, z);
|
||||
} else {
|
||||
SetTile(x, y, z, (BlockRaw)block);
|
||||
if (old >= Block.Extended) {
|
||||
RevertExtTileNoCheck(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
errorLocation = "Adding physics";
|
||||
@ -329,17 +331,20 @@ namespace MCGalaxy {
|
||||
}
|
||||
currentUndo++;
|
||||
}
|
||||
|
||||
blocks[b] = block >= Block.Extended ? Block.custom_block : (BlockRaw)block;
|
||||
|
||||
Changed = true;
|
||||
if (block >= Block.Extended) {
|
||||
blocks[b] = Block.custom_block;
|
||||
ushort x, y, z;
|
||||
IntToPos(b, out x, out y, out z);
|
||||
SetExtTileNoCheck(x, y, z, (BlockRaw)block);
|
||||
} else if (old >= Block.Extended) {
|
||||
ushort x, y, z;
|
||||
IntToPos(b, out x, out y, out z);
|
||||
RevertExtTileNoCheck(x, y, z);
|
||||
} else {
|
||||
blocks[b] = (BlockRaw)block;
|
||||
if (old >= Block.Extended) {
|
||||
ushort x, y, z;
|
||||
IntToPos(b, out x, out y, out z);
|
||||
RevertExtTileNoCheck(x, y, z);
|
||||
}
|
||||
}
|
||||
if (physics > 0 && (ActivatesPhysics(block) || data.Raw != 0)) {
|
||||
AddCheck(b, false, data);
|
||||
@ -348,7 +353,6 @@ namespace MCGalaxy {
|
||||
// Save bandwidth sending identical looking blocks, like air/op_air changes.
|
||||
return !Block.VisuallyEquals(old, block);
|
||||
} catch {
|
||||
blocks[b] = block >= Block.Extended ? Block.custom_block : (BlockRaw)block;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -184,9 +184,10 @@ namespace MCGalaxy {
|
||||
U.data.Data = 0;
|
||||
|
||||
// Is the Ext flag just an indicator for the block update?
|
||||
if (U.data.ExtBlock && (U.data.Raw & PhysicsArgs.TypeMask) == 0) {
|
||||
block |= Block.Extended;
|
||||
U.data.Raw &= ~PhysicsArgs.ExtBit;
|
||||
byte extBits = U.data.ExtBlock;
|
||||
if (extBits != 0 && (U.data.Raw & PhysicsArgs.TypeMask) == 0) {
|
||||
block |= (BlockID)(extBits << Block.ExtendedShift);
|
||||
U.data.Raw &= ~PhysicsArgs.ExtBits;
|
||||
}
|
||||
|
||||
if (DoPhysicsBlockchange(U.Index, block, false, U.data, true))
|
||||
@ -235,7 +236,7 @@ namespace MCGalaxy {
|
||||
|
||||
internal bool AddUpdate(int index, BlockID block, bool overRide = false) {
|
||||
PhysicsArgs args = default(PhysicsArgs);
|
||||
if (block >= Block.Extended) args.Raw |= PhysicsArgs.ExtBit;
|
||||
args.Raw |= (uint)(PhysicsArgs.ExtBit * (block >> Block.ExtendedShift));
|
||||
return AddUpdate(index, block, args, overRide);
|
||||
}
|
||||
|
||||
@ -248,8 +249,8 @@ namespace MCGalaxy {
|
||||
|
||||
if (overRide) {
|
||||
// Is the Ext flag just an indicator for the block update?
|
||||
if (data.ExtBlock && (data.Raw & PhysicsArgs.TypeMask) == 0) {
|
||||
data.Raw &= ~PhysicsArgs.ExtBit;
|
||||
if (data.ExtBlock != 0 && (data.Raw & PhysicsArgs.TypeMask) == 0) {
|
||||
data.Raw &= ~PhysicsArgs.ExtBits;
|
||||
}
|
||||
AddCheck(index, true, data); //Dont need to check physics here....AddCheck will do that
|
||||
Blockchange((ushort)x, (ushort)y, (ushort)z, block, true, data);
|
||||
@ -331,13 +332,13 @@ namespace MCGalaxy {
|
||||
ushort x, y, z;
|
||||
IntToPos(C.Index, out x, out y, out z);
|
||||
|
||||
BlockID block = Block.FromRaw(args.Value1, args.ExtBlock);
|
||||
BlockID block = (BlockID)(args.Value1 | (args.ExtBlock << 8));
|
||||
Blockchange(C.Index, block, true, default(PhysicsArgs));
|
||||
} else if (args.Type2 == PhysicsArgs.Revert) {
|
||||
ushort x, y, z;
|
||||
IntToPos(C.Index, out x, out y, out z);
|
||||
|
||||
BlockID block = Block.FromRaw(args.Value2, args.ExtBlock);
|
||||
BlockID block = (BlockID)(args.Value2 | (args.ExtBlock << 8));
|
||||
Blockchange(C.Index, block, true, default(PhysicsArgs));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user