Compare commits

..

No commits in common. "165c3fe0718d60b5900e5c8b1da3f75df6bf411a" and "db0e08d530c901c570fff72f3d54361906a0da54" have entirely different histories.

5 changed files with 22 additions and 21 deletions

View File

@ -15,7 +15,7 @@ const Project = struct {
pub fn find_demos(self: Project, b: *std.Build) !void { pub fn find_demos(self: Project, b: *std.Build) !void {
const demos = b.step("demos", "Build demos"); const demos = b.step("demos", "Build demos");
var dir = try std.fs.cwd().openDir(b.path("demos/").getPath(b), .{ var dir = try std.fs.cwd().openDir("demos/", .{
.iterate = true, .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(.render, ona.system_fn(render), .{.label = "render visuals"}).
with_system(.exit, ona.system_fn(cleanup), .{.label = "clean up visuals"}).build(); with_system(.exit, ona.system_fn(cleanup), .{.label = "clean up visuals"}).build();
fn update(visuals: ona.Write(Visuals), events: ona.Receive(hid.Event), display: ona.Read(gfx.Display)) !void { 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); update_spawned(&visuals.state.spawned_keyboards, @floatCast(app.state.delta_time));
update_spawned(&visuals.state.spawned_mouses); update_spawned(&visuals.state.spawned_mouses, @floatCast(app.state.delta_time));
const random = visuals.state.random.random(); const random = visuals.state.random.random();
const width: f32 = @floatFromInt(display.state.width); const width: f32 = @floatFromInt(display.state.width);
@ -85,11 +85,11 @@ fn update(visuals: ona.Write(Visuals), events: ona.Receive(hid.Event), display:
} }
} }
fn update_spawned(spawned: *ona.stack.Parallel(Spawned)) void { fn update_spawned(spawned: *ona.stack.Parallel(Spawned), delta_time: f32) void {
const float_speed = 6; const float_speed = 50;
for (spawned.values.slice(.transform)) |*transform| { for (spawned.values.slice(.transform)) |*transform| {
transform.* = transform.translated(.{0, -float_speed}); transform.* = transform.translated(.{0, float_speed * -delta_time});
} }
{ {
@ -99,7 +99,7 @@ fn update_spawned(spawned: *ona.stack.Parallel(Spawned)) void {
while (index < range) : (index += 1) { while (index < range) : (index += 1) {
const lifetime_seconds = spawned.values.get(.lifetime_seconds, index).?; const lifetime_seconds = spawned.values.get(.lifetime_seconds, index).?;
lifetime_seconds.* -= 1.0 / 60.0; lifetime_seconds.* -= delta_time;
if (lifetime_seconds.* <= 0) { if (lifetime_seconds.* <= 0) {
range -= 1; range -= 1;

View File

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

View File

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

View File

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