mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 15:30:58 -04:00
Fix remaining bugs with optimised binary format, deprecate saving binary format.
This commit is contained in:
parent
04198f7f94
commit
fb2b3bb8b9
@ -58,8 +58,8 @@ namespace MCGalaxy.Util {
|
|||||||
Directory.CreateDirectory(playerDir);
|
Directory.CreateDirectory(playerDir);
|
||||||
|
|
||||||
int numFiles = Directory.GetFiles(playerDir).Length;
|
int numFiles = Directory.GetFiles(playerDir).Length;
|
||||||
string path = Path.Combine(playerDir, numFiles + BinFormat.Extension);
|
string path = Path.Combine(playerDir, numFiles + NewFormat.Extension);
|
||||||
BinFormat.SaveUndoData(p.UndoBuffer, path);
|
NewFormat.SaveUndoData(p.UndoBuffer, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UndoPlayer(Player p, string target, Vec3U16[] marks, DateTime start, ref bool FoundUser) {
|
public static void UndoPlayer(Player p, string target, Vec3U16[] marks, DateTime start, ref bool FoundUser) {
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using MCGalaxy.Drawing;
|
using MCGalaxy.Drawing;
|
||||||
|
|
||||||
@ -30,66 +29,11 @@ namespace MCGalaxy.Util {
|
|||||||
const int entrySize = 12;
|
const int entrySize = 12;
|
||||||
|
|
||||||
protected override void SaveUndoData(List<Player.UndoPos> buffer, string path) {
|
protected override void SaveUndoData(List<Player.UndoPos> buffer, string path) {
|
||||||
using (FileStream fs = File.Create(path)) {
|
throw new NotSupportedException("Non-optimised binary undo files have been deprecated");
|
||||||
BinaryWriter w = new BinaryWriter(fs);
|
|
||||||
long entriesPos = 0;
|
|
||||||
ChunkHeader last = default(ChunkHeader);
|
|
||||||
|
|
||||||
foreach (Player.UndoPos uP in buffer) {
|
|
||||||
DateTime time = Server.StartTime.AddSeconds(uP.timeDelta);
|
|
||||||
int timeDiff = (int)(time - last.BaseTime).TotalSeconds;
|
|
||||||
if (last.LevelName != uP.mapName || timeDiff > 65535 || last.Entries == ushort.MaxValue) {
|
|
||||||
WriteChunkEntries(w, last.Entries, entriesPos);
|
|
||||||
last = WriteEmptyChunk(w, uP.mapName, time, ref entriesPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write((ushort)timeDiff);
|
|
||||||
w.Write(uP.x); w.Write(uP.y); w.Write(uP.z);
|
|
||||||
w.Write(uP.type); w.Write(uP.extType);
|
|
||||||
w.Write(uP.newtype); w.Write(uP.newExtType);
|
|
||||||
last.Entries++;
|
|
||||||
}
|
|
||||||
if (last.Entries > 0)
|
|
||||||
WriteChunkEntries(w, last.Entries, entriesPos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveUndoData(UndoCache buffer, string path) {
|
protected override void SaveUndoData(UndoCache buffer, string path) {
|
||||||
using (FileStream fs = File.Create(path)) {
|
throw new NotSupportedException("Non-optimised binary undo files have been deprecated");
|
||||||
BinaryWriter w = new BinaryWriter(fs);
|
|
||||||
long entriesPos = 0;
|
|
||||||
ChunkHeader last = default(ChunkHeader);
|
|
||||||
UndoCacheNode node = buffer.Tail;
|
|
||||||
|
|
||||||
while (node != null) {
|
|
||||||
List<UndoCacheItem> items = node.Items;
|
|
||||||
for (int i = 0; i < items.Count; i++) {
|
|
||||||
UndoCacheItem uP = items[i];
|
|
||||||
DateTime time = node.BaseTime.AddSeconds(uP.TimeDelta);
|
|
||||||
int timeDiff = (int)(time - last.BaseTime).TotalSeconds;
|
|
||||||
if (last.LevelName != node.MapName || timeDiff > 65535 || last.Entries == ushort.MaxValue) {
|
|
||||||
WriteChunkEntries(w, last.Entries, entriesPos);
|
|
||||||
last = WriteEmptyChunk(w, node.MapName, time, ref entriesPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
ushort x, y, z;
|
|
||||||
node.Unpack(uP.Index, out x, out y, out z);
|
|
||||||
byte tile = 0, extTile = 0;
|
|
||||||
uP.GetExtBlock(out tile, out extTile);
|
|
||||||
byte newTile = 0, newExtTile = 0;
|
|
||||||
uP.GetNewExtBlock(out newTile, out newExtTile);
|
|
||||||
|
|
||||||
w.Write((ushort)timeDiff);
|
|
||||||
w.Write(x); w.Write(y); w.Write(z);
|
|
||||||
w.Write(tile); w.Write(extTile);
|
|
||||||
w.Write(newTile); w.Write(newExtTile);
|
|
||||||
last.Entries++;
|
|
||||||
}
|
|
||||||
if (last.Entries > 0)
|
|
||||||
WriteChunkEntries(w, last.Entries, entriesPos);
|
|
||||||
node = node.Prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ReadUndoData(List<Player.UndoPos> buffer, string path) {
|
protected override void ReadUndoData(List<Player.UndoPos> buffer, string path) {
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using MCGalaxy.Drawing;
|
using MCGalaxy.Drawing;
|
||||||
using MCGalaxy.Levels.IO;
|
using MCGalaxy.Levels.IO;
|
||||||
@ -46,7 +45,7 @@ namespace MCGalaxy.Util {
|
|||||||
if (!LevelInfo.ExistsOffline(uP.mapName)) {
|
if (!LevelInfo.ExistsOffline(uP.mapName)) {
|
||||||
if (uP.mapName != lastLoggedName) {
|
if (uP.mapName != lastLoggedName) {
|
||||||
lastLoggedName = uP.mapName;
|
lastLoggedName = uP.mapName;
|
||||||
Server.s.Log("Missing map file\"" + lastLoggedName+ "\", skipping undo entries");
|
Server.s.Log("Missing map file \"" + lastLoggedName+ "\", skipping undo entries");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -169,7 +168,7 @@ namespace MCGalaxy.Util {
|
|||||||
DateTime time = chunk.BaseTime.AddTicks((item.Flags & 0x3FFF) * TimeSpan.TicksPerSecond);
|
DateTime time = chunk.BaseTime.AddTicks((item.Flags & 0x3FFF) * TimeSpan.TicksPerSecond);
|
||||||
if (time < start) { buffer.CheckIfSend(true); return false; }
|
if (time < start) { buffer.CheckIfSend(true); return false; }
|
||||||
|
|
||||||
int index = NetUtils.ReadI32(temp, offset + 2);
|
int index = I32(temp, offset + 2);
|
||||||
Pos.x = (ushort)(index % chunk.Width);
|
Pos.x = (ushort)(index % chunk.Width);
|
||||||
Pos.y = (ushort)((index / chunk.Width) / chunk.Length);
|
Pos.y = (ushort)((index / chunk.Width) / chunk.Length);
|
||||||
Pos.z = (ushort)((index / chunk.Width) % chunk.Length);
|
Pos.z = (ushort)((index / chunk.Width) % chunk.Length);
|
||||||
@ -213,7 +212,7 @@ namespace MCGalaxy.Util {
|
|||||||
DateTime time = chunk.BaseTime.AddTicks((flags & 0x3FFF) * TimeSpan.TicksPerSecond);
|
DateTime time = chunk.BaseTime.AddTicks((flags & 0x3FFF) * TimeSpan.TicksPerSecond);
|
||||||
if (time < start) return false;
|
if (time < start) return false;
|
||||||
|
|
||||||
int index = NetUtils.ReadI32(temp, offset + 2);
|
int index = I32(temp, offset + 2);
|
||||||
ushort x = (ushort)(index % chunk.Width);
|
ushort x = (ushort)(index % chunk.Width);
|
||||||
ushort y = (ushort)((index / chunk.Width) / chunk.Length);
|
ushort y = (ushort)((index / chunk.Width) / chunk.Length);
|
||||||
ushort z = (ushort)((index / chunk.Width) % chunk.Length);
|
ushort z = (ushort)((index / chunk.Width) % chunk.Length);
|
||||||
@ -228,6 +227,11 @@ namespace MCGalaxy.Util {
|
|||||||
return (ushort)(buffer[offset + 0] | buffer[offset + 1] << 8);
|
return (ushort)(buffer[offset + 0] | buffer[offset + 1] << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int I32(byte[] buffer, int offset) {
|
||||||
|
return buffer[offset + 0] | buffer[offset + 1] << 8 |
|
||||||
|
buffer[offset + 2] << 16 | buffer[offset + 3] << 24;
|
||||||
|
}
|
||||||
|
|
||||||
static bool CheckChunk(ChunkHeader chunk, DateTime start, Player p, out Level lvl) {
|
static bool CheckChunk(ChunkHeader chunk, DateTime start, Player p, out Level lvl) {
|
||||||
DateTime time = chunk.BaseTime;
|
DateTime time = chunk.BaseTime;
|
||||||
lvl = null;
|
lvl = null;
|
||||||
|
@ -19,7 +19,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using MCGalaxy.Drawing;
|
using MCGalaxy.Drawing;
|
||||||
|
|
||||||
namespace MCGalaxy.Util {
|
namespace MCGalaxy.Util {
|
||||||
@ -29,19 +28,11 @@ namespace MCGalaxy.Util {
|
|||||||
protected override string Extension { get { return ".undo"; } }
|
protected override string Extension { get { return ".undo"; } }
|
||||||
|
|
||||||
protected override void SaveUndoData(List<Player.UndoPos> buffer, string path) {
|
protected override void SaveUndoData(List<Player.UndoPos> buffer, string path) {
|
||||||
using (StreamWriter w = File.CreateText(path)) {
|
throw new NotSupportedException("Text undo files have been deprecated");
|
||||||
foreach (Player.UndoPos uP in buffer) {
|
|
||||||
DateTime time = Server.StartTimeLocal.AddSeconds(uP.timeDelta);
|
|
||||||
w.Write(
|
|
||||||
uP.mapName + " " + uP.x + " " + uP.y + " " + uP.z + " " +
|
|
||||||
time.ToString(CultureInfo.InvariantCulture).Replace(' ', '&') + " " +
|
|
||||||
uP.type + " " + uP.newtype + " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveUndoData(UndoCache buffer, string path) {
|
protected override void SaveUndoData(UndoCache buffer, string path) {
|
||||||
throw new NotImplementedException("The .txt based undo files are deprecated.");
|
throw new NotSupportedException("Text undo files have been deprecated");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ReadUndoData(List<Player.UndoPos> buffer, string path) {
|
protected override void ReadUndoData(List<Player.UndoPos> buffer, string path) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user