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
// 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:
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
renderer: *Renderer.Mod,
game: *Mod,
@ -56,7 +56,7 @@ fn init(
renderer.send(.init, .{});
// 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
// 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
fn tick(
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
renderer: *Renderer.Mod,
game: *Mod,
@ -136,7 +136,7 @@ fn tick(
_ = game.state().spawn_timer.lap(); // Reset the timer
for (0..5) |_| {
// 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, .scale, 1.0 / 6.0);
@ -162,7 +162,7 @@ fn tick(
} });
while (archetypes_iter.next()) |archetype| {
// 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);
for (ids, positions) |id, position| {
// Nested query to find all the other follower entities that we should move away from.
@ -175,7 +175,7 @@ fn tick(
.{ .app = &.{.follower} },
} });
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);
for (other_ids, other_positions) |other_id, other_position| {
if (id == other_id) continue;

View file

@ -143,7 +143,7 @@ fn renderFrame(
} });
var num_entities: usize = 0;
while (archetypes_iter.next()) |archetype| {
const ids = archetype.slice(.entity, .id);
const ids = archetype.slice(.entities, .id);
const positions = archetype.slice(.renderer, .position);
const scales = archetype.slice(.renderer, .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(
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod,
glyphs: *Glyphs.Mod,
@ -68,7 +68,7 @@ fn afterInit(
) !void {
// Create a sprite rendering pipeline
const texture = glyphs.state().texture;
const pipeline = try entity.new();
const pipeline = try entities.new();
try sprite_pipeline.set(pipeline, .texture, texture);
sprite_pipeline.send(.update, .{});
@ -77,7 +77,7 @@ fn afterInit(
// type than the `.physics2d` module's `.location` component if you desire.
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, .pipeline, pipeline);
try sprite.set(player, .size, vec2(@floatFromInt(r.width), @floatFromInt(r.height)));
@ -98,7 +98,7 @@ fn afterInit(
}
fn tick(
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
sprite: *gfx.Sprite.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 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, .size, vec2(@floatFromInt(r.width), @floatFromInt(r.height)));
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} },
} });
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);
for (ids, transforms) |id, *old_transform| {
var location = old_transform.translation();

View file

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

View file

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

View file

@ -52,7 +52,7 @@ fn deinit(
}
fn init(
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
sprite: *gfx.Sprite.Mod,
sprite_pipeline: *gfx.SpritePipeline.Mod,
@ -66,12 +66,12 @@ fn init(
// Create a sprite rendering pipeline
const allocator = gpa.allocator();
const pipeline = try entity.new();
const pipeline = try entities.new();
try sprite_pipeline.set(pipeline, .texture, try loadTexture(core, allocator));
sprite_pipeline.send(.update, .{});
// 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, .size, vec2(32, 32));
try sprite.set(player, .uv_transform, Mat3x3.translate(vec2(0, 0)));
@ -95,7 +95,7 @@ fn init(
}
fn tick(
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
sprite: *gfx.Sprite.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[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, .size, vec2(32, 32));
try sprite.set(new_entity, .uv_transform, Mat3x3.translate(vec2(0, 0)));
@ -162,7 +162,7 @@ fn tick(
.{ .mach_gfx_sprite = &.{.transform} },
} });
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);
for (ids, transforms) |id, *old_transform| {
_ = id;

View file

@ -63,7 +63,7 @@ fn deinit(
}
fn init(
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
text: *gfx.Text.Mod,
text_pipeline: *gfx.TextPipeline.Mod,
@ -74,21 +74,21 @@ fn init(
// TODO: a better way to initialize entities with default values
// 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_size, 48 * gfx.px_per_pt); // 48pt
try text_style.set(style1, .font_weight, gfx.font_weight_normal);
try text_style.set(style1, .italic, false);
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_size, 48 * gfx.px_per_pt); // 48pt
try text_style.set(style2, .font_weight, gfx.font_weight_normal);
try text_style.set(style2, .italic, true);
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_size, 48 * gfx.px_per_pt); // 48pt
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));
// Create a text rendering pipeline
const pipeline = try entity.new();
const pipeline = try entities.new();
try text_pipeline.set(pipeline, .is_pipeline, {});
text_pipeline.send(.update, .{});
// Create some text
const player = try entity.new();
const player = try entities.new();
try text.set(player, .pipeline, pipeline);
try text.set(player, .transform, Mat4x4.scaleScalar(upscale).mul(&Mat4x4.translate(vec3(0, 0, 0))));
@ -133,7 +133,7 @@ fn init(
}
fn tick(
entity: *mach.Entity.Mod,
entities: *mach.Entities.Mod,
core: *mach.Core.Mod,
text: *gfx.Text.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[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, .transform, Mat4x4.scaleScalar(upscale).mul(&Mat4x4.translate(new_pos)));
@ -205,7 +205,7 @@ fn tick(
.{ .mach_gfx_text = &.{.transform} },
} });
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);
for (ids, transforms) |id, *old_transform| {
_ = id;