Commit graph

705 commits

Author SHA1 Message Date
Emi
ad5e8f98e0 add default font / eliminate font-assets dependency
Our default font is a ~200K download which is not substantial enough to
warrant the need for a seperate dependency/repository.

Signed-off-by: Emi <emi@hexops.com>
2025-11-25 12:27:35 -07:00
OliveThePuffin
7cd7dce007
math: fix Shared VecN comparison operators (#1419) 2025-07-05 13:22:10 -07:00
Emi
ee996b71d3 object: fix race in appension to MPSC queue cleanup list
Fixes hexops/mach#1414

Signed-off-by: Emi <emi@hexops.com>
2025-03-15 11:50:08 -07:00
Pigeon_OwO
fa3bea0eac
sysaudio: display which audio-backend got selected (#1351) 2025-03-15 11:19:59 -07:00
Emi
aae6ab3afa cleanup
Signed-off-by: Emi <emi@hexops.com>
2025-02-25 22:35:05 -07:00
Emi
b14f8e69ee build: add @import("mach").addExecutable helper
This adds a helper that can be used people's `build.zig` code, called `@import("mach").addExecutable`,
a direct replacement for `b.addExecutable`.

The benefits of using this method are:

1. Your `build.zig` code does not need to be aware of platform-specifics that may be required to build an executable,
   for example setting a Windows manifest to ensure your app is DPI-aware.
2. You do not need to write `main.zig` entrypoint code, which although simple today is expected to become more complex
   over time as we add support for more platforms. For example, WASM and other platforms require different entrypoints
   and this can account for that without your `build.zig` containing that logic.

Steps to use:

1. Delete your `main.zig` file.
2. Define your `Modules` as a public const in your `App.zig` file, e.g.:

```zig
// The set of Mach modules our application may use.
pub const Modules = mach.Modules(.{
    mach.Core,
    App,
});
```

3. Update your `build.zig` code to use `@import("mach").addExecutable` like so:

```zig
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const app_mod = b.createModule(.{
        .root_source_file = b.path("src/App.zig"),
        .optimize = optimize,
        .target = target,
    });

    // Add Mach to our library and executable
    const mach_dep = b.dependency("mach", .{
        .target = target,
        .optimize = optimize,
    });
    app_mod.addImport("mach", mach_dep.module("mach"));

    // Use the Mach entrypoint to write main for us
    const exe = @import("mach").addExecutable(mach_dep.builder, .{
        .name = "hello-world",
        .app = app_mod,
        .target = target,
        .optimize = optimize,
    });
    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    const app_unit_tests = b.addTest(.{
        .root_module = app_mod,
    });
    const run_app_unit_tests = b.addRunArtifact(app_unit_tests);
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_app_unit_tests.step);
}
```

Signed-off-by: Emi <emi@hexops.com>
2025-02-17 20:57:14 -07:00
Emi
2410814e91 module: fix validation strings (thanks jacobly)
Signed-off-by: Emi <emi@hexops.com>
2025-02-08 19:25:18 -07:00
Emi Gutekanst
17a830f857 object: add ability to tag arbitrary objects with arbitrary tags and values
Modules define lists of objects, e.g. a `SpriteRenderer` module may define

```zig
sprites: mach.Objects(struct {
    // ...
}),
```

Previously, the only way for another Mach module to 'attach data to a sprite object' or 'tag a sprite' would be to (ab)use the graph relations system, creating their own object and using parent/child relations to express that the sprite has some tag/data associated with it. For example:

```zig
// Game.zig

is_monster: mach.Object(struct{}), // empty object just to indicate 'some other object is a monster'

// ...

// Create a 'tag object'
const is_monster_tag_obj_id = game.is_monster.new(.{});

// Add the 'tag object' as a child of our sprite
sprite_renderer.sprites.addChild(my_sprite_id, is_monster_tag_obj_id);

// ...
```

This usage of the API was quite ugly/usage, and importantly eliminated your ability to use the parent/child relations for _other_ things where they are more appropriate. However, it did mean that you didn't have to go and fork+modify the `SpriteRenderer` module that you e.g. imported as a reusable package.

With this change, we add object _tags_ and _tags with values_. Any module can add their own tags or tags with values to any object, whether it is from their module or not. For example, the `is_monster` example above could now be written as:

```zig
// Game.zig

pub const mach_tags = .{ .is_monster };

// ...

try sprite_renderer.sprites.setTag(sprite_id, Game, .is_monster, null);
const is_monster: bool = sprite_renderer.sprites.hasTag(sprite_id, Game, .is_monster);
// is_monster == true!

// No longer a monster
try sprite_renderer.sprites.removeTag(sprite_id, Game, .is_monster);
```

This allows for effectively tagging objects as distinct kinds, states, etc. even though they aren't our object and we can't modify their `struct {}` type to include an `is_monster: bool` field of our own.

Internally, the implementation stores tags using a hashmap under the assumption that not all objects in a list will have a tag.

Tags with values work almost identically, the only difference is that the last parameter to `setTag` is set to another `mach.ObjectID` which points to whatever arbitrary data you'd like to attach to the object, and `getTag` returns it. For example:

```zig
// Game.zig

pub const mach_tags = .{
    /// Whether a sprite is a monster
    .is_monster,

    /// Whether a sprite has a friendly sprite attached to it
    .{ .friend, Sprite, .sprites },
};

// ...

try sprite_renderer.sprites.setTag(sprite_id, Game, .friend, friendly_sprite_id);

const has_friend: bool = sprite_renderer.sprites.hasTag(sprite_id, Game, .friend);
// has_friend == true!

// Get our friend
const friend_id: mach.ObjectID = sprite_renderer.sprites.getTag(sprite_id, Game, .friend);
// friend_id == friendly_sprite_id

// Delete our friend
try sprite_renderer.sprites.removeTag(sprite_id, Game, .friend);
```

Signed-off-by: Emi Gutekanst <emi@hexops.com>
2025-02-08 19:13:12 -07:00
Daniel
9749cd9a65 Add matrix rotation by quaternion 2025-02-01 20:00:03 -08:00
msg-programs
6fd6a8fa67 Add format function for vector and matrix types. 2025-02-01 19:55:19 -08:00
Jonathan Marler
f9e1a9087f core: windows: refactor everything 2025-01-19 13:37:48 -07:00
Emi Gutekanst
1e2cbc4d71 module: improve error messages when systems are registered incorrectly
Signed-off-by: Emi Gutekanst <emi@hexops.com>
2025-01-17 21:23:07 -07:00
xdBronch
eb12b0f476 use multiarraylist more optimally in mach.Objects 2025-01-12 09:11:07 -07:00
Joshua Holmes
ab143504ab linux: improve logging when both backends fail 2025-01-12 09:10:24 -07:00
Joshua Holmes
377842aef8 gamemode: revert commit 41ddd22 for gamescope.zig 2025-01-12 09:10:24 -07:00
Joshua Holmes
db186847a7 core: remove core_platform build option and remove Null.zig 2025-01-12 09:05:09 -07:00
Joshua Holmes
caf297512c core: remove option to support non-blocking and only allow platform to control main loop 2025-01-12 09:05:09 -07:00
Joshua Holmes
710b5907a2 linux: remove deinit() because it doesn't seem like it's used in other platforms 2025-01-12 09:05:09 -07:00
Joshua Holmes
431684af7e linux: remove check_for_mach_updates because it was unnecessary refactoring 2025-01-12 09:05:09 -07:00
Emi Gutekanst
aab0eb62f2 {gfx,module}: fix Text update bug caused by anyUpdate reset, add peekAnyUpdate/peekUpdate
Signed-off-by: Emi Gutekanst <emi@hexops.com>
2025-01-10 20:10:58 -07:00
Emi Gutekanst
1d01c91536 gamemode: fix linux build
Signed-off-by: Emi Gutekanst <emi@hexops.com>
2024-12-31 19:14:56 -07:00
Tristan Crawford
41ddd2249f all: instrument library loading 2024-12-31 19:03:58 -07:00
Stephen Gutekanst
f5512d1750 update to latest zig version
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-30 20:50:20 -07:00
Stephen Gutekanst
ff13976518 update to latest zig version
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-30 20:50:20 -07:00
Stephen Gutekanst
b3139fbb0a update to latest zig version
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-30 20:50:20 -07:00
Aeden McClain
04d7238383
object: when cleaning up dropped items, only re-add ones that aren't already in the recycle bin. (#1324)
Signed-off-by: Aeden McClain <dev@platypro.net>
2024-12-30 11:15:15 -07:00
Stephen Gutekanst
6450e8abbf Audio: rewrite sample mixing to use SIMD properly
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-29 15:15:56 -07:00
Stephen Gutekanst
1a7753936b Audio: fix audio buffer SIMD alignment issues
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-29 13:48:18 -07:00
Aeden McClain
a350ae9ee9
sysgpu: linux: fix spir-v generation in hardware test example (#1323) 2024-12-29 11:54:05 -07:00
Stephen Gutekanst
f352670464 module: fix object_name_id bug
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-27 17:32:06 -07:00
Stephen Gutekanst
e5f48580ba gfx: minor Sprite module cleanup/improvements
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-27 16:38:42 -07:00
Stephen Gutekanst
68251d95b7 gfx: rewrite Text module to use new object system
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-27 16:36:12 -07:00
Stephen Gutekanst
47a8a0d98c gfx: rewrite Sprite module to use object system
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-26 11:51:01 -07:00
Stephen Gutekanst
8f642097e5 module: fix anyUpdated; make fields default to updated=true
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-26 11:49:50 -07:00
Stephen Gutekanst
1b7398f580 module: cleanup Objects.updated() implementation; add anyUpdated() variant
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-24 23:04:27 -07:00
Stephen Gutekanst
eae5aa40be module: correct Objects.is() checker
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-24 18:05:34 -07:00
Stephen Gutekanst
5ed75fb3ee module: remove error-prone "optimized" function variants for now
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-24 17:02:36 -07:00
Stephen Gutekanst
15c3f772ef module: perform type checking of object IDs to avoid subtle bugs
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-24 17:00:39 -07:00
Stephen Gutekanst
a28b9798a8 module: improve error message for use-after-delete of objects
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-24 16:51:23 -07:00
Stephen Gutekanst
03ded69cff core: cleanup border/decorated properties
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-24 16:02:03 -07:00
Joshua Holmes
9a4ae36cb6 linux: note that wayland cannot be resized anymore
This is because something is not working with the new Mach Object system. It should be able to be fixed after messing around with it.
2024-12-24 15:44:31 -07:00
Joshua Holmes
f39d47e49c linux: allow title to be changed again 2024-12-24 15:44:31 -07:00
Joshua Holmes
27aee7c036 x11: get x11 to build and run 2024-12-24 15:44:31 -07:00
Joshua Holmes
d6c387613d wayland: fix window initialization 2024-12-24 15:44:31 -07:00
Joshua Holmes
e8b1ef9b25 linux: implement better logging for when wayland fails or x11 is desired 2024-12-24 15:44:31 -07:00
Joshua Holmes
fdc3666a95 wayland: setup with new object system 2024-12-24 15:44:31 -07:00
Stephen Gutekanst
b3a5186f3a build: update mach-objc dependency
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-12-24 15:40:16 -07:00
foxnne
cc387ddb59 core: darwin: Only recreate swapchain and send resize event if the window size actually changed 2024-12-24 15:40:16 -07:00
foxnne
8520c6d7d4 core: windows: Update to match darwin and handle updating the swapchain and window/framebuffer sizes 2024-12-24 15:40:16 -07:00
foxnne
4ada021a15 core: darwin: Document the command key fix 2024-12-24 15:40:16 -07:00