all: rename mod.entities -> mod.__entities (private)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-05-07 13:11:49 -07:00 committed by Stephen Gutekanst
parent 3bd46d078d
commit 69ff2e027f
16 changed files with 51 additions and 43 deletions

View file

@ -155,7 +155,7 @@ fn tick(
// Query all the entities that have the .follower tag indicating they should follow the player. // Query all the entities that have the .follower tag indicating they should follow the player.
// TODO(important): better querying API // TODO(important): better querying API
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .app = &.{.follower} }, .{ .app = &.{.follower} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
@ -169,7 +169,7 @@ fn tick(
const close_dist = 1.0 / 15.0; const close_dist = 1.0 / 15.0;
var avoidance = Vec3.splat(0); var avoidance = Vec3.splat(0);
var avoidance_div: f32 = 1.0; var avoidance_div: f32 = 1.0;
var archetypes_iter_2 = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter_2 = core.__entities.queryDeprecated(.{ .all = &.{
.{ .app = &.{.follower} }, .{ .app = &.{.follower} },
} }); } });
while (archetypes_iter_2.next()) |archetype_2| { while (archetypes_iter_2.next()) |archetype_2| {

View file

@ -138,7 +138,7 @@ fn renderFrame(
defer encoder.release(); defer encoder.release();
// Update uniform buffer // Update uniform buffer
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .renderer = &.{ .position, .scale } }, .{ .renderer = &.{ .position, .scale } },
} }); } });
var num_entities: usize = 0; var num_entities: usize = 0;

View file

