Compare commits

...

3 Commits

Author SHA1 Message Date
kayomn 165c3fe071 Fix CWD path usage in build script
continuous-integration/drone/push Build is passing Details
2024-07-25 21:13:52 +01:00
kayomn 5674867adf Add missing section to readme 2024-07-25 14:26:39 +01:00
kayomn 3d4e6bb44b Remove unnecessary delta time arg to fixed-timestep systems 2024-07-25 14:25:55 +01:00
5 changed files with 21 additions and 22 deletions

View File

@ -15,7 +15,7 @@ const Project = struct {
pub fn find_demos(self: Project, b: *std.Build) !void {
const demos = b.step("demos", "Build demos");
var dir = try std.fs.cwd().openDir("demos/", .{
var dir = try std.fs.cwd().openDir(b.path("demos/").getPath(b), .{
.iterate = true,
});

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

@ -9,6 +9,7 @@
1. [Technical Details](#technical-details)
1. [Requirements](#requirements)
1. [Building](#building)
1. [Packaging](#packaging)
## Overview

View File

@ -2,8 +2,6 @@ const gfx = @import("./gfx.zig");
pub const black = greyscale(0);
pub const white = greyscale(1);
pub fn greyscale(v: f32) gfx.Color {
return .{v, v, v, 1};
}
@ -11,3 +9,5 @@ pub fn greyscale(v: f32) gfx.Color {
pub fn rgb(r: f32, g: f32, b: f32) gfx.Color {
return .{r, g, b, 1};
}
pub const white = greyscale(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;
}