Use more efficient bulk block sending for console draw ops (i.e. /undo). [Untested]

This commit is contained in:
UnknownShadow200 2016-08-25 16:06:02 +10:00
parent ad08d6fa7e
commit f17b95891f
6 changed files with 28 additions and 28 deletions

View File

@ -68,9 +68,15 @@ namespace MCGalaxy.Drawing.Ops {
static void AppendDrawOp(Player p, DrawOp op, Brush brush, Vec3S32[] marks, long affected) {
if (p == null) {
foreach (var block in op.Perform(marks, p, op.Level, brush))
op.Level.Blockchange(block.X, block.Y, block.Z, block.Block,
false, default(PhysicsArgs), block.ExtBlock);
BufferedBlockSender buffer = new BufferedBlockSender(op.Level);
foreach (var b in op.Perform(marks, p, op.Level, brush)) {
int index = op.Level.PosToInt(b.X, b.Y, b.Z);
if (!op.Level.DoPhysicsBlockchange(index, b.Block, false,
default(PhysicsArgs), b.ExtBlock)) continue;
buffer.Add(index, b.Block, b.ExtBlock);
}
buffer.Send(true);
return;
}

View File

@ -78,12 +78,10 @@ namespace MCGalaxy {
ulong flags = lvl.blockqueue[i];
int index = (int)(flags >> 32);
byte type = (flags & 0x100) != 0 ? Block.custom_block : (byte)flags;
byte extType = (flags & 0x100) != 0 ? (byte)flags : Block.air;
byte extType = (flags & 0x100) != 0 ? (byte)flags : Block.air;
bulkSender.Add(index, type, extType);
bulkSender.CheckIfSend(false);
}
bulkSender.CheckIfSend(true);
bulkSender.Send(true);
lvl.blockqueue.RemoveRange(0, count);
} catch (Exception e) {
Server.s.ErrorCase("error:" + e);

View File

@ -188,10 +188,9 @@ namespace MCGalaxy {
} catch {
Server.s.Log("Phys update issue");
}
bulkSender.CheckIfSend(false);
}
if (bulkSender != null)
bulkSender.CheckIfSend(true);
bulkSender.Send(true);
ListUpdate.Clear(); listUpdateExists.Clear();
} catch (Exception e) {
Server.s.Log("Level physics error");

View File

@ -72,7 +72,7 @@ namespace MCGalaxy {
public bool IsAfk = false, AutoAfk;
public bool cmdTimer = false;
public bool UsingWom = false;
public string BrushName = "normal", DefaultBrushArgs = "";
public string BrushName = "normal", DefaultBrushArgs = "", TransformName = "none";
public string afkMessage;
byte[] leftBuffer = new byte[0];

View File

@ -48,14 +48,14 @@ namespace MCGalaxy.Undo {
foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
if (P.LevelName != lastMap) {
lvl = LevelInfo.FindExact(P.LevelName);
buffer.CheckIfSend(true);
buffer.Send(true);
buffer.level = lvl;
}
if (lvl == null || P.Time > end) continue;
UndoBlock(args.Player, lvl, P, buffer);
}
buffer.CheckIfSend(true);
buffer.Send(true);
}
@ -82,7 +82,7 @@ namespace MCGalaxy.Undo {
foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
if (P.LevelName != lastMap) {
lvl = LevelInfo.FindExact(P.LevelName);
buffer.CheckIfSend(true);
buffer.Send(true);
buffer.level = lvl;
}
@ -91,7 +91,7 @@ namespace MCGalaxy.Undo {
if (P.X > max.X || P.Y > max.Y || P.Z > max.Z) continue;
UndoBlock(args.Player, lvl, P, buffer);
}
buffer.CheckIfSend(true);
buffer.Send(true);
}
@ -121,9 +121,8 @@ namespace MCGalaxy.Undo {
? Block.red : Block.green;
buffer.Add(lvl.PosToInt(P.X, P.Y, P.Z), highlight, 0);
buffer.CheckIfSend(false);
}
buffer.CheckIfSend(true);
buffer.Send(true);
}
@ -149,12 +148,10 @@ namespace MCGalaxy.Undo {
foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
if (P.Time > end) continue;
if (!lvl.DoBlockchange(p, P.X, P.Y, P.Z, P.Block, P.ExtBlock, true)) continue;
if (!lvl.DoBlockchange(p, P.X, P.Y, P.Z, P.Block, P.ExtBlock, true)) continue;
buffer.Add(lvl.PosToInt(P.X, P.Y, P.Z), P.Block, P.ExtBlock);
buffer.CheckIfSend(false);
}
buffer.CheckIfSend(true);
buffer.Send(true);
}
@ -206,18 +203,14 @@ namespace MCGalaxy.Undo {
lvl.changed = true;
if (pl != null) {
if (lvl.DoBlockchange(pl, P.X, P.Y, P.Z, P.Block, P.ExtBlock, true)) {
if (lvl.DoBlockchange(pl, P.X, P.Y, P.Z, P.Block, P.ExtBlock, true))
buffer.Add(lvl.PosToInt(P.X, P.Y, P.Z), P.Block, P.ExtBlock);
buffer.CheckIfSend(false);
}
} else {
bool diff = Block.Convert(lvlBlock) != Block.Convert(P.Block);
if (!diff && lvlBlock == Block.custom_block)
diff = lvl.GetExtTile(P.X, P.Y, P.Z) != P.ExtBlock;
if (diff) {
if (diff)
buffer.Add(lvl.PosToInt(P.X, P.Y, P.Z), P.Block, P.ExtBlock);
buffer.CheckIfSend(false);
}
lvl.SetTile(P.X, P.Y, P.Z, P.Block);
if (P.ExtBlock == Block.custom_block)

View File

@ -42,21 +42,25 @@ namespace MCGalaxy {
this.level = player.level;
}
public void Add(int index, byte type, byte extType) {
public bool Add(int index, byte type, byte extType) {
indices[count] = index;
if (type == Block.custom_block) types[count] = extType;
else types[count] = Block.Convert(type);
count++;
return Send(false);
}
/// <summary> Sends the block change packets if either 'force' is true,
/// or the number of blocks in the buffer has reached the limit. </summary>
public void CheckIfSend(bool force) {
/// <returns> Whether block change packets were actually sent. </returns>
public bool Send(bool force) {
if (count > 0 && (force || count == 256)) {
if (player != null) SendPlayer();
else SendLevel();
count = 0;
return false;
}
return true;
}
void SendLevel() {