Cleanup | Removed textures (for now) | Using GTL now
This commit is contained in:
parent
e7c630411b
commit
21667faac9
15 changed files with 125 additions and 343 deletions
|
|
@ -50,6 +50,12 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
exe.root_module.addImport("app", app.module("app"));
|
exe.root_module.addImport("app", app.module("app"));
|
||||||
|
|
||||||
|
const gtl = b.dependency("gtl", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
exe.root_module.addImport("gtl", gtl.module("gtl"));
|
||||||
|
|
||||||
//
|
//
|
||||||
// SYSTEM DEPENDENCIES
|
// SYSTEM DEPENDENCIES
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,12 @@
|
||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.app = .{
|
.app = .{
|
||||||
.url = "git+http://2.120.146.66:25569/abux/NYXA#93a4606c94f67b1f0a559c2efff3d8ff030b3300",
|
.url = "git+http://2.120.146.66:25569/abux/NYXA.git#4113f667319559c6bddb83c89042deb54e63b3de",
|
||||||
.hash = "app-0.0.0-AOV9_ea_AACRsUJ2lZqYiUkPed0op9qgFSWB6ihDSrll",
|
.hash = "app-0.0.0-AOV9_eK_AAA4ZmEGkvsFUM2xMTb0lYbzq4vSShMRnKZj",
|
||||||
|
},
|
||||||
|
.gtl = .{
|
||||||
|
.url = "git+http://2.120.146.66:25569/abux/GTL.git#e5cf30860977587188d810cc6524a5101312426c",
|
||||||
|
.hash = "gtl-0.0.0-e3QoJM0-AABINN7OX52K0SUL8XAqhRykEf4LTxf0wuat",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 329 B |
|
|
@ -1,9 +1,8 @@
|
||||||
const Handle = @import("app").template.Handle;
|
const Handle = @import("gtl").Handle;
|
||||||
const Texture = @import("../resource/textures.zig").Texture;
|
|
||||||
|
|
||||||
pub const Style = union(enum) {
|
pub const Style = union(enum) {
|
||||||
solid: @Vector(4, u8),
|
solid: @Vector(4, u8),
|
||||||
textured: Handle(Texture),
|
textured: Handle(undefined),
|
||||||
};
|
};
|
||||||
|
|
||||||
style: Style,
|
style: Style,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ const App = @import("app");
|
||||||
|
|
||||||
const plugin = @import("plugin/root.zig");
|
const plugin = @import("plugin/root.zig");
|
||||||
const resource = @import("resource/root.zig");
|
const resource = @import("resource/root.zig");
|
||||||
const template = @import("template/root.zig");
|
|
||||||
|
|
||||||
pub fn main(init: std.process.Init) !void {
|
pub fn main(init: std.process.Init) !void {
|
||||||
// --- APP ---
|
// --- APP ---
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ fn build(
|
||||||
) !void {
|
) !void {
|
||||||
// --- LIFETIME ---
|
// --- LIFETIME ---
|
||||||
try ctx.app.schedules.add(App.stage.init, system.core.init);
|
try ctx.app.schedules.add(App.stage.init, system.core.init);
|
||||||
try ctx.app.schedules.add(App.stage.post_init, system.core.build);
|
|
||||||
try ctx.app.schedules.add(App.stage.deinit, system.core.deinit);
|
try ctx.app.schedules.add(App.stage.deinit, system.core.deinit);
|
||||||
|
|
||||||
// --- FRAME ---
|
// --- FRAME ---
|
||||||
|
|
@ -27,11 +26,11 @@ fn build(
|
||||||
try ctx.app.schedules.add(App.stage.end_frame, system.frame.endFrame);
|
try ctx.app.schedules.add(App.stage.end_frame, system.frame.endFrame);
|
||||||
|
|
||||||
// --- UPDATE ---
|
// --- UPDATE ---
|
||||||
try ctx.app.schedules.add(App.stage.inputs, system.frame.inputs);
|
try ctx.app.schedules.add(App.stage.inputs, system.inputs.pollEvents);
|
||||||
try ctx.app.schedules.addMany(App.stage.update, &.{
|
try ctx.app.schedules.addMany(App.stage.update, &.{
|
||||||
system.frame.updateTimers,
|
system.frame.updateTimers,
|
||||||
system.frame.updateTransforms,
|
system.frame.updateTransforms,
|
||||||
system.frame.cast,
|
system.frame.cast,
|
||||||
});
|
});
|
||||||
try ctx.app.schedules.add(App.stage.draw, system.frame.draw);
|
try ctx.app.schedules.add(App.stage.draw, system.draw.draw);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,3 @@ pub const Window = @import("window.zig");
|
||||||
pub const Renderer = @import("renderer.zig");
|
pub const Renderer = @import("renderer.zig");
|
||||||
pub const Frame = @import("frame.zig");
|
pub const Frame = @import("frame.zig");
|
||||||
pub const Time = @import("time.zig");
|
pub const Time = @import("time.zig");
|
||||||
|
|
||||||
// --- ASSETS ---
|
|
||||||
pub const Textures = @import("textures.zig");
|
|
||||||
|
|
|
||||||
|
|
@ -1,132 +0,0 @@
|
||||||
const std = @import("std");
|
|
||||||
const sdl = @import("sdl");
|
|
||||||
const Renderer = @import("../resource/renderer.zig");
|
|
||||||
const Handle = @import("app").template.Handle;
|
|
||||||
const Storage = @import("../template/storage.zig").Storage;
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub const Size = union(enum) {
|
|
||||||
source,
|
|
||||||
fixed: [2]u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub const Filter = enum {
|
|
||||||
linear,
|
|
||||||
nearest,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub const Texture = struct {
|
|
||||||
path: []const u8,
|
|
||||||
size: [2]u32 = .{ 0, 0 },
|
|
||||||
filter: Filter = .nearest,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub const GPUTexture = struct {
|
|
||||||
raw: *sdl.SDL_Texture,
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// FIELDS
|
|
||||||
//
|
|
||||||
|
|
||||||
textures: Storage(Texture, GPUTexture),
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn init(alloc: std.mem.Allocator) Self {
|
|
||||||
return .{
|
|
||||||
.textures = .init(alloc),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn deinit(self: *Self) void {
|
|
||||||
self.textures.deinit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn load(
|
|
||||||
self: *Self,
|
|
||||||
name: []const u8,
|
|
||||||
path: []const u8,
|
|
||||||
) !Handle(Texture) {
|
|
||||||
return try self.textures.put(name, .{
|
|
||||||
.path = path,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn get(
|
|
||||||
self: *Self,
|
|
||||||
value: Handle(Texture),
|
|
||||||
) ?*GPUTexture {
|
|
||||||
const record = self.textures.get(value) orelse return null;
|
|
||||||
return if (record.gpu) |*v| v else null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn build(
|
|
||||||
self: *Self,
|
|
||||||
renderer: *const Renderer,
|
|
||||||
) !void {
|
|
||||||
for (self.textures.items()) |*record| {
|
|
||||||
// --- SKIP IF BUILD ---
|
|
||||||
if (record.gpu != null) continue;
|
|
||||||
|
|
||||||
// --- LOAD SURFACE ---
|
|
||||||
const surface = sdl.IMG_Load(
|
|
||||||
record.cpu.path.ptr,
|
|
||||||
) orelse {
|
|
||||||
std.debug.print("\x1b[31mFailed to load texture:\x1b[0m {s}\n", .{sdl.SDL_GetError()});
|
|
||||||
return error.Texture;
|
|
||||||
};
|
|
||||||
defer sdl.SDL_DestroySurface(surface);
|
|
||||||
|
|
||||||
// --- CREATE TEXTURE ---
|
|
||||||
const texture = sdl.SDL_CreateTextureFromSurface(
|
|
||||||
renderer.raw,
|
|
||||||
surface,
|
|
||||||
) orelse return error.Texture;
|
|
||||||
|
|
||||||
// --- SET FILTER ---
|
|
||||||
_ = sdl.SDL_SetTextureScaleMode(texture, switch (record.cpu.filter) {
|
|
||||||
.linear => sdl.SDL_SCALEMODE_LINEAR,
|
|
||||||
.nearest => sdl.SDL_SCALEMODE_PIXELART,
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- ASSIGN CPU ---
|
|
||||||
record.cpu.size = .{
|
|
||||||
@intCast(surface.*.w),
|
|
||||||
@intCast(surface.*.h),
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- ASSIGN GPU ---
|
|
||||||
record.gpu = .{
|
|
||||||
.raw = texture,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- DEBUG ---
|
|
||||||
var it = self.textures.lookup.iterator();
|
|
||||||
while (it.next()) |entry| {
|
|
||||||
const record = self.textures.get(entry.key_ptr.*) orelse continue;
|
|
||||||
|
|
||||||
std.debug.print("\x1b[35m┏━ TEXTURE\n", .{});
|
|
||||||
std.debug.print("\x1b[35m┃\x1b[0m Name: \"{s}\"\n", .{entry.value_ptr.*});
|
|
||||||
std.debug.print("\x1b[35m┃\x1b[0m Path: \"{s}\"\n", .{record.cpu.path});
|
|
||||||
std.debug.print("\x1b[35m┃\x1b[0m Size: {}x{}\n", .{ record.cpu.size[0], record.cpu.size[1] });
|
|
||||||
std.debug.print("\x1b[35m┗━\x1b[0m\n", .{});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -39,9 +39,6 @@ pub fn init(ctx: App.scheduler.Context) !void {
|
||||||
});
|
});
|
||||||
try ctx.app.resources.set(resource.Frame{});
|
try ctx.app.resources.set(resource.Frame{});
|
||||||
|
|
||||||
// --- ASSETS ---
|
|
||||||
const textures = try ctx.app.resources.getOrSet(resource.Textures.init(ctx.app.alloc));
|
|
||||||
|
|
||||||
// --- DEBUG ---
|
// --- DEBUG ---
|
||||||
std.debug.print("\x1b[35m┏━ WINDOW\n", .{});
|
std.debug.print("\x1b[35m┏━ WINDOW\n", .{});
|
||||||
std.debug.print("\x1b[35m┃\x1b[0m Title: \"{s}\"\n", .{window.title});
|
std.debug.print("\x1b[35m┃\x1b[0m Title: \"{s}\"\n", .{window.title});
|
||||||
|
|
@ -62,9 +59,9 @@ pub fn init(ctx: App.scheduler.Context) !void {
|
||||||
|
|
||||||
component.Friction{},
|
component.Friction{},
|
||||||
component.Velocity{},
|
component.Velocity{},
|
||||||
component.Transform{ .size = .{ 200, 200 } },
|
component.Transform{ .size = .{ 64, 64 } },
|
||||||
component.Material{ .style = .{
|
component.Material{ .style = .{
|
||||||
.textured = try textures.load("Player", "src/assets/textures/player.png"),
|
.solid = .{ 200, 20, 20, 255 },
|
||||||
} },
|
} },
|
||||||
component.CameraTarget{},
|
component.CameraTarget{},
|
||||||
});
|
});
|
||||||
|
|
@ -84,24 +81,9 @@ pub fn deinit(ctx: App.scheduler.Context) !void {
|
||||||
const res = try ctx.app.resources.getMany(struct {
|
const res = try ctx.app.resources.getMany(struct {
|
||||||
window: *resource.Window,
|
window: *resource.Window,
|
||||||
renderer: *resource.Renderer,
|
renderer: *resource.Renderer,
|
||||||
textures: *resource.Textures,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.textures.deinit();
|
|
||||||
sdl.SDL_DestroyRenderer(res.renderer.raw);
|
sdl.SDL_DestroyRenderer(res.renderer.raw);
|
||||||
sdl.SDL_DestroyWindow(res.window.raw);
|
sdl.SDL_DestroyWindow(res.window.raw);
|
||||||
sdl.SDL_Quit();
|
sdl.SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn build(ctx: App.scheduler.Context) !void {
|
|
||||||
const res = try ctx.app.resources.getMany(struct {
|
|
||||||
renderer: *resource.Renderer,
|
|
||||||
textures: *resource.Textures,
|
|
||||||
});
|
|
||||||
|
|
||||||
try res.textures.build(
|
|
||||||
res.renderer,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
66
src/system/draw.zig
Normal file
66
src/system/draw.zig
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const sdl = @import("sdl");
|
||||||
|
const App = @import("app");
|
||||||
|
|
||||||
|
const component = @import("../component/root.zig");
|
||||||
|
const resource = @import("../resource/root.zig");
|
||||||
|
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
pub fn draw(ctx: App.scheduler.Context) !void {
|
||||||
|
const res = try ctx.app.resources.getMany(struct {
|
||||||
|
window: *resource.Window,
|
||||||
|
renderer: *resource.Renderer,
|
||||||
|
frame: *resource.Frame,
|
||||||
|
});
|
||||||
|
|
||||||
|
// --- SET CLEAR COLOR ---
|
||||||
|
_ = sdl.SDL_SetRenderDrawColor(
|
||||||
|
res.renderer.raw,
|
||||||
|
10,
|
||||||
|
10,
|
||||||
|
10,
|
||||||
|
255,
|
||||||
|
);
|
||||||
|
|
||||||
|
// --- DRAW ---
|
||||||
|
_ = sdl.SDL_RenderClear(res.renderer.raw);
|
||||||
|
defer _ = sdl.SDL_RenderPresent(res.renderer.raw);
|
||||||
|
|
||||||
|
{ // DRAW
|
||||||
|
var query = ctx.app.world.query(struct {
|
||||||
|
transform: *component.Transform,
|
||||||
|
material: *component.Material,
|
||||||
|
camera_target: ?*component.CameraTarget,
|
||||||
|
}, .{});
|
||||||
|
while (query.next()) |e| {
|
||||||
|
const camera = if (res.frame.camera) |*v| v else continue;
|
||||||
|
|
||||||
|
// --- SHAPE ---
|
||||||
|
var rect: sdl.SDL_FRect = .{
|
||||||
|
.x = e.transform.pos[0] + camera.transform.pos[0],
|
||||||
|
.y = e.transform.pos[1] + camera.transform.pos[1],
|
||||||
|
.w = e.transform.size[0],
|
||||||
|
.h = e.transform.size[1],
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- MATERIAL ---
|
||||||
|
switch (e.material.style) {
|
||||||
|
.solid => |albedo| {
|
||||||
|
_ = sdl.SDL_SetRenderDrawColor(res.renderer.raw, albedo[0], albedo[1], albedo[2], albedo[3]);
|
||||||
|
_ = sdl.SDL_RenderFillRect(res.renderer.raw, &rect);
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
|
// .textured => |handle| {
|
||||||
|
// const gpu = res.textures.get(handle) orelse continue;
|
||||||
|
// _ = sdl.SDL_RenderTexture(
|
||||||
|
// res.renderer.raw,
|
||||||
|
// gpu.raw,
|
||||||
|
// null,
|
||||||
|
// &rect,
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,39 +5,6 @@ const App = @import("app");
|
||||||
const component = @import("../component/root.zig");
|
const component = @import("../component/root.zig");
|
||||||
const resource = @import("../resource/root.zig");
|
const resource = @import("../resource/root.zig");
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn inputs(ctx: App.scheduler.Context) !void {
|
|
||||||
const res = try ctx.app.resources.getMany(struct {
|
|
||||||
window: *resource.Window,
|
|
||||||
renderer: *resource.Renderer,
|
|
||||||
});
|
|
||||||
_ = res;
|
|
||||||
|
|
||||||
// --- POLL EVENTS ---
|
|
||||||
var raw_event: sdl.SDL_Event = undefined;
|
|
||||||
while (sdl.SDL_PollEvent(&raw_event)) {
|
|
||||||
switch (raw_event.type) {
|
|
||||||
sdl.SDL_EVENT_QUIT => try ctx.app.events.send(App.event.AppExit{}),
|
|
||||||
else => {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const keyboard: [*c]const bool = sdl.SDL_GetKeyboardState(null);
|
|
||||||
|
|
||||||
var query = ctx.app.world.query(struct {
|
|
||||||
player: *component.Player,
|
|
||||||
velocity: *component.Velocity,
|
|
||||||
}, .{});
|
|
||||||
while (query.next()) |e| {
|
|
||||||
const speed: f32 = 100.0;
|
|
||||||
if (keyboard[sdl.SDL_SCANCODE_W]) e.velocity.value[1] = -speed;
|
|
||||||
if (keyboard[sdl.SDL_SCANCODE_S]) e.velocity.value[1] = speed;
|
|
||||||
if (keyboard[sdl.SDL_SCANCODE_A]) e.velocity.value[0] = -speed;
|
|
||||||
if (keyboard[sdl.SDL_SCANCODE_D]) e.velocity.value[0] = speed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn beginFrame(ctx: App.scheduler.Context) !void {
|
pub fn beginFrame(ctx: App.scheduler.Context) !void {
|
||||||
|
|
@ -215,63 +182,3 @@ pub fn cast(ctx: App.scheduler.Context) !void {
|
||||||
e.caster.cooldown;
|
e.caster.cooldown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn draw(ctx: App.scheduler.Context) !void {
|
|
||||||
const res = try ctx.app.resources.getMany(struct {
|
|
||||||
window: *resource.Window,
|
|
||||||
renderer: *resource.Renderer,
|
|
||||||
textures: *resource.Textures,
|
|
||||||
frame: *resource.Frame,
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- SET CLEAR COLOR ---
|
|
||||||
_ = sdl.SDL_SetRenderDrawColor(
|
|
||||||
res.renderer.raw,
|
|
||||||
10,
|
|
||||||
10,
|
|
||||||
10,
|
|
||||||
255,
|
|
||||||
);
|
|
||||||
|
|
||||||
// --- DRAW ---
|
|
||||||
_ = sdl.SDL_RenderClear(res.renderer.raw);
|
|
||||||
defer _ = sdl.SDL_RenderPresent(res.renderer.raw);
|
|
||||||
|
|
||||||
{ // DRAW
|
|
||||||
var query = ctx.app.world.query(struct {
|
|
||||||
transform: *component.Transform,
|
|
||||||
material: *component.Material,
|
|
||||||
camera_target: ?*component.CameraTarget,
|
|
||||||
}, .{});
|
|
||||||
while (query.next()) |e| {
|
|
||||||
const camera = if (res.frame.camera) |*v| v else continue;
|
|
||||||
|
|
||||||
// --- SHAPE ---
|
|
||||||
var rect: sdl.SDL_FRect = .{
|
|
||||||
.x = e.transform.pos[0] + camera.transform.pos[0],
|
|
||||||
.y = e.transform.pos[1] + camera.transform.pos[1],
|
|
||||||
.w = e.transform.size[0],
|
|
||||||
.h = e.transform.size[1],
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- MATERIAL ---
|
|
||||||
switch (e.material.style) {
|
|
||||||
.solid => |albedo| {
|
|
||||||
_ = sdl.SDL_SetRenderDrawColor(res.renderer.raw, albedo[0], albedo[1], albedo[2], albedo[3]);
|
|
||||||
_ = sdl.SDL_RenderFillRect(res.renderer.raw, &rect);
|
|
||||||
},
|
|
||||||
.textured => |handle| {
|
|
||||||
const gpu = res.textures.get(handle) orelse continue;
|
|
||||||
_ = sdl.SDL_RenderTexture(
|
|
||||||
res.renderer.raw,
|
|
||||||
gpu.raw,
|
|
||||||
null,
|
|
||||||
&rect,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
39
src/system/inputs.zig
Normal file
39
src/system/inputs.zig
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const sdl = @import("sdl");
|
||||||
|
const App = @import("app");
|
||||||
|
|
||||||
|
const component = @import("../component/root.zig");
|
||||||
|
const resource = @import("../resource/root.zig");
|
||||||
|
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
/// ----------------------------------------------------
|
||||||
|
pub fn pollEvents(ctx: App.scheduler.Context) !void {
|
||||||
|
const res = try ctx.app.resources.getMany(struct {
|
||||||
|
window: *resource.Window,
|
||||||
|
renderer: *resource.Renderer,
|
||||||
|
});
|
||||||
|
_ = res;
|
||||||
|
|
||||||
|
// --- POLL EVENTS ---
|
||||||
|
var raw_event: sdl.SDL_Event = undefined;
|
||||||
|
while (sdl.SDL_PollEvent(&raw_event)) {
|
||||||
|
switch (raw_event.type) {
|
||||||
|
sdl.SDL_EVENT_QUIT => try ctx.app.events.send(App.event.AppExit{}),
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const keyboard: [*c]const bool = sdl.SDL_GetKeyboardState(null);
|
||||||
|
|
||||||
|
var query = ctx.app.world.query(struct {
|
||||||
|
player: *component.Player,
|
||||||
|
velocity: *component.Velocity,
|
||||||
|
}, .{});
|
||||||
|
while (query.next()) |e| {
|
||||||
|
const speed: f32 = 100.0;
|
||||||
|
if (keyboard[sdl.SDL_SCANCODE_W]) e.velocity.value[1] = -speed;
|
||||||
|
if (keyboard[sdl.SDL_SCANCODE_S]) e.velocity.value[1] = speed;
|
||||||
|
if (keyboard[sdl.SDL_SCANCODE_A]) e.velocity.value[0] = -speed;
|
||||||
|
if (keyboard[sdl.SDL_SCANCODE_D]) e.velocity.value[0] = speed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,2 +1,4 @@
|
||||||
pub const core = @import("core.zig");
|
pub const core = @import("core.zig");
|
||||||
pub const frame = @import("frame.zig");
|
pub const frame = @import("frame.zig");
|
||||||
|
pub const inputs = @import("inputs.zig");
|
||||||
|
pub const draw = @import("draw.zig");
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
pub const Storage = @import("storage.zig").Storage;
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
const std = @import("std");
|
|
||||||
const App = @import("app");
|
|
||||||
const Handle = App.template.Handle;
|
|
||||||
|
|
||||||
pub fn Storage(
|
|
||||||
comptime CPU: type,
|
|
||||||
comptime GPU: type,
|
|
||||||
) type {
|
|
||||||
return struct {
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub const Record = struct {
|
|
||||||
cpu: CPU,
|
|
||||||
gpu: ?GPU = null,
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// FIELDS
|
|
||||||
//
|
|
||||||
|
|
||||||
data: std.ArrayList(Record),
|
|
||||||
lookup: std.AutoHashMap(Handle(CPU), []const u8),
|
|
||||||
alloc: std.mem.Allocator,
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn init(alloc: std.mem.Allocator) Self {
|
|
||||||
return .{
|
|
||||||
.data = .empty,
|
|
||||||
.lookup = .init(alloc),
|
|
||||||
.alloc = alloc,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn deinit(self: *Self) void {
|
|
||||||
self.data.deinit(self.alloc);
|
|
||||||
self.lookup.deinit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn put(
|
|
||||||
self: *Self,
|
|
||||||
name: []const u8,
|
|
||||||
value: CPU,
|
|
||||||
) !Handle(CPU) {
|
|
||||||
// --- HANDLE ---
|
|
||||||
const handle: Handle(CPU) = .{
|
|
||||||
.idx = @intCast(self.data.items.len),
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- ADD DATA ---
|
|
||||||
try self.data.append(self.alloc, .{ .cpu = value });
|
|
||||||
errdefer _ = self.data.swapRemove(self.data.items.len - 1);
|
|
||||||
|
|
||||||
// --- ADD LOOKUP ---
|
|
||||||
try self.lookup.put(
|
|
||||||
handle,
|
|
||||||
name,
|
|
||||||
);
|
|
||||||
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn get(
|
|
||||||
self: *Self,
|
|
||||||
handle: Handle(CPU),
|
|
||||||
) ?*Record {
|
|
||||||
if (!self.lookup.contains(handle)) return null;
|
|
||||||
return &self.data.items[@intCast(handle.idx)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
/// ----------------------------------------------------
|
|
||||||
pub fn items(self: *Self) []Record {
|
|
||||||
return self.data.items;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue