diff --git a/examples/custom-renderer/App.zig b/examples/custom-renderer/App.zig index 426c6508..39805f91 100644 --- a/examples/custom-renderer/App.zig +++ b/examples/custom-renderer/App.zig @@ -162,10 +162,10 @@ fn tick( var q = try entities.query(.{ .ids = mach.Entities.Mod.read(.id), .followers = Mod.read(.follower), - .positions = Renderer.Mod.read(.position), + .positions = Renderer.Mod.write(.position), }); while (q.next()) |v| { - for (v.ids, v.positions) |id, position| { + for (v.ids, v.positions) |id, *position| { // Nested query to find all the other follower entities that we should move away from. // We will avoid all other follower entities if we're too close to them. // This is not very efficient, but it works! @@ -204,7 +204,7 @@ fn tick( new_position = new_position.lerp(&vec3(0, 0, 0), move_speed / avoidance_div); // Finally, update our entity position. - try renderer.set(id, .position, new_position); + position.* = new_position; } } diff --git a/src/Audio.zig b/src/Audio.zig index 8cc46825..b266d6ea 100644 --- a/src/Audio.zig +++ b/src/Audio.zig @@ -135,37 +135,36 @@ fn audioTick(entities: *mach.Entities.Mod, audio: *Mod) !void { var did_state_change = false; var q = try entities.query(.{ - .ids = mach.Entities.Mod.read(.id), .samples_slices = Mod.read(.samples), .channels = Mod.read(.channels), - .playings = Mod.read(.playing), - .indexes = Mod.read(.index), + .playings = Mod.write(.playing), + .indexes = Mod.write(.index), }); while (q.next()) |v| { - for (v.ids, v.samples_slices, v.channels, v.playings, v.indexes) |id, samples, channels, playing, index| { - if (!playing) continue; + for (v.samples_slices, v.channels, v.playings, v.indexes) |samples, channels, *playing, *index| { + if (!playing.*) continue; const channels_diff = player_channels - channels + 1; - const to_read = @min(samples.len - index, mixing_buffer.items.len) / channels_diff; + const to_read = @min(samples.len - index.*, mixing_buffer.items.len) / channels_diff; if (channels == 1 and player_channels > 1) { // Duplicate samples for mono sounds var i: usize = 0; - for (samples[index..][0..to_read]) |sample| { + for (samples[index.*..][0..to_read]) |sample| { mixSamplesDuplicate(mixing_buffer.items[i..][0..player_channels], sample); i += player_channels; } } else { - mixSamples(mixing_buffer.items[0..to_read], samples[index..][0..to_read]); + mixSamples(mixing_buffer.items[0..to_read], samples[index.*..][0..to_read]); } - if (index + to_read >= samples.len) { + if (index.* + to_read >= samples.len) { // No longer playing, we've read all samples did_state_change = true; - try audio.set(id, .playing, false); - try audio.set(id, .index, 0); + playing.* = false; + index.* = 0; continue; } - try audio.set(id, .index, index + to_read); + index.* = index.* + to_read; } } if (audio.state().on_state_change) |on_state_change_event| { diff --git a/src/gfx/Sprite.zig b/src/gfx/Sprite.zig index af303e85..e20ae074 100644 --- a/src/gfx/Sprite.zig +++ b/src/gfx/Sprite.zig @@ -96,6 +96,7 @@ fn updatePipeline( } } + // TODO: optimize by removing this component set call and instead use a .write() query try sprite_pipeline.set(pipeline_id, .num_sprites, num_sprites); if (num_sprites > 0) { encoder.writeBuffer(built.transforms, 0, gfx.SpritePipeline.cp_transforms[0..i]); diff --git a/src/gfx/SpritePipeline.zig b/src/gfx/SpritePipeline.zig index ade4482b..8afdbde0 100644 --- a/src/gfx/SpritePipeline.zig +++ b/src/gfx/SpritePipeline.zig @@ -155,6 +155,8 @@ fn buildPipeline( pipeline_id: mach.EntityID, texture: *gpu.Texture, ) !void { + // TODO: optimize by removing the component get/set calls in this function where possible + // and instead use .write() queries const opt_texture2 = sprite_pipeline.get(pipeline_id, .texture2); const opt_texture3 = sprite_pipeline.get(pipeline_id, .texture3); const opt_texture4 = sprite_pipeline.get(pipeline_id, .texture4); diff --git a/src/gfx/TextPipeline.zig b/src/gfx/TextPipeline.zig index 54124713..0e52932a 100644 --- a/src/gfx/TextPipeline.zig +++ b/src/gfx/TextPipeline.zig @@ -179,6 +179,8 @@ fn buildPipeline( text_pipeline: *Mod, pipeline_id: mach.EntityID, ) !void { + // TODO: optimize by removing the component get/set calls in this function where possible + // and instead use .write() queries const opt_shader = text_pipeline.get(pipeline_id, .shader); const opt_texture_sampler = text_pipeline.get(pipeline_id, .texture_sampler); const opt_blend_state = text_pipeline.get(pipeline_id, .blend_state);