Skip to content

Commit

Permalink
/abort: Get rid of 'remove unsent pending block updates made by the …
Browse files Browse the repository at this point in the history
…player' code (Thanks Goodly)

Because the actual blocks in the level blocks arrays were still updated, all this resulted in was the appearance of the map in clients becoming out of sync with the actual blocks in the map. (i.e. the blocks were actually changed, but didn't appear changed to clients until /reload ing)
  • Loading branch information
UnknownShadow200 committed Mar 18, 2022
1 parent 9e8f06f commit 4be17cc
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 22 deletions.
1 change: 0 additions & 1 deletion MCGalaxy/Commands/building/CmdAbort.cs
Expand Up @@ -38,7 +38,6 @@ public sealed class CmdAbort : Command2 {
p.DefaultBrushArgs = "";
p.Transform = NoTransform.Instance;

p.level.blockqueue.RemoveAll(p);
if (p.weapon != null) p.weapon.Disable();
p.Message("Every toggle or action was aborted.");
}
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs
Expand Up @@ -199,7 +199,7 @@ class DrawOpOutputter {
lvl.blockqueue.ClearAll();
} else if (op.TotalModified < reloadThreshold) {
if (!Block.VisuallyEquals(old, b.Block)) {
lvl.blockqueue.Add(p, index, b.Block);
lvl.blockqueue.Add(index, b.Block);
}

if (lvl.physics > 0) {
Expand Down
22 changes: 5 additions & 17 deletions MCGalaxy/Levels/BlockQueue.cs
Expand Up @@ -31,10 +31,7 @@ public sealed class BlockQueue : List<ulong> {
public static int UpdatesPerTick = 750;
static BufferedBlockSender bulkSender = new BufferedBlockSender();

const int posShift = 32;
const int idShift = 12;
const int blockMask = (1 << 12) - 1;

const int posShift = 32;
readonly object locker = new object();

/// <summary> Flushes the block updates queue for each loaded level. </summary>
Expand All @@ -51,25 +48,16 @@ public sealed class BlockQueue : List<ulong> {
}

/// <summary> Adds a block update to the end of the queue. </summary>
public void Add(Player p, int index, BlockID block) {
public void Add(int index, BlockID block) {
// Bit packing format
// 32-63: index
// 12-31: session ID
// 0-11: block type
// 0-31 : block type
ulong flags = (ulong)index << posShift;
flags |= (ulong)p.SessionID << idShift;
flags |= (ulong)block & blockMask;
flags |= (ulong)block;

lock (locker) Add(flags);
}

/// <summary> Removes all block updates from the queue associated with the given player. </summary>
public void RemoveAll(Player p) {
lock (locker) {
RemoveAll(b => (int)((b >> idShift) & Player.SessionIDMask) == p.SessionID);
}
}

/// <summary> Removes all block updates from the queue. </summary>
public void ClearAll() { lock (locker) Clear(); }

Expand All @@ -85,7 +73,7 @@ public sealed class BlockQueue : List<ulong> {
for (int i = 0; i < count; i++) {
ulong flags = this[i];
int index = (int)(flags >> posShift);
BlockID block = (BlockID)(flags & blockMask);
BlockID block = (BlockID)flags;
bulkSender.Add(index, block);
}
bulkSender.Flush();
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Levels/Level.Blocks.cs
Expand Up @@ -458,7 +458,7 @@ public sealed partial class Level : IDisposable
if (result == ChangeResult.VisuallySame) return;

if (buffered) {
p.level.blockqueue.Add(p, index, block);
p.level.blockqueue.Add(index, block);
} else {
BroadcastChange(x, y, z, block);
}
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/MCGalaxy_.csproj
Expand Up @@ -683,7 +683,6 @@
<Compile Include="util\Utils.cs" />
<Compile Include="sharkbite.thresher\Connection.cs" />
<Compile Include="sharkbite.thresher\Listener.cs" />
<Compile Include="sharkbite.thresher\NameGenerator.cs" />
<Compile Include="sharkbite.thresher\ReplyCode.cs" />
<Compile Include="sharkbite.thresher\Rfc2812Util.cs" />
<Compile Include="sharkbite.thresher\UserInfo.cs" />
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/sharkbite.thresher/Connection.cs
Expand Up @@ -106,7 +106,7 @@ string GetNewNick()
// prefer just adding _ to end of real nick
if (Nick.Length < MAX_NICKNAME_LEN) return Nick + "_";

// .. and then just randomly mutate a character
// .. and then just randomly mutate a leading character
int idx = rnd.Next(MAX_NICKNAME_LEN / 3);
char val = (char)('A' + rnd.Next(26));
return Nick.Substring(0, idx) + val + Nick.Substring(idx + 1);
Expand Down

0 comments on commit 4be17cc

Please sign in to comment.