Fix not being able to place blocks in other maps when zombie survival is active, also Blockqueue now uses BulkBlockUpdate if applicable.

This commit is contained in:
UnknownShadow200 2016-03-23 10:24:43 +11:00
parent 6fd3f50914
commit 5687901de6
6 changed files with 29 additions and 18 deletions

View File

@ -55,7 +55,7 @@ namespace MCGalaxy.Commands
else upTime += up.Seconds + " seconds";
Player.SendMessage(p, upTime);
if (Server.updateTimer.Interval > 1000) Player.SendMessage(p, "This server is currently in &5Low Lag" + Server.DefaultColor + " mode.");
}
}
}
public override void Help(Player p)
{

View File

@ -24,7 +24,8 @@ namespace MCGalaxy.Games {
public override bool HandlesManualChange(Player p, ushort x, ushort y, ushort z,
byte action, byte tile, byte b) {
if (Status == ZombieGameStatus.NotStarted
|| (p.level == null || !p.level.name.CaselessEq(CurrentLevelName))) return false;
if (CurrentLevel.BuildType == BuildType.NoModify) {
p.RevertBlock(x, y, z); return true;
} else if (CurrentLevel.BuildType == BuildType.ModifyOnly
@ -65,7 +66,8 @@ namespace MCGalaxy.Games {
public override bool HandlesMovement(Player p, ushort x, ushort y, ushort z,
byte rotX, byte rotY) {
if (p.level == null || !p.level.name.CaselessEq(CurrentLevelName)) return false;
if (Status == ZombieGameStatus.NotStarted
|| (p.level == null || !p.level.name.CaselessEq(CurrentLevelName))) return false;
if (!p.referee && noRespawn) {
if (p.pos[0] >= x + 70 || p.pos[0] <= x - 70 ) {
p.SendPos(0xFF, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]);

View File

@ -24,6 +24,7 @@ namespace MCGalaxy {
public static int blockupdates = 250;
static System.Timers.Timer blocktimer = new System.Timers.Timer(100);
static bool started = false;
static BufferedBlockSender bulkSender = new BufferedBlockSender(null);
public static void Start() {
blocktimer.Elapsed += delegate {
@ -33,6 +34,7 @@ namespace MCGalaxy {
Level[] loaded = LevelInfo.Loaded.Items;
foreach (Level l in loaded)
ProcessLevelBlocks(l);
bulkSender.level = null;
} catch (Exception ex) {
Server.ErrorLog(ex);
throw;
@ -56,30 +58,35 @@ namespace MCGalaxy {
p.level.blockqueue.Add(item);
}
static void ProcessLevelBlocks(Level l) {
static void ProcessLevelBlocks(Level lvl) {
try {
if (l.blockqueue.Count < 1) return;
if (lvl.blockqueue.Count < 1) return;
bulkSender.level = lvl;
int count = blockupdates;
if (l.blockqueue.Count < blockupdates || l.players.Count == 0)
count = l.blockqueue.Count;
if (lvl.blockqueue.Count < blockupdates || lvl.players.Count == 0)
count = lvl.blockqueue.Count;
Level.BlockPos bP = default(Level.BlockPos);
for (int c = 0; c < count; c++) {
block item = l.blockqueue[c];
block item = lvl.blockqueue[c];
bP.name = item.p.name;
ushort x, y, z;
l.IntToPos(item.index, out x, out y, out z);
lvl.IntToPos(item.index, out x, out y, out z);
bP.index = item.index;
bP.SetData(item.type, item.extType, item.type == 0);
l.Blockchange(item.p, x, y, z, item.type, item.extType);
l.blockCache.Add(bP);
if (lvl.DoBlockchange(item.p, x, y, z, item.type, item.extType)) {
bulkSender.Add(item.index, item.type, item.extType);
bulkSender.CheckIfSend(false);
lvl.blockCache.Add(bP);
}
}
l.blockqueue.RemoveRange(0, count);
bulkSender.CheckIfSend(true);
lvl.blockqueue.RemoveRange(0, count);
} catch (Exception e) {
Server.s.ErrorCase("error:" + e);
Server.s.Log(String.Format("Block cache failed for map: {0}. {1} lost.", l.name, l.blockqueue.Count));
l.blockqueue.Clear();
Server.s.Log(String.Format("Block cache failed for map: {0}. {1} lost.", lvl.name, lvl.blockqueue.Count));
lvl.blockqueue.Clear();
}
}

View File

@ -24,7 +24,7 @@ namespace MCGalaxy {
int[] indices = new int[256];
byte[] types = new byte[256];
int count = 0;
Level level;
public Level level;
public BufferedBlockSender(Level level) {
this.level = level;

View File

@ -951,7 +951,7 @@ Next: continue;
internal void RemoveInvalidUndos() {
UndoDrawOpEntry[] items = UndoDrawOps.Items;
for (int i = 0; i < items.Length; i++) {
if (!items[i].IsValid(p))
if (!items[i].IsValid(this))
UndoDrawOps.Remove(items[i]);
}
}

View File

@ -30,12 +30,14 @@ namespace MCGalaxy.Util {
public void SetStart(Player p) {
StartNode = p.UndoBuffer.Tail;
StartIndex = StartNode.Items.Count;
if (StartNode != null)
StartIndex = StartNode.Items.Count;
}
public void SetEnd(Player p) {
EndNode = p.UndoBuffer.Tail;
EndIndex = EndNode.Items.Count;
if (EndNode != null)
EndIndex = EndNode.Items.Count;
}
public bool IsValid(Player p) {