From 899083569d9cb27105bcc08404be0023174dadfa Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Tue, 19 Mar 2024 22:17:46 +0100 Subject: [PATCH] Remove redundant window ids. They were asserted to be equal to the file name, now they are initialized to the file name, removing the need for setting it manually. This makes adding new windows simpler, also affects #273. --- src/chunk.zig | 1 - src/gui/GuiWindow.zig | 2 +- src/gui/gui.zig | 2 +- src/gui/windows/change_name.zig | 1 - src/gui/windows/chat.zig | 1 - src/gui/windows/controls.zig | 1 - src/gui/windows/creative_inventory.zig | 1 - src/gui/windows/crosshair.zig | 1 - src/gui/windows/debug.zig | 1 - src/gui/windows/debug_network.zig | 1 - src/gui/windows/gpu_performance_measuring.zig | 1 - src/gui/windows/graphics.zig | 1 - src/gui/windows/healthbar.zig | 1 - src/gui/windows/hotbar.zig | 1 - src/gui/windows/inventory.zig | 1 - src/gui/windows/inventory_crafting.zig | 1 - src/gui/windows/main.zig | 1 - src/gui/windows/multiplayer.zig | 1 - src/gui/windows/performance_graph.zig | 1 - src/gui/windows/save_selection.zig | 1 - src/gui/windows/settings.zig | 1 - src/gui/windows/sound.zig | 1 - src/gui/windows/workbench.zig | 1 - src/main.zig | 6 +++--- 24 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/chunk.zig b/src/chunk.zig index 99257ed3..ac42e586 100644 --- a/src/chunk.zig +++ b/src/chunk.zig @@ -293,7 +293,6 @@ pub const Chunk = struct { } pub fn getNeighbors(self: *const Chunk, x: i32, y: i32, z: i32, neighborsArray: *[6]Block) void { - std.debug.assert(neighborsArray.length == 6); x &= chunkMask; y &= chunkMask; z &= chunkMask; diff --git a/src/gui/GuiWindow.zig b/src/gui/GuiWindow.zig index 52c214e8..74ebb4ef 100644 --- a/src/gui/GuiWindow.zig +++ b/src/gui/GuiWindow.zig @@ -52,7 +52,7 @@ contentSize: Vec2f, scale: f32 = 1, spacing: f32 = 0, relativePosition: [2]RelativePosition = .{.{.ratio = 0.5}, .{.ratio = 0.5}}, -id: []const u8, +id: []const u8 = undefined, rootComponent: ?GuiComponent = null, showTitleBar: bool = true, titleBarExpanded: bool = false, diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 642f32a4..2152e3a6 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -131,7 +131,7 @@ pub fn init() void { openWindows = List(*GuiWindow).init(main.globalAllocator); inline for(@typeInfo(windowlist).Struct.decls) |decl| { const windowStruct = @field(windowlist, decl.name); - std.debug.assert(std.mem.eql(u8, decl.name, windowStruct.window.id)); // id and file name should be the same. + windowStruct.window.id = decl.name; addWindow(&windowStruct.window); if(@hasDecl(windowStruct, "init")) { windowStruct.init(); diff --git a/src/gui/windows/change_name.zig b/src/gui/windows/change_name.zig index 507c15aa..7d26c889 100644 --- a/src/gui/windows/change_name.zig +++ b/src/gui/windows/change_name.zig @@ -14,7 +14,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "change_name", }; var textComponent: *TextInput = undefined; diff --git a/src/gui/windows/chat.zig b/src/gui/windows/chat.zig index 950b4d70..28dd710f 100644 --- a/src/gui/windows/chat.zig +++ b/src/gui/windows/chat.zig @@ -19,7 +19,6 @@ pub var window: GuiWindow = GuiWindow { }, .scale = 0.75, .contentSize = Vec2f{128, 256}, - .id = "chat", .showTitleBar = false, .hasBackground = false, .isHud = true, diff --git a/src/gui/windows/controls.zig b/src/gui/windows/controls.zig index ef46c3d4..cb010735 100644 --- a/src/gui/windows/controls.zig +++ b/src/gui/windows/controls.zig @@ -13,7 +13,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "controls", }; const padding: f32 = 8; diff --git a/src/gui/windows/creative_inventory.zig b/src/gui/windows/creative_inventory.zig index 49cb256f..18fbcb84 100644 --- a/src/gui/windows/creative_inventory.zig +++ b/src/gui/windows/creative_inventory.zig @@ -19,7 +19,6 @@ pub var window = GuiWindow { .{ .attachedToFrame = .{.selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} }, }, .contentSize = Vec2f{64*8, 64*4}, - .id = "creative_inventory", }; const padding: f32 = 8; diff --git a/src/gui/windows/crosshair.zig b/src/gui/windows/crosshair.zig index 0f4c8856..4f1bd9d7 100644 --- a/src/gui/windows/crosshair.zig +++ b/src/gui/windows/crosshair.zig @@ -13,7 +13,6 @@ const GuiComponent = gui.GuiComponent; const size: f32 = 64; pub var window = GuiWindow { .contentSize = Vec2f{size, size}, - .id = "crosshair", .showTitleBar = false, .hasBackground = false, .isHud = true, diff --git a/src/gui/windows/debug.zig b/src/gui/windows/debug.zig index 1e6c041c..825efbe8 100644 --- a/src/gui/windows/debug.zig +++ b/src/gui/windows/debug.zig @@ -16,7 +16,6 @@ pub var window = GuiWindow { .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, }, .contentSize = Vec2f{128, 16}, - .id = "debug", .isHud = false, .showTitleBar = false, .hasBackground = false, diff --git a/src/gui/windows/debug_network.zig b/src/gui/windows/debug_network.zig index efbcef06..2265505b 100644 --- a/src/gui/windows/debug_network.zig +++ b/src/gui/windows/debug_network.zig @@ -17,7 +17,6 @@ pub var window = GuiWindow { .{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, }, .contentSize = Vec2f{192, 128}, - .id = "debug_network", .isHud = false, .showTitleBar = false, .hasBackground = false, diff --git a/src/gui/windows/gpu_performance_measuring.zig b/src/gui/windows/gpu_performance_measuring.zig index f18ff863..74fa5b66 100644 --- a/src/gui/windows/gpu_performance_measuring.zig +++ b/src/gui/windows/gpu_performance_measuring.zig @@ -77,7 +77,6 @@ pub var window = GuiWindow { .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, }, .contentSize = Vec2f{256, 16}, - .id = "gpu_performance_measuring", .isHud = false, .showTitleBar = false, .hasBackground = false, diff --git a/src/gui/windows/graphics.zig b/src/gui/windows/graphics.zig index 7e8e1e51..d0a19d7b 100644 --- a/src/gui/windows/graphics.zig +++ b/src/gui/windows/graphics.zig @@ -14,7 +14,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "graphics", }; const padding: f32 = 8; diff --git a/src/gui/windows/healthbar.zig b/src/gui/windows/healthbar.zig index 532f2b89..97d2f97f 100644 --- a/src/gui/windows/healthbar.zig +++ b/src/gui/windows/healthbar.zig @@ -19,7 +19,6 @@ pub var window = GuiWindow { .{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, }, .contentSize = Vec2f{128, 16}, - .id = "healthbar", .isHud = true, .showTitleBar = false, .hasBackground = false, diff --git a/src/gui/windows/hotbar.zig b/src/gui/windows/hotbar.zig index 101813cf..5efa3a9f 100644 --- a/src/gui/windows/hotbar.zig +++ b/src/gui/windows/hotbar.zig @@ -19,7 +19,6 @@ pub var window = GuiWindow { .{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, }, .contentSize = Vec2f{64*8, 64}, - .id = "hotbar", .isHud = true, .showTitleBar = false, .hasBackground = false, diff --git a/src/gui/windows/inventory.zig b/src/gui/windows/inventory.zig index 22f488cd..7ef26cc5 100644 --- a/src/gui/windows/inventory.zig +++ b/src/gui/windows/inventory.zig @@ -22,7 +22,6 @@ pub var window = GuiWindow { .{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, }, .contentSize = Vec2f{64*8, 64*4}, - .id = "inventory", }; const padding: f32 = 8; diff --git a/src/gui/windows/inventory_crafting.zig b/src/gui/windows/inventory_crafting.zig index 6601db76..752251f5 100644 --- a/src/gui/windows/inventory_crafting.zig +++ b/src/gui/windows/inventory_crafting.zig @@ -25,7 +25,6 @@ pub var window = GuiWindow { .{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} }, }, .contentSize = Vec2f{64*8, 64*4}, - .id = "inventory_crafting", }; const padding: f32 = 8; diff --git a/src/gui/windows/main.zig b/src/gui/windows/main.zig index ecae88d4..b3776a0a 100644 --- a/src/gui/windows/main.zig +++ b/src/gui/windows/main.zig @@ -11,7 +11,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "main", }; const padding: f32 = 8; diff --git a/src/gui/windows/multiplayer.zig b/src/gui/windows/multiplayer.zig index a746917f..08b02fca 100644 --- a/src/gui/windows/multiplayer.zig +++ b/src/gui/windows/multiplayer.zig @@ -15,7 +15,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "multiplayer", }; var ipAddressLabel: *Label = undefined; diff --git a/src/gui/windows/performance_graph.zig b/src/gui/windows/performance_graph.zig index d01ac76d..5a88a465 100644 --- a/src/gui/windows/performance_graph.zig +++ b/src/gui/windows/performance_graph.zig @@ -18,7 +18,6 @@ pub var window = GuiWindow { .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, .{ .attachedToWindow = .{.reference = &chat.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, }, - .id = "performance_graph", .isHud = false, .showTitleBar = false, .hasBackground = false, diff --git a/src/gui/windows/save_selection.zig b/src/gui/windows/save_selection.zig index ae462c13..97479a76 100644 --- a/src/gui/windows/save_selection.zig +++ b/src/gui/windows/save_selection.zig @@ -17,7 +17,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "save_selection", }; const padding: f32 = 8; diff --git a/src/gui/windows/settings.zig b/src/gui/windows/settings.zig index f005de49..77675e3b 100644 --- a/src/gui/windows/settings.zig +++ b/src/gui/windows/settings.zig @@ -11,7 +11,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window: GuiWindow = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "settings", }; const padding: f32 = 8; diff --git a/src/gui/windows/sound.zig b/src/gui/windows/sound.zig index 34a2bd5a..2d1835dc 100644 --- a/src/gui/windows/sound.zig +++ b/src/gui/windows/sound.zig @@ -14,7 +14,6 @@ const VerticalList = @import("../components/VerticalList.zig"); pub var window = GuiWindow { .contentSize = Vec2f{128, 256}, - .id = "sound", }; fn musicCallback(newValue: f32) void { diff --git a/src/gui/windows/workbench.zig b/src/gui/windows/workbench.zig index f29cd1a2..2546a31b 100644 --- a/src/gui/windows/workbench.zig +++ b/src/gui/windows/workbench.zig @@ -28,7 +28,6 @@ pub var window = GuiWindow { .{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, }, .contentSize = Vec2f{64*8, 64*4}, - .id = "workbench", }; const padding: f32 = 8; diff --git a/src/main.zig b/src/main.zig index 7347ac05..7bfc93dc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -139,8 +139,8 @@ pub const std_options: std.Options = .{ } types = &[_]type{[]const u8} ++ types ++ &[_]type{[]const u8}; - comptime var comptimeTuple: std.meta.Tuple(types) = undefined; - comptime std.debug.assert(std.meta.Tuple(types) == std.meta.Tuple(types)); + const ArgsType = std.meta.Tuple(types); + comptime var comptimeTuple: ArgsType = undefined; comptime var len: usize = 0; i_1 = 0; i_2 = 0; @@ -156,7 +156,7 @@ pub const std_options: std.Options = .{ } comptimeTuple[0] = filePrefix; comptimeTuple[comptimeTuple.len - 1] = fileSuffix; - var resultArgs: std.meta.Tuple(types) = comptimeTuple; + var resultArgs: ArgsType = comptimeTuple; len = 0; i_1 = 0; i_2 = 0;