bool FindInMemoryBy(int[] ids, int startDelta, int endDelta, Action <BlockDBEntry> output) { BlockDBCacheNode node = Cache.Head; while (node != null) { int count = node.Count; BlockDBCacheEntry[] entries = node.Entries; for (int i = count - 1; i >= 0; i--) { BlockDBEntry entry = node.Unpack(entries[i]); if (entry.TimeDelta < startDelta) { return(true); } if (entry.TimeDelta > endDelta) { continue; } for (int j = 0; j < ids.Length; j++) { if (entry.PlayerID != ids[j]) { continue; } output(entry); break; } } lock (Cache.Locker) node = node.Prev; } return(false); }
public static void Output(Player p, string name, BlockDBEntry e) { ExtBlock oldBlock = ExtBlock.FromRaw(e.OldRaw, (e.Flags & BlockDBFlags.OldCustom) != 0); ExtBlock newBlock = ExtBlock.FromRaw(e.NewRaw, (e.Flags & BlockDBFlags.NewCustom) != 0); DateTime time = BlockDB.Epoch.AddSeconds(e.TimeDelta); TimeSpan delta = DateTime.UtcNow.Subtract(time); name = PlayerInfo.GetColoredName(p, name); if (newBlock.BlockID == Block.Air) { Player.Message(p, "{0} ago {1} &4deleted %S{2}{3}", delta.Shorten(true, false), name, p.level.BlockName(oldBlock), FormatReason(e.Flags)); } else { Player.Message(p, "{0} ago {1} &3placed %S{2}{3}", delta.Shorten(true, false), name, p.level.BlockName(newBlock), FormatReason(e.Flags)); } }
public static void Output(Player p, string name, BlockDBEntry entry) { byte oldBlock = entry.OldRaw, oldExt = 0, newBlock = entry.NewRaw, newExt = 0; if ((entry.Flags & BlockDBFlags.OldCustom) != 0) { oldExt = oldBlock; oldBlock = Block.custom_block; } if ((entry.Flags & BlockDBFlags.NewCustom) != 0) { newExt = newBlock; newBlock = Block.custom_block; } TimeSpan delta = DateTime.UtcNow.Subtract(entry.Time); name = PlayerInfo.GetColoredName(p, name); if (newBlock == Block.air) { Player.Message(p, "{0} ago {1} &4deleted %S{2}{3}", delta.Shorten(true, false), name, p.level.BlockName(oldBlock, oldExt), FormatReason(entry.Flags)); } else { Player.Message(p, "{0} ago {1} &3placed %S{2}{3}", delta.Shorten(true, false), name, p.level.BlockName(newBlock, newExt), FormatReason(entry.Flags)); } }
public static void WriteEntries(Stream s, FastList <BlockDBEntry> entries) { byte[] bulk = new byte[BulkEntries * EntrySize]; for (int i = 0; i < entries.Count; i += BulkEntries) { int count = Math.Min(BulkEntries, entries.Count - i); for (int j = 0; j < count; j++) { BlockDBEntry entry = entries.Items[i + j]; WriteI32(entry.PlayerID, bulk, j * EntrySize); WriteI32(entry.TimeDelta, bulk, j * EntrySize + 4); WriteI32(entry.Index, bulk, j * EntrySize + 8); bulk[j * EntrySize + 12] = entry.OldRaw; bulk[j * EntrySize + 13] = entry.NewRaw; WriteU16(entry.Flags, bulk, j * EntrySize + 14); } s.Write(bulk, 0, count * EntrySize); } }
void FindInMemoryAt(ushort x, ushort y, ushort z, Action <BlockDBEntry> output) { int index = (y * Dims.Z + z) * Dims.X + x; BlockDBCacheNode node = Cache.Tail; while (node != null) { BlockDBCacheEntry[] entries = node.Entries; int count = node.Count; for (int i = 0; i < count; i++) { if (entries[i].Index != index) { continue; } BlockDBEntry entry = node.Unpack(entries[i]); output(entry); } lock (Cache.Locker) node = node.Next; } }
// Inlined WriteI32/WriteU16 for better performance static void WriteEntry(BlockDBEntry entry, byte[] bulk, int index) { bulk[index + 0] = (byte)(entry.PlayerID); bulk[index + 1] = (byte)(entry.PlayerID >> 8); bulk[index + 2] = (byte)(entry.PlayerID >> 16); bulk[index + 3] = (byte)(entry.PlayerID >> 24); bulk[index + 4] = (byte)(entry.TimeDelta); bulk[index + 5] = (byte)(entry.TimeDelta >> 8); bulk[index + 6] = (byte)(entry.TimeDelta >> 16); bulk[index + 7] = (byte)(entry.TimeDelta >> 24); bulk[index + 8] = (byte)(entry.Index); bulk[index + 9] = (byte)(entry.Index >> 8); bulk[index + 10] = (byte)(entry.Index >> 16); bulk[index + 11] = (byte)(entry.Index >> 24); bulk[index + 12] = entry.OldRaw; bulk[index + 13] = entry.NewRaw; bulk[index + 14] = (byte)(entry.Flags); bulk[index + 15] = (byte)(entry.Flags >> 8); }
public static void Output(Player p, string name, BlockDBEntry e) { BlockID oldBlock = e.OldBlock, newBlock = e.NewBlock; DateTime time = BlockDB.Epoch.AddSeconds(e.TimeDelta); TimeSpan delta = DateTime.UtcNow.Subtract(time); name = p.FormatNick(name); if (newBlock == Block.Air) { p.Message("{0} ago {1} &4deleted &S{2}{3}", delta.Shorten(true, false), name, Block.GetName(p, oldBlock), FormatReason(e.Flags)); } else { p.Message("{0} ago {1} &3placed &S{2}{3}", delta.Shorten(true, false), name, Block.GetName(p, newBlock), FormatReason(e.Flags)); } }
public override void WriteEntries(Stream s, BlockDBCache cache) { byte[] bulk = new byte[BulkEntries * EntrySize]; BlockDBCacheNode node = cache.Tail; while (node != null) { int count = node.Count; for (int i = 0; i < count; i += BulkEntries) { int bulkCount = Math.Min(BulkEntries, count - i); for (int j = 0; j < bulkCount; j++) { BlockDBEntry entry = node.Unpack(node.Entries[i + j]); WriteEntry(entry, bulk, j * EntrySize); } s.Write(bulk, 0, bulkCount * EntrySize); } lock (cache.Locker) node = node.Next; } }