Improved documentation and consistancy

This commit is contained in:
abux 2026-08-02 13:23:12 +01:00
parent e20ce39550
commit 0e174f878f
10 changed files with 85 additions and 6 deletions

View file

@ -1,3 +1,7 @@
//! ----------------------------------------------------
//! ANSI Colors for terminal
//! ----------------------------------------------------
// --- RESET --- // --- RESET ---
pub const reset = "\x1b[0m"; pub const reset = "\x1b[0m";

View file

@ -1,6 +1,24 @@
//! ----------------------------------------------------
//! ----------------------------------------------------
const std = @import("std"); 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( pub fn FixedArrayList(
comptime T: type, comptime T: type,

View file

@ -1,3 +1,6 @@
//! ----------------------------------------------------
//! ----------------------------------------------------
const std = @import("std"); const std = @import("std");
const FixedArrayList = @import("fixed_array_list.zig").FixedArrayList; const FixedArrayList = @import("fixed_array_list.zig").FixedArrayList;
const Handle = @import("handle.zig").Handle; const Handle = @import("handle.zig").Handle;
@ -6,6 +9,15 @@ const Handle = @import("handle.zig").Handle;
/// # Example /// # Example
/// ///
/// ```zig /// ```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( pub fn FixedSlotMap(

View file

@ -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 // PRIVATE
// //
@ -106,7 +124,7 @@ test "SlotMap" {
} }
} }
test "SlotMap-DEP" { test "SlotMap-DEP" { // TODO: Yes...
{ {
// --- LOG --- // --- LOG ---
log.warn("...", .{}, @src()); log.warn("...", .{}, @src());
@ -173,7 +191,7 @@ test "SlotMap-DEP" {
test "RingBuffer" { test "RingBuffer" {
std.debug.print("{s}━━━ RING BUFFER ━━━{s}\n", .{ ansi.blue, ansi.reset }); 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("w");
try prev_inputs.push("s"); try prev_inputs.push("s");

View file

@ -1,3 +1,6 @@
/// ----------------------------------------------------
/// Generational Handle
/// ----------------------------------------------------
pub fn Handle(comptime T: type) type { pub fn Handle(comptime T: type) type {
_ = T; _ = T;
return struct { return struct {

View file

@ -1,3 +1,6 @@
//! ----------------------------------------------------
//! ----------------------------------------------------
const std = @import("std"); const std = @import("std");
const SlotMap = @import("slot_map.zig").SlotMap; const SlotMap = @import("slot_map.zig").SlotMap;
const Handle = @import("handle.zig").Handle; const Handle = @import("handle.zig").Handle;

View file

@ -1,3 +1,6 @@
//! ----------------------------------------------------
//! ----------------------------------------------------
const std = @import("std"); const std = @import("std");
const ansi = @import("ansi.zig"); const ansi = @import("ansi.zig");

View file

@ -48,10 +48,19 @@ pub fn RingBuffer(
// FIELDS // FIELDS
// //
buffers: [Capacity]T = std.mem.zeroes([Capacity]T), buffers: [Capacity]T,
head: usize = 0, head: usize,
tail: usize = 0, tail: usize,
count: usize = 0, count: usize,
/// ----------------------------------------------------
/// ----------------------------------------------------
pub const empty = Self{
.buffers = undefined,
.head = 0,
.tail = 0,
.count = 0,
};
/// ---------------------------------------------------- /// ----------------------------------------------------
/// ---------------------------------------------------- /// ----------------------------------------------------

View file

@ -1,3 +1,6 @@
//! ----------------------------------------------------
//! ----------------------------------------------------
const std = @import("std"); const std = @import("std");
const Handle = @import("handle.zig").Handle; const Handle = @import("handle.zig").Handle;

View file

@ -1,5 +1,11 @@
//! ----------------------------------------------------
//! ----------------------------------------------------
const std = @import("std"); const std = @import("std");
/// ----------------------------------------------------
/// Returns hash of @typeName(T)
/// ----------------------------------------------------
pub fn of(comptime T: type) u64 { pub fn of(comptime T: type) u64 {
return std.hash.Wyhash.hash( return std.hash.Wyhash.hash(
694721, 694721,