From 2b4dbc2875ed481e40e383fd97bb4cff0985c0ac Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Sat, 30 Sep 2023 15:47:39 +0200 Subject: [PATCH 1/2] Remove test cell in main menu --- src/Renderer.zig | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Renderer.zig b/src/Renderer.zig index a229140..cc424cf 100644 --- a/src/Renderer.zig +++ b/src/Renderer.zig @@ -5,7 +5,6 @@ const Self = @This(); const colors = @import("color.zig"); color: colors.Color = .{ 0, 0, 0, 0 }, -textureTest: Texture, const max_objects: usize = 16384; const quadSize: usize = 9 * 6; @@ -13,17 +12,11 @@ const quadSize: usize = 9 * 6; pub fn init() !Self { rl.initWindow(1280, 720, "USG", 120); - var renderer = Self{ - .textureTest = Texture.init("res/cell.png"), - }; - - return renderer; + return Self{}; } pub fn render(self: *Self) void { - //_ = self; - - self.textureTest.drawTo(20, 100, 160, 160, colors.pink); + _ = self; rl.drawFPS(10, 10); rl.endDrawing(); From e370e2bb666e04774f99b940b27a34bae691694a Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Sat, 30 Sep 2023 18:49:14 +0200 Subject: [PATCH 2/2] Implement getting all the input names --- src/input.zig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.zig | 5 +++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/input.zig b/src/input.zig index 4490a6b..f204b8d 100644 --- a/src/input.zig +++ b/src/input.zig @@ -1,4 +1,7 @@ +const Self = @This(); + const rl = @import("raylib.zig"); +const std = @import("std"); pub const Input = struct { name: []const u8, @@ -16,6 +19,12 @@ pub const Input = struct { } }; +pub fn loadConfig() void { + for (comptime getInputNames()) |name| { + std.debug.print("{s}\n", .{name}); + } +} + fn init(comptime name: []const u8, comptime key_code: []const u8) Input { return Input{ .name = name, @@ -38,3 +47,40 @@ pub var game_drop = init("Drop Piece", "W"); pub var game_swap_piece = init("Swap Piece", "SPACE"); pub var game_rotate_r = init("Rotate Piece Clockwise", "RIGHT"); pub var game_rotate_l = init("Rotate Piece Counterclockwise", "LEFT"); + +// Get the names of the Input(s) defined in this file with introspection +fn getInputNames() [getInputCount()][]const u8 { + comptime { + const decls = std.meta.declarations(Self); + + var ret: [getInputCount()][]const u8 = undefined; + + var i: usize = 0; + inline for (decls) |i_decl| { + const field = @field(Self, i_decl.name); + + if (@TypeOf(field) == Input) { + ret[i] = i_decl.name; + i += 1; + } + } + + return ret; + } +} + +// With reflection count the amount of declarations of type "Input" +fn getInputCount() usize { + comptime { + const decls = std.meta.declarations(Self); + + var i: usize = 0; + inline for (decls) |i_decl| { + const field = @field(Self, i_decl.name); + + if (@TypeOf(field) == Input) i += 1; + } + + return i; + } +} diff --git a/src/main.zig b/src/main.zig index b285b4b..151cd0e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,15 +8,16 @@ const MainMenu = @import("MainMenu.zig"); const config = @import("Config/config.zig"); const State = @import("flow.zig").State; +const input = @import("input.zig"); pub fn main() !void { - var configIterator = config.getConfigIterator("test") catch unreachable; while (configIterator.next()) |option| { - std.debug.print("Key: {s}, Option: {s}\n", .{option.key, option.value}); + std.debug.print("Key: {s}, Option: {s}\n", .{ option.key, option.value }); } configIterator.deinit(); + input.loadConfig(); var renderer = try Renderer.init(); defer renderer.deinit();