big refactor to new lifetime rules
This commit is contained in:
parent
c36cae7db9
commit
81aaaa81b7
|
|
@ -201,17 +201,6 @@ pub const Program = struct {
|
|||
|
||||
const run_exe = b.step(b.fmt("run-{s}", .{self.name}), "runs the program");
|
||||
run_exe.dependOn(&run.step);
|
||||
|
||||
// const runArtifact = b.addRunArtifact(exe);
|
||||
// if (b.args) |args| {
|
||||
// runArtifact.addArgs(args);
|
||||
// }
|
||||
|
||||
// // Set CWD to the build.zig directory so the exe can find zig-out/modules/
|
||||
// runArtifact.setCwd(b.path("."));
|
||||
|
||||
// const run_exe = b.step(b.fmt("run-{s}", .{self.name}), "runs the program");
|
||||
// run_exe.dependOn(&runArtifact.step);
|
||||
}
|
||||
|
||||
// 2. create the actual library that the loader will try to load
|
||||
|
|
@ -221,51 +210,6 @@ pub const Program = struct {
|
|||
// return the actual library not the loader
|
||||
return exe;
|
||||
}
|
||||
|
||||
// const b = self.b;
|
||||
|
||||
// const exe = self.nw_builder.addExecutable(.{
|
||||
// .name = opts.name,
|
||||
// .target = self.target,
|
||||
// .optimize = self.optimize,
|
||||
// .root_source_file = self.nw_builder.path("engine/main.zig"),
|
||||
// });
|
||||
|
||||
// b.installArtifact(exe);
|
||||
// const runArtifact = b.addRunArtifact(exe);
|
||||
// if (b.args) |args| {
|
||||
// runArtifact.addArgs(args);
|
||||
// }
|
||||
// const run_exe = b.step(self.b.fmt("run-{s}", .{opts.name}), opts.desc);
|
||||
// run_exe.dependOn(&runArtifact.step);
|
||||
|
||||
// // main path = name/main.zig
|
||||
// const mod = b.addModule(opts.name, .{
|
||||
// .target = self.target,
|
||||
// .optimize = self.optimize,
|
||||
// .root_source_file = opts.root_source_file,
|
||||
// .imports = opts.imports,
|
||||
// });
|
||||
|
||||
// exe.root_module.addImport("main", mod);
|
||||
// // todo.. remove this one and see what happens
|
||||
// exe.root_module.addImport("core", self.nwdep.module("core"));
|
||||
// // mod.addImport("Backlog", self.nw_mod);
|
||||
// exe.root_module.addOptions("BacklogOptions", self.options);
|
||||
|
||||
// if (self.cookShaders) {
|
||||
// const cookShadersScript = b.fmt("{s}/tools/scripts/cookShaders.py", .{self.backlogRoot});
|
||||
// const cookShadersCommand = b.addSystemCommand(&[_][]const u8{"python"});
|
||||
// cookShadersCommand.addArg(cookShadersScript);
|
||||
|
||||
// run_exe.dependOn(&cookShadersCommand.step);
|
||||
// }
|
||||
|
||||
// b.getInstallStep().dependOn(self.nw_builder.getInstallStep());
|
||||
|
||||
// // run_exe.dependOn(b.getInstallStep());
|
||||
|
||||
// return mod;
|
||||
};
|
||||
|
||||
const std = @import("std");
|
||||
|
|
|
|||
|
|
@ -120,11 +120,6 @@ pub const AssetLoaderInterface = struct {
|
|||
unreachable;
|
||||
}
|
||||
|
||||
if (!@hasDecl(TargetType, "destroy")) {
|
||||
@compileLog("Tried to generate AssetLoaderInterface for type ", TargetType, "but it's missing func destroy.");
|
||||
unreachable;
|
||||
}
|
||||
|
||||
const self = @This(){
|
||||
.typeName = @typeName(TargetType),
|
||||
.typeSize = @sizeOf(TargetType),
|
||||
|
|
@ -159,15 +154,15 @@ pub const AssetReferenceSys = struct {
|
|||
|
||||
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "AssetReference");
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = @This(){
|
||||
.loaders = .{},
|
||||
.allocator = allocator,
|
||||
.outstandingAssetJobs = std.atomic.Value(i32).init(0),
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn registerLoader(self: *@This(), loader: anytype) !void {
|
||||
|
|
@ -210,6 +205,5 @@ pub const AssetReferenceSys = struct {
|
|||
// i.destroy(self.allocator);
|
||||
// }
|
||||
self.loaders.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -73,8 +73,10 @@ pub const SoundEngine = struct {
|
|||
allocator: std.mem.Allocator,
|
||||
volume: f32 = 1.0,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = @This(){
|
||||
.engine = allocator.create(ma.ma_engine) catch unreachable,
|
||||
.sounds = .{},
|
||||
|
|
@ -83,8 +85,6 @@ pub const SoundEngine = struct {
|
|||
};
|
||||
|
||||
_ = ma.ma_engine_init(null, self.engine);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn shutdown(self: *@This()) void {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub const ConfigRegistry = struct {
|
|||
allocator: std.mem.Allocator = undefined,
|
||||
configMap: ?ConfigMap = null,
|
||||
|
||||
pub fn create(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ pub const ConfigRegistry = struct {
|
|||
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
pub fn deinit(self: *@This()) void {
|
||||
if (self.configMap) |*map| {
|
||||
map.deinit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub const Console = struct {
|
|||
|
||||
commandMap: std.StringHashMapUnmanaged(ConsoleCommand) = .{},
|
||||
|
||||
pub fn create(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ pub const Console = struct {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.arena.deinit();
|
||||
self.commandMap.deinit(self.allocator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -279,10 +279,6 @@ pub const EcsRegistry = struct {
|
|||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
_ = self;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
for (self.containers.items) |ref| {
|
||||
ref.vtable.evictFromRegistry(ref.ptr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ pub const ModuleLoader = struct {
|
|||
|
||||
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "core.ModuleLoader");
|
||||
|
||||
pub fn create(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -215,7 +215,7 @@ pub const ModuleLoader = struct {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
pub fn deinit(self: *@This()) void {
|
||||
// std.fs.cwd().deleteTree(".modulecache") catch {};
|
||||
self.arena.deinit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ pub const GameObjectSystem = struct {
|
|||
|
||||
objectSpawnEvents: std.ArrayListUnmanaged(SpawnEvent) = .{},
|
||||
|
||||
pub fn create(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ pub const GameObjectSystem = struct {
|
|||
_ = dt;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.typesArena.deinit();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,14 +15,13 @@ pub const Impl = struct {
|
|||
};
|
||||
|
||||
// renderer plugin
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
const ImguiArgs = struct { imguiIni: []const u8 = "imgui.ini" };
|
||||
|
|
@ -109,11 +108,6 @@ pub const Impl = struct {
|
|||
_ = ig.dockSpaceOverViewport(ig.getMainViewport(), .{ .passthru_central_node = true }, null);
|
||||
_ = dt;
|
||||
}
|
||||
|
||||
// renderer plugin
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
const c = @import("cimgui").c;
|
||||
const ig = @import("cimgui");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "game.TopBar");
|
||||
pub const Slack = core.SlackStruct(@This(), 256);
|
||||
|
||||
allocator: std.mem.Allocator,
|
||||
arena: std.heap.ArenaAllocator,
|
||||
|
|
@ -7,8 +6,10 @@ windowsMenu: std.ArrayListUnmanaged(*MenuEntry) = .{},
|
|||
entriesByName: std.AutoHashMapUnmanaged(u32, *MenuEntry) = .{},
|
||||
menuOpen: bool = false,
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try Slack.create(allocator);
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.arena = std.heap.ArenaAllocator.init(allocator),
|
||||
|
|
@ -21,8 +22,6 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
|||
.ctx = self,
|
||||
.windowFunction = windowOpen,
|
||||
});
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn setEntryOpen(self: *@This(), name: []const u8, open: ?bool) void {
|
||||
|
|
@ -108,7 +107,6 @@ pub fn tick(self: *@This(), dt: f64) void {
|
|||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.arena.deinit();
|
||||
self.allocator.destroy(Slack.fromPtr(self));
|
||||
}
|
||||
|
||||
pub const MenuEntry = struct {
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@ consolePressedEnter: bool = false,
|
|||
|
||||
pub var NeonObjectTable = core.EngineObjectVTable.from(@This(), "extras.consoleWindow");
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.buffer = core.logging.LogBuffer.init(allocator),
|
||||
};
|
||||
|
||||
self.setup();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn setup(self: *@This()) void {
|
||||
|
|
@ -65,7 +65,6 @@ pub fn windowOpen(entry: *imgui.utils.MenuEntry, dt: f64) void {
|
|||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.buffer.deinit();
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const imgui = @import("../imgui.zig");
|
||||
|
|
|
|||
|
|
@ -159,8 +159,9 @@ const ENetSessionData = struct {
|
|||
}
|
||||
};
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn create(self: *@This(), allocator: std.mem.Allocator, first: bool) !*@This() {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
|
|
@ -399,7 +400,6 @@ pub fn destroy(self: *@This()) void {
|
|||
self.deadSessions.deinit(self.allocator);
|
||||
|
||||
enet_mod.deinitialize();
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const core = @import("core");
|
||||
|
|
|
|||
|
|
@ -28,15 +28,14 @@ pub const NetEngine = struct {
|
|||
arena: std.heap.ArenaAllocator,
|
||||
transport: ?TransportRef = null,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !*@This() {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = @This(){
|
||||
.allocator = allocator,
|
||||
.arena = std.heap.ArenaAllocator.init(allocator),
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn arenaAllocator(self: *@This()) std.mem.Allocator {
|
||||
|
|
|
|||
|
|
@ -139,8 +139,11 @@ pub const PhysicsRuntime = struct {
|
|||
try self.idToEntity.put(self.allocator, bodyId, entity);
|
||||
}
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first) {
|
||||
return;
|
||||
}
|
||||
|
||||
try zphysics.init(std.heap.smp_allocator, .{});
|
||||
//try zphysics.init(allocator, .{});
|
||||
|
||||
|
|
@ -162,11 +165,6 @@ pub const PhysicsRuntime = struct {
|
|||
);
|
||||
|
||||
self.system = system;
|
||||
|
||||
//try core.defineComponent(PhysicsCharacter, self.allocator);
|
||||
// try core.defineComponent(PhysicsCollider, self.allocator);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn tick(self: *@This(), dt: f64) void {
|
||||
|
|
@ -230,7 +228,6 @@ pub const PhysicsRuntime = struct {
|
|||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
const allocator = self.allocator;
|
||||
self.system.optimizeBroadPhase();
|
||||
for (PhysicsCharacter.BaseContainer.list.items) |physChar| {
|
||||
physChar.deinit();
|
||||
|
|
@ -266,8 +263,6 @@ pub const PhysicsRuntime = struct {
|
|||
self.system.destroy();
|
||||
|
||||
zphysics.deinit();
|
||||
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn createShape(self: *@This(), name: *core.Name, settings: ShapeSettings) !void {
|
||||
|
|
|
|||
|
|
@ -1,308 +0,0 @@
|
|||
const std = @import("std");
|
||||
const zphysics = @import("zphysics");
|
||||
const core = @import("core");
|
||||
const zm = core.zm;
|
||||
|
||||
pub const ObjectLayers = struct {
|
||||
pub const non_moving: zphysics.ObjectLayer = 0;
|
||||
pub const moving: zphysics.ObjectLayer = 1;
|
||||
pub const len: u32 = 2;
|
||||
};
|
||||
|
||||
pub const BroadPhaseLayers = struct {
|
||||
pub const non_moving: zphysics.BroadPhaseLayer = 0;
|
||||
pub const moving: zphysics.BroadPhaseLayer = 1;
|
||||
pub const len: u32 = 2;
|
||||
};
|
||||
|
||||
const BroadPhaseLayerInterface = extern struct {
|
||||
usingnamespace zphysics.BroadPhaseLayerInterface.Methods(@This());
|
||||
__v: *const zphysics.BroadPhaseLayerInterface.VTable = &vtable,
|
||||
|
||||
object_to_broad_phase: [ObjectLayers.len]zphysics.BroadPhaseLayer = undefined,
|
||||
|
||||
const vtable = zphysics.BroadPhaseLayerInterface.VTable{
|
||||
.getNumBroadPhaseLayers = _getNumBroadPhaseLayers,
|
||||
.getBroadPhaseLayer = _getBroadPhaseLayer,
|
||||
};
|
||||
|
||||
fn init() BroadPhaseLayerInterface {
|
||||
var layer_interface: BroadPhaseLayerInterface = .{};
|
||||
layer_interface.object_to_broad_phase[ObjectLayers.non_moving] = BroadPhaseLayers.non_moving;
|
||||
layer_interface.object_to_broad_phase[ObjectLayers.moving] = BroadPhaseLayers.moving;
|
||||
return layer_interface;
|
||||
}
|
||||
|
||||
fn _getNumBroadPhaseLayers(_: *const zphysics.BroadPhaseLayerInterface) callconv(.c) u32 {
|
||||
return BroadPhaseLayers.len;
|
||||
}
|
||||
|
||||
fn _getBroadPhaseLayer(
|
||||
interface_self: *const zphysics.BroadPhaseLayerInterface,
|
||||
object_layer: zphysics.ObjectLayer,
|
||||
) callconv(.c) zphysics.BroadPhaseLayer {
|
||||
const self: *const BroadPhaseLayerInterface = @ptrCast(interface_self);
|
||||
return self.object_to_broad_phase[object_layer];
|
||||
}
|
||||
};
|
||||
|
||||
const ObjectVsBroadPhaseLayerFilter = extern struct {
|
||||
usingnamespace zphysics.ObjectVsBroadPhaseLayerFilter.Methods(@This());
|
||||
__v: *const zphysics.ObjectVsBroadPhaseLayerFilter.VTable = &vtable,
|
||||
|
||||
const vtable = zphysics.ObjectVsBroadPhaseLayerFilter.VTable{ .shouldCollide = _shouldCollide };
|
||||
|
||||
fn _shouldCollide(
|
||||
_: *const zphysics.ObjectVsBroadPhaseLayerFilter,
|
||||
object_layer: zphysics.ObjectLayer,
|
||||
broad_phase_layer: zphysics.BroadPhaseLayer,
|
||||
) callconv(.c) bool {
|
||||
return switch (object_layer) {
|
||||
ObjectLayers.non_moving => broad_phase_layer == BroadPhaseLayers.moving,
|
||||
ObjectLayers.moving => true,
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const ObjectLayerPairFilter = extern struct {
|
||||
usingnamespace zphysics.ObjectLayerPairFilter.Methods(@This());
|
||||
__v: *const zphysics.ObjectLayerPairFilter.VTable = &vtable,
|
||||
|
||||
const vtable = zphysics.ObjectLayerPairFilter.VTable{ .shouldCollide = _shouldCollide };
|
||||
|
||||
fn _shouldCollide(
|
||||
_: *const zphysics.ObjectLayerPairFilter,
|
||||
a: zphysics.ObjectLayer,
|
||||
b: zphysics.ObjectLayer,
|
||||
) callconv(.c) bool {
|
||||
return switch (a) {
|
||||
ObjectLayers.non_moving => b == ObjectLayers.moving,
|
||||
ObjectLayers.moving => true,
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const PhysicsRuntime = struct {
|
||||
allocator: std.mem.Allocator,
|
||||
bpli: BroadPhaseLayerInterface,
|
||||
ovbplf: ObjectVsBroadPhaseLayerFilter,
|
||||
olpf: ObjectLayerPairFilter,
|
||||
max_bodies: u32,
|
||||
|
||||
system: *zphysics.PhysicsSystem = undefined,
|
||||
|
||||
primBoxSettings: *zphysics.BoxShapeSettings = undefined,
|
||||
primBoxShape: *zphysics.Shape = undefined,
|
||||
|
||||
primSphereSettings: *zphysics.SphereShapeSettings = undefined,
|
||||
primSphereShape: *zphysics.Shape = undefined,
|
||||
|
||||
floorShapeSettings: *zphysics.BoxShapeSettings = undefined,
|
||||
floorShape: *zphysics.Shape = undefined,
|
||||
|
||||
spherePositions: std.ArrayList(core.Vectorf),
|
||||
sphereRotations: std.ArrayList(core.Quat),
|
||||
sphereIds: std.ArrayList(zphysics.BodyId),
|
||||
|
||||
newBallTime: f64 = 5,
|
||||
offset: f32 = 0,
|
||||
|
||||
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This());
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.bpli = BroadPhaseLayerInterface.init(),
|
||||
.ovbplf = .{},
|
||||
.olpf = .{},
|
||||
.spherePositions = std.ArrayList(core.Vectorf).init(allocator),
|
||||
.sphereRotations = std.ArrayList(core.Quat).init(allocator),
|
||||
.sphereIds = std.ArrayList(zphysics.BodyId).init(allocator),
|
||||
.max_bodies = 8192,
|
||||
};
|
||||
|
||||
const system = try zphysics.PhysicsSystem.create(
|
||||
@as(*const zphysics.BroadPhaseLayerInterface, @ptrCast(&self.bpli)),
|
||||
@as(*const zphysics.ObjectVsBroadPhaseLayerFilter, @ptrCast(&self.ovbplf)),
|
||||
@as(*const zphysics.ObjectLayerPairFilter, @ptrCast(&self.olpf)),
|
||||
.{
|
||||
.max_bodies = self.max_bodies,
|
||||
.num_body_mutexes = 0,
|
||||
.max_body_pairs = 8192 * 2,
|
||||
.max_contact_constraints = 8192 * 2,
|
||||
},
|
||||
);
|
||||
|
||||
self.system = system;
|
||||
|
||||
const bodyInterface = self.system.getBodyInterfaceMut();
|
||||
|
||||
// primBoxSettings: *zphysics.BoxShapeSettings = undefined,
|
||||
// primBoxShape: *zphysics.Shape = undefined,
|
||||
|
||||
// primSphereSettings: *zphysics.SphereShapeSettings = undefined,
|
||||
// primSphereShape: *zphysics.Shape = undefined,
|
||||
|
||||
// setup primitives for settings.
|
||||
self.primBoxSettings = try zphysics.BoxShapeSettings.create(.{ 2.0, 2.0, 2.0 });
|
||||
self.primBoxShape = try self.primBoxSettings.createShape();
|
||||
|
||||
self.primSphereSettings = try zphysics.SphereShapeSettings.create(0.5);
|
||||
self.primSphereShape = try self.primSphereSettings.createShape();
|
||||
|
||||
self.floorShapeSettings = try zphysics.BoxShapeSettings.create(.{ 300, 1, 300 });
|
||||
self.floorShape = try self.floorShapeSettings.createShape();
|
||||
|
||||
// create floor
|
||||
_ = try bodyInterface.createAndAddBody(.{
|
||||
.position = .{ 0, -1, 0, 1 },
|
||||
.rotation = .{ 0, 0, 0, 1 },
|
||||
.shape = self.floorShape,
|
||||
.motion_type = .static,
|
||||
.object_layer = ObjectLayers.non_moving,
|
||||
}, .activate);
|
||||
|
||||
const roomSize = 7;
|
||||
// create up and down walls
|
||||
{
|
||||
const rotation = zm.quatFromMat(zm.rotationZ(core.radians(90.0)));
|
||||
_ = try bodyInterface.createAndAddBody(.{
|
||||
.position = .{ roomSize, -1, 0, 1 },
|
||||
.rotation = rotation,
|
||||
.shape = self.floorShape,
|
||||
.motion_type = .static,
|
||||
.object_layer = ObjectLayers.non_moving,
|
||||
}, .activate);
|
||||
|
||||
_ = try bodyInterface.createAndAddBody(.{
|
||||
.position = .{ -roomSize, -1, 0, 1 },
|
||||
.rotation = rotation,
|
||||
.shape = self.floorShape,
|
||||
.motion_type = .static,
|
||||
.object_layer = ObjectLayers.non_moving,
|
||||
}, .activate);
|
||||
}
|
||||
|
||||
// create left and right walls
|
||||
{
|
||||
const rotation = zm.quatFromMat(zm.rotationX(core.radians(90.0)));
|
||||
_ = try bodyInterface.createAndAddBody(.{
|
||||
.position = .{ 0, -1, -roomSize, 1 },
|
||||
.rotation = rotation,
|
||||
.shape = self.floorShape,
|
||||
.motion_type = .static,
|
||||
.object_layer = ObjectLayers.non_moving,
|
||||
}, .activate);
|
||||
|
||||
_ = try bodyInterface.createAndAddBody(.{
|
||||
.position = .{ 0, -1, roomSize, 1 },
|
||||
.rotation = rotation,
|
||||
.shape = self.floorShape,
|
||||
.motion_type = .static,
|
||||
.object_layer = ObjectLayers.non_moving,
|
||||
}, .activate);
|
||||
}
|
||||
|
||||
for (0..2) |i| {
|
||||
_ = try bodyInterface.createAndAddBody(
|
||||
.{
|
||||
.position = .{ 0, @as(f32, @floatFromInt(i)) * 1.1 + 1.0, 2, 1 },
|
||||
.rotation = .{ 0, 0, 0, 1 },
|
||||
.shape = self.primSphereShape,
|
||||
.motion_type = .dynamic,
|
||||
.object_layer = ObjectLayers.moving,
|
||||
.restitution = 0.4,
|
||||
.angular_velocity = .{ 0, 0, 0, 0 },
|
||||
},
|
||||
.activate,
|
||||
);
|
||||
_ = try bodyInterface.createAndAddBody(
|
||||
.{
|
||||
.position = .{ 5, @as(f32, @floatFromInt(i)) * 1.1 + 1.0, 2, 1 },
|
||||
.rotation = .{ 0, 0, 0, 1 },
|
||||
.shape = self.primSphereShape,
|
||||
.motion_type = .dynamic,
|
||||
.restitution = 0.4,
|
||||
.object_layer = ObjectLayers.moving,
|
||||
.angular_velocity = .{ 0, 0, 0, 0 },
|
||||
},
|
||||
.activate,
|
||||
);
|
||||
}
|
||||
|
||||
self.system.optimizeBroadPhase();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn updateSpherePositions(self: *@This()) !void {
|
||||
try self.system.getBodyIds(&self.sphereIds);
|
||||
try self.spherePositions.resize(self.sphereIds.items.len);
|
||||
try self.sphereRotations.resize(self.sphereIds.items.len);
|
||||
const lockInterface = self.system.getBodyLockInterface();
|
||||
|
||||
for (self.sphereIds.items, 0..) |bodyId, i| {
|
||||
var readLock: zphysics.BodyLockRead = .{};
|
||||
readLock.lock(lockInterface, bodyId);
|
||||
defer readLock.unlock();
|
||||
|
||||
if (readLock.body) |body| {
|
||||
self.spherePositions.items[i] = core.Vectorf.fromArray(body.position);
|
||||
self.sphereRotations.items[i] = body.rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo... schedule physics timers
|
||||
pub fn tick(self: *@This(), dt: f64) void {
|
||||
self.system.update(@floatCast(dt), .{}) catch unreachable;
|
||||
self.updateSpherePositions() catch unreachable;
|
||||
|
||||
// self.newBallTime -= dt;
|
||||
|
||||
// if (self.newBallTime < 0) {
|
||||
// const bodyInterface = self.system.getBodyInterfaceMut();
|
||||
// self.newBallTime = 5.0;
|
||||
// self.offset += 0.01;
|
||||
|
||||
// _ = bodyInterface.createAndAddBody(
|
||||
// .{
|
||||
// .position = .{ 0 + self.offset, 15, 0, 1 },
|
||||
// .rotation = .{ 0, 0, 0, 1 },
|
||||
// .shape = self.primSphereShape,
|
||||
// .motion_type = .dynamic,
|
||||
// .object_layer = ObjectLayers.moving,
|
||||
// .restitution = 0.4,
|
||||
// .angular_velocity = .{ 0, 0, 0, 0 },
|
||||
// .inertia_multiplier = 30,
|
||||
// },
|
||||
// .activate,
|
||||
// ) catch unreachable;
|
||||
|
||||
// self.system.optimizeBroadPhase();
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
const allocator = self.allocator;
|
||||
|
||||
self.primSphereShape.release();
|
||||
self.primSphereSettings.release();
|
||||
|
||||
self.floorShape.release();
|
||||
self.floorShapeSettings.release();
|
||||
|
||||
self.primBoxShape.release();
|
||||
self.primBoxSettings.release();
|
||||
|
||||
self.system.destroy();
|
||||
self.sphereIds.deinit();
|
||||
self.spherePositions.deinit();
|
||||
self.sphereRotations.deinit();
|
||||
allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
const std = @import("std");
|
||||
const core = @import("core");
|
||||
const windowing = @import("windowing.zig");
|
||||
|
||||
// GameInput implements the RawInputListenerInterface
|
||||
// This is a data driven input system where mappings are defined,
|
||||
// and keys are assigned to mapping contexts
|
||||
|
||||
pub const GameInputSystem = struct {
|
||||
pub const RawInputListenerVTable = windowing.RawInputListenerInterface.from(@This());
|
||||
|
||||
stub: u32 = 0,
|
||||
|
||||
pub fn OnIoEvent(self: *@This(), event: windowing.IOEvent) windowing.InputListenerError!void {
|
||||
_ = event;
|
||||
_ = self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
_ = self;
|
||||
}
|
||||
};
|
||||
|
|
@ -191,8 +191,6 @@ pub const PlatformInstance = struct {
|
|||
self.allocator.free(self.iconPath);
|
||||
self.processFuncs.deinit(self.allocator);
|
||||
self.platformRequests.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
// shutdown
|
||||
}
|
||||
|
||||
pub fn onExitSignal(self: *@This()) !void {
|
||||
|
|
@ -204,10 +202,10 @@ pub const PlatformInstance = struct {
|
|||
return self.windowDestroyed;
|
||||
}
|
||||
|
||||
pub fn init(
|
||||
allocator: std.mem.Allocator,
|
||||
) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.nfdRuntime = try nfd.NFDRuntime.create(allocator, .{}),
|
||||
|
|
@ -217,8 +215,6 @@ pub const PlatformInstance = struct {
|
|||
//.extent = .{ .x = @floatFromInt(params.extent.x), .y = @floatFromInt(params.extent.y) },
|
||||
//.hasVideo = params.hasVideo,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn setParams(self: *@This(), params: PlatformParams) !void {
|
||||
|
|
|
|||
|
|
@ -417,8 +417,10 @@ pub const AnimationSystem = struct {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn init(alloc: std.mem.Allocator) !*@This() {
|
||||
const self = try alloc.create(@This());
|
||||
pub fn init(self: *@This(), alloc: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.backingAllocator = alloc,
|
||||
.arena = std.heap.ArenaAllocator.init(alloc),
|
||||
|
|
@ -433,7 +435,6 @@ pub const AnimationSystem = struct {
|
|||
Animator.allocator = alloc;
|
||||
|
||||
core.engine_logs("Animation System initialized");
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
|
|
@ -466,7 +467,6 @@ pub const AnimationSystem = struct {
|
|||
self.arena.deinit();
|
||||
self.skeletons.deinit(self.backingAllocator);
|
||||
self.animTracks.deinit(self.backingAllocator);
|
||||
self.backingAllocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,19 +19,14 @@ pub const AnimationLoader = struct {
|
|||
self.sys.newAnimTrack(assetRef.name, animation) catch return error.UnableToLoad;
|
||||
}
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.sys = animation_system.gAnimationSys,
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -56,19 +51,14 @@ pub const SkeletonLoader = struct {
|
|||
self.sys.newSkeleton(assetRef.name, sk) catch return error.UnableToLoad;
|
||||
}
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.sys = animation_system.gAnimationSys,
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -410,8 +410,9 @@ pub const ParticleSystem = struct {
|
|||
|
||||
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "rend.ParticleSystem");
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.particleArena = std.heap.ArenaAllocator.init(allocator),
|
||||
|
|
@ -420,8 +421,6 @@ pub const ParticleSystem = struct {
|
|||
|
||||
ParticleRandRangef.randomEngine = std.Random.DefaultPrng.init(0x1234);
|
||||
ParticleRandRangef.randomFunc = ParticleRandRangef.randomEngine.random();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn tick(self: *@This(), dt: f64) void {
|
||||
|
|
@ -437,7 +436,6 @@ pub const ParticleSystem = struct {
|
|||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.particleArena.deinit();
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,10 @@ const assetReferences = [_]assets.AssetImportReference{
|
|||
),
|
||||
};
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.debugDraws = try core.RingQueueU(DebugPrimitive).init(allocator, MaxObjectCount),
|
||||
.allocator = allocator,
|
||||
|
|
@ -50,8 +52,6 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
|||
try assets.loadList(assetReferences);
|
||||
|
||||
gDebugDrawSys = self;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn updateMeshes(self: *@This()) void {
|
||||
|
|
@ -243,7 +243,6 @@ pub fn setup(self: *@This(), device: *gpu.GPUDevice) !void {
|
|||
pub fn destroy(self: *@This()) void {
|
||||
self.debugDraws.deinit(self.allocator);
|
||||
self.drawsThisFrame.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
// ==================== Primitives ===================
|
||||
|
|
|
|||
|
|
@ -5,23 +5,19 @@ allocator: std.mem.Allocator,
|
|||
pub var LoaderInterfaceVTable = assets.AssetLoaderInterface.from("Mesh", @This());
|
||||
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "rend.MeshAssetLoader");
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn discardAll(self: *@This()) void {
|
||||
_ = self;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
// unfortunately this one is blocking
|
||||
pub fn loadAsset(self: *@This(), assetRef: assets.AssetRef, propertiesBag: ?assets.AssetPropertiesBag) assets.AssetLoaderError!void {
|
||||
_ = self;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@ const SgpuParticleRenderInfo = struct {
|
|||
texture: *rend.Texture,
|
||||
};
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
|
@ -39,8 +41,6 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
|||
.size = MaxParticleCount * @sizeOf(meshes_vert.Scene),
|
||||
.props = 0,
|
||||
});
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn uploadSsbos(self: *@This(), copyPass: *gpu.GPUCopyPass) !void {
|
||||
|
|
@ -121,10 +121,9 @@ pub fn setup(self: *@This(), device: *gpu.GPUDevice) !void {
|
|||
_ = device;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.spans.deinit(self.allocator);
|
||||
self.renderInfo.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const assets = @import("assets");
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ brightnessFactor: f32 = 4.0,
|
|||
|
||||
sampler: *gpu.GPUSampler = undefined,
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
self.* = .{ .allocator = allocator };
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
return self;
|
||||
self.* = .{ .allocator = allocator };
|
||||
}
|
||||
|
||||
pub fn setup(self: *@This(), device: *gpu.GPUDevice) !void {
|
||||
|
|
@ -87,10 +87,6 @@ fn createPipeline(self: *@This()) !void {
|
|||
}));
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn render(self: *@This(), cmd: *gpu.GPUCommandBuffer) void {
|
||||
const targetInfo: [2]gpu.GPUColorTargetInfo = .{
|
||||
std.mem.zeroInit(gpu.GPUColorTargetInfo, .{
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@
|
|||
pub var LoaderInterfaceVTable = assets.AssetLoaderInterface.from("Texture", @This());
|
||||
pub var NeonObjectTable: core.EngineObjectVTable = core.EngineObjectVTable.from(@This(), "rend.TextureList");
|
||||
|
||||
allocator: std.mem.Allocator,
|
||||
allocator: std.mem.Allocator = undefined,
|
||||
device: *gpu.GPUDevice = undefined,
|
||||
|
||||
map: std.AutoHashMapUnmanaged(u32, *Texture) = .{},
|
||||
requestMap: std.AutoHashMapUnmanaged(u32, bool) = .{},
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn setup(self: *@This(), device: *gpu.GPUDevice) !void {
|
||||
|
|
@ -339,14 +339,13 @@ pub fn discardAll(self: *@This()) void {
|
|||
_ = self;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
pub fn deinit(self: *@This()) void {
|
||||
var iter = self.map.valueIterator();
|
||||
while (iter.next()) |x| {
|
||||
self.allocator.destroy(x.*);
|
||||
}
|
||||
self.requestMap.deinit(self.allocator);
|
||||
self.map.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
|
|
|
|||
|
|
@ -99,15 +99,14 @@ pub const Renderer = struct {
|
|||
|
||||
pub const MaxObjectCount = 50000;
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
||||
self.hdrTextureFormat = .textureformatR16g16b16a16Float;
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn imageExtents(self: @This()) core.Vectorf {
|
||||
|
|
@ -1178,7 +1177,6 @@ pub const Renderer = struct {
|
|||
|
||||
self.uploads.deinit(self.allocator);
|
||||
self.destroys.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -21,14 +21,13 @@ enable: bool = true,
|
|||
// float bias; // = 0.025;
|
||||
// int numSamples; // up to 64
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !*@This() {
|
||||
const self = try allocator.create(@This());
|
||||
pub fn init(self: *@This(), allocator: std.mem.Allocator, first: bool) !void {
|
||||
if (!first)
|
||||
return;
|
||||
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn setup(self: *@This(), device: *gpu.GPUDevice) !void {
|
||||
|
|
@ -216,10 +215,6 @@ pub fn createPipeline(self: *@This()) !void {
|
|||
self.ssaoPipeline = ctx.device.createGPUGraphicsPipeline(&pci);
|
||||
}
|
||||
|
||||
pub fn destroy(self: *@This()) void {
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const core = @import("core");
|
||||
const rend = @import("../rend.zig");
|
||||
const std = @import("std");
|
||||
|
|
|
|||
Loading…
Reference in New Issue