all: move standalone libraries to libs/ subdirectory
The root dir of our repository has grown quite a lot the past few months.
I'd like to make it more clear where the bulk of the engine lives (`src/`) and
also make it more clear which Mach libraries are consumable as standalone projects.
As for the name of this directory, `libs` was my first choice but there's a bit of
a convention of that being external libraries in Zig projects _today_, while these
are libraries maintained as part of Mach in this repository - not external ones.
We will name this directory `libs`, and if we have a need for external libraries
we will use `external` or `deps` for that directory name. I considered other names
such as `components`, `systems`, `modules` (which are bad as they overlap with
major ECS / engine concepts), and it seems likely the official Zig package manager
will break the convention of using a `libs` dir anyway.
Performed via:
```sh
mkdir libs/
git mv freetype libs/
git mv basisu libs/
git mv gamemode libs/
git mv glfw libs/
git mv gpu libs/
git mv gpu-dawn libs/
git mv sysaudio libs/
git mv sysjs libs/
git mv ecs libs/
```
git-subtree-dir: glfw
git-subtree-mainline: 0d5b853443
git-subtree-split: 572d1144f11b353abdb64fff828b25a4f0fbb7ca
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
git mv ecs libs/
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
79ec61396f
commit
0645429df9
240 changed files with 6 additions and 6 deletions
167
libs/glfw/src/mod.zig
Normal file
167
libs/glfw/src/mod.zig
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
//! Modifier key flags
|
||||
//!
|
||||
//! See glfw.setKeyCallback for how these are used.
|
||||
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
// must be in sync with GLFW C constants in modifier group, search for "@defgroup mods Modifier key flags"
|
||||
/// A bitmask of all key modifiers
|
||||
pub const Mods = packed struct {
|
||||
shift: bool = false,
|
||||
control: bool = false,
|
||||
alt: bool = false,
|
||||
super: bool = false,
|
||||
caps_lock: bool = false,
|
||||
num_lock: bool = false,
|
||||
_reserved: u2 = 0,
|
||||
|
||||
inline fn verifyIntType(comptime IntType: type) void {
|
||||
comptime {
|
||||
switch (@typeInfo(IntType)) {
|
||||
.Int => {},
|
||||
else => @compileError("Int was not of int type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub inline fn toInt(self: Mods, comptime IntType: type) IntType {
|
||||
verifyIntType(IntType);
|
||||
return @intCast(IntType, @bitCast(u8, self));
|
||||
}
|
||||
|
||||
pub inline fn fromInt(flags: anytype) Mods {
|
||||
verifyIntType(@TypeOf(flags));
|
||||
return @bitCast(Mods, @intCast(u8, flags));
|
||||
}
|
||||
};
|
||||
|
||||
/// Holds all GLFW mod values in their raw form.
|
||||
pub const RawMods = struct {
|
||||
/// If this bit is set one or more Shift keys were held down.
|
||||
pub const shift = c.GLFW_MOD_SHIFT;
|
||||
|
||||
/// If this bit is set one or more Control keys were held down.
|
||||
pub const control = c.GLFW_MOD_CONTROL;
|
||||
|
||||
/// If this bit is set one or more Alt keys were held down.
|
||||
pub const alt = c.GLFW_MOD_ALT;
|
||||
|
||||
/// If this bit is set one or more Super keys were held down.
|
||||
pub const super = c.GLFW_MOD_SUPER;
|
||||
|
||||
/// If this bit is set the Caps Lock key is enabled and the glfw.lock_key_mods input mode is set.
|
||||
pub const caps_lock = c.GLFW_MOD_CAPS_LOCK;
|
||||
|
||||
/// If this bit is set the Num Lock key is enabled and the glfw.lock_key_mods input mode is set.
|
||||
pub const num_lock = c.GLFW_MOD_NUM_LOCK;
|
||||
};
|
||||
|
||||
test "shift int to bitmask" {
|
||||
const std = @import("std");
|
||||
|
||||
const int_mod = RawMods.shift;
|
||||
const mod = Mods.fromInt(int_mod);
|
||||
|
||||
try std.testing.expect(mod.shift == true);
|
||||
try std.testing.expect(mod.control == false);
|
||||
try std.testing.expect(mod.alt == false);
|
||||
try std.testing.expect(mod.super == false);
|
||||
try std.testing.expect(mod.caps_lock == false);
|
||||
try std.testing.expect(mod.num_lock == false);
|
||||
}
|
||||
|
||||
test "shift int and alt to bitmask" {
|
||||
const std = @import("std");
|
||||
|
||||
const int_mod = RawMods.shift | RawMods.alt;
|
||||
const mod = Mods.fromInt(int_mod);
|
||||
|
||||
try std.testing.expect(mod.shift == true);
|
||||
try std.testing.expect(mod.control == false);
|
||||
try std.testing.expect(mod.alt == true);
|
||||
try std.testing.expect(mod.super == false);
|
||||
try std.testing.expect(mod.caps_lock == false);
|
||||
try std.testing.expect(mod.num_lock == false);
|
||||
}
|
||||
|
||||
test "super int to bitmask" {
|
||||
const std = @import("std");
|
||||
|
||||
const int_mod = RawMods.super;
|
||||
const mod = Mods.fromInt(int_mod);
|
||||
|
||||
try std.testing.expect(mod.shift == false);
|
||||
try std.testing.expect(mod.control == false);
|
||||
try std.testing.expect(mod.alt == false);
|
||||
try std.testing.expect(mod.super == true);
|
||||
try std.testing.expect(mod.caps_lock == false);
|
||||
try std.testing.expect(mod.num_lock == false);
|
||||
}
|
||||
|
||||
test "num lock int to bitmask" {
|
||||
const std = @import("std");
|
||||
|
||||
const int_mod = RawMods.num_lock;
|
||||
const mod = Mods.fromInt(int_mod);
|
||||
|
||||
try std.testing.expect(mod.shift == false);
|
||||
try std.testing.expect(mod.control == false);
|
||||
try std.testing.expect(mod.alt == false);
|
||||
try std.testing.expect(mod.super == false);
|
||||
try std.testing.expect(mod.caps_lock == false);
|
||||
try std.testing.expect(mod.num_lock == true);
|
||||
}
|
||||
|
||||
test "all int to bitmask" {
|
||||
const std = @import("std");
|
||||
|
||||
const int_mod = RawMods.shift | RawMods.control |
|
||||
RawMods.alt | RawMods.super |
|
||||
RawMods.caps_lock | RawMods.num_lock;
|
||||
const mod = Mods.fromInt(int_mod);
|
||||
|
||||
try std.testing.expect(mod.shift == true);
|
||||
try std.testing.expect(mod.control == true);
|
||||
try std.testing.expect(mod.alt == true);
|
||||
try std.testing.expect(mod.super == true);
|
||||
try std.testing.expect(mod.caps_lock == true);
|
||||
try std.testing.expect(mod.num_lock == true);
|
||||
}
|
||||
|
||||
test "shift bitmask to int" {
|
||||
const std = @import("std");
|
||||
|
||||
const mod = Mods{ .shift = true };
|
||||
const int_mod = mod.toInt(c_int);
|
||||
|
||||
try std.testing.expectEqual(int_mod, RawMods.shift);
|
||||
}
|
||||
|
||||
test "shift and alt bitmask to int" {
|
||||
const std = @import("std");
|
||||
|
||||
const mod = Mods{ .shift = true, .alt = true };
|
||||
const int_mod = mod.toInt(c_int);
|
||||
|
||||
try std.testing.expectEqual(int_mod, RawMods.shift | RawMods.alt);
|
||||
}
|
||||
|
||||
test "all bitmask to int" {
|
||||
const std = @import("std");
|
||||
|
||||
const mod = Mods{
|
||||
.shift = true,
|
||||
.control = true,
|
||||
.alt = true,
|
||||
.super = true,
|
||||
.caps_lock = true,
|
||||
.num_lock = true,
|
||||
};
|
||||
const int_mod = mod.toInt(c_int);
|
||||
|
||||
const expected = RawMods.shift | RawMods.control |
|
||||
RawMods.alt | RawMods.super |
|
||||
RawMods.caps_lock | RawMods.num_lock;
|
||||
|
||||
try std.testing.expectEqual(int_mod, expected);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue