feat: add support for RG35XX Plus/H
- Use linux EGL backend for rendering - Use linux evdev backend for input - Use seizer's new ButtonInput abstractionci-dev
parent
b199c7d52e
commit
4a6e419213
|
@ -16,8 +16,8 @@
|
|||
// internet connectivity.
|
||||
.dependencies = .{
|
||||
.seizer = .{
|
||||
.url = "https://github.com/leroycep/seizer/archive/ec651ce18e423a8fdda3b1a3369d9121c45d96f0.tar.gz",
|
||||
.hash = "122028487862f2462ba02191adbc6676b621b37fa05e0962f0a5990d4079ed34140e",
|
||||
.url = "https://github.com/leroycep/seizer/archive/d425db26fbbf5a99faa70ea07fb7d2b028f690d1.tar.gz",
|
||||
.hash = "1220250791e125cf4d342020eb3af65c36a8b971559ae9ffafc187c0cb116ee3d6e2",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
|
|
127
src/main.zig
127
src/main.zig
|
@ -23,7 +23,7 @@ pub fn init(context: *seizer.Context) !void {
|
|||
gpa = context.gpa;
|
||||
prng = std.rand.DefaultPrng.init(@bitCast(std.time.timestamp()));
|
||||
|
||||
const window = try context.createWindow(.{
|
||||
_ = try context.createWindow(.{
|
||||
.title = "Seizer Solitaire",
|
||||
.on_render = render,
|
||||
.on_destroy = destroy,
|
||||
|
@ -44,41 +44,36 @@ pub fn init(context: *seizer.Context) !void {
|
|||
}
|
||||
}
|
||||
|
||||
// update joystick to gamepad mappings
|
||||
update_gamepad_mappings_file: {
|
||||
const sdl_controller_config_filepath = std.process.getEnvVarOwned(gpa, "SDL_GAMECONTROLLERCONFIG_FILE") catch break :update_gamepad_mappings_file;
|
||||
defer gpa.free(sdl_controller_config_filepath);
|
||||
|
||||
std.log.debug("Loading gamepad mappings from file: \"{}\"", .{std.zig.fmtEscapes(sdl_controller_config_filepath)});
|
||||
|
||||
const controller_config_data = std.fs.cwd().readFileAllocOptions(
|
||||
gpa,
|
||||
sdl_controller_config_filepath,
|
||||
512 * 1024 * 1024,
|
||||
null,
|
||||
@alignOf(u8),
|
||||
0,
|
||||
) catch break :update_gamepad_mappings_file;
|
||||
defer gpa.free(controller_config_data);
|
||||
|
||||
if (!seizer.backend.glfw.Joystick.updateGamepadMappings(controller_config_data)) {
|
||||
std.log.warn("Failed to update gamepad mappings from file", .{});
|
||||
}
|
||||
}
|
||||
update_gamepad_mappings: {
|
||||
const sdl_controller_config = std.process.getEnvVarOwned(gpa, "SDL_GAMECONTROLLERCONFIG") catch break :update_gamepad_mappings;
|
||||
defer gpa.free(sdl_controller_config);
|
||||
|
||||
std.log.debug("Loading gamepad mappings from environment variable", .{});
|
||||
|
||||
const sdl_controller_configz = gpa.dupeZ(u8, sdl_controller_config) catch break :update_gamepad_mappings;
|
||||
|
||||
if (!seizer.backend.glfw.Joystick.updateGamepadMappings(sdl_controller_configz)) {
|
||||
std.log.warn("Failed to update gamepad mappings from environment variable", .{});
|
||||
}
|
||||
}
|
||||
|
||||
window.glfw_window.setKeyCallback(key_input_callback);
|
||||
try context.addButtonInput(.{
|
||||
.title = "move_up",
|
||||
.on_event = moveUp,
|
||||
.default_bindings = &.{.dpad_up},
|
||||
});
|
||||
try context.addButtonInput(.{
|
||||
.title = "move_down",
|
||||
.on_event = moveDown,
|
||||
.default_bindings = &.{.dpad_down},
|
||||
});
|
||||
try context.addButtonInput(.{
|
||||
.title = "move_left",
|
||||
.on_event = moveLeft,
|
||||
.default_bindings = &.{.dpad_left},
|
||||
});
|
||||
try context.addButtonInput(.{
|
||||
.title = "move_right",
|
||||
.on_event = moveRight,
|
||||
.default_bindings = &.{.dpad_right},
|
||||
});
|
||||
try context.addButtonInput(.{
|
||||
.title = "select_or_place",
|
||||
.on_event = doSelectOrPlace,
|
||||
.default_bindings = &.{.a},
|
||||
});
|
||||
try context.addButtonInput(.{
|
||||
.title = "deselect",
|
||||
.on_event = deselect,
|
||||
.default_bindings = &.{.b},
|
||||
});
|
||||
}
|
||||
|
||||
fn destroy(window: *seizer.Window) void {
|
||||
|
@ -100,17 +95,6 @@ fn destroy(window: *seizer.Window) void {
|
|||
}
|
||||
|
||||
fn render(window: *seizer.Window) !void {
|
||||
for (1..@intFromEnum(seizer.backend.glfw.Joystick.Id.last)) |i| {
|
||||
const joystick = seizer.backend.glfw.Joystick{ .jid = @enumFromInt(i) };
|
||||
if (joystick.getGamepadState()) |gamepad| {
|
||||
if (gamepad.getButton(.a) == .press) doSelectOrPlace();
|
||||
if (gamepad.getButton(.dpad_left) == .press) moveLeft();
|
||||
if (gamepad.getButton(.dpad_right) == .press) moveRight();
|
||||
if (gamepad.getButton(.dpad_up) == .press) moveUp();
|
||||
if (gamepad.getButton(.dpad_down) == .press) moveDown();
|
||||
}
|
||||
}
|
||||
|
||||
gl.clearColor(0.2, 0.4, 0.2, 1.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
|
||||
|
@ -228,14 +212,6 @@ fn render(window: *seizer.Window) !void {
|
|||
}
|
||||
}
|
||||
|
||||
var text_writer = canvas.textWriter(.{});
|
||||
for (1..@intFromEnum(seizer.backend.glfw.Joystick.Id.last)) |i| {
|
||||
const joystick = seizer.backend.glfw.Joystick{ .jid = @enumFromInt(i) };
|
||||
if (joystick.getName()) |name| {
|
||||
text_writer.writer().print("connected_controller[{}] = {s}\n", .{ i, name }) catch {};
|
||||
}
|
||||
}
|
||||
|
||||
canvas.end();
|
||||
}
|
||||
|
||||
|
@ -257,30 +233,14 @@ pub fn makeStandardDeck(allocator: std.mem.Allocator) ![]Card {
|
|||
return deck;
|
||||
}
|
||||
|
||||
pub fn key_input_callback(
|
||||
window: seizer.backend.glfw.Window,
|
||||
key: seizer.backend.glfw.Key,
|
||||
scancode: i32,
|
||||
action: seizer.backend.glfw.Action,
|
||||
mods: seizer.backend.glfw.Mods,
|
||||
) void {
|
||||
_ = window;
|
||||
_ = scancode;
|
||||
_ = mods;
|
||||
switch (action) {
|
||||
.press => switch (key) {
|
||||
.z => doSelectOrPlace(),
|
||||
.left => moveLeft(),
|
||||
.right => moveRight(),
|
||||
.down => moveDown(),
|
||||
.up => moveUp(),
|
||||
else => {},
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
pub fn deselect(pressed: bool) !void {
|
||||
if (!pressed) return;
|
||||
selected_deck = null;
|
||||
selected_card = 0;
|
||||
}
|
||||
|
||||
pub fn doSelectOrPlace() void {
|
||||
pub fn doSelectOrPlace(pressed: bool) !void {
|
||||
if (!pressed) return;
|
||||
if (selected_deck == null) {
|
||||
if (hovered_deck == &draw_pile and !draw_pile_exhausted) {
|
||||
drawn_cards.ensureUnusedCapacity(gpa, 3) catch return;
|
||||
|
@ -384,7 +344,8 @@ pub fn doSelectOrPlace() void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn moveLeft() void {
|
||||
pub fn moveLeft(pressed: bool) !void {
|
||||
if (!pressed) return;
|
||||
if (hovered_deck == null) {
|
||||
hovered_deck = &draw_pile;
|
||||
hovered_card = 0;
|
||||
|
@ -415,7 +376,8 @@ pub fn moveLeft() void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn moveRight() void {
|
||||
pub fn moveRight(pressed: bool) !void {
|
||||
if (!pressed) return;
|
||||
if (hovered_deck == null) {
|
||||
hovered_deck = &draw_pile;
|
||||
hovered_card = 0;
|
||||
|
@ -446,7 +408,9 @@ pub fn moveRight() void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn moveUp() void {
|
||||
pub fn moveUp(pressed: bool) !void {
|
||||
if (!pressed) return;
|
||||
|
||||
if (hovered_deck == null) {
|
||||
hovered_deck = &draw_pile;
|
||||
hovered_card = 0;
|
||||
|
@ -486,7 +450,8 @@ pub fn moveUp() void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn moveDown() void {
|
||||
pub fn moveDown(pressed: bool) !void {
|
||||
if (!pressed) return;
|
||||
if (hovered_deck == null) {
|
||||
hovered_deck = &draw_pile;
|
||||
hovered_card = 0;
|
||||
|
|
Loading…
Reference in New Issue