Compare commits
3 Commits
db0e08d530
...
165c3fe071
Author | SHA1 | Date |
---|---|---|
kayomn | 165c3fe071 | |
kayomn | 5674867adf | |
kayomn | 3d4e6bb44b |
|
@ -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("demos/", .{
|
var dir = try std.fs.cwd().openDir(b.path("demos/").getPath(b), .{
|
||||||
.iterate = true,
|
.iterate = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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), app: ona.Read(ona.App), events: ona.Receive(hid.Event), display: ona.Read(gfx.Display)) !void {
|
fn update(visuals: ona.Write(Visuals), 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_keyboards);
|
||||||
update_spawned(&visuals.state.spawned_mouses, @floatCast(app.state.delta_time));
|
update_spawned(&visuals.state.spawned_mouses);
|
||||||
|
|
||||||
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), app: ona.Read(ona.App), events: ona.Recei
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_spawned(spawned: *ona.stack.Parallel(Spawned), delta_time: f32) void {
|
fn update_spawned(spawned: *ona.stack.Parallel(Spawned)) void {
|
||||||
const float_speed = 50;
|
const float_speed = 6;
|
||||||
|
|
||||||
for (spawned.values.slice(.transform)) |*transform| {
|
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) {
|
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.* -= delta_time;
|
lifetime_seconds.* -= 1.0 / 60.0;
|
||||||
|
|
||||||
if (lifetime_seconds.* <= 0) {
|
if (lifetime_seconds.* <= 0) {
|
||||||
range -= 1;
|
range -= 1;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@ 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};
|
||||||
}
|
}
|
||||||
|
@ -11,3 +9,5 @@ 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);
|
||||||
|
|
|
@ -32,7 +32,6 @@ 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 {
|
||||||
|
@ -115,7 +114,6 @@ 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,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -129,11 +127,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 += app.delta_time;
|
accumulated_time += delta_time;
|
||||||
|
|
||||||
try world.run_event(events.pre_update);
|
try world.run_event(events.pre_update);
|
||||||
|
|
||||||
|
@ -911,6 +909,14 @@ 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 {
|
||||||
|
@ -922,11 +928,3 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue