// // PRIVATE // const std = @import("std"); // // PUBLIC // pub const log = @import("log.zig"); pub const ansi = @import("ansi.zig"); pub const Handle = @import("handle.zig").Handle; pub const SlotMap = @import("slot_map.zig").SlotMap; pub const KeyedSlotMap = @import("keyed_slot_map.zig").KeyedSlotMap; pub const RingBuffer = @import("ring_buffer.zig").RingBuffer; pub const TypeID = @import("type_id.zig").of; // // STRUCTS // // --- SHADER --- const ShaderID = union(enum) { pbr, unlit, custom: Handle(ShaderID) }; const GPUShader = struct { raw: *anyopaque }; // --- PIPELINE --- const PipelineKey = struct { shader: ShaderID }; const GPUPipeline = struct { raw: *anyopaque }; // --- MATERIAL --- const MaterialDep = struct { shader: ShaderID = .pbr, albedo: @Vector(4, f32) = .{ 0, 0, 0, 1 }, }; /// ---------------------------------------------------- /// ---------------------------------------------------- const Material = struct { /// ---------------------------------------------------- /// ---------------------------------------------------- pub const Style = struct { albedo: @Vector(4, f32) = .{ 1, 1, 1, 1 }, metallic: f32 = 0.0, roughness: f32 = 0.5, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const Unique = struct { shader: ShaderID = .pbr, front_face: enum { cw, ccw } = .ccw, cull_mode: enum { back, front, none } = .back, topology: enum { triangle_list, point_list, line_list } = .triangle_list, blend_mode: enum { none, alpha, additive, multiply } = .none, }; // // FIELDS // style: Style = .{}, unique: Unique = .{}, }; test "SlotMap" { // --- ALLOCATOR --- const alloc = std.testing.allocator; std.debug.print("{s}━━━ SLOTMAP ━━━{s}\n", .{ ansi.blue, ansi.reset }); // --- MATERIALS --- var materials: SlotMap(Material) = .init(alloc); defer materials.deinit(); // --- ADD MATERIALS --- _ = try materials.put(.{ .style = .{ .albedo = .{ 0.8, 0.2, 0.2, 1.0 } } }); _ = try materials.put(.{ .unique = .{ .topology = .line_list } }); // --- # --- if (log.print(.debug, "MATERIALS", ansi.blue)) |a| { defer a.end(); // --- # --- for (materials.items()) |material| { if (a.section(.debug, "", ansi.cyan)) |b| { defer b.end(); // --- STYLE --- if (b.section(.debug, "STYLE", ansi.yellow)) |style| { defer style.end(); style.write("Albedo: rgba({}, {}, {}, {})", .{ material.style.albedo[0], material.style.albedo[1], material.style.albedo[2], material.style.albedo[3] }); style.write("Metallic: {}", .{material.style.metallic}); style.write("Roughness: {}", .{material.style.roughness}); } // --- STYLE --- if (b.section(.debug, "UNIQUE", ansi.red)) |unique| { defer unique.end(); unique.write("Shader: {s}", .{@tagName(material.unique.shader)}); unique.write("Topology: {s}", .{@tagName(material.unique.topology)}); unique.write("Cull Mode: {s}", .{@tagName(material.unique.cull_mode)}); } } } } } test "SlotMap-DEP" { { // --- LOG --- log.warn("...", .{}, @src()); log.err("...", .{}, @src()); log.info("...", .{}, @src()); log.debug("...", .{}, @src()); log.trace("...", .{}, @src()); // --- PRINT --- if (log.print(.debug, "DEVICE INFO", ansi.bold ++ ansi.red)) |a| { defer a.end(); // --- VALUES --- a.write("device -> {s}", .{"GTX"}); a.write("vendor -> {s}", .{"Nvidia"}); // --- SECTION --- if (a.section(.err, "MEMORY", ansi.green)) |b| { defer b.end(); b.write("VRAM -> {}GB", .{24}); } } log.set(.{ .style = .rounded }); // --- PRINT --- if (log.print(.debug, "DEVICE INFO", ansi.bold ++ ansi.red)) |a| { defer a.end(); // --- VALUES --- a.write("device -> {s}", .{"GTX"}); a.write("vendor -> {s}", .{"Nvidia"}); // --- SECTION --- if (a.section(.err, "MEMORY", ansi.green)) |b| { defer b.end(); b.write("VRAM -> {}GB", .{24}); } } log.set(.{ .style = .pipe }); // --- PRINT --- if (log.print(.debug, "DEVICE INFO", ansi.bold ++ ansi.red)) |a| { defer a.end(); // --- VALUES --- a.write("device -> {s}", .{"GTX"}); a.write("vendor -> {s}", .{"Nvidia"}); // --- SECTION --- if (a.section(.err, "MEMORY", ansi.green)) |b| { defer b.end(); // --- VALUES --- b.write("VRAM -> {}GB", .{24}); } } } // // RING BUFFER EXAMPLE // var prev_inputs: RingBuffer([]const u8, 256) = .{}; try prev_inputs.push("w"); try prev_inputs.push("s"); try prev_inputs.push("a"); try prev_inputs.push("d"); var i: usize = 0; while (prev_inputs.pop()) |data| { defer i += 1; log.debug("[{}][PreviousInputs] -> \"{s}\"", .{ i, data }, null); } }