From 84965904b3604877811f49621016c4e7f76d6d1e Mon Sep 17 00:00:00 2001 From: Jeeves Date: Tue, 11 Feb 2025 13:07:08 -0700 Subject: [PATCH] misc --- src/main.zig | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main.zig b/src/main.zig index dd89d4a..ae66d5b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -78,7 +78,6 @@ pub const Component = struct { x: u16 = 0, y: u16 = 0, - state: *anyopaque, processFn: *const fn (*Component) void, }; @@ -89,13 +88,23 @@ pub const Circuit = struct { }; pub const Battery = struct { - pub fn process(component: *Component) Signal {} + component: Component = .{ .processFn = process }, + value: f32, + + pub fn process(component: *Component, inputs: []*Signal) []Signal { + _ = inputs; + const self: *Battery = @fieldParentPtr("component", component); + return &[_]Signal{.{ + .digital = std.math.sign(self.value), + .analog = self.value, + }}; + } }; pub const Signal = struct { - digital: i2, - analog: f32, - color: u24, + digital: i2 = 0, + analog: f32 = 0.0, + color: u24 = 0, }; // pub const Wire = struct {