mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 03:06:55 -04:00
Rename queue methods to push/pop and redefine back and front to what seemss to be the standard (#1723)
the back is now the goto push location, the front is now the goto pop location. It was the other way around before due to confusion. successor to #1709 I also decided to do the isEmpty changes discussed in #1709 fixes #1320
This commit is contained in:
parent
27865e313e
commit
2dc2a6e790
@ -47,7 +47,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
|
||||
pub fn reset() void {
|
||||
mutex.lock();
|
||||
while(commands.dequeue()) |cmd| {
|
||||
while(commands.popFront()) |cmd| {
|
||||
var reader = utils.BinaryReader.init(&.{});
|
||||
cmd.finalize(main.globalAllocator, .client, &reader) catch |err| {
|
||||
std.log.err("Got error while cleaning remaining inventory commands: {s}", .{@errorName(err)});
|
||||
@ -68,7 +68,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
const data = cmd.serializePayload(main.stackAllocator);
|
||||
defer main.stackAllocator.free(data);
|
||||
main.network.Protocols.inventory.sendCommand(main.game.world.?.conn, cmd.payload, data);
|
||||
commands.enqueue(cmd);
|
||||
commands.pushBack(cmd);
|
||||
}
|
||||
|
||||
fn nextId() u32 {
|
||||
@ -104,7 +104,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
pub fn receiveConfirmation(reader: *utils.BinaryReader) !void {
|
||||
mutex.lock();
|
||||
defer mutex.unlock();
|
||||
try commands.dequeue().?.finalize(main.globalAllocator, .client, reader);
|
||||
try commands.popFront().?.finalize(main.globalAllocator, .client, reader);
|
||||
}
|
||||
|
||||
pub fn receiveFailure() void {
|
||||
@ -112,7 +112,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
defer mutex.unlock();
|
||||
var tempData = main.List(Command).init(main.stackAllocator);
|
||||
defer tempData.deinit();
|
||||
while(commands.dequeue_front()) |_cmd| {
|
||||
while(commands.popBack()) |_cmd| {
|
||||
var cmd = _cmd;
|
||||
cmd.undo();
|
||||
tempData.append(cmd);
|
||||
@ -127,7 +127,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
while(tempData.popOrNull()) |_cmd| {
|
||||
var cmd = _cmd;
|
||||
cmd.do(main.globalAllocator, .client, null, main.game.Player.gamemode.raw) catch unreachable;
|
||||
commands.enqueue(cmd);
|
||||
commands.pushBack(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
defer mutex.unlock();
|
||||
var tempData = main.List(Command).init(main.stackAllocator);
|
||||
defer tempData.deinit();
|
||||
while(commands.dequeue_front()) |_cmd| {
|
||||
while(commands.popBack()) |_cmd| {
|
||||
var cmd = _cmd;
|
||||
cmd.undo();
|
||||
tempData.append(cmd);
|
||||
@ -145,7 +145,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
while(tempData.popOrNull()) |_cmd| {
|
||||
var cmd = _cmd;
|
||||
cmd.do(main.globalAllocator, .client, null, main.game.Player.gamemode.raw) catch unreachable;
|
||||
commands.enqueue(cmd);
|
||||
commands.pushBack(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
main.game.Player.setGamemode(gamemode);
|
||||
var tempData = main.List(Command).init(main.stackAllocator);
|
||||
defer tempData.deinit();
|
||||
while(commands.dequeue_front()) |_cmd| {
|
||||
while(commands.popBack()) |_cmd| {
|
||||
var cmd = _cmd;
|
||||
cmd.undo();
|
||||
tempData.append(cmd);
|
||||
@ -163,7 +163,7 @@ pub const Sync = struct { // MARK: Sync
|
||||
while(tempData.popOrNull()) |_cmd| {
|
||||
var cmd = _cmd;
|
||||
cmd.do(main.globalAllocator, .client, null, gamemode) catch unreachable;
|
||||
commands.enqueue(cmd);
|
||||
commands.pushBack(cmd);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -58,11 +58,11 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
||||
}
|
||||
|
||||
fn scheduleCommand(command: Command) void {
|
||||
commands.enqueue(command);
|
||||
commands.pushBack(command);
|
||||
}
|
||||
|
||||
fn executeCommands() void {
|
||||
while(commands.dequeue()) |command| {
|
||||
while(commands.popFront()) |command| {
|
||||
switch(command.action) {
|
||||
.open => {
|
||||
executeOpenWindowCommand(command.window);
|
||||
|
@ -57,53 +57,53 @@ pub const History = struct {
|
||||
self.down.deinit(main.globalAllocator);
|
||||
}
|
||||
fn clear(self: *History) void {
|
||||
while(self.up.dequeue()) |msg| {
|
||||
while(self.up.popFront()) |msg| {
|
||||
main.globalAllocator.free(msg);
|
||||
}
|
||||
while(self.down.dequeue()) |msg| {
|
||||
while(self.down.popFront()) |msg| {
|
||||
main.globalAllocator.free(msg);
|
||||
}
|
||||
}
|
||||
fn flushUp(self: *History) void {
|
||||
while(self.down.dequeueFront()) |msg| {
|
||||
while(self.down.popBack()) |msg| {
|
||||
if(msg.len == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(self.up.forceEnqueueFront(msg)) |old| {
|
||||
if(self.up.forcePushBack(msg)) |old| {
|
||||
main.globalAllocator.free(old);
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn isDuplicate(self: *History, new: []const u8) bool {
|
||||
if(new.len == 0) return true;
|
||||
if(self.down.peekFront()) |msg| {
|
||||
if(self.down.peekBack()) |msg| {
|
||||
if(std.mem.eql(u8, msg, new)) return true;
|
||||
}
|
||||
if(self.up.peekFront()) |msg| {
|
||||
if(self.up.peekBack()) |msg| {
|
||||
if(std.mem.eql(u8, msg, new)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pub fn pushDown(self: *History, new: []const u8) void {
|
||||
if(self.down.forceEnqueueFront(new)) |old| {
|
||||
if(self.down.forcePushBack(new)) |old| {
|
||||
main.globalAllocator.free(old);
|
||||
}
|
||||
}
|
||||
pub fn pushUp(self: *History, new: []const u8) void {
|
||||
if(self.up.forceEnqueueFront(new)) |old| {
|
||||
if(self.up.forcePushBack(new)) |old| {
|
||||
main.globalAllocator.free(old);
|
||||
}
|
||||
}
|
||||
pub fn cycleUp(self: *History) bool {
|
||||
if(self.down.dequeueFront()) |msg| {
|
||||
if(self.down.popBack()) |msg| {
|
||||
self.pushUp(msg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pub fn cycleDown(self: *History) void {
|
||||
if(self.up.dequeueFront()) |msg| {
|
||||
if(self.up.popBack()) |msg| {
|
||||
self.pushDown(msg);
|
||||
}
|
||||
}
|
||||
@ -121,7 +121,7 @@ pub fn deinit() void {
|
||||
label.deinit();
|
||||
}
|
||||
history.deinit();
|
||||
while(messageQueue.dequeue()) |msg| {
|
||||
while(messageQueue.popFront()) |msg| {
|
||||
main.globalAllocator.free(msg);
|
||||
}
|
||||
messageHistory.deinit();
|
||||
@ -173,7 +173,7 @@ pub fn loadNextHistoryEntry(_: usize) void {
|
||||
messageHistory.pushDown(main.globalAllocator.dupe(u8, input.currentString.items));
|
||||
messageHistory.cycleDown();
|
||||
}
|
||||
const msg = messageHistory.down.peekFront() orelse "";
|
||||
const msg = messageHistory.down.peekBack() orelse "";
|
||||
input.setString(msg);
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ pub fn loadPreviousHistoryEntry(_: usize) void {
|
||||
if(messageHistory.isDuplicate(input.currentString.items)) {} else {
|
||||
messageHistory.pushUp(main.globalAllocator.dupe(u8, input.currentString.items));
|
||||
}
|
||||
const msg = messageHistory.down.peekFront() orelse "";
|
||||
const msg = messageHistory.down.peekBack() orelse "";
|
||||
input.setString(msg);
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ pub fn onClose() void {
|
||||
while(history.popOrNull()) |label| {
|
||||
label.deinit();
|
||||
}
|
||||
while(messageQueue.dequeue()) |msg| {
|
||||
while(messageQueue.popFront()) |msg| {
|
||||
main.globalAllocator.free(msg);
|
||||
}
|
||||
messageHistory.clear();
|
||||
@ -204,9 +204,9 @@ pub fn onClose() void {
|
||||
}
|
||||
|
||||
pub fn update() void {
|
||||
if(!messageQueue.empty()) {
|
||||
if(!messageQueue.isEmpty()) {
|
||||
const currentTime: i32 = @truncate(std.time.milliTimestamp());
|
||||
while(messageQueue.dequeue()) |msg| {
|
||||
while(messageQueue.popFront()) |msg| {
|
||||
history.append(Label.init(.{0, 0}, 256, msg, .left));
|
||||
main.globalAllocator.free(msg);
|
||||
expirationTime.append(currentTime +% messageTimeout);
|
||||
@ -243,7 +243,7 @@ pub fn render() void {
|
||||
}
|
||||
|
||||
pub fn addMessage(msg: []const u8) void {
|
||||
messageQueue.enqueue(main.globalAllocator.dupe(u8, msg));
|
||||
messageQueue.pushBack(main.globalAllocator.dupe(u8, msg));
|
||||
}
|
||||
|
||||
pub fn sendMessage(_: usize) void {
|
||||
|
@ -237,7 +237,7 @@ pub const ItemDropManager = struct { // MARK: ItemDropManager
|
||||
}
|
||||
|
||||
self.emptyMutex.unlock();
|
||||
self.changeQueue.enqueue(.{.add = .{i, drop}});
|
||||
self.changeQueue.pushBack(.{.add = .{i, drop}});
|
||||
}
|
||||
|
||||
fn addWithIndex(self: *ItemDropManager, i: u16, pos: Vec3d, vel: Vec3d, rot: Vec3f, itemStack: ItemStack, despawnTime: i32, pickupCooldown: i32) void {
|
||||
@ -269,11 +269,11 @@ pub const ItemDropManager = struct { // MARK: ItemDropManager
|
||||
}
|
||||
|
||||
self.emptyMutex.unlock();
|
||||
self.changeQueue.enqueue(.{.add = .{i, drop}});
|
||||
self.changeQueue.pushBack(.{.add = .{i, drop}});
|
||||
}
|
||||
|
||||
fn processChanges(self: *ItemDropManager) void {
|
||||
while(self.changeQueue.dequeue()) |data| {
|
||||
while(self.changeQueue.popFront()) |data| {
|
||||
switch(data) {
|
||||
.add => |addData| {
|
||||
self.internalAdd(addData[0], addData[1]);
|
||||
@ -506,7 +506,7 @@ pub const ClientItemDropManager = struct { // MARK: ClientItemDropManager
|
||||
self.super.emptyMutex.lock();
|
||||
self.super.isEmpty.set(i);
|
||||
self.super.emptyMutex.unlock();
|
||||
self.super.changeQueue.enqueue(.{.remove = i});
|
||||
self.super.changeQueue.pushBack(.{.remove = i});
|
||||
}
|
||||
|
||||
pub fn loadFrom(self: *ClientItemDropManager, zon: ZonElement) void {
|
||||
|
@ -495,13 +495,13 @@ const ToolPhysics = struct { // MARK: ToolPhysics
|
||||
outer: for(tool.materialGrid, 0..) |row, x| {
|
||||
for(row, 0..) |entry, y| {
|
||||
if(entry != null) {
|
||||
floodfillQueue.enqueue(.{@intCast(x), @intCast(y)});
|
||||
floodfillQueue.pushBack(.{@intCast(x), @intCast(y)});
|
||||
gridCellsReached[x][y] = true;
|
||||
break :outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
while(floodfillQueue.dequeue()) |pos| {
|
||||
while(floodfillQueue.popFront()) |pos| {
|
||||
for([4]Vec2i{.{-1, 0}, .{1, 0}, .{0, -1}, .{0, 1}}) |delta| {
|
||||
const newPos = pos + delta;
|
||||
if(newPos[0] < 0 or newPos[0] >= gridCellsReached.len) continue;
|
||||
@ -511,7 +511,7 @@ const ToolPhysics = struct { // MARK: ToolPhysics
|
||||
if(gridCellsReached[x][y]) continue;
|
||||
if(tool.materialGrid[x][y] == null) continue;
|
||||
gridCellsReached[x][y] = true;
|
||||
floodfillQueue.enqueue(newPos);
|
||||
floodfillQueue.pushBack(newPos);
|
||||
}
|
||||
}
|
||||
for(tool.materialGrid, 0..) |row, x| {
|
||||
|
@ -1509,7 +1509,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
if(nextByte & 0x80 == 0) break;
|
||||
if(header.size > std.math.maxInt(@TypeOf(header.size)) >> 7) return error.Invalid;
|
||||
}
|
||||
self.buffer.discardElements(i + 1);
|
||||
self.buffer.discardElementsFront(i + 1);
|
||||
self.currentReadPosition +%= @intCast(i + 1);
|
||||
return header;
|
||||
}
|
||||
@ -1524,7 +1524,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
const amount = @min(@as(usize, @intCast(self.availablePosition -% self.currentReadPosition)), self.header.?.size - self.protocolBuffer.items.len);
|
||||
if(self.availablePosition -% self.currentReadPosition == 0) return;
|
||||
|
||||
self.buffer.dequeueSlice(self.protocolBuffer.addManyAssumeCapacity(amount)) catch unreachable;
|
||||
self.buffer.popSliceFront(self.protocolBuffer.addManyAssumeCapacity(amount)) catch unreachable;
|
||||
self.currentReadPosition +%= @intCast(amount);
|
||||
if(self.protocolBuffer.items.len != self.header.?.size) return;
|
||||
|
||||
@ -1611,7 +1611,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
self.lastUnsentTime = time;
|
||||
}
|
||||
if(data.len + self.buffer.len > std.math.maxInt(SequenceIndex)) return error.OutOfMemory;
|
||||
self.buffer.enqueue(protocolIndex);
|
||||
self.buffer.pushBack(protocolIndex);
|
||||
self.nextIndex +%= 1;
|
||||
_ = internalHeaderOverhead.fetchAdd(1, .monotonic);
|
||||
const bits = 1 + if(data.len == 0) 0 else std.math.log2_int(usize, data.len);
|
||||
@ -1619,11 +1619,11 @@ pub const Connection = struct { // MARK: Connection
|
||||
for(0..bytes) |i| {
|
||||
const shift = 7*(bytes - i - 1);
|
||||
const byte = (data.len >> @intCast(shift) & 0x7f) | if(i == bytes - 1) @as(u8, 0) else 0x80;
|
||||
self.buffer.enqueue(@intCast(byte));
|
||||
self.buffer.pushBack(@intCast(byte));
|
||||
self.nextIndex +%= 1;
|
||||
_ = internalHeaderOverhead.fetchAdd(1, .monotonic);
|
||||
}
|
||||
self.buffer.enqueueSlice(data);
|
||||
self.buffer.pushBackSlice(data);
|
||||
self.nextIndex +%= @intCast(data.len);
|
||||
}
|
||||
|
||||
@ -1658,7 +1658,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
smallestUnconfirmed = range.start;
|
||||
}
|
||||
}
|
||||
self.buffer.discard(@intCast(smallestUnconfirmed -% self.fullyConfirmedIndex)) catch unreachable;
|
||||
self.buffer.discardFront(@intCast(smallestUnconfirmed -% self.fullyConfirmedIndex)) catch unreachable;
|
||||
self.fullyConfirmedIndex = smallestUnconfirmed;
|
||||
return result;
|
||||
}
|
||||
@ -1678,7 +1678,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
range.wasResentAsFirstPacket = true;
|
||||
}
|
||||
range.wasResent = true;
|
||||
self.lostRanges.enqueue(range);
|
||||
self.lostRanges.pushBack(range);
|
||||
_ = packetsResent.fetchAdd(1, .monotonic);
|
||||
}
|
||||
if(hadDoubleLoss) return .doubleLoss;
|
||||
@ -1689,10 +1689,10 @@ pub const Connection = struct { // MARK: Connection
|
||||
pub fn getNextPacketToSend(self: *SendBuffer, byteIndex: *SequenceIndex, buf: []u8, time: i64, considerForCongestionControl: bool, allowedDelay: i64) ?usize {
|
||||
self.unconfirmedRanges.ensureUnusedCapacity(1) catch unreachable;
|
||||
// Resend old packet:
|
||||
if(self.lostRanges.dequeue()) |_range| {
|
||||
if(self.lostRanges.popFront()) |_range| {
|
||||
var range = _range;
|
||||
if(range.len > buf.len) { // MTU changed → split the data
|
||||
self.lostRanges.enqueue_back(.{
|
||||
self.lostRanges.pushFront(.{
|
||||
.start = range.start +% @as(SequenceIndex, @intCast(buf.len)),
|
||||
.len = range.len - @as(SequenceIndex, @intCast(buf.len)),
|
||||
.timestamp = range.timestamp,
|
||||
@ -2018,7 +2018,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
|
||||
writer.writeEnum(ChannelId, .confirmation);
|
||||
|
||||
while(self.queuedConfirmations.dequeue()) |confirmation| {
|
||||
while(self.queuedConfirmations.popFront()) |confirmation| {
|
||||
writer.writeEnum(ChannelId, confirmation.channel);
|
||||
writer.writeInt(u16, std.math.lossyCast(u16, @divTrunc(timestamp -% confirmation.receiveTimeStamp, 2)));
|
||||
writer.writeInt(SequenceIndex, confirmation.start);
|
||||
@ -2108,7 +2108,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
.lossy => {
|
||||
const start = try reader.readInt(SequenceIndex);
|
||||
if(try self.lossyChannel.receive(self, start, reader.remaining) == .accepted) {
|
||||
self.queuedConfirmations.enqueue(.{
|
||||
self.queuedConfirmations.pushBack(.{
|
||||
.channel = channel,
|
||||
.start = start,
|
||||
.receiveTimeStamp = networkTimestamp(),
|
||||
@ -2118,7 +2118,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
.fast => {
|
||||
const start = try reader.readInt(SequenceIndex);
|
||||
if(try self.fastChannel.receive(self, start, reader.remaining) == .accepted) {
|
||||
self.queuedConfirmations.enqueue(.{
|
||||
self.queuedConfirmations.pushBack(.{
|
||||
.channel = channel,
|
||||
.start = start,
|
||||
.receiveTimeStamp = networkTimestamp(),
|
||||
@ -2128,7 +2128,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
.slow => {
|
||||
const start = try reader.readInt(SequenceIndex);
|
||||
if(try self.slowChannel.receive(self, start, reader.remaining) == .accepted) {
|
||||
self.queuedConfirmations.enqueue(.{
|
||||
self.queuedConfirmations.pushBack(.{
|
||||
.channel = channel,
|
||||
.start = start,
|
||||
.receiveTimeStamp = networkTimestamp(),
|
||||
@ -2199,7 +2199,7 @@ pub const Connection = struct { // MARK: Connection
|
||||
self.relativeSendTime >>= 1;
|
||||
}
|
||||
|
||||
while(timestamp -% self.nextConfirmationTimestamp > 0 and !self.queuedConfirmations.empty()) {
|
||||
while(timestamp -% self.nextConfirmationTimestamp > 0 and !self.queuedConfirmations.isEmpty()) {
|
||||
self.sendConfirmationPacket(timestamp);
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ pub const ChannelChunk = struct {
|
||||
}
|
||||
|
||||
self.lock.lockWrite();
|
||||
while(lightQueue.dequeue()) |entry| {
|
||||
while(lightQueue.popFront()) |entry| {
|
||||
const index = chunk.getIndex(entry.x, entry.y, entry.z);
|
||||
const oldValue: [3]u8 = self.data.getValue(index);
|
||||
const newValue: [3]u8 = .{
|
||||
@ -136,7 +136,7 @@ pub const ChannelChunk = struct {
|
||||
}
|
||||
const neighborIndex = chunk.getIndex(nx, ny, nz);
|
||||
calculateIncomingOcclusion(&result.value, self.ch.data.getValue(neighborIndex), self.ch.pos.voxelSize, neighbor.reverse());
|
||||
if(result.value[0] != 0 or result.value[1] != 0 or result.value[2] != 0) lightQueue.enqueue(result);
|
||||
if(result.value[0] != 0 or result.value[1] != 0 or result.value[2] != 0) lightQueue.pushBack(result);
|
||||
}
|
||||
}
|
||||
self.data.optimizeLayout();
|
||||
@ -173,7 +173,7 @@ pub const ChannelChunk = struct {
|
||||
var isFirstIteration: bool = isFirstBlock;
|
||||
|
||||
self.lock.lockWrite();
|
||||
while(lightQueue.dequeue()) |entry| {
|
||||
while(lightQueue.popFront()) |entry| {
|
||||
const index = chunk.getIndex(entry.x, entry.y, entry.z);
|
||||
const oldValue: [3]u8 = self.data.getValue(index);
|
||||
var activeValue: @Vector(3, bool) = @bitCast(entry.activeValue);
|
||||
@ -228,7 +228,7 @@ pub const ChannelChunk = struct {
|
||||
}
|
||||
const neighborIndex = chunk.getIndex(nx, ny, nz);
|
||||
calculateIncomingOcclusion(&result.value, self.ch.data.getValue(neighborIndex), self.ch.pos.voxelSize, neighbor.reverse());
|
||||
lightQueue.enqueue(result);
|
||||
lightQueue.pushBack(result);
|
||||
}
|
||||
}
|
||||
self.lock.unlockWrite();
|
||||
@ -247,23 +247,23 @@ pub const ChannelChunk = struct {
|
||||
}
|
||||
|
||||
fn propagateFromNeighbor(self: *ChannelChunk, lightQueue: *main.utils.CircularBufferQueue(Entry), lights: []const Entry, lightRefreshList: *main.List(chunk.ChunkPosition)) void {
|
||||
std.debug.assert(lightQueue.empty());
|
||||
std.debug.assert(lightQueue.isEmpty());
|
||||
for(lights) |entry| {
|
||||
const index = chunk.getIndex(entry.x, entry.y, entry.z);
|
||||
var result = entry;
|
||||
calculateIncomingOcclusion(&result.value, self.ch.data.getValue(index), self.ch.pos.voxelSize, @enumFromInt(entry.sourceDir));
|
||||
if(result.value[0] != 0 or result.value[1] != 0 or result.value[2] != 0) lightQueue.enqueue(result);
|
||||
if(result.value[0] != 0 or result.value[1] != 0 or result.value[2] != 0) lightQueue.pushBack(result);
|
||||
}
|
||||
self.propagateDirect(lightQueue, lightRefreshList);
|
||||
}
|
||||
|
||||
fn propagateDestructiveFromNeighbor(self: *ChannelChunk, lightQueue: *main.utils.CircularBufferQueue(Entry), lights: []const Entry, constructiveEntries: *main.ListUnmanaged(ChunkEntries), lightRefreshList: *main.List(chunk.ChunkPosition)) main.ListUnmanaged(PositionEntry) {
|
||||
std.debug.assert(lightQueue.empty());
|
||||
std.debug.assert(lightQueue.isEmpty());
|
||||
for(lights) |entry| {
|
||||
const index = chunk.getIndex(entry.x, entry.y, entry.z);
|
||||
var result = entry;
|
||||
calculateIncomingOcclusion(&result.value, self.ch.data.getValue(index), self.ch.pos.voxelSize, @enumFromInt(entry.sourceDir));
|
||||
lightQueue.enqueue(result);
|
||||
lightQueue.pushBack(result);
|
||||
}
|
||||
return self.propagateDestructive(lightQueue, constructiveEntries, false, lightRefreshList);
|
||||
}
|
||||
@ -274,9 +274,9 @@ pub const ChannelChunk = struct {
|
||||
for(lights) |pos| {
|
||||
const index = chunk.getIndex(pos[0], pos[1], pos[2]);
|
||||
if(self.isSun) {
|
||||
lightQueue.enqueue(.{.x = @intCast(pos[0]), .y = @intCast(pos[1]), .z = @intCast(pos[2]), .value = .{255, 255, 255}, .sourceDir = 6, .activeValue = 0b111});
|
||||
lightQueue.pushBack(.{.x = @intCast(pos[0]), .y = @intCast(pos[1]), .z = @intCast(pos[2]), .value = .{255, 255, 255}, .sourceDir = 6, .activeValue = 0b111});
|
||||
} else {
|
||||
lightQueue.enqueue(.{.x = @intCast(pos[0]), .y = @intCast(pos[1]), .z = @intCast(pos[2]), .value = extractColor(self.ch.data.getValue(index).light()), .sourceDir = 6, .activeValue = 0b111});
|
||||
lightQueue.pushBack(.{.x = @intCast(pos[0]), .y = @intCast(pos[1]), .z = @intCast(pos[2]), .value = extractColor(self.ch.data.getValue(index).light()), .sourceDir = 6, .activeValue = 0b111});
|
||||
}
|
||||
}
|
||||
if(checkNeighbors) {
|
||||
@ -320,7 +320,7 @@ pub const ChannelChunk = struct {
|
||||
calculateOutgoingOcclusion(&value, self.ch.data.getValue(neighborIndex), self.ch.pos.voxelSize, neighbor);
|
||||
if(value[0] == 0 and value[1] == 0 and value[2] == 0) continue;
|
||||
calculateIncomingOcclusion(&value, self.ch.data.getValue(index), self.ch.pos.voxelSize, neighbor.reverse());
|
||||
if(value[0] != 0 or value[1] != 0 or value[2] != 0) lightQueue.enqueue(.{.x = @intCast(x), .y = @intCast(y), .z = @intCast(z), .value = value, .sourceDir = neighbor.toInt(), .activeValue = 0b111});
|
||||
if(value[0] != 0 or value[1] != 0 or value[2] != 0) lightQueue.pushBack(.{.x = @intCast(x), .y = @intCast(y), .z = @intCast(z), .value = value, .sourceDir = neighbor.toInt(), .activeValue = 0b111});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -381,7 +381,7 @@ pub const ChannelChunk = struct {
|
||||
self.lock.lockRead();
|
||||
for(lights) |pos| {
|
||||
const index = chunk.getIndex(pos[0], pos[1], pos[2]);
|
||||
lightQueue.enqueue(.{.x = @intCast(pos[0]), .y = @intCast(pos[1]), .z = @intCast(pos[2]), .value = self.data.getValue(index), .sourceDir = 6, .activeValue = 0b111});
|
||||
lightQueue.pushBack(.{.x = @intCast(pos[0]), .y = @intCast(pos[1]), .z = @intCast(pos[2]), .value = self.data.getValue(index), .sourceDir = 6, .activeValue = 0b111});
|
||||
}
|
||||
self.lock.unlockRead();
|
||||
var constructiveEntries: main.ListUnmanaged(ChunkEntries) = .{};
|
||||
@ -407,7 +407,7 @@ pub const ChannelChunk = struct {
|
||||
};
|
||||
if(value[0] == 0 and value[1] == 0 and value[2] == 0) continue;
|
||||
channelChunk.data.setValue(index, .{0, 0, 0});
|
||||
lightQueue.enqueue(.{.x = entry.x, .y = entry.y, .z = entry.z, .value = value, .sourceDir = 6, .activeValue = 0b111});
|
||||
lightQueue.pushBack(.{.x = entry.x, .y = entry.y, .z = entry.z, .value = value, .sourceDir = 6, .activeValue = 0b111});
|
||||
}
|
||||
channelChunk.lock.unlockWrite();
|
||||
channelChunk.propagateDirect(&lightQueue, lightRefreshList);
|
||||
|
@ -110,12 +110,12 @@ pub fn deinit() void {
|
||||
}
|
||||
|
||||
updatableList.clearAndFree();
|
||||
while(mapUpdatableList.dequeue()) |map| {
|
||||
while(mapUpdatableList.popFront()) |map| {
|
||||
map.deferredDeinit();
|
||||
}
|
||||
mapUpdatableList.deinit();
|
||||
priorityMeshUpdateList.deinit();
|
||||
while(blockUpdateList.dequeue()) |blockUpdate| {
|
||||
while(blockUpdateList.popFront()) |blockUpdate| {
|
||||
blockUpdate.deinitManaged(main.globalAllocator);
|
||||
}
|
||||
blockUpdateList.deinit();
|
||||
@ -623,12 +623,12 @@ pub noinline fn updateAndGetRenderChunks(conn: *network.Connection, frustum: *co
|
||||
if(hasMesh) {
|
||||
node.active = true;
|
||||
node.rendered = true;
|
||||
searchList.enqueue(node);
|
||||
searchList.pushBack(node);
|
||||
}
|
||||
}
|
||||
var nodeList = main.List(*ChunkMeshNode).initCapacity(main.stackAllocator, 1024);
|
||||
defer nodeList.deinit();
|
||||
while(searchList.dequeue()) |node| {
|
||||
while(searchList.popFront()) |node| {
|
||||
std.debug.assert(node.finishedMeshing);
|
||||
std.debug.assert(node.active);
|
||||
if(!node.active) continue;
|
||||
@ -656,7 +656,7 @@ pub noinline fn updateAndGetRenderChunks(conn: *network.Connection, frustum: *co
|
||||
continue;
|
||||
node2.active = true;
|
||||
node2.rendered = true;
|
||||
searchList.enqueue(node2);
|
||||
searchList.pushBack(node2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -684,7 +684,7 @@ pub noinline fn updateAndGetRenderChunks(conn: *network.Connection, frustum: *co
|
||||
std.debug.assert(node2.finishedMeshing);
|
||||
node2.active = true;
|
||||
node2.rendered = true;
|
||||
searchList.enqueue_back(node2);
|
||||
searchList.pushFront(node2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -738,11 +738,11 @@ pub noinline fn updateAndGetRenderChunks(conn: *network.Connection, frustum: *co
|
||||
}
|
||||
|
||||
pub fn updateMeshes(targetTime: i64) void { // MARK: updateMeshes()=
|
||||
if(!blockUpdateList.empty()) batchUpdateBlocks();
|
||||
if(!blockUpdateList.isEmpty()) batchUpdateBlocks();
|
||||
|
||||
mutex.lock();
|
||||
defer mutex.unlock();
|
||||
while(priorityMeshUpdateList.dequeue()) |pos| {
|
||||
while(priorityMeshUpdateList.popFront()) |pos| {
|
||||
const mesh = getMesh(pos) orelse continue;
|
||||
if(!mesh.needsMeshUpdate) {
|
||||
continue;
|
||||
@ -753,7 +753,7 @@ pub fn updateMeshes(targetTime: i64) void { // MARK: updateMeshes()=
|
||||
mesh.uploadData();
|
||||
if(std.time.milliTimestamp() >= targetTime) break; // Update at least one mesh.
|
||||
}
|
||||
while(mapUpdatableList.dequeue()) |map| {
|
||||
while(mapUpdatableList.popFront()) |map| {
|
||||
if(!isMapInRenderDistance(map.pos)) {
|
||||
map.deferredDeinit();
|
||||
} else {
|
||||
@ -811,7 +811,7 @@ fn batchUpdateBlocks() void {
|
||||
defer regenerateMeshList.deinit();
|
||||
|
||||
// First of all process all the block updates:
|
||||
while(blockUpdateList.dequeue()) |blockUpdate| {
|
||||
while(blockUpdateList.popFront()) |blockUpdate| {
|
||||
defer blockUpdate.deinitManaged(main.globalAllocator);
|
||||
const pos = chunk.ChunkPosition{.wx = blockUpdate.x, .wy = blockUpdate.y, .wz = blockUpdate.z, .voxelSize = 1};
|
||||
if(getMesh(pos)) |mesh| {
|
||||
@ -835,7 +835,7 @@ pub fn addToUpdateList(mesh: *chunk_meshing.ChunkMesh) void {
|
||||
mutex.lock();
|
||||
defer mutex.unlock();
|
||||
if(mesh.finishedMeshing) {
|
||||
priorityMeshUpdateList.enqueue(mesh.pos);
|
||||
priorityMeshUpdateList.pushBack(mesh.pos);
|
||||
mesh.needsMeshUpdate = true;
|
||||
}
|
||||
}
|
||||
@ -906,7 +906,7 @@ pub const MeshGenerationTask = struct { // MARK: MeshGenerationTask
|
||||
// MARK: updaters
|
||||
|
||||
pub fn updateBlock(update: BlockUpdate) void {
|
||||
blockUpdateList.enqueue(BlockUpdate.initManaged(main.globalAllocator, update));
|
||||
blockUpdateList.pushBack(BlockUpdate.initManaged(main.globalAllocator, update));
|
||||
}
|
||||
|
||||
pub fn updateChunkMesh(mesh: *chunk.Chunk) void {
|
||||
@ -914,7 +914,7 @@ pub fn updateChunkMesh(mesh: *chunk.Chunk) void {
|
||||
}
|
||||
|
||||
pub fn updateLightMap(map: *LightMap.LightMapFragment) void {
|
||||
mapUpdatableList.enqueue(map);
|
||||
mapUpdatableList.pushBack(map);
|
||||
}
|
||||
|
||||
// MARK: Block breaking animation
|
||||
|
@ -60,17 +60,17 @@ pub const WorldEditData = struct {
|
||||
self.changes.deinit();
|
||||
}
|
||||
pub fn clear(self: *History) void {
|
||||
while(self.changes.dequeue()) |item| item.deinit();
|
||||
while(self.changes.popFront()) |item| item.deinit();
|
||||
}
|
||||
pub fn push(self: *History, value: Value) void {
|
||||
if(self.changes.reachedCapacity()) {
|
||||
if(self.changes.dequeue()) |oldValue| oldValue.deinit();
|
||||
if(self.changes.popFront()) |oldValue| oldValue.deinit();
|
||||
}
|
||||
|
||||
self.changes.enqueue(value);
|
||||
self.changes.pushBack(value);
|
||||
}
|
||||
pub fn pop(self: *History) ?Value {
|
||||
return self.changes.dequeue_front();
|
||||
return self.changes.popBack();
|
||||
}
|
||||
};
|
||||
pub fn init() WorldEditData {
|
||||
@ -336,7 +336,7 @@ fn init(name: []const u8, singlePlayerPort: ?u16) void { // MARK: init()
|
||||
|
||||
fn deinit() void {
|
||||
users.clearAndFree();
|
||||
while(userDeinitList.dequeue()) |user| {
|
||||
while(userDeinitList.popFront()) |user| {
|
||||
user.deinit();
|
||||
}
|
||||
userDeinitList.deinit();
|
||||
@ -390,7 +390,7 @@ fn getInitialEntityList(allocator: main.heap.NeverFailingAllocator) []const u8 {
|
||||
fn update() void { // MARK: update()
|
||||
world.?.update();
|
||||
|
||||
while(userConnectList.dequeue()) |user| {
|
||||
while(userConnectList.popFront()) |user| {
|
||||
connectInternal(user);
|
||||
}
|
||||
|
||||
@ -429,7 +429,7 @@ fn update() void { // MARK: update()
|
||||
}
|
||||
}
|
||||
|
||||
while(userDeinitList.dequeue()) |user| {
|
||||
while(userDeinitList.popFront()) |user| {
|
||||
user.decreaseRefCount();
|
||||
}
|
||||
}
|
||||
@ -462,7 +462,7 @@ pub fn stop() void {
|
||||
pub fn disconnect(user: *User) void { // MARK: disconnect()
|
||||
if(!user.connected.load(.unordered)) return;
|
||||
removePlayer(user);
|
||||
userDeinitList.enqueue(user);
|
||||
userDeinitList.pushBack(user);
|
||||
user.connected.store(false, .unordered);
|
||||
}
|
||||
|
||||
@ -497,7 +497,7 @@ pub fn removePlayer(user: *User) void { // MARK: removePlayer()
|
||||
}
|
||||
|
||||
pub fn connect(user: *User) void {
|
||||
userConnectList.enqueue(user);
|
||||
userConnectList.pushBack(user);
|
||||
}
|
||||
|
||||
pub fn connectInternal(user: *User) void {
|
||||
|
@ -641,12 +641,12 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
self.forceSave() catch |err| {
|
||||
std.log.err("Error while saving the world: {s}", .{@errorName(err)});
|
||||
};
|
||||
while(self.chunkUpdateQueue.dequeue()) |updateRequest| {
|
||||
while(self.chunkUpdateQueue.popFront()) |updateRequest| {
|
||||
updateRequest.ch.save(self);
|
||||
updateRequest.ch.decreaseRefCount();
|
||||
}
|
||||
self.chunkUpdateQueue.deinit();
|
||||
while(self.regionUpdateQueue.dequeue()) |updateRequest| {
|
||||
while(self.regionUpdateQueue.popFront()) |updateRequest| {
|
||||
updateRequest.region.store();
|
||||
updateRequest.region.decreaseRefCount();
|
||||
}
|
||||
@ -814,13 +814,13 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
while(true) {
|
||||
while(self.chunkUpdateQueue.dequeue()) |updateRequest| {
|
||||
while(self.chunkUpdateQueue.popFront()) |updateRequest| {
|
||||
self.mutex.unlock();
|
||||
defer self.mutex.lock();
|
||||
updateRequest.ch.save(self);
|
||||
updateRequest.ch.decreaseRefCount();
|
||||
}
|
||||
while(self.regionUpdateQueue.dequeue()) |updateRequest| {
|
||||
while(self.regionUpdateQueue.popFront()) |updateRequest| {
|
||||
self.mutex.unlock();
|
||||
defer self.mutex.lock();
|
||||
updateRequest.region.store();
|
||||
@ -829,7 +829,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
self.mutex.unlock();
|
||||
std.Thread.sleep(1_000_000);
|
||||
self.mutex.lock();
|
||||
if(main.threadPool.queueSize() == 0 and self.chunkUpdateQueue.peek() == null and self.regionUpdateQueue.peek() == null) break;
|
||||
if(main.threadPool.queueSize() == 0 and self.chunkUpdateQueue.peekFront() == null and self.regionUpdateQueue.peekFront() == null) break;
|
||||
}
|
||||
std.log.info("Finished LOD update.", .{});
|
||||
|
||||
@ -1124,14 +1124,14 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
const insertionTime = newTime -% main.settings.storageTime;
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
while(self.chunkUpdateQueue.dequeue()) |updateRequest| {
|
||||
while(self.chunkUpdateQueue.popFront()) |updateRequest| {
|
||||
self.mutex.unlock();
|
||||
defer self.mutex.lock();
|
||||
updateRequest.ch.save(self);
|
||||
updateRequest.ch.decreaseRefCount();
|
||||
if(updateRequest.milliTimeStamp -% insertionTime <= 0) break;
|
||||
}
|
||||
while(self.regionUpdateQueue.dequeue()) |updateRequest| {
|
||||
while(self.regionUpdateQueue.popFront()) |updateRequest| {
|
||||
self.mutex.unlock();
|
||||
defer self.mutex.lock();
|
||||
updateRequest.region.store();
|
||||
@ -1271,13 +1271,13 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
||||
|
||||
pub fn queueChunkUpdateAndDecreaseRefCount(self: *ServerWorld, ch: *ServerChunk) void {
|
||||
self.mutex.lock();
|
||||
self.chunkUpdateQueue.enqueue(.{.ch = ch, .milliTimeStamp = std.time.milliTimestamp()});
|
||||
self.chunkUpdateQueue.pushBack(.{.ch = ch, .milliTimeStamp = std.time.milliTimestamp()});
|
||||
self.mutex.unlock();
|
||||
}
|
||||
|
||||
pub fn queueRegionFileUpdateAndDecreaseRefCount(self: *ServerWorld, region: *storage.RegionFile) void {
|
||||
self.mutex.lock();
|
||||
self.regionUpdateQueue.enqueue(.{.region = region, .milliTimeStamp = std.time.milliTimestamp()});
|
||||
self.regionUpdateQueue.pushBack(.{.region = region, .milliTimeStamp = std.time.milliTimestamp()});
|
||||
self.mutex.unlock();
|
||||
}
|
||||
};
|
||||
|
@ -338,54 +338,50 @@ pub fn FixedSizeCircularBuffer(T: type, capacity: comptime_int) type { // MARK:
|
||||
allocator.destroy(self.mem);
|
||||
}
|
||||
|
||||
pub fn peekFront(self: Self) ?T {
|
||||
pub fn peekBack(self: Self) ?T {
|
||||
if(self.len == 0) return null;
|
||||
return self.mem[self.startIndex + self.len - 1 & mask];
|
||||
}
|
||||
|
||||
pub fn peekBack(self: Self) ?T {
|
||||
pub fn peekFront(self: Self) ?T {
|
||||
if(self.len == 0) return null;
|
||||
return self.mem[self.startIndex];
|
||||
}
|
||||
|
||||
pub fn enqueueFront(self: *Self, elem: T) !void {
|
||||
pub fn pushBack(self: *Self, elem: T) !void {
|
||||
if(self.len >= capacity) return error.OutOfMemory;
|
||||
self.enqueueFrontAssumeCapacity(elem);
|
||||
self.pushBackAssumeCapacity(elem);
|
||||
}
|
||||
|
||||
pub fn forceEnqueueFront(self: *Self, elem: T) ?T {
|
||||
const result = if(self.len >= capacity) self.dequeueBack() else null;
|
||||
self.enqueueFrontAssumeCapacity(elem);
|
||||
pub fn forcePushBack(self: *Self, elem: T) ?T {
|
||||
const result = if(self.len >= capacity) self.popFront() else null;
|
||||
self.pushBackAssumeCapacity(elem);
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn enqueueFrontAssumeCapacity(self: *Self, elem: T) void {
|
||||
pub fn pushBackAssumeCapacity(self: *Self, elem: T) void {
|
||||
self.mem[self.startIndex + self.len & mask] = elem;
|
||||
self.len += 1;
|
||||
}
|
||||
|
||||
pub fn enqueue(self: *Self, elem: T) !void {
|
||||
return self.enqueueFront(elem);
|
||||
}
|
||||
|
||||
pub fn enqueueBack(self: *Self, elem: T) !void {
|
||||
pub fn pushFront(self: *Self, elem: T) !void {
|
||||
if(self.len >= capacity) return error.OutOfMemory;
|
||||
self.enqueueBackAssumeCapacity(elem);
|
||||
self.pushFrontAssumeCapacity(elem);
|
||||
}
|
||||
|
||||
pub fn enqueueBackAssumeCapacity(self: *Self, elem: T) void {
|
||||
pub fn pushFrontAssumeCapacity(self: *Self, elem: T) void {
|
||||
self.startIndex = (self.startIndex -% 1) & mask;
|
||||
self.mem[self.startIndex] = elem;
|
||||
self.len += 1;
|
||||
}
|
||||
|
||||
pub fn forceEnqueueBack(self: *Self, elem: T) ?T {
|
||||
const result = if(self.len >= capacity) self.dequeueFront() else null;
|
||||
self.enqueueBackAssumeCapacity(elem);
|
||||
pub fn forcePushFront(self: *Self, elem: T) ?T {
|
||||
const result = if(self.len >= capacity) self.popBack() else null;
|
||||
self.pushFrontAssumeCapacity(elem);
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn enqueueSlice(self: *Self, elems: []const T) !void {
|
||||
pub fn pushBackSlice(self: *Self, elems: []const T) !void {
|
||||
if(elems.len + self.len > capacity) {
|
||||
return error.OutOfMemory;
|
||||
}
|
||||
@ -417,17 +413,13 @@ pub fn FixedSizeCircularBuffer(T: type, capacity: comptime_int) type { // MARK:
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dequeue(self: *Self) ?T {
|
||||
return self.dequeueBack();
|
||||
}
|
||||
|
||||
pub fn dequeueFront(self: *Self) ?T {
|
||||
pub fn popBack(self: *Self) ?T {
|
||||
if(self.len == 0) return null;
|
||||
self.len -= 1;
|
||||
return self.mem[self.startIndex + self.len & mask];
|
||||
}
|
||||
|
||||
pub fn dequeueBack(self: *Self) ?T {
|
||||
pub fn popFront(self: *Self) ?T {
|
||||
if(self.len == 0) return null;
|
||||
const result = self.mem[self.startIndex];
|
||||
self.startIndex = (self.startIndex + 1) & mask;
|
||||
@ -435,7 +427,7 @@ pub fn FixedSizeCircularBuffer(T: type, capacity: comptime_int) type { // MARK:
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn dequeueSlice(self: *Self, out: []T) !void {
|
||||
pub fn popSliceFront(self: *Self, out: []T) !void {
|
||||
if(out.len > self.len) return error.OutOfBounds;
|
||||
const start = self.startIndex;
|
||||
const end = start + out.len;
|
||||
@ -450,7 +442,7 @@ pub fn FixedSizeCircularBuffer(T: type, capacity: comptime_int) type { // MARK:
|
||||
self.len -= out.len;
|
||||
}
|
||||
|
||||
pub fn discardElements(self: *Self, n: usize) void {
|
||||
pub fn discardElementsFront(self: *Self, n: usize) void {
|
||||
self.len -= n;
|
||||
self.startIndex = (self.startIndex + n) & mask;
|
||||
}
|
||||
@ -501,7 +493,7 @@ pub fn CircularBufferQueue(comptime T: type) type { // MARK: CircularBufferQueue
|
||||
self.mask = self.mem.len - 1;
|
||||
}
|
||||
|
||||
pub fn enqueue(self: *Self, elem: T) void {
|
||||
pub fn pushBack(self: *Self, elem: T) void {
|
||||
if(self.len == self.mem.len) {
|
||||
self.increaseCapacity();
|
||||
}
|
||||
@ -509,7 +501,7 @@ pub fn CircularBufferQueue(comptime T: type) type { // MARK: CircularBufferQueue
|
||||
self.len += 1;
|
||||
}
|
||||
|
||||
pub fn enqueueSlice(self: *Self, elems: []const T) void {
|
||||
pub fn pushBackSlice(self: *Self, elems: []const T) void {
|
||||
while(elems.len + self.len > self.mem.len) {
|
||||
self.increaseCapacity();
|
||||
}
|
||||
@ -525,7 +517,7 @@ pub fn CircularBufferQueue(comptime T: type) type { // MARK: CircularBufferQueue
|
||||
self.len += elems.len;
|
||||
}
|
||||
|
||||
pub fn enqueue_back(self: *Self, elem: T) void {
|
||||
pub fn pushFront(self: *Self, elem: T) void {
|
||||
if(self.len == self.mem.len) {
|
||||
self.increaseCapacity();
|
||||
}
|
||||
@ -534,28 +526,28 @@ pub fn CircularBufferQueue(comptime T: type) type { // MARK: CircularBufferQueue
|
||||
self.len += 1;
|
||||
}
|
||||
|
||||
pub fn dequeue(self: *Self) ?T {
|
||||
if(self.empty()) return null;
|
||||
pub fn popFront(self: *Self) ?T {
|
||||
if(self.isEmpty()) return null;
|
||||
const result = self.mem[self.startIndex];
|
||||
self.startIndex = (self.startIndex + 1) & self.mask;
|
||||
self.len -= 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn dequeue_front(self: *Self) ?T {
|
||||
if(self.empty()) return null;
|
||||
pub fn popBack(self: *Self) ?T {
|
||||
if(self.isEmpty()) return null;
|
||||
self.len -= 1;
|
||||
return self.mem[self.startIndex + self.len & self.mask];
|
||||
}
|
||||
|
||||
pub fn discard(self: *Self, amount: usize) !void {
|
||||
pub fn discardFront(self: *Self, amount: usize) !void {
|
||||
if(amount > self.len) return error.OutOfBounds;
|
||||
self.startIndex = (self.startIndex + amount) & self.mask;
|
||||
self.len -= amount;
|
||||
}
|
||||
|
||||
pub fn peek(self: *Self) ?T {
|
||||
if(self.empty()) return null;
|
||||
pub fn peekFront(self: *Self) ?T {
|
||||
if(self.isEmpty()) return null;
|
||||
return self.mem[self.startIndex];
|
||||
}
|
||||
|
||||
@ -577,7 +569,7 @@ pub fn CircularBufferQueue(comptime T: type) type { // MARK: CircularBufferQueue
|
||||
return self.mem[(self.startIndex + offset) & self.mask];
|
||||
}
|
||||
|
||||
pub fn empty(self: *Self) bool {
|
||||
pub fn isEmpty(self: *Self) bool {
|
||||
return self.len == 0;
|
||||
}
|
||||
|
||||
@ -604,22 +596,22 @@ pub fn ConcurrentQueue(comptime T: type) type { // MARK: ConcurrentQueue
|
||||
self.super.deinit();
|
||||
}
|
||||
|
||||
pub fn enqueue(self: *Self, elem: T) void {
|
||||
pub fn pushBack(self: *Self, elem: T) void {
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
self.super.enqueue(elem);
|
||||
self.super.pushBack(elem);
|
||||
}
|
||||
|
||||
pub fn dequeue(self: *Self) ?T {
|
||||
pub fn popFront(self: *Self) ?T {
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
return self.super.dequeue();
|
||||
return self.super.popFront();
|
||||
}
|
||||
|
||||
pub fn empty(self: *Self) bool {
|
||||
pub fn isEmpty(self: *Self) bool {
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
return self.super.empty();
|
||||
return self.super.isEmpty();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user