mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-10-03 02:21:53 -04:00
Add comments to BlockQueue
This commit is contained in:
parent
0c30e2a2e0
commit
235eb3cdfd
@ -22,17 +22,22 @@ using MCGalaxy.Tasks;
|
|||||||
using BlockID = System.UInt16;
|
using BlockID = System.UInt16;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
|
/// <summary> Manages a list of block updates to periodically broadcast to players. </summary>
|
||||||
public sealed class BlockQueue : List<ulong> {
|
public sealed class BlockQueue : List<ulong> {
|
||||||
|
|
||||||
|
/// <summary> Time in milliseconds between ticks. </summary>
|
||||||
public static int Interval = 100;
|
public static int Interval = 100;
|
||||||
|
/// <summary> Maximum number of block updates broadcasted in one tick. </summary>
|
||||||
public static int UpdatesPerTick = 750;
|
public static int UpdatesPerTick = 750;
|
||||||
static BufferedBlockSender bulkSender = new BufferedBlockSender();
|
static BufferedBlockSender bulkSender = new BufferedBlockSender();
|
||||||
|
|
||||||
const int posShift = 32;
|
const int posShift = 32;
|
||||||
const int idShift = 12;
|
const int idShift = 12;
|
||||||
const int blockMask = (1 << 12) - 1;
|
const int blockMask = (1 << 12) - 1;
|
||||||
|
|
||||||
readonly object locker = new object();
|
readonly object locker = new object();
|
||||||
|
|
||||||
|
/// <summary> Flushes the block updates queue for each loaded level. </summary>
|
||||||
public static void Loop(SchedulerTask task) {
|
public static void Loop(SchedulerTask task) {
|
||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
foreach (Level lvl in loaded) {
|
foreach (Level lvl in loaded) {
|
||||||
@ -45,6 +50,7 @@ namespace MCGalaxy {
|
|||||||
task.Delay = TimeSpan.FromMilliseconds(Interval);
|
task.Delay = TimeSpan.FromMilliseconds(Interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Adds a block update to the end of the queue. </summary>
|
||||||
public void Add(Player p, int index, BlockID block) {
|
public void Add(Player p, int index, BlockID block) {
|
||||||
// Bit packing format
|
// Bit packing format
|
||||||
// 32-63: index
|
// 32-63: index
|
||||||
@ -57,12 +63,14 @@ namespace MCGalaxy {
|
|||||||
lock (locker) Add(flags);
|
lock (locker) Add(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Removes all block updates from the queue associated with the given player. </summary>
|
||||||
public void RemoveAll(Player p) {
|
public void RemoveAll(Player p) {
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
RemoveAll(b => (int)((b >> idShift) & Player.SessionIDMask) == p.SessionID);
|
RemoveAll(b => (int)((b >> idShift) & Player.SessionIDMask) == p.SessionID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Removes all block updates from the queue. </summary>
|
||||||
public void ClearAll() { lock (locker) Clear(); }
|
public void ClearAll() { lock (locker) Clear(); }
|
||||||
|
|
||||||
void Process(Level lvl) {
|
void Process(Level lvl) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user