From 22feb42730c06de3320861a68583d7cde992af0d Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 6 May 2024 14:26:30 -0700 Subject: [PATCH] module: denote const vs. mut component queries Signed-off-by: Stephen Gutekanst --- src/module/entities.zig | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/module/entities.zig b/src/module/entities.zig index 8ee529e6..f7624a8e 100644 --- a/src/module/entities.zig +++ b/src/module/entities.zig @@ -641,9 +641,13 @@ pub fn Entities(comptime modules: anytype) type { /// Logical AND operator for query expressions op_and: []const @This(), - /// Match a specific module component. + /// Match a specific module component, indicating it will only be read. // TODO: add component name type and consider replacing StringTable approach with global enum - component: StringTable.Index, + const_component: StringTable.Index, + + /// Match a specific module component, indicating it will be mutated. + // TODO: add component name type and consider replacing StringTable approach with global enum + mut_component: StringTable.Index, pub fn match(q: @This(), archetype: *Archetype) bool { switch (q) { @@ -651,7 +655,7 @@ pub fn Entities(comptime modules: anytype) type { for (qs) |and_q| if (!and_q.match(archetype)) return false; return true; }, - .component => |component_name| { + .const_component, .mut_component => |component_name| { for (archetype.columns) |column| if (column.name == component_name) return true; return false; }, @@ -933,8 +937,8 @@ test "example" { // Dynamic queries (e.g. issued from another programming language without comptime) var q = try world.queryDynamic(.{ .op_and = &.{ - .{ .component = world.componentName(EntityModule.name, .id) }, - .{ .component = world.componentName(Game.name, .rotation) }, + .{ .const_component = world.componentName(EntityModule.name, .id) }, + .{ .const_component = world.componentName(Game.name, .rotation) }, }, }); while (q.next()) |archtype| {