all: update to global vs. local ECS change
See hexops/mach-ecs@ef06fb6473 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
11aed4d16f
commit
8ff30c931f
4 changed files with 649 additions and 642 deletions
|
|
@ -12,8 +12,8 @@
|
|||
},
|
||||
.dependencies = .{
|
||||
.mach_ecs = .{
|
||||
.url = "https://pkg.machengine.org/mach-ecs/46fbc9175a70a8cc983b88f911aa076b625e0fb2.tar.gz",
|
||||
.hash = "1220acdc7bdb09425ccdd92bb906c4e30e3391c95ab15049c946c98cc6643a7ad250",
|
||||
.url = "https://pkg.machengine.org/mach-ecs/ef06fb647353356eff080ad3ec337e028b492d41.tar.gz",
|
||||
.hash = "1220014851adb37d191430ac371cc467e0e0eb633b84b856c7a37e41a3149dea7ce8",
|
||||
},
|
||||
.mach_core = .{
|
||||
.url = "https://pkg.machengine.org/mach-core/cce02fb96ca787378289c5855b381f0ca9f3e090.tar.gz",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ pub const Engine = struct {
|
|||
|
||||
pub const name = .engine;
|
||||
|
||||
pub fn engineInit(world: *World) !void {
|
||||
pub const local = struct {
|
||||
pub fn init(world: *World) !void {
|
||||
core.allocator = allocator;
|
||||
try core.init(.{});
|
||||
const state = &world.mod.engine.state;
|
||||
|
|
@ -27,28 +28,29 @@ pub const Engine = struct {
|
|||
.label = "engine.state.encoder",
|
||||
});
|
||||
|
||||
try world.send(.init, .{});
|
||||
try world.send(null, .init, .{});
|
||||
}
|
||||
|
||||
pub fn engineDeinit(
|
||||
pub fn deinit(
|
||||
world: *World,
|
||||
engine: *World.Mod(.engine),
|
||||
) !void {
|
||||
// TODO: this triggers a device loss error, which we should handle correctly
|
||||
// engine.state.device.release();
|
||||
engine.state.queue.release();
|
||||
try world.send(.deinit, .{});
|
||||
try world.send(null, .deinit, .{});
|
||||
core.deinit();
|
||||
world.deinit();
|
||||
_ = gpa.deinit();
|
||||
}
|
||||
|
||||
pub fn engineExit(world: *World) !void {
|
||||
try world.send(.exit, .{});
|
||||
// Engine module's exit handler
|
||||
pub fn exit(world: *World) !void {
|
||||
try world.send(null, .exit, .{});
|
||||
world.mod.engine.state.exit = true;
|
||||
}
|
||||
|
||||
pub fn engineBeginPass(
|
||||
pub fn beginPass(
|
||||
engine: *World.Mod(.engine),
|
||||
clear_color: gpu.Color,
|
||||
) !void {
|
||||
|
|
@ -69,7 +71,7 @@ pub const Engine = struct {
|
|||
engine.state.pass = engine.state.encoder.beginRenderPass(&pass_info);
|
||||
}
|
||||
|
||||
pub fn engineEndPass(
|
||||
pub fn endPass(
|
||||
engine: *World.Mod(.engine),
|
||||
) !void {
|
||||
// End this pass
|
||||
|
|
@ -87,25 +89,26 @@ pub const Engine = struct {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn enginePresent() !void {
|
||||
pub fn present() !void {
|
||||
core.swap_chain.present();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
pub const App = struct {
|
||||
world: World,
|
||||
|
||||
pub fn init(app: *@This()) !void {
|
||||
app.* = .{ .world = try World.init(allocator) };
|
||||
try app.world.send(.engineInit, .{});
|
||||
try app.world.send(.engine, .init, .{});
|
||||
}
|
||||
|
||||
pub fn deinit(app: *@This()) void {
|
||||
try app.world.send(.engineDeinit, .{});
|
||||
try app.world.send(.engine, .deinit, .{});
|
||||
}
|
||||
|
||||
pub fn update(app: *@This()) !bool {
|
||||
try app.world.send(.tick, .{});
|
||||
try app.world.send(null, .tick, .{});
|
||||
return app.world.mod.engine.state.exit;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -120,7 +120,13 @@ pub const PipelineOptions = struct {
|
|||
pipeline_layout: ?*gpu.PipelineLayout = null,
|
||||
};
|
||||
|
||||
pub fn machGfxSpriteInit(
|
||||
pub fn deinit(sprite_mod: *mach.Mod(.mach_gfx_sprite)) !void {
|
||||
for (sprite_mod.state.pipelines.entries.items(.value)) |*pipeline| pipeline.deinit();
|
||||
sprite_mod.state.pipelines.deinit(sprite_mod.allocator);
|
||||
}
|
||||
|
||||
pub const local = struct {
|
||||
pub fn init(
|
||||
sprite_mod: *mach.Mod(.mach_gfx_sprite),
|
||||
) !void {
|
||||
sprite_mod.state = .{
|
||||
|
|
@ -129,7 +135,7 @@ pub fn machGfxSpriteInit(
|
|||
};
|
||||
}
|
||||
|
||||
pub fn machGfxSpriteInitPipeline(
|
||||
pub fn initPipeline(
|
||||
engine: *mach.Mod(.engine),
|
||||
sprite_mod: *mach.Mod(.mach_gfx_sprite),
|
||||
opt: PipelineOptions,
|
||||
|
|
@ -243,7 +249,7 @@ pub fn machGfxSpriteInitPipeline(
|
|||
.bind_group_layouts = &bind_group_layouts,
|
||||
}));
|
||||
defer pipeline_layout.release();
|
||||
const render = device.createRenderPipeline(&gpu.RenderPipeline.Descriptor{
|
||||
const render_pipeline = device.createRenderPipeline(&gpu.RenderPipeline.Descriptor{
|
||||
.fragment = &fragment,
|
||||
.layout = pipeline_layout,
|
||||
.vertex = gpu.VertexState{
|
||||
|
|
@ -253,7 +259,7 @@ pub fn machGfxSpriteInitPipeline(
|
|||
});
|
||||
|
||||
pipeline.value_ptr.* = Pipeline{
|
||||
.render = render,
|
||||
.render = render_pipeline,
|
||||
.texture_sampler = texture_sampler,
|
||||
.texture = opt.texture,
|
||||
.texture2 = opt.texture2,
|
||||
|
|
@ -269,12 +275,7 @@ pub fn machGfxSpriteInitPipeline(
|
|||
pipeline.value_ptr.reference();
|
||||
}
|
||||
|
||||
pub fn deinit(sprite_mod: *mach.Mod(.mach_gfx_sprite)) !void {
|
||||
for (sprite_mod.state.pipelines.entries.items(.value)) |*pipeline| pipeline.deinit();
|
||||
sprite_mod.state.pipelines.deinit(sprite_mod.allocator);
|
||||
}
|
||||
|
||||
pub fn machGfxSpriteUpdated(
|
||||
pub fn updated(
|
||||
engine: *mach.Mod(.engine),
|
||||
sprite_mod: *mach.Mod(.mach_gfx_sprite),
|
||||
pipeline_id: u32,
|
||||
|
|
@ -323,7 +324,7 @@ pub fn machGfxSpriteUpdated(
|
|||
engine.state.queue.submit(&[_]*gpu.CommandBuffer{command});
|
||||
}
|
||||
|
||||
pub fn machGfxSpritePreRender(
|
||||
pub fn preRender(
|
||||
engine: *mach.Mod(.engine),
|
||||
sprite_mod: *mach.Mod(.mach_gfx_sprite),
|
||||
pipeline_id: u32,
|
||||
|
|
@ -351,7 +352,7 @@ pub fn machGfxSpritePreRender(
|
|||
engine.state.encoder.writeBuffer(pipeline.uniforms, 0, &[_]Uniforms{uniforms});
|
||||
}
|
||||
|
||||
pub fn machGfxSpriteRender(
|
||||
pub fn render(
|
||||
engine: *mach.Mod(.engine),
|
||||
sprite_mod: *mach.Mod(.mach_gfx_sprite),
|
||||
pipeline_id: u32,
|
||||
|
|
@ -366,3 +367,4 @@ pub fn machGfxSpriteRender(
|
|||
pass.setBindGroup(0, pipeline.bind_group, &.{});
|
||||
pass.draw(total_vertices, 1, 0, 0);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -170,7 +170,13 @@ pub const PipelineOptions = struct {
|
|||
pipeline_layout: ?*gpu.PipelineLayout = null,
|
||||
};
|
||||
|
||||
pub fn machGfxTextInit(
|
||||
pub fn deinit(text_mod: *mach.Mod(.mach_gfx_text)) !void {
|
||||
for (text_mod.state.pipelines.entries.items(.value)) |*pipeline| pipeline.deinit(text_mod.allocator);
|
||||
text_mod.state.pipelines.deinit(text_mod.allocator);
|
||||
}
|
||||
|
||||
pub const local = struct {
|
||||
pub fn init(
|
||||
text_mod: *mach.Mod(.mach_gfx_text),
|
||||
) !void {
|
||||
text_mod.state = .{
|
||||
|
|
@ -179,7 +185,7 @@ pub fn machGfxTextInit(
|
|||
};
|
||||
}
|
||||
|
||||
pub fn machGfxTextInitPipeline(
|
||||
pub fn initPipeline(
|
||||
engine: *mach.Mod(.engine),
|
||||
text_mod: *mach.Mod(.mach_gfx_text),
|
||||
opt: PipelineOptions,
|
||||
|
|
@ -311,7 +317,7 @@ pub fn machGfxTextInitPipeline(
|
|||
.bind_group_layouts = &bind_group_layouts,
|
||||
}));
|
||||
defer pipeline_layout.release();
|
||||
const render = device.createRenderPipeline(&gpu.RenderPipeline.Descriptor{
|
||||
const render_pipeline = device.createRenderPipeline(&gpu.RenderPipeline.Descriptor{
|
||||
.fragment = &fragment,
|
||||
.layout = pipeline_layout,
|
||||
.vertex = gpu.VertexState{
|
||||
|
|
@ -321,7 +327,7 @@ pub fn machGfxTextInitPipeline(
|
|||
});
|
||||
|
||||
pipeline.value_ptr.* = Pipeline{
|
||||
.render = render,
|
||||
.render = render_pipeline,
|
||||
.texture_sampler = texture_sampler,
|
||||
.texture = texture,
|
||||
.texture_atlas = texture_atlas,
|
||||
|
|
@ -339,12 +345,7 @@ pub fn machGfxTextInitPipeline(
|
|||
pipeline.value_ptr.reference();
|
||||
}
|
||||
|
||||
pub fn deinit(text_mod: *mach.Mod(.mach_gfx_text)) !void {
|
||||
for (text_mod.state.pipelines.entries.items(.value)) |*pipeline| pipeline.deinit(text_mod.allocator);
|
||||
text_mod.state.pipelines.deinit(text_mod.allocator);
|
||||
}
|
||||
|
||||
pub fn machGfxTextUpdated(
|
||||
pub fn updated(
|
||||
engine: *mach.Mod(.engine),
|
||||
text_mod: *mach.Mod(.mach_gfx_text),
|
||||
pipeline_id: u32,
|
||||
|
|
@ -498,7 +499,7 @@ pub fn machGfxTextUpdated(
|
|||
engine.state.queue.submit(&[_]*gpu.CommandBuffer{command});
|
||||
}
|
||||
|
||||
pub fn machGfxTextPreRender(
|
||||
pub fn preRender(
|
||||
engine: *mach.Mod(.engine),
|
||||
text_mod: *mach.Mod(.mach_gfx_text),
|
||||
pipeline_id: u32,
|
||||
|
|
@ -526,7 +527,7 @@ pub fn machGfxTextPreRender(
|
|||
engine.state.encoder.writeBuffer(pipeline.uniforms, 0, &[_]Uniforms{uniforms});
|
||||
}
|
||||
|
||||
pub fn machGfxTextRender(
|
||||
pub fn render(
|
||||
engine: *mach.Mod(.engine),
|
||||
text_mod: *mach.Mod(.mach_gfx_text),
|
||||
pipeline_id: u32,
|
||||
|
|
@ -541,3 +542,4 @@ pub fn machGfxTextRender(
|
|||
pass.setBindGroup(0, pipeline.bind_group, &.{});
|
||||
pass.draw(total_vertices, 1, 0, 0);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue