saving
This commit is contained in:
parent
cf0f27cc92
commit
6bf5b3516f
|
|
@ -20,22 +20,16 @@ pub fn prepare(self: *@This()) !void {
|
|||
const x = e.addComponent(core.Scene).?;
|
||||
x.setMobility(.moveable);
|
||||
}
|
||||
|
||||
// try self.testThing();
|
||||
}
|
||||
|
||||
pub fn tick(self: *@This(), dt: f64) void {
|
||||
// std.Thread.sleep(1000_000);
|
||||
self.timeLeft -= dt;
|
||||
|
||||
const start = core.getEngineTime();
|
||||
|
||||
core.parallelJob(UpdateWorldTransformsJob{}, false, 1) catch unreachable;
|
||||
|
||||
// wait 10 ms
|
||||
while (core.getEngineTime() - start < 0.010) {
|
||||
// std.Thread.sleep(10_000_000);
|
||||
}
|
||||
while (core.getEngineTime() - start < 0.010) { }
|
||||
|
||||
if (self.timeLeft < 0)
|
||||
core.exitNow();
|
||||
|
|
@ -45,98 +39,6 @@ pub fn deinit(self: *@This()) void {
|
|||
self.allocator.destroy(self);
|
||||
}
|
||||
|
||||
const Src = std.builtin.SourceLocation;
|
||||
pub fn BarrierCV(src: Src) type {
|
||||
return struct {
|
||||
pub const Src = src;
|
||||
|
||||
pub var count: u32 = 0;
|
||||
pub var generation: u32 = 0;
|
||||
pub var mutex: std.Thread.Mutex = .{};
|
||||
pub var cv: std.Thread.Condition = .{};
|
||||
|
||||
pub fn sync(threadId: u32, barrierCount: u32) !void {
|
||||
_ = threadId;
|
||||
|
||||
mutex.lock();
|
||||
defer mutex.unlock();
|
||||
|
||||
count += 1;
|
||||
|
||||
if (count == barrierCount) {
|
||||
// 2 second timeout
|
||||
count = 0;
|
||||
generation += 1;
|
||||
cv.broadcast();
|
||||
} else {
|
||||
try cv.timedWait(&mutex, 1000 * 1000 * 1000 * 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn BarrierSpin(src: Src) type {
|
||||
return struct {
|
||||
pub const Src = src;
|
||||
|
||||
pub var count: std.atomic.Value(u32) = std.atomic.Value(u32).init(0);
|
||||
pub var park: std.atomic.Value(bool) = std.atomic.Value(bool).init(false);
|
||||
|
||||
pub fn sync(threadId: u32, barrierCount: u32) !void {
|
||||
_ = threadId;
|
||||
|
||||
const c = count.fetchAdd(1, .release);
|
||||
if (c + 1 == barrierCount) {
|
||||
park.store(true, .release);
|
||||
while (count.load(.acquire) > 1) {}
|
||||
_ = count.fetchSub(1, .release);
|
||||
park.store(false, .release);
|
||||
} else {
|
||||
while (park.load(.acquire) == false) {}
|
||||
_ = count.fetchSub(1, .seq_cst);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub const Barrier = BarrierSpin;
|
||||
|
||||
const MultiJob = struct {
|
||||
threadId: u32 = 0,
|
||||
threadCount: u32 = 1,
|
||||
threadName: []const u8,
|
||||
|
||||
pub fn func(ctx: @This(), job: *core.JobContext) void {
|
||||
_ = job;
|
||||
core.tracy.SetThreadName(@ptrCast(ctx.threadName.ptr));
|
||||
ctx.loop() catch {};
|
||||
|
||||
if (core.getEngine().isShuttingDown()) {}
|
||||
|
||||
Barrier(@src()).sync(ctx.threadId, ctx.threadCount) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn loop(ctx: @This()) !void {
|
||||
while (!core.getEngine().isShuttingDown()) {
|
||||
try Barrier(@src()).sync(ctx.threadId, ctx.threadCount);
|
||||
try ctx.tick();
|
||||
if (ctx.threadId == 0) {
|
||||
const z = core.tracy.ZoneN(@src(), "Thread 0 sleep");
|
||||
defer z.End();
|
||||
core.waitSeconds(0.01);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick(ctx: @This()) !void {
|
||||
const z = core.tracy.ZoneN(@src(), "MultiJob Tick");
|
||||
defer z.End();
|
||||
// std.Thread.sleep(100_000 * ctx.threadId);
|
||||
|
||||
try Barrier(@src()).sync(ctx.threadId, ctx.threadCount);
|
||||
}
|
||||
};
|
||||
|
||||
const UpdateWorldTransformsJob = struct {
|
||||
world: ?*anyopaque = null,
|
||||
|
||||
|
|
@ -161,8 +63,8 @@ const UpdateWorldTransformsJob = struct {
|
|||
const denseRepr = core.Scene.SceneObjectContainer.denseItems(._repr);
|
||||
|
||||
const z3 = core.tracy.ZoneN(@src(), "Merge Outputs");
|
||||
|
||||
// merge outputs
|
||||
// current a noop just iterate over the outputlist
|
||||
for (outputList.items) |outIndex| {
|
||||
if (denseRepr[outIndex].merge.cmpxchgStrong(false, true, .seq_cst, .acquire) != null) {
|
||||
denseRepr[outIndex].transform = outputs[outIndex];
|
||||
|
|
|
|||
Loading…
Reference in New Issue