Remove unnecessary delta time arg to fixed-timestep systems

This commit is contained in:
kayomn 2024-07-25 14:25:55 +01:00
parent db0e08d530
commit 3d4e6bb44b
2 changed files with 17 additions and 19 deletions

View File

@ -41,9 +41,9 @@ pub const main = ona.App.setup.
with_system(.render, ona.system_fn(render), .{.label = "render visuals"}).
with_system(.exit, ona.system_fn(cleanup), .{.label = "clean up visuals"}).build();
fn update(visuals: ona.Write(Visuals), app: ona.Read(ona.App), events: ona.Receive(hid.Event), display: ona.Read(gfx.Display)) !void {
update_spawned(&visuals.state.spawned_keyboards, @floatCast(app.state.delta_time));
update_spawned(&visuals.state.spawned_mouses, @floatCast(app.state.delta_time));
fn update(visuals: ona.Write(Visuals), events: ona.Receive(hid.Event), display: ona.Read(gfx.Display)) !void {
update_spawned(&visuals.state.spawned_keyboards);
update_spawned(&visuals.state.spawned_mouses);
const random = visuals.state.random.random();
const width: f32 = @floatFromInt(display.state.width);
@ -85,11 +85,11 @@ fn update(visuals: ona.Write(Visuals), app: ona.Read(ona.App), events: ona.Recei
}
}
fn update_spawned(spawned: *ona.stack.Parallel(Spawned), delta_time: f32) void {
const float_speed = 50;
fn update_spawned(spawned: *ona.stack.Parallel(Spawned)) void {
const float_speed = 6;
for (spawned.values.slice(.transform)) |*transform| {
transform.* = transform.translated(.{0, float_speed * -delta_time});
transform.* = transform.translated(.{0, -float_speed});
}
{
@ -99,7 +99,7 @@ fn update_spawned(spawned: *ona.stack.Parallel(Spawned), delta_time: f32) void {
while (index < range) : (index += 1) {
const lifetime_seconds = spawned.values.get(.lifetime_seconds, index).?;
lifetime_seconds.* -= delta_time;
lifetime_seconds.* -= 1.0 / 60.0;
if (lifetime_seconds.* <= 0) {
range -= 1;

View File

@ -32,7 +32,6 @@ pub const App = struct {
events: *const Events,
target_frame_time: f64,
elapsed_time: f64,
delta_time: f64,
is_running: bool,
pub const Events = struct {
@ -115,7 +114,6 @@ pub const App = struct {
.events = &events,
.target_frame_time = 1.0 / 60.0,
.elapsed_time = 0,
.delta_time = 0,
.is_running = true,
});
@ -129,11 +127,11 @@ pub const App = struct {
while (app.is_running) {
const ticks_current = std.time.milliTimestamp();
const milliseconds_per_second = 1000.0;
const delta_time = @as(f64, @floatFromInt(ticks_current - ticks_previous)) / milliseconds_per_second;
app.delta_time = @as(f64, @floatFromInt(ticks_current - ticks_previous)) / milliseconds_per_second;
app.elapsed_time = @as(f64, @floatFromInt(ticks_current - ticks_initial)) / milliseconds_per_second;
ticks_previous = ticks_current;
accumulated_time += app.delta_time;
accumulated_time += delta_time;
try world.run_event(events.pre_update);
@ -911,6 +909,14 @@ pub fn system_fn(comptime call: anytype) *const SystemInfo {
return system_info;
}
pub fn thread_restriction(comptime State: type) ThreadRestriction {
if (@hasDecl(State, "thread_restriction")) {
return State.thread_restriction;
}
return .none;
}
pub fn type_id(comptime T: type) TypeID {
const TypeHandle = struct {
comptime {
@ -922,11 +928,3 @@ pub fn type_id(comptime T: type) TypeID {
return @enumFromInt(@intFromPtr(&TypeHandle.byte));
}
pub fn thread_restriction(comptime State: type) ThreadRestriction {
if (@hasDecl(State, "thread_restriction")) {
return State.thread_restriction;
}
return .none;
}