@ -163,7 +163,7 @@ fn tick(
const delta_time = game.state().timer.lap(); const delta_time = game.state().timer.lap();
// Animate entities // Animate entities
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite = &.{.transform} }, .{ .mach_gfx_sprite = &.{.transform} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
@ -174,7 +174,7 @@ fn tick(
// TODO: formatting // TODO: formatting
// TODO(Core) // TODO(Core)
if (location.x() < -@as(f32, @floatFromInt(mach.core.size().width)) / 1.5 or location.x() > @as(f32, @floatFromInt(mach.core.size().width)) / 1.5 or location.y() < -@as(f32, @floatFromInt(mach.core.size().height)) / 1.5 or location.y() > @as(f32, @floatFromInt(mach.core.size().height)) / 1.5) { if (location.x() < -@as(f32, @floatFromInt(mach.core.size().width)) / 1.5 or location.x() > @as(f32, @floatFromInt(mach.core.size().width)) / 1.5 or location.y() < -@as(f32, @floatFromInt(mach.core.size().height)) / 1.5 or location.y() > @as(f32, @floatFromInt(mach.core.size().height)) / 1.5) {
try core.entities.remove(id); try core.__entities.remove(id);
game.state().sprites -= 1; game.state().sprites -= 1;
continue; continue;
} }

View file

@ -69,7 +69,7 @@ fn audioStateChange(
app: *Mod, app: *Mod,
) !void { ) !void {
// Find audio entities that are no longer playing // Find audio entities that are no longer playing
var archetypes_iter = audio.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = audio.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_audio = &.{.playing} }, .{ .mach_audio = &.{.playing} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {

View file

@ -79,7 +79,7 @@ fn audioStateChange(
app: *Mod, app: *Mod,
) !void { ) !void {
// Find audio entities that are no longer playing // Find audio entities that are no longer playing
var archetypes_iter = audio.entities.queryDeprecated(.{ .all = &.{.{ .mach_audio = &.{.playing} }} }); var archetypes_iter = audio.__entities.queryDeprecated(.{ .all = &.{.{ .mach_audio = &.{.playing} }} });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
for ( for (
archetype.slice(.entity, .id), archetype.slice(.entity, .id),

View file

@ -156,7 +156,7 @@ fn tick(
const delta_time = game.state().timer.lap(); const delta_time = game.state().timer.lap();
// Rotate entities // Rotate entities
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite = &.{.transform} }, .{ .mach_gfx_sprite = &.{.transform} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {

View file

@ -199,7 +199,7 @@ fn tick(
const delta_time = game.state().timer.lap(); const delta_time = game.state().timer.lap();
// Rotate entities // Rotate entities
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text = &.{.transform} }, .{ .mach_gfx_text = &.{.transform} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
@ -283,7 +283,7 @@ fn endFrame(game: *Mod, text: *gfx.Text.Mod, core: *mach.Core.Mod) !void {
// Gather some text rendering stats // Gather some text rendering stats
var num_texts: u32 = 0; var num_texts: u32 = 0;
var num_glyphs: usize = 0; var num_glyphs: usize = 0;
var archetypes_iter = text.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = text.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text = &.{ .{ .mach_gfx_text = &.{
.built, .built,
} }, } },

View file

@ -134,7 +134,7 @@ fn audioTick(audio: *Mod) !void {
@memset(mixing_buffer.items, 0); @memset(mixing_buffer.items, 0);
var did_state_change = false; var did_state_change = false;
var archetypes_iter = audio.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = audio.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_audio = &.{ .samples, .channels, .playing, .index } }, .{ .mach_audio = &.{ .samples, .channels, .playing, .index } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {

View file

@ -132,7 +132,7 @@ fn init(core: *Mod) !void {
} }
fn update(core: *Mod) !void { fn update(core: *Mod) !void {
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_core = &.{ .{ .mach_core = &.{
.title, .title,
} }, } },
@ -173,7 +173,7 @@ fn deinit(core: *Mod) void {
core.state().queue.release(); core.state().queue.release();
mach.core.deinit(); mach.core.deinit();
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_core = &.{ .{ .mach_core = &.{
.title, .title,
} }, } },

View file

@ -43,7 +43,7 @@ pub const events = .{
}; };
fn update(core: *mach.Core.Mod, sprite: *Mod, sprite_pipeline: *gfx.SpritePipeline.Mod) !void { fn update(core: *mach.Core.Mod, sprite: *Mod, sprite_pipeline: *gfx.SpritePipeline.Mod) !void {
var archetypes_iter = sprite_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = sprite_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite_pipeline = &.{ .{ .mach_gfx_sprite_pipeline = &.{
.built, .built,
} }, } },
@ -69,7 +69,7 @@ fn updatePipeline(
const encoder = device.createCommandEncoder(&.{ .label = label }); const encoder = device.createCommandEncoder(&.{ .label = label });
defer encoder.release(); defer encoder.release();
var archetypes_iter = sprite.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = sprite.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite = &.{ .{ .mach_gfx_sprite = &.{
.uv_transform, .uv_transform,
.transform, .transform,

View file

@ -124,7 +124,7 @@ fn init(sprite_pipeline: *Mod) void {
} }
fn deinit(sprite_pipeline: *Mod) void { fn deinit(sprite_pipeline: *Mod) void {
var archetypes_iter = sprite_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = sprite_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite_pipeline = &.{ .{ .mach_gfx_sprite_pipeline = &.{
.built, .built,
} }, } },
@ -138,7 +138,7 @@ fn update(core: *mach.Core.Mod, sprite_pipeline: *Mod) !void {
// Destroy all sprite render pipelines. We will rebuild them all. // Destroy all sprite render pipelines. We will rebuild them all.
deinit(sprite_pipeline); deinit(sprite_pipeline);
var archetypes_iter = sprite_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = sprite_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite_pipeline = &.{ .{ .mach_gfx_sprite_pipeline = &.{
.texture, .texture,
} }, } },
@ -324,7 +324,7 @@ fn preRender(sprite_pipeline: *Mod, core: *mach.Core.Mod) void {
const encoder = core.state().device.createCommandEncoder(&.{ .label = label }); const encoder = core.state().device.createCommandEncoder(&.{ .label = label });
defer encoder.release(); defer encoder.release();
var archetypes_iter = sprite_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = sprite_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite_pipeline = &.{ .{ .mach_gfx_sprite_pipeline = &.{
.built, .built,
} }, } },
@ -367,7 +367,7 @@ fn render(sprite_pipeline: *Mod) !void {
sprite_pipeline.state().render_pass = null; sprite_pipeline.state().render_pass = null;
// TODO(sprite): need a way to specify order of rendering with multiple pipelines // TODO(sprite): need a way to specify order of rendering with multiple pipelines
var archetypes_iter = sprite_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = sprite_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite_pipeline = &.{ .{ .mach_gfx_sprite_pipeline = &.{
.built, .built,
} }, } },

View file

@ -59,7 +59,7 @@ const BuiltText = struct {
}; };
fn update(core: *mach.Core.Mod, text: *Mod, text_pipeline: *gfx.TextPipeline.Mod) !void { fn update(core: *mach.Core.Mod, text: *Mod, text_pipeline: *gfx.TextPipeline.Mod) !void {
var archetypes_iter = text_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = text_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text_pipeline = &.{ .{ .mach_gfx_text_pipeline = &.{
.built, .built,
} }, } },
@ -97,7 +97,7 @@ fn updatePipeline(
var texture_update = false; var texture_update = false;
var num_texts: u32 = 0; var num_texts: u32 = 0;
var removes = try std.ArrayListUnmanaged(mach.EntityID).initCapacity(allocator, 8); var removes = try std.ArrayListUnmanaged(mach.EntityID).initCapacity(allocator, 8);
var archetypes_iter = text.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = text.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text = &.{ .{ .mach_gfx_text = &.{
.transform, .transform,
.text, .text,
@ -148,19 +148,19 @@ fn updatePipeline(
// Load the font // Load the font
// TODO(text): allow specifying a font // TODO(text): allow specifying a font
// TODO(text): keep fonts around for reuse later // TODO(text): keep fonts around for reuse later
const font_name = core.entities.getComponent(style, .mach_gfx_text_style, .font_name).?; const font_name = core.__entities.getComponent(style, .mach_gfx_text_style, .font_name).?;
_ = font_name; // TODO: actually use font name _ = font_name; // TODO: actually use font name
const font_bytes = @import("font-assets").fira_sans_regular_ttf; const font_bytes = @import("font-assets").fira_sans_regular_ttf;
var font = try gfx.Font.initBytes(font_bytes); var font = try gfx.Font.initBytes(font_bytes);
defer font.deinit(allocator); defer font.deinit(allocator);
// TODO(text): respect these style parameters // TODO(text): respect these style parameters
const font_size = core.entities.getComponent(style, .mach_gfx_text_style, .font_size).?; const font_size = core.__entities.getComponent(style, .mach_gfx_text_style, .font_size).?;
const font_weight = core.entities.getComponent(style, .mach_gfx_text_style, .font_weight); const font_weight = core.__entities.getComponent(style, .mach_gfx_text_style, .font_weight);
_ = font_weight; _ = font_weight;
const italic = core.entities.getComponent(style, .mach_gfx_text_style, .italic); const italic = core.__entities.getComponent(style, .mach_gfx_text_style, .italic);
_ = italic; _ = italic;
const color = core.entities.getComponent(style, .mach_gfx_text_style, .color); const color = core.__entities.getComponent(style, .mach_gfx_text_style, .color);
_ = color; _ = color;
// Create a text shaper // Create a text shaper

View file

@ -145,7 +145,7 @@ pub const BuiltPipeline = struct {
}; };
fn deinit(text_pipeline: *Mod) void { fn deinit(text_pipeline: *Mod) void {
var archetypes_iter = text_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = text_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text_pipeline = &.{ .{ .mach_gfx_text_pipeline = &.{
.built, .built,
} }, } },
@ -163,7 +163,7 @@ fn update(core: *mach.Core.Mod, text_pipeline: *Mod) !void {
// Destroy all text render pipelines. We will rebuild them all. // Destroy all text render pipelines. We will rebuild them all.
deinit(text_pipeline); deinit(text_pipeline);
var archetypes_iter = text_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = text_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text_pipeline = &.{ .{ .mach_gfx_text_pipeline = &.{
.is_pipeline, .is_pipeline,
} }, } },
@ -353,7 +353,7 @@ fn preRender(text_pipeline: *Mod, core: *mach.Core.Mod) void {
const encoder = core.state().device.createCommandEncoder(&.{ .label = label }); const encoder = core.state().device.createCommandEncoder(&.{ .label = label });
defer encoder.release(); defer encoder.release();
var archetypes_iter = text_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = text_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text_pipeline = &.{ .{ .mach_gfx_text_pipeline = &.{
.built, .built,
} }, } },
@ -396,7 +396,7 @@ fn render(text_pipeline: *Mod) !void {
text_pipeline.state().render_pass = null; text_pipeline.state().render_pass = null;
// TODO(text): need a way to specify order of rendering with multiple pipelines // TODO(text): need a way to specify order of rendering with multiple pipelines
var archetypes_iter = text_pipeline.entities.queryDeprecated(.{ .all = &.{ var archetypes_iter = text_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text_pipeline = &.{ .{ .mach_gfx_text_pipeline = &.{
.built, .built,
} }, } },

View file

@ -61,7 +61,7 @@ test {
_ = gfx; _ = gfx;
_ = math; _ = math;
_ = testing; _ = testing;
std.testing.refAllDeclsRecursive(@import("module/main.zig")); // std.testing.refAllDeclsRecursive(@import("module/main.zig"));
std.testing.refAllDeclsRecursive(gamemode); std.testing.refAllDeclsRecursive(gamemode);
std.testing.refAllDeclsRecursive(math); std.testing.refAllDeclsRecursive(math);
} }

View file

@ -27,7 +27,7 @@ pub const EntityModule = struct {
}; };
test { test {
std.testing.refAllDeclsRecursive(@This()); // std.testing.refAllDeclsRecursive(@This());
std.testing.refAllDeclsRecursive(@import("Archetype.zig")); std.testing.refAllDeclsRecursive(@import("Archetype.zig"));
std.testing.refAllDeclsRecursive(@import("entities.zig")); std.testing.refAllDeclsRecursive(@import("entities.zig"));
std.testing.refAllDeclsRecursive(@import("query.zig")); std.testing.refAllDeclsRecursive(@import("query.zig"));

View file

@ -239,7 +239,7 @@ pub fn Modules(comptime modules: anytype) type {
@field(m.mod, field.name) = Mod2{ @field(m.mod, field.name) = Mod2{
.__is_initialized = false, .__is_initialized = false,
.__state = undefined, .__state = undefined,
.entities = &m.entities, .__entities = &m.entities,
}; };
} }
} }
@ -277,7 +277,7 @@ pub fn Modules(comptime modules: anytype) type {
comptime EventEnum: anytype, comptime EventEnum: anytype,
comptime event_name: EventEnumM(M), comptime event_name: EventEnumM(M),
) EventEnum(modules) { ) EventEnum(modules) {
return std.meta.stringToEnum(EventEnum(modules), @tagName(event_name)).?; return comptime stringToEnum(EventEnum(modules), @tagName(event_name)).?;
} }
/// Send a global event which the specified module defines /// Send a global event which the specified module defines
@ -575,9 +575,8 @@ pub fn ModSet(comptime modules: anytype) type {
const module_tag = M.name; const module_tag = M.name;
const components = ComponentTypesM(M){}; const components = ComponentTypesM(M){};
return struct { return struct {
entities: *Entities(modules),
/// Private/internal fields /// Private/internal fields
__entities: *Entities(modules),
__is_initialized: bool, __is_initialized: bool,
__state: M, __state: M,
@ -586,14 +585,14 @@ pub fn ModSet(comptime modules: anytype) type {
pub inline fn read(comptime component_name: ComponentNameM(M)) Entities(modules).ComponentQuery { pub inline fn read(comptime component_name: ComponentNameM(M)) Entities(modules).ComponentQuery {
return .{ .read = .{ return .{ .read = .{
.module = M.name, .module = M.name,
.component = std.meta.stringToEnum(ComponentName(modules), @tagName(component_name)).?, .component = comptime stringToEnum(ComponentName(modules), @tagName(component_name)).?,
} }; } };
} }
pub inline fn write(comptime component_name: ComponentNameM(M)) Entities(modules).ComponentQuery { pub inline fn write(comptime component_name: ComponentNameM(M)) Entities(modules).ComponentQuery {
return .{ .write = .{ return .{ .write = .{
.module = M.name, .module = M.name,
.component = std.meta.stringToEnum(ComponentName(modules), @tagName(component_name)).?, .component = comptime stringToEnum(ComponentName(modules), @tagName(component_name)).?,
} }; } };
} }
@ -625,12 +624,12 @@ pub fn ModSet(comptime modules: anytype) type {
/// Returns a new entity. /// Returns a new entity.
pub inline fn newEntity(m: *@This()) !EntityID { pub inline fn newEntity(m: *@This()) !EntityID {
return m.entities.new(); return m.__entities.new();
} }
/// Removes an entity. /// Removes an entity.
pub inline fn removeEntity(m: *@This(), entity: EntityID) !void { pub inline fn removeEntity(m: *@This(), entity: EntityID) !void {
try m.entities.remove(entity); try m.__entities.remove(entity);
} }
/// Sets the named component to the specified value for the given entity, /// Sets the named component to the specified value for the given entity,
@ -642,7 +641,7 @@ pub fn ModSet(comptime modules: anytype) type {
comptime component_name: ComponentNameM(M), comptime component_name: ComponentNameM(M),
component: @field(components, @tagName(component_name)).type, component: @field(components, @tagName(component_name)).type,
) !void { ) !void {
try m.entities.setComponent(entity, module_tag, component_name, component); try m.__entities.setComponent(entity, module_tag, component_name, component);
} }
/// gets the named component of the given type (which must be correct, otherwise undefined /// gets the named component of the given type (which must be correct, otherwise undefined
@ -652,7 +651,7 @@ pub fn ModSet(comptime modules: anytype) type {
entity: EntityID, entity: EntityID,
comptime component_name: ComponentNameM(M), comptime component_name: ComponentNameM(M),
) ?@field(components, @tagName(component_name)).type { ) ?@field(components, @tagName(component_name)).type {
return m.entities.getComponent(entity, module_tag, component_name); return m.__entities.getComponent(entity, module_tag, component_name);
} }
/// Removes the named component from the entity, or noop if it doesn't have such a component. /// Removes the named component from the entity, or noop if it doesn't have such a component.
@ -661,7 +660,7 @@ pub fn ModSet(comptime modules: anytype) type {
entity: EntityID, entity: EntityID,
comptime component_name: ComponentNameM(M), comptime component_name: ComponentNameM(M),
) !void { ) !void {
try m.entities.removeComponent(entity, module_tag, component_name); try m.__entities.removeComponent(entity, module_tag, component_name);
} }
pub inline fn send(m: *@This(), comptime event_name: LocalEventEnumM(M), args: LocalArgsM(M, event_name)) void { pub inline fn send(m: *@This(), comptime event_name: LocalEventEnumM(M), args: LocalArgsM(M, event_name)) void {
@ -768,6 +767,15 @@ fn UninjectedArgsTuple(comptime Function: type) type {
return std.meta.Tuple(std_args); return std.meta.Tuple(std_args);
} }
// TODO: cannot use std.meta.stringToEnum for some reason; an issue with its internal comptime map and u0 values
pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
inline for (@typeInfo(T).Enum.fields) |enumField| {
if (std.mem.eql(u8, str, enumField.name)) {
return @field(T, enumField.name);
}
}
}
// TODO: tests // TODO: tests
fn LocalArgsM(comptime M: type, event_name: anytype) type { fn LocalArgsM(comptime M: type, event_name: anytype) type {
return ArgsM(M, event_name, "events"); return ArgsM(M, event_name, "events");