aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 7d859fcc2f545ec13b55239bf095d0584f0dd023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const std = @import("std");
const rl = @import("raylib");
const z = @import("zgui");
const part = @import("particle.zig");
const cfg = @import("config.zig");
const img = @import("imgui.zig");

const c = @cImport({
    @cDefine("NO_FONT_AWESOME", "1");
    @cInclude("rlImGui.h");
});

pub fn main() !void {
    cfg.rules = part.ruleMatrix();
    part.printRules(cfg.rules);

    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();

    rl.initWindow(cfg.screenWidth, cfg.screenHeight, "Particle Simulator");
    defer rl.closeWindow();

    rl.setTargetFPS(60);

    c.rlImGuiSetup(true);
    defer c.rlImGuiShutdown();

    z.initNoContext(gpa.allocator());
    defer z.deinitNoContext();
    const imgui_width: f32 = cfg.screenWidth / 2;
    const imgui_height: f32 = cfg.screenHeight / 3;
    z.setNextWindowPos(.{ .x = 0, .y = 0 });
    z.setNextWindowSize(.{ .w = imgui_width, .h = imgui_height });

    var particles = try part.initParticles(gpa.allocator(), cfg.initialParticles);
    defer particles.deinit(gpa.allocator());

    while (!rl.windowShouldClose()) {
        rl.beginDrawing();
        defer rl.endDrawing();
        if (rl.isKeyPressed(rl.KeyboardKey.key_q)) break;
        rl.clearBackground(rl.Color.black);

        part.updateVelocities(particles, cfg.rules);
        part.updatePosition(particles);
        part.draw(particles);
        try img.update();
    }
}