all: rename mach.Entity.Mod -> mach.Entities.Mod

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-05-07 16:41:39 -07:00 committed by Stephen Gutekanst
parent 11ebce62a3
commit 541ce9e7c0
18 changed files with 69 additions and 69 deletions

View file

@ -48,7 +48,7 @@ fn init(
// These are injected dependencies - as long as these modules were registered in the top-level // These are injected dependencies - as long as these modules were registered in the top-level
// of the program we can have these types injected here, letting us work with other modules in // of the program we can have these types injected here, letting us work with other modules in
// our program seamlessly and with a type-safe API: // our program seamlessly and with a type-safe API:
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
renderer: *Renderer.Mod, renderer: *Renderer.Mod,
game: *Mod, game: *Mod,
@ -56,7 +56,7 @@ fn init(
renderer.send(.init, .{}); renderer.send(.init, .{});
// Create our player entity. // Create our player entity.
const player = try entity.new(); const player = try entities.new();
// Give our player entity a .renderer.position and .renderer.scale component. Note that these // Give our player entity a .renderer.position and .renderer.scale component. Note that these
// are defined by the Renderer module, so we use `renderer: *Renderer.Mod` to interact with // are defined by the Renderer module, so we use `renderer: *Renderer.Mod` to interact with
@ -82,7 +82,7 @@ fn init(
// TODO(important): remove need for returning an error here // TODO(important): remove need for returning an error here
fn tick( fn tick(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
renderer: *Renderer.Mod, renderer: *Renderer.Mod,
game: *Mod, game: *Mod,
@ -136,7 +136,7 @@ fn tick(
_ = game.state().spawn_timer.lap(); // Reset the timer _ = game.state().spawn_timer.lap(); // Reset the timer
for (0..5) |_| { for (0..5) |_| {
// Spawn a new entity at the same position as the player, but smaller in scale. // Spawn a new entity at the same position as the player, but smaller in scale.
const new_entity = try entity.new(); const new_entity = try entities.new();
try renderer.set(new_entity, .position, player_pos); try renderer.set(new_entity, .position, player_pos);
try renderer.set(new_entity, .scale, 1.0 / 6.0); try renderer.set(new_entity, .scale, 1.0 / 6.0);
@ -162,7 +162,7 @@ fn tick(
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
// Iterate the ID and position of each entity // Iterate the ID and position of each entity
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const positions = archetype.slice(.renderer, .position); const positions = archetype.slice(.renderer, .position);
for (ids, positions) |id, position| { for (ids, positions) |id, position| {
// Nested query to find all the other follower entities that we should move away from. // Nested query to find all the other follower entities that we should move away from.
@ -175,7 +175,7 @@ fn tick(
.{ .app = &.{.follower} }, .{ .app = &.{.follower} },
} }); } });
while (archetypes_iter_2.next()) |archetype_2| { while (archetypes_iter_2.next()) |archetype_2| {
const other_ids = archetype_2.slice(.entity, .id); const other_ids = archetype_2.slice(.entities, .id);
const other_positions = archetype_2.slice(.renderer, .position); const other_positions = archetype_2.slice(.renderer, .position);
for (other_ids, other_positions) |other_id, other_position| { for (other_ids, other_positions) |other_id, other_position| {
if (id == other_id) continue; if (id == other_id) continue;

View file

@ -143,7 +143,7 @@ fn renderFrame(
} }); } });
var num_entities: usize = 0; var num_entities: usize = 0;
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const positions = archetype.slice(.renderer, .position); const positions = archetype.slice(.renderer, .position);
const scales = archetype.slice(.renderer, .scale); const scales = archetype.slice(.renderer, .scale);
for (ids, positions, scales) |id, position, scale| { for (ids, positions, scales) |id, position, scale| {

View file

@ -60,7 +60,7 @@ fn init(core: *mach.Core.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod, glyphs:
} }
fn afterInit( fn afterInit(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
sprite: *gfx.Sprite.Mod, sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod,
glyphs: *Glyphs.Mod, glyphs: *Glyphs.Mod,
@ -68,7 +68,7 @@ fn afterInit(
) !void { ) !void {
// Create a sprite rendering pipeline // Create a sprite rendering pipeline
const texture = glyphs.state().texture; const texture = glyphs.state().texture;
const pipeline = try entity.new(); const pipeline = try entities.new();
try sprite_pipeline.set(pipeline, .texture, texture); try sprite_pipeline.set(pipeline, .texture, texture);
sprite_pipeline.send(.update, .{}); sprite_pipeline.send(.update, .{});
@ -77,7 +77,7 @@ fn afterInit(
// type than the `.physics2d` module's `.location` component if you desire. // type than the `.physics2d` module's `.location` component if you desire.
const r = glyphs.state().regions.get('?').?; const r = glyphs.state().regions.get('?').?;
const player = try entity.new(); const player = try entities.new();
try sprite.set(player, .transform, Mat4x4.translate(vec3(-0.02, 0, 0))); try sprite.set(player, .transform, Mat4x4.translate(vec3(-0.02, 0, 0)));
try sprite.set(player, .pipeline, pipeline); try sprite.set(player, .pipeline, pipeline);
try sprite.set(player, .size, vec2(@floatFromInt(r.width), @floatFromInt(r.height))); try sprite.set(player, .size, vec2(@floatFromInt(r.width), @floatFromInt(r.height)));
@ -98,7 +98,7 @@ fn afterInit(
} }
fn tick( fn tick(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
sprite: *gfx.Sprite.Mod, sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod,
@ -152,7 +152,7 @@ fn tick(
const rand_index = game.state().rand.random().intRangeAtMost(usize, 0, glyphs.state().regions.count() - 1); const rand_index = game.state().rand.random().intRangeAtMost(usize, 0, glyphs.state().regions.count() - 1);
const r = glyphs.state().regions.entries.get(rand_index).value; const r = glyphs.state().regions.entries.get(rand_index).value;
const new_entity = try entity.new(); const new_entity = try entities.new();
try sprite.set(new_entity, .transform, Mat4x4.translate(new_pos).mul(&Mat4x4.scaleScalar(0.3))); try sprite.set(new_entity, .transform, Mat4x4.translate(new_pos).mul(&Mat4x4.scaleScalar(0.3)));
try sprite.set(new_entity, .size, vec2(@floatFromInt(r.width), @floatFromInt(r.height))); try sprite.set(new_entity, .size, vec2(@floatFromInt(r.width), @floatFromInt(r.height)));
try sprite.set(new_entity, .uv_transform, Mat3x3.translate(vec2(@floatFromInt(r.x), @floatFromInt(r.y)))); try sprite.set(new_entity, .uv_transform, Mat3x3.translate(vec2(@floatFromInt(r.x), @floatFromInt(r.y))));
@ -169,7 +169,7 @@ fn tick(
.{ .mach_gfx_sprite = &.{.transform} }, .{ .mach_gfx_sprite = &.{.transform} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const transforms = archetype.slice(.mach_gfx_sprite, .transform); const transforms = archetype.slice(.mach_gfx_sprite, .transform);
for (ids, transforms) |id, *old_transform| { for (ids, transforms) |id, *old_transform| {
var location = old_transform.translation(); var location = old_transform.translation();

View file

@ -65,7 +65,7 @@ fn deinit(core: *mach.Core.Mod, audio: *mach.Audio.Mod) void {
} }
fn audioStateChange( fn audioStateChange(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
audio: *mach.Audio.Mod, audio: *mach.Audio.Mod,
app: *Mod, app: *Mod,
) !void { ) !void {
@ -75,14 +75,14 @@ fn audioStateChange(
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
for ( for (
archetype.slice(.entity, .id), archetype.slice(.entities, .id),
archetype.slice(.mach_audio, .playing), archetype.slice(.mach_audio, .playing),
) |id, playing| { ) |id, playing| {
if (playing) continue; if (playing) continue;
if (app.get(id, .play_after)) |frequency| { if (app.get(id, .play_after)) |frequency| {
// Play a new sound // Play a new sound
const e = try entity.new(); const e = try entities.new();
try audio.set(e, .samples, try fillTone(audio, frequency)); try audio.set(e, .samples, try fillTone(audio, frequency));
try audio.set(e, .channels, @intCast(audio.state().player.channels().len)); try audio.set(e, .channels, @intCast(audio.state().player.channels().len));
try audio.set(e, .playing, true); try audio.set(e, .playing, true);
@ -90,13 +90,13 @@ fn audioStateChange(
} }
// Remove the entity for the old sound // Remove the entity for the old sound
try entity.remove(id); try entities.remove(id);
} }
} }
} }
fn tick( fn tick(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
audio: *mach.Audio.Mod, audio: *mach.Audio.Mod,
app: *Mod, app: *Mod,
@ -123,7 +123,7 @@ fn tick(
// Piano keys // Piano keys
else => { else => {
// Play a new sound // Play a new sound
const e = try entity.new(); const e = try entities.new();
try audio.set(e, .samples, try fillTone(audio, keyToFrequency(ev.key))); try audio.set(e, .samples, try fillTone(audio, keyToFrequency(ev.key)));
try audio.set(e, .channels, @intCast(audio.state().player.channels().len)); try audio.set(e, .channels, @intCast(audio.state().player.channels().len));
try audio.set(e, .playing, true); try audio.set(e, .playing, true);

View file

@ -33,7 +33,7 @@ pub const components = .{
sfx: Opus, sfx: Opus,
fn init( fn init(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
audio: *mach.Audio.Mod, audio: *mach.Audio.Mod,
app: *Mod, app: *Mod,
@ -53,7 +53,7 @@ fn init(
// Initialize module state // Initialize module state
app.init(.{ .sfx = sfx }); app.init(.{ .sfx = sfx });
const bgm_entity = try entity.new(); const bgm_entity = try entities.new();
try app.set(bgm_entity, .is_bgm, {}); try app.set(bgm_entity, .is_bgm, {});
try audio.set(bgm_entity, .samples, bgm.samples); try audio.set(bgm_entity, .samples, bgm.samples);
try audio.set(bgm_entity, .channels, bgm.channels); try audio.set(bgm_entity, .channels, bgm.channels);
@ -80,7 +80,7 @@ fn deinit(core: *mach.Core.Mod, audio: *mach.Audio.Mod) void {
} }
fn audioStateChange( fn audioStateChange(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
audio: *mach.Audio.Mod, audio: *mach.Audio.Mod,
app: *Mod, app: *Mod,
) !void { ) !void {
@ -88,7 +88,7 @@ fn audioStateChange(
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(.entities, .id),
archetype.slice(.mach_audio, .playing), archetype.slice(.mach_audio, .playing),
) |id, playing| { ) |id, playing| {
if (playing) continue; if (playing) continue;
@ -99,14 +99,14 @@ fn audioStateChange(
try audio.set(id, .playing, true); try audio.set(id, .playing, true);
} else { } else {
// Remove the entity for the old sound // Remove the entity for the old sound
try entity.remove(id); try entities.remove(id);
} }
} }
} }
} }
fn tick( fn tick(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
audio: *mach.Audio.Mod, audio: *mach.Audio.Mod,
app: *Mod, app: *Mod,
@ -128,7 +128,7 @@ fn tick(
}, },
else => { else => {
// Play a new SFX // Play a new SFX
const e = try entity.new(); const e = try entities.new();
try audio.set(e, .samples, app.state().sfx.samples); try audio.set(e, .samples, app.state().sfx.samples);
try audio.set(e, .channels, app.state().sfx.channels); try audio.set(e, .channels, app.state().sfx.channels);
try audio.set(e, .index, 0); try audio.set(e, .index, 0);

View file

@ -52,7 +52,7 @@ fn deinit(
} }
fn init( fn init(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
sprite: *gfx.Sprite.Mod, sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod,
@ -66,12 +66,12 @@ fn init(
// Create a sprite rendering pipeline // Create a sprite rendering pipeline
const allocator = gpa.allocator(); const allocator = gpa.allocator();
const pipeline = try entity.new(); const pipeline = try entities.new();
try sprite_pipeline.set(pipeline, .texture, try loadTexture(core, allocator)); try sprite_pipeline.set(pipeline, .texture, try loadTexture(core, allocator));
sprite_pipeline.send(.update, .{}); sprite_pipeline.send(.update, .{});
// Create our player sprite // Create our player sprite
const player = try entity.new(); const player = try entities.new();
try sprite.set(player, .transform, Mat4x4.translate(vec3(-0.02, 0, 0))); try sprite.set(player, .transform, Mat4x4.translate(vec3(-0.02, 0, 0)));
try sprite.set(player, .size, vec2(32, 32)); try sprite.set(player, .size, vec2(32, 32));
try sprite.set(player, .uv_transform, Mat3x3.translate(vec2(0, 0))); try sprite.set(player, .uv_transform, Mat3x3.translate(vec2(0, 0)));
@ -95,7 +95,7 @@ fn init(
} }
fn tick( fn tick(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
sprite: *gfx.Sprite.Mod, sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod, sprite_pipeline: *gfx.SpritePipeline.Mod,
@ -145,7 +145,7 @@ fn tick(
new_pos.v[0] += game.state().rand.random().floatNorm(f32) * 25; new_pos.v[0] += game.state().rand.random().floatNorm(f32) * 25;
new_pos.v[1] += game.state().rand.random().floatNorm(f32) * 25; new_pos.v[1] += game.state().rand.random().floatNorm(f32) * 25;
const new_entity = try entity.new(); const new_entity = try entities.new();
try sprite.set(new_entity, .transform, Mat4x4.translate(new_pos).mul(&Mat4x4.scale(Vec3.splat(0.3)))); try sprite.set(new_entity, .transform, Mat4x4.translate(new_pos).mul(&Mat4x4.scale(Vec3.splat(0.3))));
try sprite.set(new_entity, .size, vec2(32, 32)); try sprite.set(new_entity, .size, vec2(32, 32));
try sprite.set(new_entity, .uv_transform, Mat3x3.translate(vec2(0, 0))); try sprite.set(new_entity, .uv_transform, Mat3x3.translate(vec2(0, 0)));
@ -162,7 +162,7 @@ fn tick(
.{ .mach_gfx_sprite = &.{.transform} }, .{ .mach_gfx_sprite = &.{.transform} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const transforms = archetype.slice(.mach_gfx_sprite, .transform); const transforms = archetype.slice(.mach_gfx_sprite, .transform);
for (ids, transforms) |id, *old_transform| { for (ids, transforms) |id, *old_transform| {
_ = id; _ = id;

View file

@ -63,7 +63,7 @@ fn deinit(
} }
fn init( fn init(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
text: *gfx.Text.Mod, text: *gfx.Text.Mod,
text_pipeline: *gfx.TextPipeline.Mod, text_pipeline: *gfx.TextPipeline.Mod,
@ -74,21 +74,21 @@ fn init(
// TODO: a better way to initialize entities with default values // TODO: a better way to initialize entities with default values
// TODO(text): most of these style options are not respected yet. // TODO(text): most of these style options are not respected yet.
const style1 = try entity.new(); const style1 = try entities.new();
try text_style.set(style1, .font_name, "Roboto Medium"); // TODO try text_style.set(style1, .font_name, "Roboto Medium"); // TODO
try text_style.set(style1, .font_size, 48 * gfx.px_per_pt); // 48pt try text_style.set(style1, .font_size, 48 * gfx.px_per_pt); // 48pt
try text_style.set(style1, .font_weight, gfx.font_weight_normal); try text_style.set(style1, .font_weight, gfx.font_weight_normal);
try text_style.set(style1, .italic, false); try text_style.set(style1, .italic, false);
try text_style.set(style1, .color, vec4(0.6, 1.0, 0.6, 1.0)); try text_style.set(style1, .color, vec4(0.6, 1.0, 0.6, 1.0));
const style2 = try entity.new(); const style2 = try entities.new();
try text_style.set(style2, .font_name, "Roboto Medium"); // TODO try text_style.set(style2, .font_name, "Roboto Medium"); // TODO
try text_style.set(style2, .font_size, 48 * gfx.px_per_pt); // 48pt try text_style.set(style2, .font_size, 48 * gfx.px_per_pt); // 48pt
try text_style.set(style2, .font_weight, gfx.font_weight_normal); try text_style.set(style2, .font_weight, gfx.font_weight_normal);
try text_style.set(style2, .italic, true); try text_style.set(style2, .italic, true);
try text_style.set(style2, .color, vec4(0.6, 1.0, 0.6, 1.0)); try text_style.set(style2, .color, vec4(0.6, 1.0, 0.6, 1.0));
const style3 = try entity.new(); const style3 = try entities.new();
try text_style.set(style3, .font_name, "Roboto Medium"); // TODO try text_style.set(style3, .font_name, "Roboto Medium"); // TODO
try text_style.set(style3, .font_size, 48 * gfx.px_per_pt); // 48pt try text_style.set(style3, .font_size, 48 * gfx.px_per_pt); // 48pt
try text_style.set(style3, .font_weight, gfx.font_weight_bold); try text_style.set(style3, .font_weight, gfx.font_weight_bold);
@ -96,12 +96,12 @@ fn init(
try text_style.set(style3, .color, vec4(0.6, 1.0, 0.6, 1.0)); try text_style.set(style3, .color, vec4(0.6, 1.0, 0.6, 1.0));
// Create a text rendering pipeline // Create a text rendering pipeline
const pipeline = try entity.new(); const pipeline = try entities.new();
try text_pipeline.set(pipeline, .is_pipeline, {}); try text_pipeline.set(pipeline, .is_pipeline, {});
text_pipeline.send(.update, .{}); text_pipeline.send(.update, .{});
// Create some text // Create some text
const player = try entity.new(); const player = try entities.new();
try text.set(player, .pipeline, pipeline); try text.set(player, .pipeline, pipeline);
try text.set(player, .transform, Mat4x4.scaleScalar(upscale).mul(&Mat4x4.translate(vec3(0, 0, 0)))); try text.set(player, .transform, Mat4x4.scaleScalar(upscale).mul(&Mat4x4.translate(vec3(0, 0, 0))));
@ -133,7 +133,7 @@ fn init(
} }
fn tick( fn tick(
entity: *mach.Entity.Mod, entities: *mach.Entities.Mod,
core: *mach.Core.Mod, core: *mach.Core.Mod,
text: *gfx.Text.Mod, text: *gfx.Text.Mod,
text_pipeline: *gfx.TextPipeline.Mod, text_pipeline: *gfx.TextPipeline.Mod,
@ -183,7 +183,7 @@ fn tick(
new_pos.v[0] += game.state().rand.random().floatNorm(f32) * 50; new_pos.v[0] += game.state().rand.random().floatNorm(f32) * 50;
new_pos.v[1] += game.state().rand.random().floatNorm(f32) * 50; new_pos.v[1] += game.state().rand.random().floatNorm(f32) * 50;
const new_entity = try entity.new(); const new_entity = try entities.new();
try text.set(new_entity, .pipeline, game.state().pipeline); try text.set(new_entity, .pipeline, game.state().pipeline);
try text.set(new_entity, .transform, Mat4x4.scaleScalar(upscale).mul(&Mat4x4.translate(new_pos))); try text.set(new_entity, .transform, Mat4x4.scaleScalar(upscale).mul(&Mat4x4.translate(new_pos)));
@ -205,7 +205,7 @@ fn tick(
.{ .mach_gfx_text = &.{.transform} }, .{ .mach_gfx_text = &.{.transform} },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const transforms = archetype.slice(.mach_gfx_text, .transform); const transforms = archetype.slice(.mach_gfx_text, .transform);
for (ids, transforms) |id, *old_transform| { for (ids, transforms) |id, *old_transform| {
_ = id; _ = id;

View file

@ -139,7 +139,7 @@ fn audioTick(audio: *Mod) !void {
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
for ( for (
archetype.slice(.entity, .id), archetype.slice(.entities, .id),
archetype.slice(.mach_audio, .samples), archetype.slice(.mach_audio, .samples),
archetype.slice(.mach_audio, .channels), archetype.slice(.mach_audio, .channels),
archetype.slice(.mach_audio, .playing), archetype.slice(.mach_audio, .playing),

View file

@ -106,7 +106,7 @@ fn start(core: *Mod) !void {
core.state().run_state = .running; core.state().run_state = .running;
} }
fn init(entity: *mach.Entity.Mod, core: *Mod) !void { fn init(entities: *mach.Entities.Mod, core: *Mod) !void {
mach.core.allocator = gpa.allocator(); // TODO: banish this global allocator mach.core.allocator = gpa.allocator(); // TODO: banish this global allocator
// Initialize GPU implementation // Initialize GPU implementation
@ -116,7 +116,7 @@ fn init(entity: *mach.Entity.Mod, core: *Mod) !void {
try mach.core.init(.{}); try mach.core.init(.{});
// TODO(important): update this information upon framebuffer resize events // TODO(important): update this information upon framebuffer resize events
const main_window = try entity.new(); const main_window = try entities.new();
try core.set(main_window, .framebuffer_format, mach.core.descriptor.format); try core.set(main_window, .framebuffer_format, mach.core.descriptor.format);
try core.set(main_window, .framebuffer_width, mach.core.descriptor.width); try core.set(main_window, .framebuffer_width, mach.core.descriptor.width);
try core.set(main_window, .framebuffer_height, mach.core.descriptor.height); try core.set(main_window, .framebuffer_height, mach.core.descriptor.height);
@ -141,7 +141,7 @@ fn update(core: *Mod) !void {
var num_windows: usize = 0; var num_windows: usize = 0;
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
for ( for (
archetype.slice(.entity, .id), archetype.slice(.entities, .id),
archetype.slice(.mach_core, .title), archetype.slice(.mach_core, .title),
) |window_id, title| { ) |window_id, title| {
num_windows += 1; num_windows += 1;

View file

@ -49,7 +49,7 @@ fn update(core: *mach.Core.Mod, sprite: *Mod, sprite_pipeline: *gfx.SpritePipeli
} }, } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const built_pipelines = archetype.slice(.mach_gfx_sprite_pipeline, .built); const built_pipelines = archetype.slice(.mach_gfx_sprite_pipeline, .built);
for (ids, built_pipelines) |pipeline_id, *built| { for (ids, built_pipelines) |pipeline_id, *built| {
try updatePipeline(core, sprite, sprite_pipeline, pipeline_id, built); try updatePipeline(core, sprite, sprite_pipeline, pipeline_id, built);

View file

@ -144,7 +144,7 @@ fn update(core: *mach.Core.Mod, sprite_pipeline: *Mod) !void {
} }, } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const textures = archetype.slice(.mach_gfx_sprite_pipeline, .texture); const textures = archetype.slice(.mach_gfx_sprite_pipeline, .texture);
for (ids, textures) |pipeline_id, texture| { for (ids, textures) |pipeline_id, texture| {
@ -373,7 +373,7 @@ fn render(sprite_pipeline: *Mod) !void {
} }, } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const built_pipelines = archetype.slice(.mach_gfx_sprite_pipeline, .built); const built_pipelines = archetype.slice(.mach_gfx_sprite_pipeline, .built);
for (ids, built_pipelines) |pipeline_id, built| { for (ids, built_pipelines) |pipeline_id, built| {
// Draw the sprite batch // Draw the sprite batch

View file

@ -65,7 +65,7 @@ fn update(core: *mach.Core.Mod, text: *Mod, text_pipeline: *gfx.TextPipeline.Mod
} }, } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const built_pipelines = archetype.slice(.mach_gfx_text_pipeline, .built); const built_pipelines = archetype.slice(.mach_gfx_text_pipeline, .built);
for (ids, built_pipelines) |pipeline_id, *built| { for (ids, built_pipelines) |pipeline_id, *built| {
try updatePipeline(core, text, text_pipeline, pipeline_id, built); try updatePipeline(core, text, text_pipeline, pipeline_id, built);
@ -106,7 +106,7 @@ fn updatePipeline(
} }, } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const transforms = archetype.slice(.mach_gfx_text, .transform); const transforms = archetype.slice(.mach_gfx_text, .transform);
const segment_slices = archetype.slice(.mach_gfx_text, .text); const segment_slices = archetype.slice(.mach_gfx_text, .text);
const style_slices = archetype.slice(.mach_gfx_text, .style); const style_slices = archetype.slice(.mach_gfx_text, .style);

View file

@ -169,7 +169,7 @@ fn update(core: *mach.Core.Mod, text_pipeline: *Mod) !void {
} }, } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
for (ids) |pipeline_id| { for (ids) |pipeline_id| {
try buildPipeline(core, text_pipeline, pipeline_id); try buildPipeline(core, text_pipeline, pipeline_id);
} }
@ -402,7 +402,7 @@ fn render(text_pipeline: *Mod) !void {
} }, } },
} }); } });
while (archetypes_iter.next()) |archetype| { while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id); const ids = archetype.slice(.entities, .id);
const built_pipelines = archetype.slice(.mach_gfx_text_pipeline, .built); const built_pipelines = archetype.slice(.mach_gfx_text_pipeline, .built);
for (ids, built_pipelines) |pipeline_id, built| { for (ids, built_pipelines) |pipeline_id, built| {
// Draw the text batch // Draw the text batch

View file

@ -40,7 +40,7 @@ pub const EventID = @import("module/main.zig").EventID;
pub const AnyEvent = @import("module/main.zig").AnyEvent; pub const AnyEvent = @import("module/main.zig").AnyEvent;
pub const merge = @import("module/main.zig").merge; pub const merge = @import("module/main.zig").merge;
pub const builtin_modules = @import("module/main.zig").builtin_modules; pub const builtin_modules = @import("module/main.zig").builtin_modules;
pub const Entity = @import("module/main.zig").Entity; pub const Entities = @import("module/main.zig").Entities;
/// To use experimental sysgpu graphics API, you can write this in your main.zig: /// To use experimental sysgpu graphics API, you can write this in your main.zig:
/// ///

View file

@ -290,8 +290,8 @@ pub fn Slicer(comptime modules: anytype) type {
@field(component_types_by_name, @tagName(namespace_name)), @field(component_types_by_name, @tagName(namespace_name)),
@tagName(component_name), @tagName(component_name),
).type; ).type;
if (namespace_name == .entity and component_name == .id) { if (namespace_name == .entities and component_name == .id) {
const name_id = slicer.archetype.component_names.index("entity.id").?; const name_id = slicer.archetype.component_names.index("entities.id").?;
return slicer.archetype.getColumnValues(name_id, Type).?[0..slicer.archetype.len]; return slicer.archetype.getColumnValues(name_id, Type).?[0..slicer.archetype.len];
} }
const name = @tagName(namespace_name) ++ "." ++ @tagName(component_name); const name = @tagName(namespace_name) ++ "." ++ @tagName(component_name);

View file

@ -9,7 +9,7 @@ const StringTable = @import("StringTable.zig");
const ComponentTypesByName = @import("module.zig").ComponentTypesByName; const ComponentTypesByName = @import("module.zig").ComponentTypesByName;
const merge = @import("main.zig").merge; const merge = @import("main.zig").merge;
const builtin_modules = @import("main.zig").builtin_modules; const builtin_modules = @import("main.zig").builtin_modules;
const Entity = @import("main.zig").Entity; const Entities = @import("main.zig").Entities;
const ModuleName = @import("module.zig").ModuleName; const ModuleName = @import("module.zig").ModuleName;
const ComponentNameM = @import("module.zig").ComponentNameM; const ComponentNameM = @import("module.zig").ComponentNameM;
const ComponentName = @import("module.zig").ComponentName; const ComponentName = @import("module.zig").ComponentName;
@ -130,7 +130,7 @@ pub fn Database(comptime modules: anytype) type {
.component_names = component_names, .component_names = component_names,
.buckets = buckets, .buckets = buckets,
}; };
entities.id_name = entities.componentName(Entity.name, .id); entities.id_name = entities.componentName(Entities.name, .id);
const columns = try allocator.alloc(Archetype.Column, 1); const columns = try allocator.alloc(Archetype.Column, 1);
columns[0] = .{ columns[0] = .{
@ -1076,7 +1076,7 @@ test "example" {
// Query for all entities that have all of the given components // Query for all entities that have all of the given components
const W = @TypeOf(world); const W = @TypeOf(world);
var q = try world.query(.{ var q = try world.query(.{
.ids = W.ComponentQuery{ .read = W.ModuleComponentName{ .module = Entity.name, .component = .id } }, .ids = W.ComponentQuery{ .read = W.ModuleComponentName{ .module = Entities.name, .component = .id } },
.rotations = W.ComponentQuery{ .write = W.ModuleComponentName{ .module = Game.name, .component = .rotation } }, .rotations = W.ComponentQuery{ .write = W.ModuleComponentName{ .module = Game.name, .component = .rotation } },
}); });
while (q.next()) |v| { while (q.next()) |v| {
@ -1090,7 +1090,7 @@ test "example" {
// Dynamic queries (e.g. issued from another programming language without comptime) // Dynamic queries (e.g. issued from another programming language without comptime)
var q2 = try world.queryDynamic(.{ var q2 = try world.queryDynamic(.{
.op_and = &.{ .op_and = &.{
.{ .read = world.componentName(Entity.name, .id) }, .{ .read = world.componentName(Entities.name, .id) },
.{ .read = world.componentName(Game.name, .rotation) }, .{ .read = world.componentName(Game.name, .rotation) },
}, },
}); });

View file

@ -13,11 +13,11 @@ pub const AnyEvent = @import("module.zig").AnyEvent;
pub const Merge = @import("module.zig").Merge; pub const Merge = @import("module.zig").Merge;
pub const merge = @import("module.zig").merge; pub const merge = @import("module.zig").merge;
pub const builtin_modules = .{Entity}; pub const builtin_modules = .{Entities};
/// Builtin .entity module /// Builtin .entities module
pub const Entity = struct { pub const Entities = struct {
pub const name = .entity; pub const name = .entities;
pub const Mod = mach.Mod(@This()); pub const Mod = mach.Mod(@This());
@ -82,15 +82,15 @@ test "entities DB" {
defer world.deinit(allocator); defer world.deinit(allocator);
// Initialize module state. // Initialize module state.
var entity = &world.mod.entity; var entities = &world.mod.entities;
var physics = &world.mod.physics; var physics = &world.mod.physics;
var renderer = &world.mod.renderer; var renderer = &world.mod.renderer;
physics.init(.{ .pointer = 123 }); physics.init(.{ .pointer = 123 });
_ = physics.state().pointer; // == 123 _ = physics.state().pointer; // == 123
const player1 = try entity.new(); const player1 = try try entities.new();
const player2 = try entity.new(); const player2 = try try entities.new();
const player3 = try entity.new(); const player3 = try try entities.new();
try physics.set(player1, .id, 1001); try physics.set(player1, .id, 1001);
try renderer.set(player1, .id, 1001); try renderer.set(player1, .id, 1001);

View file

@ -575,8 +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){};
if (M.name == .entity) { if (M.name == .entities) {
// The .entity module is a special builtin module, with its own unique API. // The .entities module is a special builtin module, with its own unique API.
return struct { return struct {
/// Private/internal fields /// Private/internal fields
__entities: *Database(modules), __entities: *Database(modules),