From 0e174f878fe7aa66e329e43feccb0d9f85dc4742 Mon Sep 17 00:00:00 2001 From: abux Date: Sun, 2 Aug 2026 13:23:12 +0100 Subject: [PATCH] Improved documentation and consistancy --- src/ansi.zig | 4 ++++ src/fixed_array_list.zig | 18 ++++++++++++++++++ src/fixed_slot_map.zig | 12 ++++++++++++ src/gtl.zig | 22 ++++++++++++++++++++-- src/handle.zig | 3 +++ src/keyed_slot_map.zig | 3 +++ src/log.zig | 3 +++ src/ring_buffer.zig | 17 +++++++++++++---- src/slot_map.zig | 3 +++ src/type_id.zig | 6 ++++++ 10 files changed, 85 insertions(+), 6 deletions(-) diff --git a/src/ansi.zig b/src/ansi.zig index 81e9231..1969550 100644 --- a/src/ansi.zig +++ b/src/ansi.zig @@ -1,3 +1,7 @@ +//! ---------------------------------------------------- +//! ANSI Colors for terminal +//! ---------------------------------------------------- + // --- RESET --- pub const reset = "\x1b[0m"; diff --git a/src/fixed_array_list.zig b/src/fixed_array_list.zig index 992ea12..4fe9096 100644 --- a/src/fixed_array_list.zig +++ b/src/fixed_array_list.zig @@ -1,6 +1,24 @@ +//! ---------------------------------------------------- +//! ---------------------------------------------------- + const std = @import("std"); /// ---------------------------------------------------- +/// # Example +/// +/// ```zig +/// var entities: FixedArrayList(u32, 4) = .empty; +/// +/// try entities.append(1); +/// try entities.append(2); +/// try entities.append(3); +/// +/// if (entities.getPtr(0)) |v| v.* = 69; +/// +/// for (entities.items()) |item| { +/// std.debug.print("Entity: {}\n", .{item}); +/// } +/// ``` /// ---------------------------------------------------- pub fn FixedArrayList( comptime T: type, diff --git a/src/fixed_slot_map.zig b/src/fixed_slot_map.zig index a3d89da..9b05d74 100644 --- a/src/fixed_slot_map.zig +++ b/src/fixed_slot_map.zig @@ -1,3 +1,6 @@ +//! ---------------------------------------------------- +//! ---------------------------------------------------- + const std = @import("std"); const FixedArrayList = @import("fixed_array_list.zig").FixedArrayList; const Handle = @import("handle.zig").Handle; @@ -6,6 +9,15 @@ const Handle = @import("handle.zig").Handle; /// # Example /// /// ```zig +/// var materials: FixedSlotMap(Material, 3) = .empty; +/// +/// _ = try materials.put(.{}); +/// _ = try materials.put(.{}); +/// const handle = try materials.put(.{ .unique = .{ .topology = .line_list } }); +/// +/// if (materials.get(handle)) |v| { +/// std.debug.print("Material: {}\n", .{v.unique.topology}); +/// } /// ``` /// ---------------------------------------------------- pub fn FixedSlotMap( diff --git a/src/gtl.zig b/src/gtl.zig index 2ccc890..da8423f 100644 --- a/src/gtl.zig +++ b/src/gtl.zig @@ -1,3 +1,21 @@ +//! ---------------------------------------------------- +//! # Game Template Library +//! +//! Low *cortisol* library for games and game engines +//! +//! # Features +//! +//! **dynamic** +//! | SlotMap +//! | KeyedSlotMap +//! | Handle(T) **Generational** +//! +//! **fixed** +//! | FixedArrayList +//! | FixedSlotMap +//! | RingBuffer +//! ---------------------------------------------------- + // // PRIVATE // @@ -106,7 +124,7 @@ test "SlotMap" { } } -test "SlotMap-DEP" { +test "SlotMap-DEP" { // TODO: Yes... { // --- LOG --- log.warn("...", .{}, @src()); @@ -173,7 +191,7 @@ test "SlotMap-DEP" { test "RingBuffer" { std.debug.print("{s}━━━ RING BUFFER ━━━{s}\n", .{ ansi.blue, ansi.reset }); - var prev_inputs: RingBuffer([]const u8, 256) = .{}; + var prev_inputs: RingBuffer([]const u8, 256) = .empty; try prev_inputs.push("w"); try prev_inputs.push("s"); diff --git a/src/handle.zig b/src/handle.zig index 9acdae5..123f885 100644 --- a/src/handle.zig +++ b/src/handle.zig @@ -1,3 +1,6 @@ +/// ---------------------------------------------------- +/// Generational Handle +/// ---------------------------------------------------- pub fn Handle(comptime T: type) type { _ = T; return struct { diff --git a/src/keyed_slot_map.zig b/src/keyed_slot_map.zig index cc6b168..311b18d 100644 --- a/src/keyed_slot_map.zig +++ b/src/keyed_slot_map.zig @@ -1,3 +1,6 @@ +//! ---------------------------------------------------- +//! ---------------------------------------------------- + const std = @import("std"); const SlotMap = @import("slot_map.zig").SlotMap; const Handle = @import("handle.zig").Handle; diff --git a/src/log.zig b/src/log.zig index d3ea8b3..83e1f1d 100644 --- a/src/log.zig +++ b/src/log.zig @@ -1,3 +1,6 @@ +//! ---------------------------------------------------- +//! ---------------------------------------------------- + const std = @import("std"); const ansi = @import("ansi.zig"); diff --git a/src/ring_buffer.zig b/src/ring_buffer.zig index 570cc4b..3ba46e0 100644 --- a/src/ring_buffer.zig +++ b/src/ring_buffer.zig @@ -48,10 +48,19 @@ pub fn RingBuffer( // FIELDS // - buffers: [Capacity]T = std.mem.zeroes([Capacity]T), - head: usize = 0, - tail: usize = 0, - count: usize = 0, + buffers: [Capacity]T, + head: usize, + tail: usize, + count: usize, + + /// ---------------------------------------------------- + /// ---------------------------------------------------- + pub const empty = Self{ + .buffers = undefined, + .head = 0, + .tail = 0, + .count = 0, + }; /// ---------------------------------------------------- /// ---------------------------------------------------- diff --git a/src/slot_map.zig b/src/slot_map.zig index 04254c5..ca813d3 100644 --- a/src/slot_map.zig +++ b/src/slot_map.zig @@ -1,3 +1,6 @@ +//! ---------------------------------------------------- +//! ---------------------------------------------------- + const std = @import("std"); const Handle = @import("handle.zig").Handle; diff --git a/src/type_id.zig b/src/type_id.zig index c756d00..2b66d13 100644 --- a/src/type_id.zig +++ b/src/type_id.zig @@ -1,5 +1,11 @@ +//! ---------------------------------------------------- +//! ---------------------------------------------------- + const std = @import("std"); +/// ---------------------------------------------------- +/// Returns hash of @typeName(T) +/// ---------------------------------------------------- pub fn of(comptime T: type) u64 { return std.hash.Wyhash.hash( 694721,