NYXEngine/src/plugins/input/system/input.zig

55 lines
2 KiB
Zig
Raw Normal View History

2026-07-28 23:30:07 +01:00
//! ----------------------------------------------------
//! ----------------------------------------------------
2026-07-29 15:56:52 +01:00
const std = @import("std");
2026-07-28 23:30:07 +01:00
const sdl = @import("sdl");
2026-07-29 15:56:52 +01:00
const sdl_glue = @import("sdl_glue");
const wgpu = @import("wgpu");
2026-07-28 23:30:07 +01:00
const App = @import("app");
2026-07-29 15:56:52 +01:00
const Window = @import("../../window/resource/window.zig");
const Resized = @import("../../window/event/resized.zig");
const WGPUInstance = @import("../../platform/resource/wgpu_instance.zig");
const WGPUDevice = @import("../../device/resource/wgpu_device.zig");
2026-07-28 23:30:07 +01:00
/// ----------------------------------------------------
/// ----------------------------------------------------
pub fn pollEvents(app: *App) !void {
2026-07-29 15:56:52 +01:00
// --- # ---
const res = try app.resources.getMany(struct {
instance: *WGPUInstance,
window: *Window,
device: *WGPUDevice,
});
2026-07-28 23:30:07 +01:00
var event: sdl.SDL_Event = undefined;
while (sdl.SDL_PollEvent(&event)) {
switch (event.type) {
sdl.SDL_EVENT_QUIT => try app.events.send(App.event.AppExit{}),
2026-07-29 15:56:52 +01:00
sdl.SDL_EVENT_WINDOW_RESIZED => {
// --- # ---
try app.events.send(Resized{
.width = @intCast(event.window.data1),
.height = @intCast(event.window.data2),
});
// --- RELEASE ---
sdl_glue.wgpuSurfaceUnconfigure(res.window.surface);
// --- CONFIGURE SURFACE ---
sdl_glue.wgpuSurfaceConfigure(
res.window.surface,
&sdl_glue.WGPUSurfaceConfiguration{
.device = @ptrCast(res.device.raw),
.format = 28, // TODO: Get format properly, idk, store it somewhere
.width = @intCast(event.window.data1),
.height = @intCast(event.window.data2),
.usage = sdl_glue.WGPUTextureUsage_RenderAttachment,
},
);
},
2026-07-28 23:30:07 +01:00
else => {},
}
}
}