mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Pack items in BlockQueue into a ulong. (Saves 4 bytes per entry as struct was packed to 4 byte alignment.)
This commit is contained in:
parent
146419d22f
commit
3b4966944e
@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
p.DefaultBrushArgs = "";
|
p.DefaultBrushArgs = "";
|
||||||
|
|
||||||
lock (p.level.queueLock)
|
lock (p.level.queueLock)
|
||||||
p.level.blockqueue.RemoveAll(b => b.SessionID == p.SessionID);
|
p.level.blockqueue.RemoveAll(b => (int)((b >> 9) & Player.SessionIDMask) == p.SessionID);
|
||||||
Player.Message(p, "Every toggle or action was aborted.");
|
Player.Message(p, "Every toggle or action was aborted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,11 +52,18 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static void Addblock(Player p, int index, byte type, byte extType = 0) {
|
public static void Addblock(Player p, int index, byte type, byte extType = 0) {
|
||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
QueuedBlock item;
|
// Bit packing format
|
||||||
item.SessionID = p.SessionID; item.Index = index;
|
// 32-63: index
|
||||||
item.Type = type; item.ExtType = extType;
|
// 9-31: session ID
|
||||||
|
// 8: is ext block or not
|
||||||
|
// 0-7: raw type
|
||||||
|
ulong flags = (ulong)index << 32;
|
||||||
|
flags |= (ulong)p.SessionID << 9;
|
||||||
|
flags |= (type == Block.custom_block ? 0x100UL : 0x000UL);
|
||||||
|
flags |= (type == Block.custom_block ? extType : type);
|
||||||
|
|
||||||
lock (p.level.queueLock)
|
lock (p.level.queueLock)
|
||||||
p.level.blockqueue.Add(item);
|
p.level.blockqueue.Add(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessLevelBlocks(Level lvl) {
|
static void ProcessLevelBlocks(Level lvl) {
|
||||||
@ -67,9 +74,13 @@ namespace MCGalaxy {
|
|||||||
if (lvl.blockqueue.Count < blockupdates || !lvl.HasPlayers())
|
if (lvl.blockqueue.Count < blockupdates || !lvl.HasPlayers())
|
||||||
count = lvl.blockqueue.Count;
|
count = lvl.blockqueue.Count;
|
||||||
|
|
||||||
for (int c = 0; c < count; c++) {
|
for (int i = 0; i < count; i++) {
|
||||||
QueuedBlock item = lvl.blockqueue[c];
|
ulong flags = lvl.blockqueue[i];
|
||||||
bulkSender.Add(item.Index, item.Type, item.ExtType);
|
int index = (int)(flags >> 32);
|
||||||
|
byte type = (flags & 0x100) != 0 ? Block.custom_block : (byte)flags;
|
||||||
|
byte extType = (flags & 0x100) != 0 ? (byte)flags : Block.air;
|
||||||
|
|
||||||
|
bulkSender.Add(index, type, extType);
|
||||||
bulkSender.CheckIfSend(false);
|
bulkSender.CheckIfSend(false);
|
||||||
}
|
}
|
||||||
bulkSender.CheckIfSend(true);
|
bulkSender.CheckIfSend(true);
|
||||||
@ -80,7 +91,5 @@ namespace MCGalaxy {
|
|||||||
lvl.blockqueue.Clear();
|
lvl.blockqueue.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct QueuedBlock { public int SessionID, Index; public byte Type, ExtType; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +235,7 @@ namespace MCGalaxy
|
|||||||
|
|
||||||
public bool bufferblocks = Server.bufferblocks;
|
public bool bufferblocks = Server.bufferblocks;
|
||||||
internal readonly object queueLock = new object(), saveLock = new object(), savePropsLock = new object();
|
internal readonly object queueLock = new object(), saveLock = new object(), savePropsLock = new object();
|
||||||
public List<BlockQueue.QueuedBlock> blockqueue = new List<BlockQueue.QueuedBlock>();
|
public List<ulong> blockqueue = new List<ulong>();
|
||||||
readonly object physThreadLock = new object();
|
readonly object physThreadLock = new object();
|
||||||
BufferedBlockSender bulkSender;
|
BufferedBlockSender bulkSender;
|
||||||
|
|
||||||
|
@ -183,6 +183,7 @@ namespace MCGalaxy {
|
|||||||
public bool voted = false;
|
public bool voted = false;
|
||||||
public bool flipHead = false;
|
public bool flipHead = false;
|
||||||
public GameProps Game = new GameProps();
|
public GameProps Game = new GameProps();
|
||||||
|
public const int SessionIDMask = (1 << 23) - 1;
|
||||||
public int SessionID;
|
public int SessionID;
|
||||||
|
|
||||||
//Countdown
|
//Countdown
|
||||||
|
@ -65,14 +65,14 @@ namespace MCGalaxy {
|
|||||||
name = playername;
|
name = playername;
|
||||||
truename = playername;
|
truename = playername;
|
||||||
DisplayName = playername;
|
DisplayName = playername;
|
||||||
SessionID = Interlocked.Increment(ref sessionCounter);
|
SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player(Socket s) {
|
public Player(Socket s) {
|
||||||
try {
|
try {
|
||||||
socket = s;
|
socket = s;
|
||||||
ip = socket.RemoteEndPoint.ToString().Split(':')[0];
|
ip = socket.RemoteEndPoint.ToString().Split(':')[0];
|
||||||
SessionID = Interlocked.Increment(ref sessionCounter);
|
SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask;
|
||||||
Server.s.Log(ip + " connected to the server.");
|
Server.s.Log(ip + " connected to the server.");
|
||||||
|
|
||||||
for (byte i = 0; i < 128; i++) bindings[i] = i;
|
for (byte i = 0; i < 128; i++) bindings[i] = i;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user