Skip to content

Commit

Permalink
Fix /undo, /redo, and /undo physics.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Feb 13, 2016
1 parent f437eb4 commit 78e57fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
5 changes: 0 additions & 5 deletions Commands/building/CmdRedo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ public override void Use(Player p, string message) {
byte type = lvl.GetTile(Pos.x, Pos.y, Pos.z), extType = 0;
if (type == Block.custom_block)
extType = lvl.GetExtTile(Pos.x, Pos.y, Pos.z);

lvl.Blockchange(p, Pos.x, Pos.y, Pos.z, Pos.type, Pos.extType);
Pos.newtype = Pos.type; Pos.newExtType = Pos.extType;
Pos.type = type; Pos.extType = extType;
Pos.timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;
p.UndoBuffer.Add(Pos);
}

Player.SendMessage(p, "Redo performed.");
Expand Down
3 changes: 1 addition & 2 deletions Commands/building/CmdUndo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ void UndoOnlinePlayer(Player p, long seconds, string whoName, Player who) {
try {
Player.UndoPos Pos = who.UndoBuffer[i];
if (!CheckBlockPlayer(p, seconds, Pos, ref saveLevel)) break;
who.UndoBuffer.RemoveAt(i);
} catch { }
}
bool foundUser = false;
Expand Down Expand Up @@ -191,7 +190,7 @@ bool CheckBlockPhysics(Player p, long seconds, int i, Level.UndoPos undo) {
p.level.currentUndo = i;
p.level.IntToPos(undo.location, out x, out y, out z);
p.level.currentUndo = undoIndex;
p.level.Blockchange(x, y, z, undo.oldType, true, "", undo.oldExtType);
p.level.Blockchange(x, y, z, undo.oldType, true, "", undo.oldExtType, false);
}
return true;
}
Expand Down
37 changes: 20 additions & 17 deletions Levels/Level.Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void Blockchange(Player p, ushort x, ushort y, ushort z, byte type, byte
}
}

public void Blockchange(int b, byte type, bool overRide = false, string extraInfo = "", byte extType = 0) { //Block change made by physics
public void Blockchange(int b, byte type, bool overRide = false, string extraInfo = "", byte extType = 0, bool addUndo = true) { //Block change made by physics
if (b < 0 || b >= blocks.Length || blocks == null) return;
if (b >= blocks.Length) return;
byte oldBlock = blocks[b];
Expand All @@ -385,21 +385,23 @@ public void Blockchange(int b, byte type, bool overRide = false, string extraInf
if (b == Block.lava_sponge && physics > 0 && type != Block.lava_sponge)
PhysSpongeRemoved(b, true);

UndoPos uP;
uP.location = b;
uP.newType = type; uP.newExtType = extType;
uP.oldType = oldBlock; uP.oldExtType = oldExtType;
uP.timePerformed = DateTime.Now;
if (addUndo) {
UndoPos uP;
uP.location = b;
uP.newType = type; uP.newExtType = extType;
uP.oldType = oldBlock; uP.oldExtType = oldExtType;
uP.timePerformed = DateTime.Now;

if (currentUndo > Server.physUndo) {
currentUndo = 0;
UndoBuffer[currentUndo] = uP;
} else if (UndoBuffer.Count < Server.physUndo) {
currentUndo++;
UndoBuffer.Add(uP);
} else {
currentUndo++;
UndoBuffer[currentUndo] = uP;
if (currentUndo > Server.physUndo) {
currentUndo = 0;
UndoBuffer[currentUndo] = uP;
} else if (UndoBuffer.Count < Server.physUndo) {
currentUndo++;
UndoBuffer.Add(uP);
} else {
currentUndo++;
UndoBuffer[currentUndo] = uP;
}
}

blocks[b] = type;
Expand Down Expand Up @@ -427,8 +429,9 @@ public void Blockchange(int b, byte type, bool overRide = false, string extraInf
}
}

public void Blockchange(ushort x, ushort y, ushort z, byte type, bool overRide = false, string extraInfo = "", byte extType = 0) {
Blockchange(PosToInt(x, y, z), type, overRide, extraInfo, extType); //Block change made by physics
public void Blockchange(ushort x, ushort y, ushort z, byte type, bool overRide = false,
string extraInfo = "", byte extType = 0, bool addUndo = true) {
Blockchange(PosToInt(x, y, z), type, overRide, extraInfo, extType, addUndo); //Block change made by physics
}

public void Blockchange(ushort x, ushort y, ushort z, byte type, byte extType) {
Expand Down
1 change: 1 addition & 0 deletions Levels/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ public unsafe void saveChanges() {
}
tempCache.Clear();
blockCache = new List<BlockPos>();
Server.s.Log("Saved BlockDB changes for:" + name);
}

unsafe bool DoSaveChanges(List<BlockPos> tempCache, char* ptr, string date,
Expand Down

0 comments on commit 78e57fc

Please sign in to comment.