diff --git a/src/main.zig b/src/main.zig index 5453830..dfe640f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,6 +6,7 @@ const particles = @import("particles.zig"); const plot = @import("plot.zig"); const allocator = std.heap.page_allocator; +const DEBUG = true; const screenWidth = 1200; const screenHeight = 800; @@ -16,13 +17,20 @@ fn ItoF(x: i32) f32 { fn rectangle(x: u16, y: u16, width: u16, height: u16) rl.Rectangle { return rl.Rectangle{ .x = @as(f32, @floatFromInt(x)), .y = @as(f32, @floatFromInt(y)), .width = @as(f32, @floatFromInt(width)), .height = @as(f32, @floatFromInt(height)) }; } - +const Settings = struct { + particleCount: f32 = 1, + spread_x: f32 = 0, + spread_y: f32 = 0, + color: rl.Color = .{ .r = 255, .g = 255, .b = 0, .a = 100 }, + active: i32 = 0, + editMode: bool = false, +}; pub fn main() anyerror!void { - var value: f32 = 0; - var value2: f32 = 0; - var value3: f32 = 0; - var color: rl.Color = undefined; + if(DEBUG) { + std.debug.print("DEBUG mode enabled",.{}); + } + var settings = Settings{}; var emitter = particles.Emitter{}; try emitter.init(allocator, screenWidth, screenHeight); @@ -42,55 +50,72 @@ pub fn main() anyerror!void { rl.setTargetFPS(60); const file = try plot.open("plot.dat"); - var plotStr: []u8 = undefined; - var plotStrBuf: [128]u8 = undefined; + try plot.log(file, "acceleration, position, velocity, show\n"); var att: [10]particles.Attractor = undefined; - var active: i32 = 0; - var editMode: bool = false; - while (!rl.windowShouldClose()) { // Detect window close button or ESC key + while (!rl.windowShouldClose()) { rl.beginDrawing(); defer rl.endDrawing(); - rl.clearBackground(rl.Color{ - .r = 0, - .g = 0, - .b = 0, - .a = 255, - }); + updateGui(&settings); - if (rg.guiDropdownBox(rectangle(10, 10, 100, 20), "Settings;Particles", &active, editMode) != 0) { - editMode = !editMode; - std.debug.print("dropdownbox: {}", .{active}); - } - - if (active == 1) { - if (rg.guiWindowBox(rectangle(10, 10, 800, 600), "Window Box") == 1) { - active = 0; - editMode = false; - } - - _ = rg.guiSlider(rectangle(10, 150, 600, 10), "0", "500", &value, ItoF(0), ItoF(500)); - _ = rg.guiSlider(rectangle(10, 170, 600, 10), "-3", "3", &value2, ItoF(-100), ItoF(100)); - _ = rg.guiSlider(rectangle(10, 190, 600, 10), "-3", "3", &value3, -100, 100); - _ = rg.guiColorPicker(rectangle(10, 200, 300, 100), "Choose Color", &color); - } if (rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) { - emitter.emit(@as(u32, @intFromFloat(value)), value2, value3); + emitter.emit( + @as(u32, @intFromFloat(settings.particleCount)), + settings.spread_x, + settings.spread_y + ); } - plotStr = try std.fmt.bufPrint(&plotStrBuf, "{d}, {d}, {d}, {d}\n", .{ emitter.particles[0].acceleration.a.x, emitter.particles[0].position.a.x, emitter.particles[0].velocity.a.x, emitter.particles[0].show }); - try plot.log(file, plotStr); - rl.beginBlendMode(rl.BlendMode.blend_additive); - emitter.update(&att, texture, color); + emitter.update(&att, texture, settings.color); rl.endBlendMode(); + + try log_emitter(file,0,emitter); + } plot.close(file); } -fn updateGUI() !void {} + +fn log_emitter(file : std.fs.File, index : u32, emitter : particles.Emitter) !void +{ + var plotStr: []u8 = undefined; + var plotStrBuf: [128]u8 = undefined; + plotStr = try std.fmt.bufPrint(&plotStrBuf, "{d}, {d}, {d}, {d}\n", .{ + emitter.particles[index].acceleration.a.x, + emitter.particles[index].position.a.x, + emitter.particles[index].velocity.a.x, + emitter.particles[index].show }); + try plot.log(file, plotStr); +} + +fn updateGui(set: *Settings) void { + rl.clearBackground(rl.Color{ + .r = 0, + .g = 0, + .b = 0, + .a = 255, + }); + + if (rg.guiDropdownBox(rectangle(10, 10, 100, 20), "Settings;Particles", &set.active, set.editMode) != 0) { + set.editMode = !set.editMode; + std.debug.print("dropdownbox: {}", .{set.active}); + } + + if (set.active == 1) { + if (rg.guiWindowBox(rectangle(10, 10, 800, 600), "Window Box") == 1) { + set.active = 0; + set.editMode = false; + } + + _ = rg.guiSlider(rectangle(10, 150, 600, 10), "0", "500", &set.particleCount, 0, 500); + _ = rg.guiSlider(rectangle(10, 170, 600, 10), "-3", "3", &set.spread_x, -100, 100); + _ = rg.guiSlider(rectangle(10, 190, 600, 10), "-3", "3", &set.spread_y, -100, 100); + _ = rg.guiColorPicker(rectangle(10, 200, 300, 100), "Choose Color", &set.color); + } +} test "simple test" { var list = std.ArrayList(i32).init(std.testing.allocator); diff --git a/src/particles.zig b/src/particles.zig index e673dc3..1a6368c 100644 --- a/src/particles.zig +++ b/src/particles.zig @@ -48,7 +48,6 @@ pub const Particle = struct { self.acceleration.a.x = xrnr; self.acceleration.a.y = yrnr; self.position.a.x = @floatFromInt(rl.getMouseX() - @divTrunc(self.max_x, 2)); - std.debug.print("divtrunc x: {}\n,max_x:{}\n", .{ @divTrunc(self.max_x, 2), self.max_x }); self.position.a.y = @floatFromInt(rl.getMouseY() - @divTrunc(self.max_y, 2)); self.velocity.a.x = 0; self.velocity.a.y = 0; diff --git a/src/plot.zig b/src/plot.zig index 894405e..6eeb647 100644 --- a/src/plot.zig +++ b/src/plot.zig @@ -1,5 +1,8 @@ const std = @import("std"); - +pub fn init() void +{ + +} pub fn log(self : std.fs.File,data : []const u8) !void { try self.writeAll(data); diff --git a/zig-out/bin/raylib-test b/zig-out/bin/raylib-test index 78ebf5d..5e02296 100755 Binary files a/zig-out/bin/raylib-test and b/zig-out/bin/raylib-test differ