From 72207c973e6639618babd6a78a7adfbe707e7f38 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Sat, 14 Sep 2024 14:54:09 +0200 Subject: [PATCH] Refactor: Use decl literals, a recent addition to Zig. --- src/assets.zig | 14 +++---- src/blocks.zig | 28 +++++++------- src/chunk.zig | 6 +-- src/entity.zig | 2 +- src/game.zig | 10 ++--- src/graphics.zig | 22 +++++------ src/gui/components/HorizontalList.zig | 2 +- src/gui/components/TextInput.zig | 2 +- src/gui/components/VerticalList.zig | 2 +- src/gui/gui.zig | 14 +++---- src/gui/windows/chat.zig | 6 +-- src/gui/windows/creative_inventory.zig | 2 +- src/gui/windows/inventory_crafting.zig | 4 +- src/gui/windows/invite.zig | 2 +- src/gui/windows/multiplayer.zig | 2 +- src/itemdrop.zig | 8 ++-- src/items.zig | 8 ++-- src/json.zig | 18 ++++----- src/models.zig | 10 ++--- src/network.zig | 38 +++++++++---------- src/renderer.zig | 4 +- src/renderer/chunk_meshing.zig | 6 +-- src/renderer/lighting.zig | 2 +- src/renderer/mesh_storage.zig | 2 +- src/rotation.zig | 10 ++--- src/server/command/_command.zig | 2 +- src/server/server.zig | 10 ++--- src/server/storage.zig | 2 +- src/server/terrain/CaveBiomeMap.zig | 2 +- src/server/terrain/CaveMap.zig | 2 +- src/server/terrain/ClimateMap.zig | 2 +- src/server/terrain/LightMap.zig | 2 +- src/server/terrain/StructureMap.zig | 4 +- src/server/terrain/SurfaceMap.zig | 4 +- src/server/terrain/biomes.zig | 18 ++++----- .../terrain/noise/CachedFractalNoise.zig | 2 +- src/server/world.zig | 16 ++++---- src/utils.zig | 12 +++--- src/utils/file_monitor.zig | 10 ++--- 39 files changed, 156 insertions(+), 156 deletions(-) diff --git a/src/assets.zig b/src/assets.zig index f048e0ba..549708b8 100644 --- a/src/assets.zig +++ b/src/assets.zig @@ -174,13 +174,13 @@ pub fn readAssets(externalAllocator: NeverFailingAllocator, assetPath: []const u pub fn init() void { biomes_zig.init(); blocks_zig.init(); - arena = main.utils.NeverFailingArenaAllocator.init(main.globalAllocator); + arena = .init(main.globalAllocator); arenaAllocator = arena.allocator(); - commonBlocks = std.StringHashMap(JsonElement).init(arenaAllocator.allocator); - commonItems = std.StringHashMap(JsonElement).init(arenaAllocator.allocator); - commonBiomes = std.StringHashMap(JsonElement).init(arenaAllocator.allocator); - commonRecipes = main.List([]const u8).init(arenaAllocator); - commonModels = std.StringHashMap([]const u8).init(arenaAllocator.allocator); + commonBlocks = .init(arenaAllocator.allocator); + commonItems = .init(arenaAllocator.allocator); + commonBiomes = .init(arenaAllocator.allocator); + commonRecipes = .init(arenaAllocator); + commonModels = .init(arenaAllocator.allocator); readAssets(arenaAllocator, "assets/", &commonBlocks, &commonItems, &commonBiomes, &commonRecipes, &commonModels); } @@ -218,7 +218,7 @@ pub const Palette = struct { // MARK: Palette pub fn init(allocator: NeverFailingAllocator, json: JsonElement, firstElement: ?[]const u8) !*Palette { const self = allocator.create(Palette); self.* = Palette { - .palette = main.List([]const u8).init(allocator), + .palette = .init(allocator), }; errdefer self.deinit(); if(json != .JsonObject or json.JsonObject.count() == 0) { diff --git a/src/blocks.zig b/src/blocks.zig index e3e29fd7..a1edb745 100644 --- a/src/blocks.zig +++ b/src/blocks.zig @@ -87,12 +87,12 @@ var reverseIndices = std.StringHashMap(u16).init(allocator.allocator); var size: u32 = 0; -pub var ores: main.List(Ore) = main.List(Ore).init(allocator); +pub var ores: main.List(Ore) = .init(allocator); var unfinishedOreSourceBlockIds: main.List([][]const u8) = undefined; pub fn init() void { - unfinishedOreSourceBlockIds = main.List([][]const u8).init(main.globalAllocator); + unfinishedOreSourceBlockIds = .init(main.globalAllocator); } pub fn deinit() void { @@ -218,7 +218,7 @@ pub fn reset() void { ores.clearAndFree(); meshes.reset(); _ = arena.reset(.free_all); - reverseIndices = std.StringHashMap(u16).init(arena.allocator().allocator); + reverseIndices = .init(arena.allocator().allocator); std.debug.assert(unfinishedOreSourceBlockIds.items.len == 0); } @@ -394,17 +394,17 @@ pub const meshes = struct { // MARK: meshes pub fn init() void { animationShader = Shader.initComputeAndGetUniforms("assets/cubyz/shaders/animation_pre_processing.glsl", "", &animationUniforms); - blockTextureArray = TextureArray.init(); - emissionTextureArray = TextureArray.init(); - reflectivityAndAbsorptionTextureArray = TextureArray.init(); - textureIDs = main.List([]const u8).init(main.globalAllocator); - animation = main.List(AnimationData).init(main.globalAllocator); - blockTextures = main.List(Image).init(main.globalAllocator); - emissionTextures = main.List(Image).init(main.globalAllocator); - reflectivityTextures = main.List(Image).init(main.globalAllocator); - absorptionTextures = main.List(Image).init(main.globalAllocator); - textureFogData = main.List(FogData).init(main.globalAllocator); - arenaForWorld = main.utils.NeverFailingArenaAllocator.init(main.globalAllocator); + blockTextureArray = .init(); + emissionTextureArray = .init(); + reflectivityAndAbsorptionTextureArray = .init(); + textureIDs = .init(main.globalAllocator); + animation = .init(main.globalAllocator); + blockTextures = .init(main.globalAllocator); + emissionTextures = .init(main.globalAllocator); + reflectivityTextures = .init(main.globalAllocator); + absorptionTextures = .init(main.globalAllocator); + textureFogData = .init(main.globalAllocator); + arenaForWorld = .init(main.globalAllocator); } pub fn deinit() void { diff --git a/src/chunk.zig b/src/chunk.zig index 6c13a98b..1b086a94 100644 --- a/src/chunk.zig +++ b/src/chunk.zig @@ -130,8 +130,8 @@ var serverPool: std.heap.MemoryPoolAligned(ServerChunk, @alignOf(ServerChunk)) = var serverPoolMutex: std.Thread.Mutex = .{}; pub fn init() void { - memoryPool = std.heap.MemoryPoolAligned(Chunk, @alignOf(Chunk)).init(main.globalAllocator.allocator); - serverPool = std.heap.MemoryPoolAligned(ServerChunk, @alignOf(ServerChunk)).init(main.globalAllocator.allocator); + memoryPool = .init(main.globalAllocator.allocator); + serverPool = .init(main.globalAllocator.allocator); } pub fn deinit() void { @@ -281,7 +281,7 @@ pub const ServerChunk = struct { // MARK: ServerChunk .voxelSizeMask = pos.voxelSize - 1, .widthShift = voxelSizeShift + chunkShift, }, - .refCount = std.atomic.Value(u16).init(1), + .refCount = .init(1), }; self.super.data.init(); return self; diff --git a/src/entity.zig b/src/entity.zig index 2b196e65..52bc8690 100644 --- a/src/entity.zig +++ b/src/entity.zig @@ -89,7 +89,7 @@ pub const ClientEntityManager = struct { pub var mutex: std.Thread.Mutex = std.Thread.Mutex{}; pub fn init() void { - entities = main.VirtualList(ClientEntity, 1 << 20).init(); + entities = .init(); shader = graphics.Shader.initAndGetUniforms("assets/cubyz/shaders/entity_vertex.vs", "assets/cubyz/shaders/entity_fragment.fs", "", &uniforms); } diff --git a/src/game.zig b/src/game.zig index 0596cb44..0ec524a5 100644 --- a/src/game.zig +++ b/src/game.zig @@ -330,9 +330,9 @@ pub const Player = struct { // MARK: Player pub var eyeCoyote: f64 = 0; pub var eyeStep: @Vector(3, bool) = .{false, false, false}; pub var id: u32 = 0; - pub var isFlying: Atomic(bool) = Atomic(bool).init(false); - pub var isGhost: Atomic(bool) = Atomic(bool).init(false); - pub var hyperSpeed: Atomic(bool) = Atomic(bool).init(false); + pub var isFlying: Atomic(bool) = .init(false); + pub var isGhost: Atomic(bool) = .init(false); + pub var hyperSpeed: Atomic(bool) = .init(false); pub var mutex: std.Thread.Mutex = std.Thread.Mutex{}; pub var inventory__SEND_CHANGES_TO_SERVER: Inventory = undefined; pub var selectedSlot: u32 = 0; @@ -477,7 +477,7 @@ pub const World = struct { // MARK: World gravity: f64 = 9.81*1.5, // TODO: Balance name: []const u8, milliTime: i64, - gameTime: Atomic(i64) = Atomic(i64).init(0), + gameTime: Atomic(i64) = .init(0), spawn: Vec3f = undefined, blockPalette: *assets.Palette = undefined, biomePalette: *assets.Palette = undefined, @@ -499,7 +499,7 @@ pub const World = struct { // MARK: World main.blocks.meshes.generateTextureArray(); main.models.uploadModels(); - self.playerBiome = Atomic(*const main.server.terrain.biomes.Biome).init(main.server.terrain.biomes.getById("")); + self.playerBiome = .init(main.server.terrain.biomes.getById("")); main.audio.setMusic(self.playerBiome.raw.preferredMusic); } diff --git a/src/graphics.zig b/src/graphics.zig index 51ca0038..70a82c48 100644 --- a/src/graphics.zig +++ b/src/graphics.zig @@ -654,16 +654,16 @@ pub const TextBuffer = struct { // MARK: TextBuffer var parser = Parser { .unicodeIterator = std.unicode.Utf8Iterator{.bytes = text, .i = 0}, .currentFontEffect = initialFontEffect, - .parsedText = main.List(u32).init(main.stackAllocator), - .fontEffects = main.List(FontEffect).init(allocator), - .characterIndex = main.List(u32).init(allocator), + .parsedText = .init(main.stackAllocator), + .fontEffects = .init(allocator), + .characterIndex = .init(allocator), .showControlCharacters = showControlCharacters }; defer parser.fontEffects.deinit(); defer parser.parsedText.deinit(); defer parser.characterIndex.deinit(); - self.lines = main.List(Line).init(allocator); - self.lineBreaks = main.List(LineBreak).init(allocator); + self.lines = .init(allocator); + self.lineBreaks = .init(allocator); parser.parse(); if(parser.parsedText.items.len == 0) { self.lineBreaks.append(.{.index = 0, .width = 0}); @@ -1027,8 +1027,8 @@ const TextRendering = struct { // MARK: TextRendering harfbuzzFace = hbft.hb_ft_face_create_referenced(freetypeFace); harfbuzzFont = hbft.hb_font_create(harfbuzzFace); - glyphMapping = main.List(u31).init(main.globalAllocator); - glyphData = main.List(Glyph).init(main.globalAllocator); + glyphMapping = .init(main.globalAllocator); + glyphData = .init(main.globalAllocator); glyphData.append(undefined); // 0 is a reserved value. c.glGenTextures(2, &glyphTexture); c.glBindTexture(c.GL_TEXTURE_2D, glyphTexture[0]); @@ -1319,7 +1319,7 @@ pub fn LargeBuffer(comptime Entry: type) type { // MARK: LargerBuffer const Self = @This(); fn createBuffer(self: *Self, size: u31) void { - self.ssbo = SSBO.init(); + self.ssbo = .init(); c.glBindBuffer(c.GL_SHADER_STORAGE_BUFFER, self.ssbo.bufferID); const flags = c.GL_MAP_WRITE_BIT | c.GL_DYNAMIC_STORAGE_BIT; const bytes = @as(c.GLsizeiptr, size)*@sizeOf(Entry); @@ -1336,10 +1336,10 @@ pub fn LargeBuffer(comptime Entry: type) type { // MARK: LargerBuffer fence.* = c.glFenceSync(c.GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } for(&self.fencedFreeLists) |*list| { - list.* = main.List(SubAllocation).init(allocator); + list.* = .init(allocator); } - self.freeBlocks = main.List(SubAllocation).init(allocator); + self.freeBlocks = .init(allocator); self.freeBlocks.append(.{.start = 0, .len = size}); } @@ -1935,7 +1935,7 @@ const block_texture = struct { // MARK: block_texture fn init() void { shader = Shader.initAndGetUniforms("assets/cubyz/shaders/item_texture_post.vs", "assets/cubyz/shaders/item_texture_post.fs", "", &uniforms); - depthTexture = Texture.init(); + depthTexture = .init(); depthTexture.bind(); var data: [128*128]f32 = undefined; diff --git a/src/gui/components/HorizontalList.zig b/src/gui/components/HorizontalList.zig index 6bc24f7d..b791b364 100644 --- a/src/gui/components/HorizontalList.zig +++ b/src/gui/components/HorizontalList.zig @@ -19,7 +19,7 @@ children: main.List(GuiComponent), pub fn init() *HorizontalList { const self = main.globalAllocator.create(HorizontalList); self.* = HorizontalList { - .children = main.List(GuiComponent).init(main.globalAllocator), + .children = .init(main.globalAllocator), .pos = .{0, 0}, .size = .{0, 0}, }; diff --git a/src/gui/components/TextInput.zig b/src/gui/components/TextInput.zig index ec619560..fb6d7eef 100644 --- a/src/gui/components/TextInput.zig +++ b/src/gui/components/TextInput.zig @@ -48,7 +48,7 @@ pub fn init(pos: Vec2f, maxWidth: f32, maxHeight: f32, text: []const u8, onNewli self.* = TextInput { .pos = pos, .size = .{maxWidth, maxHeight}, - .currentString = main.List(u8).init(main.globalAllocator), + .currentString = .init(main.globalAllocator), .textBuffer = TextBuffer.init(main.globalAllocator, text, .{}, true, .left), .maxWidth = maxWidth, .maxHeight = maxHeight, diff --git a/src/gui/components/VerticalList.zig b/src/gui/components/VerticalList.zig index 1a17ebcc..703ba55c 100644 --- a/src/gui/components/VerticalList.zig +++ b/src/gui/components/VerticalList.zig @@ -29,7 +29,7 @@ pub fn init(pos: Vec2f, maxHeight: f32, padding: f32) *VerticalList { const scrollBar = ScrollBar.init(undefined, scrollBarWidth, maxHeight - 2*border, 0); const self = main.globalAllocator.create(VerticalList); self.* = VerticalList { - .children = main.List(GuiComponent).init(main.globalAllocator), + .children = .init(main.globalAllocator), .pos = pos, .size = .{0, 0}, .padding = padding, diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 6c388c2b..f651605f 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -52,7 +52,7 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue fn init() void { mutex.lock(); defer mutex.unlock(); - commands = List(Command).init(main.globalAllocator); + commands = .init(main.globalAllocator); } fn deinit() void { @@ -128,9 +128,9 @@ pub const Callback = struct { pub fn init() void { // MARK: init() GuiCommandQueue.init(); - windowList = List(*GuiWindow).init(main.globalAllocator); - hudWindows = List(*GuiWindow).init(main.globalAllocator); - openWindows = List(*GuiWindow).init(main.globalAllocator); + windowList = .init(main.globalAllocator); + hudWindows = .init(main.globalAllocator); + openWindows = .init(main.globalAllocator); inline for(@typeInfo(windowlist).@"struct".decls) |decl| { const windowStruct = @field(windowlist, decl.name); windowStruct.window.id = decl.name; @@ -596,8 +596,8 @@ pub const inventory = struct { // MARK: inventory var initialAmount: u16 = 0; pub fn init() void { - deliveredItemSlots = List(*ItemSlot).init(main.globalAllocator); - deliveredItemStacksAmountAdded = List(u16).init(main.globalAllocator); + deliveredItemSlots = .init(main.globalAllocator); + deliveredItemStacksAmountAdded = .init(main.globalAllocator); carriedItemSlot = ItemSlot.init(.{0, 0}, carriedItemStack, undefined, undefined, .default, .normal); carriedItemSlot.renderFrame = false; } @@ -695,7 +695,7 @@ pub const inventory = struct { // MARK: inventory if(carriedItemStack.amount == 0) if(hoveredItemSlot) |hovered| { if(hovered.itemStack.item) |item| { const tooltip = item.getTooltip(); - var textBuffer: graphics.TextBuffer = graphics.TextBuffer.init(main.stackAllocator, tooltip, .{}, false, .left); + var textBuffer = graphics.TextBuffer.init(main.stackAllocator, tooltip, .{}, false, .left); defer textBuffer.deinit(); var size = textBuffer.calculateLineBreaks(16, 256); size[0] = 0; diff --git a/src/gui/windows/chat.zig b/src/gui/windows/chat.zig index c49fb8d1..7b4a9aa9 100644 --- a/src/gui/windows/chat.zig +++ b/src/gui/windows/chat.zig @@ -70,9 +70,9 @@ fn refresh() void { } pub fn onOpen() void { - history = main.List(*Label).init(main.globalAllocator); - expirationTime = main.List(i32).init(main.globalAllocator); - messageQueue = main.List([]const u8).init(main.globalAllocator); + history = .init(main.globalAllocator); + expirationTime = .init(main.globalAllocator); + messageQueue = .init(main.globalAllocator); historyStart = 0; fadeOutEnd = 0; input = TextInput.init(.{0, 0}, 256, 32, "", .{.callback = &sendMessage}); diff --git a/src/gui/windows/creative_inventory.zig b/src/gui/windows/creative_inventory.zig index 7857a7cf..fa15ab1a 100644 --- a/src/gui/windows/creative_inventory.zig +++ b/src/gui/windows/creative_inventory.zig @@ -48,7 +48,7 @@ fn lessThan(_: void, lhs: Item, rhs: Item) bool { } pub fn onOpen() void { - items = main.List(Item).init(main.globalAllocator); + items = .init(main.globalAllocator); var itemIterator = main.items.iterator(); while(itemIterator.next()) |item| { items.append(Item{.baseItem = item.*}); diff --git a/src/gui/windows/inventory_crafting.zig b/src/gui/windows/inventory_crafting.zig index c5082875..0f4e436a 100644 --- a/src/gui/windows/inventory_crafting.zig +++ b/src/gui/windows/inventory_crafting.zig @@ -159,8 +159,8 @@ fn refresh() void { } pub fn onOpen() void { - availableItems = main.List(*BaseItem).init(main.globalAllocator); - itemAmount = main.List(u32).init(main.globalAllocator); + availableItems = .init(main.globalAllocator); + itemAmount = .init(main.globalAllocator); refresh(); } diff --git a/src/gui/windows/invite.zig b/src/gui/windows/invite.zig index 361c3277..d49a3f72 100644 --- a/src/gui/windows/invite.zig +++ b/src/gui/windows/invite.zig @@ -23,7 +23,7 @@ var ipAddressEntry: *TextInput = undefined; const padding: f32 = 8; var ipAddress: []const u8 = ""; -var gotIpAddress: std.atomic.Value(bool) = std.atomic.Value(bool).init(false); +var gotIpAddress: std.atomic.Value(bool) = .init(false); var thread: ?std.Thread = null; const width: f32 = 420; diff --git a/src/gui/windows/multiplayer.zig b/src/gui/windows/multiplayer.zig index 4aab320e..2d401bfd 100644 --- a/src/gui/windows/multiplayer.zig +++ b/src/gui/windows/multiplayer.zig @@ -24,7 +24,7 @@ const padding: f32 = 8; var connection: ?*ConnectionManager = null; var ipAddress: []const u8 = ""; -var gotIpAddress: std.atomic.Value(bool) = std.atomic.Value(bool).init(false); +var gotIpAddress: std.atomic.Value(bool) = .init(false); var thread: ?std.Thread = null; const width: f32 = 420; diff --git a/src/itemdrop.zig b/src/itemdrop.zig index be76f640..69c86f84 100644 --- a/src/itemdrop.zig +++ b/src/itemdrop.zig @@ -71,7 +71,7 @@ pub const ItemDropManager = struct { // MARK: ItemDropManager .allocator = allocator, .list = std.MultiArrayList(ItemDrop){}, .lastUpdates = JsonElement.initArray(allocator), - .isEmpty = std.bit_set.ArrayBitSet(usize, maxCapacity).initFull(), + .isEmpty = .initFull(), .world = world, .gravity = gravity, .airDragFactor = gravity/maxSpeed, @@ -590,12 +590,12 @@ pub const ItemDropRenderer = struct { // MARK: ItemDropRenderer pub fn init() void { itemShader = graphics.Shader.initAndGetUniforms("assets/cubyz/shaders/item_drop.vs", "assets/cubyz/shaders/item_drop.fs", "", &itemUniforms); - itemModelSSBO = graphics.SSBO.init(); + itemModelSSBO = .init(); itemModelSSBO.bufferData(i32, &[3]i32{1, 1, 1}); itemModelSSBO.bind(2); - modelData = main.List(u32).init(main.globalAllocator); - freeSlots = main.List(*ItemVoxelModel).init(main.globalAllocator); + modelData = .init(main.globalAllocator); + freeSlots = .init(main.globalAllocator); } pub fn deinit() void { diff --git a/src/items.zig b/src/items.zig index c32178d3..d9b84d1a 100644 --- a/src/items.zig +++ b/src/items.zig @@ -173,7 +173,7 @@ const TextureGenerator = struct { // MARK: TextureGenerator items: main.List(*const BaseItem), pub fn init(allocator: NeverFailingAllocator) PixelData { return PixelData { - .items = main.List(*const BaseItem).init(allocator), + .items = .init(allocator), }; } pub fn deinit(self: *PixelData) void { @@ -1299,9 +1299,9 @@ pub fn recipes() []Recipe { } pub fn globalInit() void { - arena = main.utils.NeverFailingArenaAllocator.init(main.globalAllocator); - reverseIndices = std.StringHashMap(*BaseItem).init(arena.allocator().allocator); - recipeList = main.List(Recipe).init(arena.allocator()); + arena = .init(main.globalAllocator); + reverseIndices = .init(arena.allocator().allocator); + recipeList = .init(arena.allocator()); itemListSize = 0; } diff --git a/src/json.zig b/src/json.zig index 858be88a..7145cc04 100644 --- a/src/json.zig +++ b/src/json.zig @@ -25,14 +25,14 @@ pub const JsonElement = union(JsonType) { // MARK: JsonElement JsonObject: *std.StringHashMap(JsonElement), pub fn initObject(allocator: NeverFailingAllocator) JsonElement { - const map: *std.StringHashMap(JsonElement) = allocator.create(std.StringHashMap(JsonElement)); - map.* = std.StringHashMap(JsonElement).init(allocator.allocator); + const map = allocator.create(std.StringHashMap(JsonElement)); + map.* = .init(allocator.allocator); return JsonElement{.JsonObject=map}; } pub fn initArray(allocator: NeverFailingAllocator) JsonElement { - const list: *List(JsonElement) = allocator.create(List(JsonElement)); - list.* = List(JsonElement).init(allocator); + const list = allocator.create(List(JsonElement)); + list.* = .init(allocator); return JsonElement{.JsonArray=list}; } @@ -456,7 +456,7 @@ const Parser = struct { // MARK: Parser } fn parseString(allocator: NeverFailingAllocator, chars: []const u8, index: *u32) []const u8 { - var builder: List(u8) = List(u8).init(allocator); + var builder = List(u8).init(allocator); while(index.* < chars.len): (index.* += 1) { if(chars[index.*] == '\"') { index.* += 1; @@ -487,8 +487,8 @@ const Parser = struct { // MARK: Parser } fn parseArray(allocator: NeverFailingAllocator, chars: []const u8, index: *u32) JsonElement { - const list: *List(JsonElement) = allocator.create(List(JsonElement)); - list.* = List(JsonElement).init(allocator); + const list = allocator.create(List(JsonElement)); + list.* = .init(allocator); while(index.* < chars.len) { skipWhitespaces(chars, index); if(index.* >= chars.len) break; @@ -507,8 +507,8 @@ const Parser = struct { // MARK: Parser } fn parseObject(allocator: NeverFailingAllocator, chars: []const u8, index: *u32) JsonElement { - const map: *std.StringHashMap(JsonElement) = allocator.create(std.StringHashMap(JsonElement)); - map.* = std.StringHashMap(JsonElement).init(allocator.allocator); + const map = allocator.create(std.StringHashMap(JsonElement)); + map.* = .init(allocator.allocator); while(index.* < chars.len) { skipWhitespaces(chars, index); if(index.* >= chars.len) break; diff --git a/src/models.zig b/src/models.zig index cafe5da0..0cdc1f3a 100644 --- a/src/models.zig +++ b/src/models.zig @@ -529,12 +529,12 @@ pub fn registerModel(id: []const u8, data: []const u8) u16 { // TODO: Entity models. pub fn init() void { - models = main.List(Model).init(main.globalAllocator); - quads = main.List(QuadInfo).init(main.globalAllocator); - extraQuadInfos = main.List(ExtraQuadInfo).init(main.globalAllocator); - quadDeduplication = std.AutoHashMap([@sizeOf(QuadInfo)]u8, u16).init(main.globalAllocator.allocator); + models = .init(main.globalAllocator); + quads = .init(main.globalAllocator); + extraQuadInfos = .init(main.globalAllocator); + quadDeduplication = .init(main.globalAllocator.allocator); - nameToIndex = std.StringHashMap(u16).init(main.globalAllocator.allocator); + nameToIndex = .init(main.globalAllocator.allocator); nameToIndex.put("none", Model.init(&.{})) catch unreachable; } diff --git a/src/network.zig b/src/network.zig index 448a056c..a9b0355c 100644 --- a/src/network.zig +++ b/src/network.zig @@ -390,8 +390,8 @@ pub const ConnectionManager = struct { // MARK: ConnectionManager thread: std.Thread = undefined, threadId: std.Thread.Id = undefined, externalAddress: Address = undefined, - online: Atomic(bool) = Atomic(bool).init(false), - running: Atomic(bool) = Atomic(bool).init(true), + online: Atomic(bool) = .init(false), + running: Atomic(bool) = .init(true), connections: main.List(*Connection) = undefined, requests: main.List(*Request) = undefined, @@ -421,9 +421,9 @@ pub const ConnectionManager = struct { // MARK: ConnectionManager const result: *ConnectionManager = main.globalAllocator.create(ConnectionManager); errdefer main.globalAllocator.destroy(result); result.* = .{}; - result.connections = main.List(*Connection).init(main.globalAllocator); - result.requests = main.List(*Request).init(main.globalAllocator); - result.packetSendRequests = std.PriorityQueue(PacketSendRequest, void, PacketSendRequest.compare).init(main.globalAllocator.allocator, {}); + result.connections = .init(main.globalAllocator); + result.requests = .init(main.globalAllocator); + result.packetSendRequests = .init(main.globalAllocator.allocator, {}); result.localPort = localPort; result.socket = Socket.init(localPort) catch |err| blk: { @@ -650,8 +650,8 @@ const UnconfirmedPacket = struct { }; // MARK: Protocols -pub var bytesReceived: [256]Atomic(usize) = [_]Atomic(usize) {Atomic(usize).init(0)} ** 256; -pub var packetsReceived: [256]Atomic(usize) = [_]Atomic(usize) {Atomic(usize).init(0)} ** 256; +pub var bytesReceived: [256]Atomic(usize) = .{Atomic(usize).init(0)} ** 256; +pub var packetsReceived: [256]Atomic(usize) = .{Atomic(usize).init(0)} ** 256; pub const Protocols = struct { pub var list: [256]?*const fn(*Connection, []const u8) anyerror!void = [_]?*const fn(*Connection, []const u8) anyerror!void {null} ** 256; pub var isAsynchronous: [256]bool = .{false} ** 256; @@ -1282,8 +1282,8 @@ pub const Connection = struct { // MARK: Connection const timeUnit = 100_000_000; // Statistics: - pub var packetsSent: Atomic(u32) = Atomic(u32).init(0); - pub var packetsResent: Atomic(u32) = Atomic(u32).init(0); + pub var packetsSent: Atomic(u32) = .init(0); + pub var packetsResent: Atomic(u32) = .init(0); manager: *ConnectionManager, user: ?*main.server.User, @@ -1318,8 +1318,8 @@ pub const Connection = struct { // MARK: Connection congestionControl_bandWidthUsed: usize = 0, congestionControl_curPosition: usize = 0, - disconnected: Atomic(bool) = Atomic(bool).init(false), - handShakeState: Atomic(u8) = Atomic(u8).init(Protocols.handShake.stepStart), + disconnected: Atomic(bool) = .init(false), + handShakeState: Atomic(u8) = .init(Protocols.handShake.stepStart), handShakeWaiting: std.Thread.Condition = std.Thread.Condition{}, lastConnection: i64, @@ -1339,14 +1339,14 @@ pub const Connection = struct { // MARK: Connection .congestionControl_sendTimeLimit = @as(i64, @truncate(std.time.nanoTimestamp())) +% timeUnit*21/20, }; errdefer main.globalAllocator.free(result.packetMemory); - result.unconfirmedPackets = main.List(UnconfirmedPacket).init(main.globalAllocator); + result.unconfirmedPackets = .init(main.globalAllocator); errdefer result.unconfirmedPackets.deinit(); - result.packetQueue = main.utils.CircularBufferQueue(UnconfirmedPacket).init(main.globalAllocator, 1024); + result.packetQueue = .init(main.globalAllocator, 1024); errdefer result.packetQueue.deinit(); result.receivedPackets = [3]main.List(u32){ - main.List(u32).init(main.globalAllocator), - main.List(u32).init(main.globalAllocator), - main.List(u32).init(main.globalAllocator), + .init(main.globalAllocator), + .init(main.globalAllocator), + .init(main.globalAllocator), }; errdefer for(&result.receivedPackets) |*list| { list.deinit(); @@ -1385,7 +1385,7 @@ pub const Connection = struct { // MARK: Connection self.receivedPackets[2].clearRetainingCapacity(); self.lastIndex = 0; self.lastIncompletePacket = 0; - self.handShakeState = Atomic(u8).init(Protocols.handShake.stepStart); + self.handShakeState = .init(Protocols.handShake.stepStart); } pub fn deinit(self: *Connection) void { @@ -1524,9 +1524,9 @@ pub const Connection = struct { // MARK: Connection self.mutex.lock(); defer self.mutex.unlock(); - var runLengthEncodingStarts: main.List(u32) = main.List(u32).init(main.stackAllocator); + var runLengthEncodingStarts = main.List(u32).init(main.stackAllocator); defer runLengthEncodingStarts.deinit(); - var runLengthEncodingLengths: main.List(u32) = main.List(u32).init(main.stackAllocator); + var runLengthEncodingLengths = main.List(u32).init(main.stackAllocator); defer runLengthEncodingLengths.deinit(); for(self.receivedPackets) |list| { diff --git a/src/renderer.zig b/src/renderer.zig index faa7e572..ce5eae8f 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -69,7 +69,7 @@ pub fn init() void { }; chunk_meshing.init(); mesh_storage.init(); - reflectionCubeMap = graphics.CubeMapTexture.init(); + reflectionCubeMap = .init(); reflectionCubeMap.generate(reflectionCubeMapSize, reflectionCubeMapSize); initReflectionCubeMap(); } @@ -312,7 +312,7 @@ const Bloom = struct { // MARK: Bloom pub fn init() void { buffer1.init(false, c.GL_LINEAR, c.GL_CLAMP_TO_EDGE); buffer2.init(false, c.GL_LINEAR, c.GL_CLAMP_TO_EDGE); - emptyBuffer = graphics.Texture.init(); + emptyBuffer = .init(); emptyBuffer.generate(graphics.Image.emptyImage); firstPassShader = graphics.Shader.init("assets/cubyz/shaders/bloom/first_pass.vs", "assets/cubyz/shaders/bloom/first_pass.fs", ""); secondPassShader = graphics.Shader.init("assets/cubyz/shaders/bloom/second_pass.vs", "assets/cubyz/shaders/bloom/second_pass.fs", ""); diff --git a/src/renderer/chunk_meshing.zig b/src/renderer/chunk_meshing.zig index 73c33367..9a76c6d7 100644 --- a/src/renderer/chunk_meshing.zig +++ b/src/renderer/chunk_meshing.zig @@ -684,12 +684,12 @@ pub const ChunkMesh = struct { // MARK: ChunkMesh sortingOutputBuffer: []FaceData = &.{}, culledSortingCount: u31 = 0, lastTransparentUpdatePos: Vec3i = Vec3i{0, 0, 0}, - refCount: std.atomic.Value(u32) = std.atomic.Value(u32).init(1), - needsLightRefresh: std.atomic.Value(bool) = std.atomic.Value(bool).init(false), + refCount: std.atomic.Value(u32) = .init(1), + needsLightRefresh: std.atomic.Value(bool) = .init(false), needsMeshUpdate: bool = false, finishedMeshing: bool = false, finishedLighting: bool = false, - litNeighbors: Atomic(u32) = Atomic(u32).init(0), + litNeighbors: Atomic(u32) = .init(0), mutex: std.Thread.Mutex = .{}, chunkAllocation: graphics.SubAllocation = .{.start = 0, .len = 0}, min: Vec3f = undefined, diff --git a/src/renderer/lighting.zig b/src/renderer/lighting.zig index 1c789407..09ce5df9 100644 --- a/src/renderer/lighting.zig +++ b/src/renderer/lighting.zig @@ -11,7 +11,7 @@ var memoryPool: std.heap.MemoryPool(ChannelChunk) = undefined; var memoryPoolMutex: std.Thread.Mutex = .{}; pub fn init() void { - memoryPool = std.heap.MemoryPool(ChannelChunk).init(main.globalAllocator.allocator); + memoryPool = .init(main.globalAllocator.allocator); } pub fn deinit() void { diff --git a/src/renderer/mesh_storage.zig b/src/renderer/mesh_storage.zig index 2dbd7b39..66ba1802 100644 --- a/src/renderer/mesh_storage.zig +++ b/src/renderer/mesh_storage.zig @@ -55,7 +55,7 @@ var blockUpdateList: main.List(BlockUpdate) = undefined; pub fn init() void { // MARK: init() lastRD = 0; - blockUpdateList = main.List(BlockUpdate).init(main.globalAllocator); + blockUpdateList = .init(main.globalAllocator); for(&storageLists) |*storageList| { storageList.* = main.globalAllocator.create([storageSize*storageSize*storageSize]ChunkMeshNode); for(storageList.*) |*val| { diff --git a/src/rotation.zig b/src/rotation.zig index e4814dc3..29b431c2 100644 --- a/src/rotation.zig +++ b/src/rotation.zig @@ -93,7 +93,7 @@ pub const RotationModes = struct { var rotatedModels: std.StringHashMap(u16) = undefined; fn init() void { - rotatedModels = std.StringHashMap(u16).init(main.globalAllocator.allocator); + rotatedModels = .init(main.globalAllocator.allocator); } fn deinit() void { @@ -138,7 +138,7 @@ pub const RotationModes = struct { var rotatedModels: std.StringHashMap(u16) = undefined; fn init() void { - rotatedModels = std.StringHashMap(u16).init(main.globalAllocator.allocator); + rotatedModels = .init(main.globalAllocator.allocator); } fn deinit() void { @@ -189,7 +189,7 @@ pub const RotationModes = struct { }; fn init() void { - fenceModels = std.StringHashMap(u16).init(main.globalAllocator.allocator); + fenceModels = .init(main.globalAllocator.allocator); } fn deinit() void { @@ -557,7 +557,7 @@ pub const RotationModes = struct { }; fn init() void { - rotatedModels = std.StringHashMap(u16).init(main.globalAllocator.allocator); + rotatedModels = .init(main.globalAllocator.allocator); } fn deinit() void { @@ -668,7 +668,7 @@ pub const RotationModes = struct { // MARK: init/register pub fn init() void { - rotationModes = std.StringHashMap(RotationMode).init(main.globalAllocator.allocator); + rotationModes = .init(main.globalAllocator.allocator); inline for(@typeInfo(RotationModes).@"struct".decls) |declaration| { register(@field(RotationModes, declaration.name)); } diff --git a/src/server/command/_command.zig b/src/server/command/_command.zig index 6b87e6c0..dfa0e468 100644 --- a/src/server/command/_command.zig +++ b/src/server/command/_command.zig @@ -13,7 +13,7 @@ pub const Command = struct { pub var commands: std.StringHashMap(Command) = undefined; pub fn init() void { - commands = std.StringHashMap(Command).init(main.globalAllocator.allocator); + commands = .init(main.globalAllocator.allocator); const commandList = @import("_list.zig"); inline for(@typeInfo(commandList).@"struct".decls) |decl| { commands.put(decl.name, .{ diff --git a/src/server/server.zig b/src/server/server.zig index 41a28fc5..468c3811 100644 --- a/src/server/server.zig +++ b/src/server/server.zig @@ -38,9 +38,9 @@ pub const User = struct { // MARK: User lastRenderDistance: u16 = 0, lastPos: Vec3i = @splat(0), - connected: Atomic(bool) = Atomic(bool).init(true), + connected: Atomic(bool) = .init(true), - refCount: Atomic(u32) = Atomic(u32).init(1), + refCount: Atomic(u32) = .init(1), pub fn initAndIncreaseRefCount(manager: *ConnectionManager, ipPort: []const u8) !*User { const self = main.globalAllocator.create(User); @@ -195,7 +195,7 @@ pub var userDeinitList: main.List(*User) = undefined; pub var connectionManager: *ConnectionManager = undefined; -pub var running: std.atomic.Value(bool) = std.atomic.Value(bool).init(false); +pub var running: std.atomic.Value(bool) = .init(false); var lastTime: i128 = undefined; pub var mutex: std.Thread.Mutex = .{}; @@ -205,8 +205,8 @@ pub var thread: ?std.Thread = null; fn init(name: []const u8, singlePlayerPort: ?u16) void { // MARK: init() std.debug.assert(world == null); // There can only be one world. command.init(); - users = main.List(*User).init(main.globalAllocator); - userDeinitList = main.List(*User).init(main.globalAllocator); + users = .init(main.globalAllocator); + userDeinitList = .init(main.globalAllocator); lastTime = std.time.nanoTimestamp(); connectionManager = ConnectionManager.init(main.settings.defaultPort, false) catch |err| { std.log.err("Couldn't create socket: {s}", .{@errorName(err)}); diff --git a/src/server/storage.zig b/src/server/storage.zig index 6dba9a29..e19b2205 100644 --- a/src/server/storage.zig +++ b/src/server/storage.zig @@ -17,7 +17,7 @@ pub const RegionFile = struct { // MARK: RegionFile pos: chunk.ChunkPosition, mutex: std.Thread.Mutex = .{}, modified: bool = false, - refCount: Atomic(u16) = Atomic(u16).init(1), + refCount: Atomic(u16) = .init(1), saveFolder: []const u8, pub fn getIndex(x: usize, y: usize, z: usize) usize { diff --git a/src/server/terrain/CaveBiomeMap.zig b/src/server/terrain/CaveBiomeMap.zig index 28491ec7..94e51549 100644 --- a/src/server/terrain/CaveBiomeMap.zig +++ b/src/server/terrain/CaveBiomeMap.zig @@ -27,7 +27,7 @@ pub const CaveBiomeMapFragment = struct { // MARK: caveBiomeMapFragment pos: main.chunk.ChunkPosition, biomeMap: [1 << 3*(caveBiomeMapShift - caveBiomeShift)][2]*const Biome = undefined, - refCount: std.atomic.Value(u16) = std.atomic.Value(u16).init(0), + refCount: std.atomic.Value(u16) = .init(0), pub fn init(self: *CaveBiomeMapFragment, wx: i32, wy: i32, wz: i32) void { self.* = .{ diff --git a/src/server/terrain/CaveMap.zig b/src/server/terrain/CaveMap.zig index 05023120..f9ea2b4f 100644 --- a/src/server/terrain/CaveMap.zig +++ b/src/server/terrain/CaveMap.zig @@ -21,7 +21,7 @@ pub const CaveMapFragment = struct { // MARK: CaveMapFragment data: [width*width]u64 = undefined, pos: ChunkPosition, voxelShift: u5, - refCount: Atomic(u16) = Atomic(u16).init(0), + refCount: Atomic(u16) = .init(0), pub fn init(self: *CaveMapFragment, wx: i32, wy: i32, wz: i32, voxelSize: u31) void { diff --git a/src/server/terrain/ClimateMap.zig b/src/server/terrain/ClimateMap.zig index e1207497..fe89b2fa 100644 --- a/src/server/terrain/ClimateMap.zig +++ b/src/server/terrain/ClimateMap.zig @@ -45,7 +45,7 @@ pub const ClimateMapFragment = struct { pos: ClimateMapFragmentPosition, map: [mapSize >> MapFragment.biomeShift][mapSize >> MapFragment.biomeShift]BiomeSample = undefined, - refCount: Atomic(u16) = Atomic(u16).init(0), + refCount: Atomic(u16) = .init(0), pub fn init(self: *ClimateMapFragment, wx: i32, wy: i32) void { self.* = .{ diff --git a/src/server/terrain/LightMap.zig b/src/server/terrain/LightMap.zig index 81c13aa7..14a847a7 100644 --- a/src/server/terrain/LightMap.zig +++ b/src/server/terrain/LightMap.zig @@ -21,7 +21,7 @@ pub const LightMapFragment = struct { startHeight: [mapSize*mapSize]i16 = undefined, pos: MapFragmentPosition, - refCount: Atomic(u16) = Atomic(u16).init(0), + refCount: Atomic(u16) = .init(0), pub fn init(self: *LightMapFragment, wx: i32, wy: i32, voxelSize: u31) void { self.* = .{ diff --git a/src/server/terrain/StructureMap.zig b/src/server/terrain/StructureMap.zig index d7e7b47f..25f11102 100644 --- a/src/server/terrain/StructureMap.zig +++ b/src/server/terrain/StructureMap.zig @@ -31,7 +31,7 @@ pub const StructureMapFragment = struct { pos: ChunkPosition, voxelShift: u5, - refCount: Atomic(u16) = Atomic(u16).init(0), + refCount: Atomic(u16) = .init(0), arena: main.utils.NeverFailingArenaAllocator, allocator: main.utils.NeverFailingAllocator, @@ -43,7 +43,7 @@ pub const StructureMapFragment = struct { .voxelSize = voxelSize, }, .voxelShift = @ctz(voxelSize), - .arena = main.utils.NeverFailingArenaAllocator.init(main.globalAllocator), + .arena = .init(main.globalAllocator), .allocator = self.arena.allocator(), }; @memset(&self.data, .{}); diff --git a/src/server/terrain/SurfaceMap.zig b/src/server/terrain/SurfaceMap.zig index 9c50e55e..8b7b3da6 100644 --- a/src/server/terrain/SurfaceMap.zig +++ b/src/server/terrain/SurfaceMap.zig @@ -70,9 +70,9 @@ pub const MapFragment = struct { // MARK: MapFragment maxHeight: i32 = 0, pos: MapFragmentPosition, - wasStored: Atomic(bool) = .{.raw = false}, + wasStored: Atomic(bool) = .init(false), - refCount: Atomic(u16) = Atomic(u16).init(0), + refCount: Atomic(u16) = .init(0), pub fn init(self: *MapFragment, wx: i32, wy: i32, voxelSize: u31) void { self.* = .{ diff --git a/src/server/terrain/biomes.zig b/src/server/terrain/biomes.zig index 5084aa4c..fa5e9a07 100644 --- a/src/server/terrain/biomes.zig +++ b/src/server/terrain/biomes.zig @@ -50,7 +50,7 @@ pub const SimpleStructureModel = struct { // MARK: SimpleStructureModel var modelRegistry: std.StringHashMapUnmanaged(VTable) = .{}; - var arena: main.utils.NeverFailingArenaAllocator = main.utils.NeverFailingArenaAllocator.init(main.globalAllocator); + var arena: main.utils.NeverFailingArenaAllocator = .init(main.globalAllocator); pub fn reset() void { std.debug.assert(arena.reset(.free_all)); @@ -425,7 +425,7 @@ pub const TreeNode = union(enum) { // MARK: TreeNode for(currentSlice) |biome| { self.leaf.totalChance += biome.chance; } - self.leaf.aliasTable = main.utils.AliasTable(Biome).init(allocator, currentSlice); + self.leaf.aliasTable = .init(allocator, currentSlice); return self; } var chanceLower: f32 = 0; @@ -462,9 +462,9 @@ pub const TreeNode = union(enum) { // MARK: TreeNode var upperIndex: usize = undefined; { var lists: [3]main.ListUnmanaged(Biome) = .{ - main.ListUnmanaged(Biome).initCapacity(main.stackAllocator, currentSlice.len), - main.ListUnmanaged(Biome).initCapacity(main.stackAllocator, currentSlice.len), - main.ListUnmanaged(Biome).initCapacity(main.stackAllocator, currentSlice.len), + .initCapacity(main.stackAllocator, currentSlice.len), + .initCapacity(main.stackAllocator, currentSlice.len), + .initCapacity(main.stackAllocator, currentSlice.len), }; defer for(lists) |list| { list.deinit(main.stackAllocator); @@ -542,9 +542,9 @@ const UnfinishedSubBiomeData = struct { var unfinishedSubBiomes: std.StringHashMapUnmanaged(main.ListUnmanaged(UnfinishedSubBiomeData)) = .{}; pub fn init() void { - biomes = main.List(Biome).init(main.globalAllocator); - caveBiomes = main.List(Biome).init(main.globalAllocator); - biomesById = std.StringHashMap(*Biome).init(main.globalAllocator.allocator); + biomes = .init(main.globalAllocator); + caveBiomes = .init(main.globalAllocator); + biomesById = .init(main.globalAllocator.allocator); const list = @import("simple_structures/_list.zig"); inline for(@typeInfo(list).@"struct".decls) |decl| { SimpleStructureModel.registerGenerator(@field(list, decl.name)); @@ -609,7 +609,7 @@ pub fn finishLoading() void { for(subBiomeDataList.items) |item| { parentBiome.subBiomeTotalChance += item.chance; } - parentBiome.subBiomes = main.utils.AliasTable(*const Biome).initFromContext(main.globalAllocator, subBiomeDataList.items); + parentBiome.subBiomes = .initFromContext(main.globalAllocator, subBiomeDataList.items); subBiomeDataList.deinit(main.globalAllocator); } unfinishedSubBiomes.clearAndFree(main.globalAllocator.allocator); diff --git a/src/server/terrain/noise/CachedFractalNoise.zig b/src/server/terrain/noise/CachedFractalNoise.zig index cbc7ec17..6bdf977d 100644 --- a/src/server/terrain/noise/CachedFractalNoise.zig +++ b/src/server/terrain/noise/CachedFractalNoise.zig @@ -20,7 +20,7 @@ pub fn init(wx: i32, wy: i32, voxelSize: u31, size: u31, worldSeed: u64, scale: .voxelSize = voxelSize, .voxelSizeShift = @ctz(voxelSize), }, - .cache = Array2D(f32).init(main.globalAllocator, cacheWidth, cacheWidth), + .cache = .init(main.globalAllocator, cacheWidth, cacheWidth), .scale = scale, .worldSeed = worldSeed, }; diff --git a/src/server/world.zig b/src/server/world.zig index 94ca0a6d..0df38d06 100644 --- a/src/server/world.zig +++ b/src/server/world.zig @@ -24,14 +24,14 @@ const Entity = server.Entity; const storage = @import("storage.zig"); pub const EntityChunk = struct { - chunk: std.atomic.Value(?*ServerChunk) = .{.raw = null}, + chunk: std.atomic.Value(?*ServerChunk) = .init(null), refCount: std.atomic.Value(u32), pos: chunk.ChunkPosition, pub fn initAndIncreaseRefCount(pos: ChunkPosition) *EntityChunk { const self = main.globalAllocator.create(EntityChunk); self.* = .{ - .refCount = std.atomic.Value(u32).init(1), + .refCount = .init(1), .pos = pos, }; return self; @@ -254,7 +254,7 @@ const ChunkManager = struct { // MARK: ChunkManager .world = world, .terrainGenerationProfile = try server.terrain.TerrainGenerationProfile.init(settings, world.seed), }; - entityChunkHashMap = @TypeOf(entityChunkHashMap).init(main.globalAllocator.allocator); + entityChunkHashMap = .init(main.globalAllocator.allocator); server.terrain.init(self.terrainGenerationProfile); storage.init(); return self; @@ -381,7 +381,7 @@ const WorldIO = struct { // MARK: WorldIO /// Load the seed, which is needed before custom item and ore generation. pub fn loadWorldSeed(self: WorldIO) !u64 { - const worldData: JsonElement = try self.dir.readToJson(main.stackAllocator, "world.dat"); + const worldData = try self.dir.readToJson(main.stackAllocator, "world.dat"); defer worldData.free(main.stackAllocator); if(worldData.get(u32, "version", 0) != worldDataVersion) { std.log.err("Cannot read world file version {}. Expected version {}.", .{worldData.get(u32, "version", 0), worldDataVersion}); @@ -391,7 +391,7 @@ const WorldIO = struct { // MARK: WorldIO } pub fn loadWorldData(self: WorldIO) !void { - const worldData: JsonElement = try self.dir.readToJson(main.stackAllocator, "world.dat"); + const worldData = try self.dir.readToJson(main.stackAllocator, "world.dat"); defer worldData.free(main.stackAllocator); self.world.doGameTimeCycle = worldData.get(bool, "doGameTimeCycle", true); @@ -401,7 +401,7 @@ const WorldIO = struct { // MARK: WorldIO } pub fn saveWorldData(self: WorldIO) !void { - const worldData: JsonElement = JsonElement.initObject(main.stackAllocator); + const worldData = JsonElement.initObject(main.stackAllocator); defer worldData.free(main.stackAllocator); worldData.put("version", worldDataVersion); worldData.put("seed", self.world.seed); @@ -464,8 +464,8 @@ pub const ServerWorld = struct { // MARK: ServerWorld .lastUnimportantDataSent = std.time.milliTimestamp(), .seed = @bitCast(@as(i64, @truncate(std.time.nanoTimestamp()))), .name = main.globalAllocator.dupe(u8, name), - .chunkUpdateQueue = main.utils.CircularBufferQueue(ChunkUpdateRequest).init(main.globalAllocator, 256), - .regionUpdateQueue = main.utils.CircularBufferQueue(RegionUpdateRequest).init(main.globalAllocator, 256), + .chunkUpdateQueue = .init(main.globalAllocator, 256), + .regionUpdateQueue = .init(main.globalAllocator, 256), }; self.itemDropManager.init(main.globalAllocator, self, self.gravity); errdefer self.itemDropManager.deinit(); diff --git a/src/utils.zig b/src/utils.zig index c7734b79..7018e593 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -765,7 +765,7 @@ pub const NeverFailingArenaAllocator = struct { // MARK: NeverFailingArena pub fn init(child_allocator: NeverFailingAllocator) NeverFailingArenaAllocator { return .{ - .arena = std.heap.ArenaAllocator.init(child_allocator.allocator), + .arena = .init(child_allocator.allocator), }; } @@ -802,7 +802,7 @@ pub const BufferFallbackAllocator = struct { // MARK: BufferFallbackAllocator pub fn init(buffer: []u8, fallbackAllocator: NeverFailingAllocator) BufferFallbackAllocator { return .{ - .fixedBuffer = std.heap.FixedBufferAllocator.init(buffer), + .fixedBuffer = .init(buffer), .fallbackAllocator = fallbackAllocator, }; } @@ -1178,7 +1178,7 @@ pub fn DynamicPackedIntArray(size: comptime_int) type { // MARK: DynamicPackedIn pub fn resize(self: *Self, allocator: main.utils.NeverFailingAllocator, newBitSize: u5) void { if(newBitSize == self.bitSize) return; - var newSelf: Self = Self.initCapacity(allocator, newBitSize); + var newSelf = Self.initCapacity(allocator, newBitSize); for(0..size) |i| { newSelf.setValue(i, self.getValue(i)); @@ -1430,8 +1430,8 @@ pub fn Cache(comptime T: type, comptime numberOfBuckets: u32, comptime bucketSiz return struct { buckets: [numberOfBuckets]Bucket = [_]Bucket {Bucket{}} ** numberOfBuckets, - cacheRequests: Atomic(usize) = Atomic(usize).init(0), - cacheMisses: Atomic(usize) = Atomic(usize).init(0), + cacheRequests: Atomic(usize) = .init(0), + cacheMisses: Atomic(usize) = .init(0), /// Tries to find the entry that fits to the supplied hashable. pub fn find(self: *@This(), compareAndHash: anytype, comptime postGetFunction: ?fn(*T) void) ?*T { @@ -1630,7 +1630,7 @@ pub fn GenericInterpolation(comptime elements: comptime_int) type { // MARK: Gen } pub const TimeDifference = struct { // MARK: TimeDifference - difference: Atomic(i16) = Atomic(i16).init(0), + difference: Atomic(i16) = .init(0), firstValue: bool = true, pub fn addDataPoint(self: *TimeDifference, time: i16) void { diff --git a/src/utils/file_monitor.zig b/src/utils/file_monitor.zig index 22f17a38..c0cb2d02 100644 --- a/src/utils/file_monitor.zig +++ b/src/utils/file_monitor.zig @@ -65,8 +65,8 @@ const LinuxImpl = struct { // MARK: LinuxImpl if(fd == -1) { std.log.err("Error while initializing inotifiy: {}", .{std.posix.errno(fd)}); } - watchDescriptors = std.StringHashMap(*DirectoryInfo).init(main.globalAllocator.allocator); - callbacks = std.AutoHashMap(c_int, *DirectoryInfo).init(main.globalAllocator.allocator); + watchDescriptors = .init(main.globalAllocator.allocator); + callbacks = .init(main.globalAllocator.allocator); } fn deinit() void { @@ -228,9 +228,9 @@ const WindowsImpl = struct { // MARK: WindowsImpl }; fn init() void { - notificationHandlers = std.StringHashMap(*DirectoryInfo).init(main.globalAllocator.allocator); - callbacks = main.List(*DirectoryInfo).init(main.globalAllocator); - justTheHandles = main.List(HANDLE).init(main.globalAllocator); + notificationHandlers = .init(main.globalAllocator.allocator); + callbacks = .init(main.globalAllocator); + justTheHandles = .init(main.globalAllocator); } fn deinit() void {