138 lines
4.3 KiB
Zig
138 lines
4.3 KiB
Zig
const core = @import("core");
|
|
const std = @import("std");
|
|
const memory = core.MemoryTracker;
|
|
|
|
const engine_log = core.engine_log;
|
|
const engine_logs = core.engine_logs;
|
|
|
|
test "simple systems setup for core" {
|
|
std.testing.refAllDecls(core.algorithm);
|
|
|
|
memory.MTSetup(std.testing.allocator, .{ .timeline = false });
|
|
defer memory.MTShutdown();
|
|
const tracker = memory.MTGet().?;
|
|
const allocator = tracker.allocator();
|
|
|
|
std.debug.print("Starting up \n", .{});
|
|
engine_logs("systems starting");
|
|
try core.start_module(.{ .name = "test" }, .{ .unitTest = true }, allocator);
|
|
defer core.shutdown_module(allocator);
|
|
|
|
engine_logs("systems started, shutting down");
|
|
memory.MTPrintStatsDelta();
|
|
|
|
try test_loadingConfigs();
|
|
try test_consoleCommands();
|
|
try test_gameObjects(std.testing.allocator);
|
|
|
|
try memory.dumpTimeline("test-core-timeline.txt");
|
|
}
|
|
|
|
fn test_loadingConfigs() !void {
|
|
if (core.getConfigVar(u32, "platform.extent.width")) |width| {
|
|
core.engine_log("config: {d}", .{width});
|
|
}
|
|
|
|
if (core.getConfigVar(u64, "platform.extent.height")) |height| {
|
|
core.engine_log("config: {d}", .{height});
|
|
}
|
|
|
|
if (core.getConfigVar(f32, "platform.extent.height")) |height| {
|
|
core.engine_log("config f32: {d}", .{height});
|
|
}
|
|
|
|
if (core.getConfigVar(f64, "platform.extent.height")) |height| {
|
|
core.engine_log("config f64: {d}", .{height});
|
|
}
|
|
|
|
if (core.getConfigVar([]const u8, "platform.windowName")) |height| {
|
|
core.engine_log("config string: {s}", .{height});
|
|
}
|
|
|
|
try core.assert(core.configVar(f64, "platform.extent.height", 0) == core.getConfigVar(f64, "platform.extent.height").?);
|
|
}
|
|
|
|
fn test_consoleCommands() !void {
|
|
const ConsoleCommands = struct {
|
|
pub fn echo(args: []const u8) void {
|
|
core.engine_log("{s}", .{args});
|
|
}
|
|
|
|
pub fn foo(args: []const u8) void {
|
|
core.engine_log("foo function called with args {s}", .{args});
|
|
}
|
|
};
|
|
|
|
try core.console.addCommand("echo", ConsoleCommands.echo);
|
|
try core.console.addCommand("foo", ConsoleCommands.foo);
|
|
|
|
const T = struct {
|
|
var ScreenResolution: u32 = undefined;
|
|
|
|
pub fn F(args: []const u8) void {
|
|
core.engine_log("Setting screen resolution to = {s}", .{args});
|
|
ScreenResolution = std.fmt.parseInt(u32, args, 10) catch return;
|
|
}
|
|
};
|
|
|
|
T.ScreenResolution = core.configVar(u32, "Some.bullshit.ScreenResolution", 420);
|
|
try core.assert(T.ScreenResolution == 420);
|
|
try core.console.addCommand("ScreenResolution", T.F);
|
|
core.console.evaluate("ScreenResolution 1");
|
|
try core.assert(T.ScreenResolution == 1);
|
|
|
|
core.console.evaluate("echo lmfao");
|
|
core.console.evaluate("foo lmfao");
|
|
}
|
|
|
|
fn test_gameObjects(allocator: std.mem.Allocator) !void {
|
|
engine_logs("test: gameobjects... ");
|
|
|
|
const objList = try core.GameObjectList.create(allocator);
|
|
defer objList.destroy();
|
|
|
|
const GameObject = struct {
|
|
data: core.GameObjectData = undefined,
|
|
entity: core.Entity,
|
|
|
|
pub fn create(alloc: std.mem.Allocator) !*@This() {
|
|
const self = try alloc.create(@This());
|
|
self.entity = try core.createEntity();
|
|
_ = self.entity.addComponent(core.Scene);
|
|
|
|
return self;
|
|
}
|
|
|
|
pub fn getEntity(self: *@This()) core.Entity {
|
|
return self.entity;
|
|
}
|
|
|
|
pub fn tick(self: *@This(), dt: f64) void {
|
|
_ = dt;
|
|
engine_log("gameObject ticking.... {d} {d}", .{ self.data.index, self.entity.handle.index });
|
|
}
|
|
|
|
pub fn destroy(self: *@This()) void {
|
|
self.entity.destroy();
|
|
self.data.release(self);
|
|
}
|
|
};
|
|
|
|
const gameObject = try objList.newObject(GameObject);
|
|
|
|
const gameObject2 = try objList.newObject(GameObject);
|
|
objList.tick(0.016);
|
|
gameObject.destroy();
|
|
|
|
objList.tick(0.016);
|
|
gameObject2.destroy();
|
|
objList.tick(0.016);
|
|
|
|
const spawnFunc = core.GameObjectList.spawnObjectFunction(GameObject);
|
|
const interface = spawnFunc(objList).?;
|
|
|
|
core.engine_log("handle = {x}", .{interface.vtable.getEntity.?(interface.ptr).handle.index});
|
|
|
|
objList.tick(0.016);
|
|
}
|