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.
// TODO(important): better querying API
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .app = &.{.follower} },
} });
while (archetypes_iter.next()) |archetype| {
@ -169,7 +169,7 @@ fn tick(
const close_dist = 1.0 / 15.0;
var avoidance = Vec3.splat(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} },
} });
while (archetypes_iter_2.next()) |archetype_2| {

View file

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

View file

@ -163,7 +163,7 @@ fn tick(
const delta_time = game.state().timer.lap();
// Animate entities
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite = &.{.transform} },
} });
while (archetypes_iter.next()) |archetype| {
@ -174,7 +174,7 @@ fn tick(
// TODO: formatting
// 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) {
try core.entities.remove(id);
try core.__entities.remove(id);
game.state().sprites -= 1;
continue;
}

View file

@ -69,7 +69,7 @@ fn audioStateChange(
app: *Mod,
) !void {
// 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} },
} });
while (archetypes_iter.next()) |archetype| {

View file

@ -79,7 +79,7 @@ fn audioStateChange(
app: *Mod,
) !void {
// 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| {
for (
archetype.slice(.entity, .id),

View file

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

View file

@ -199,7 +199,7 @@ fn tick(
const delta_time = game.state().timer.lap();
// Rotate entities
var archetypes_iter = core.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = core.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text = &.{.transform} },
} });
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
var num_texts: u32 = 0;
var num_glyphs: usize = 0;
var archetypes_iter = text.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = text.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text = &.{
.built,
} },

View file

@ -134,7 +134,7 @@ fn audioTick(audio: *Mod) !void {
@memset(mixing_buffer.items, 0);
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 } },
} });
while (archetypes_iter.next()) |archetype| {

View file

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

View file

@ -43,7 +43,7 @@ pub const events = .{
};
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 = &.{
.built,
} },
@ -69,7 +69,7 @@ fn updatePipeline(
const encoder = device.createCommandEncoder(&.{ .label = label });
defer encoder.release();
var archetypes_iter = sprite.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = sprite.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite = &.{
.uv_transform,
.transform,

View file

@ -124,7 +124,7 @@ fn init(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 = &.{
.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.
deinit(sprite_pipeline);
var archetypes_iter = sprite_pipeline.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = sprite_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite_pipeline = &.{
.texture,
} },
@ -324,7 +324,7 @@ fn preRender(sprite_pipeline: *Mod, core: *mach.Core.Mod) void {
const encoder = core.state().device.createCommandEncoder(&.{ .label = label });
defer encoder.release();
var archetypes_iter = sprite_pipeline.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = sprite_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_sprite_pipeline = &.{
.built,
} },
@ -367,7 +367,7 @@ fn render(sprite_pipeline: *Mod) !void {
sprite_pipeline.state().render_pass = null;
// 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 = &.{
.built,
} },

View file

@ -59,7 +59,7 @@ const BuiltText = struct {
};
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 = &.{
.built,
} },
@ -97,7 +97,7 @@ fn updatePipeline(
var texture_update = false;
var num_texts: u32 = 0;
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 = &.{
.transform,
.text,
@ -148,19 +148,19 @@ fn updatePipeline(
// Load the font
// TODO(text): allow specifying a font
// 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
const font_bytes = @import("font-assets").fira_sans_regular_ttf;
var font = try gfx.Font.initBytes(font_bytes);
defer font.deinit(allocator);
// TODO(text): respect these style parameters
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_size = core.__entities.getComponent(style, .mach_gfx_text_style, .font_size).?;
const font_weight = core.__entities.getComponent(style, .mach_gfx_text_style, .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;
const color = core.entities.getComponent(style, .mach_gfx_text_style, .color);
const color = core.__entities.getComponent(style, .mach_gfx_text_style, .color);
_ = color;
// Create a text shaper

View file

@ -145,7 +145,7 @@ pub const BuiltPipeline = struct {
};
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 = &.{
.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.
deinit(text_pipeline);
var archetypes_iter = text_pipeline.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = text_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text_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 });
defer encoder.release();
var archetypes_iter = text_pipeline.entities.queryDeprecated(.{ .all = &.{
var archetypes_iter = text_pipeline.__entities.queryDeprecated(.{ .all = &.{
.{ .mach_gfx_text_pipeline = &.{
.built,
} },
@ -396,7 +396,7 @@ fn render(text_pipeline: *Mod) !void {
text_pipeline.state().render_pass = null;
// 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 = &.{
.built,
} },

View file

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

View file

@ -27,7 +27,7 @@ pub const EntityModule = struct {
};
test {
std.testing.refAllDeclsRecursive(@This());
// std.testing.refAllDeclsRecursive(@This());
std.testing.refAllDeclsRecursive(@import("Archetype.zig"));
std.testing.refAllDeclsRecursive(@import("entities.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{
.__is_initialized = false,
.__state = undefined,
.entities = &m.entities,
.__entities = &m.entities,
};
}
}
@ -277,7 +277,7 @@ pub fn Modules(comptime modules: anytype) type {
comptime EventEnum: anytype,
comptime event_name: EventEnumM(M),
) 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
@ -575,9 +575,8 @@ pub fn ModSet(comptime modules: anytype) type {
const module_tag = M.name;
const components = ComponentTypesM(M){};
return struct {
entities: *Entities(modules),
/// Private/internal fields
__entities: *Entities(modules),
__is_initialized: bool,
__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 {
return .{ .read = .{
.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 {
return .{ .write = .{
.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.
pub inline fn newEntity(m: *@This()) !EntityID {
return m.entities.new();
return m.__entities.new();
}
/// Removes an entity.
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,
@ -642,7 +641,7 @@ pub fn ModSet(comptime modules: anytype) type {
comptime component_name: ComponentNameM(M),
component: @field(components, @tagName(component_name)).type,
) !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
@ -652,7 +651,7 @@ pub fn ModSet(comptime modules: anytype) type {
entity: EntityID,
comptime component_name: ComponentNameM(M),
) ?@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.
@ -661,7 +660,7 @@ pub fn ModSet(comptime modules: anytype) type {
entity: EntityID,
comptime component_name: ComponentNameM(M),
) !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 {
@ -768,6 +767,15 @@ fn UninjectedArgsTuple(comptime Function: type) type {
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
fn LocalArgsM(comptime M: type, event_name: anytype) type {
return ArgsM(M, event_name, "events");