You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
const std = @import("std");
|
|
const ringbuffer = @import("ringbuffer");
|
|
|
|
pub const lua = @import("lua.zig");
|
|
pub const util = @import("util.zig");
|
|
pub const model = @import("model/model.zig");
|
|
|
|
pub const Config = @import("config.zig");
|
|
pub const Simulation = @import("simulation/simulation.zig");
|
|
|
|
pub const Queue = ringbuffer.RingBuffer;
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{
|
|
.stack_trace_frames = 30,
|
|
}){};
|
|
defer std.debug.assert(gpa.deinit() != .leak);
|
|
|
|
const alloc = gpa.allocator();
|
|
|
|
var arena = std.heap.ArenaAllocator.init(alloc);
|
|
defer arena.deinit();
|
|
|
|
const arena_alloc = arena.allocator();
|
|
|
|
const config = try Config.load(arena_alloc, "config.json");
|
|
|
|
std.log.info("begin", .{});
|
|
|
|
var simulation: Simulation = undefined;
|
|
try simulation.init(alloc, config.start);
|
|
defer simulation.deinit();
|
|
|
|
var l = try lua.init(alloc, config.start, &simulation);
|
|
|
|
var i: usize = 0;
|
|
const lim = if (std.os.argv.len >= 2)
|
|
try std.fmt.parseInt(usize, std.mem.span(std.os.argv[1]), 10)
|
|
else
|
|
5;
|
|
|
|
try lua.call(void, alloc, l, "start", .{});
|
|
while (i < lim) : (i += 1) {
|
|
try lua.call(void, alloc, l, "printInventory", .{});
|
|
try simulation.runConsumption(config.run);
|
|
try lua.call(void, alloc, l, "printConsumption", .{});
|
|
try lua.update(alloc, config.run, l);
|
|
try simulation.runProduction(config.run);
|
|
try lua.call(void, alloc, l, "printProduction", .{});
|
|
simulation.time += 1;
|
|
}
|
|
|
|
try lua.deinit(alloc, l);
|
|
|
|
std.log.info("end", .{});
|
|
}
|
|
|