summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig38
-rw-r--r--src/ecs/ecs.zig6
-rw-r--r--src/main.zig20
-rw-r--r--src/rendering/gltf.zig3
4 files changed, 40 insertions, 27 deletions
diff --git a/build.zig b/build.zig
index 0fbbc59..d86f76b 100644
--- a/build.zig
+++ b/build.zig
@@ -56,10 +56,16 @@ pub fn build(b: *std.Build) void {
glfw.linkLibC();
const mods = b.addModule("mods", .{
- .root_source_file = b.path("src/mods/mods.zig"),
- .target = target,
- .optimize = optimize,
- });
+ .root_source_file = b.path("src/mods/mods.zig"),
+ .target = target,
+ .optimize = optimize,
+ });
+
+ const ecs = b.addModule("ecs", .{
+ .root_source_file = b.path("src/ecs/ecs.zig"),
+ .target = target,
+ .optimize = optimize,
+ });
const exe = b.addExecutable(.{
.root_source_file = b.path("src/main.zig"),
@@ -68,9 +74,9 @@ pub fn build(b: *std.Build) void {
.name = "sideros",
});
exe.root_module.addImport("mods", mods);
+ exe.root_module.addImport("ecs", ecs);
exe.addIncludePath(b.path("ext/glfw/include"));
-
exe.linkSystemLibrary("vulkan");
compileAllShaders(b, exe);
exe.linkLibrary(glfw);
@@ -78,25 +84,25 @@ pub fn build(b: *std.Build) void {
b.installArtifact(exe);
- // TODO: This does not generate documentation correctly?
+ // TODO: This does not generate documentation correctly?
const install_docs = b.addInstallDirectory(.{
- .source_dir = exe.getEmittedDocs(),
- .install_dir = .prefix,
- .install_subdir = "docs",
+ .source_dir = exe.getEmittedDocs(),
+ .install_dir = .prefix,
+ .install_subdir = "docs",
});
const docs_step = b.step("docs", "Generate documentation");
docs_step.dependOn(&install_docs.step);
- // NOTE: This is a hack to generate documentation
+ // NOTE: This is a hack to generate documentation
const mods_lib = b.addStaticLibrary(.{
- .root_module = mods,
- .name = "mods",
+ .root_module = mods,
+ .name = "mods",
});
const mods_docs = b.addInstallDirectory(.{
- .source_dir = mods_lib.getEmittedDocs(),
- .install_dir = .prefix,
- .install_subdir = "docs/mods",
- });
+ .source_dir = mods_lib.getEmittedDocs(),
+ .install_dir = .prefix,
+ .install_subdir = "docs/mods",
+ });
docs_step.dependOn(&mods_docs.step);
const run_cmd = b.addRunArtifact(exe);
diff --git a/src/ecs/ecs.zig b/src/ecs/ecs.zig
new file mode 100644
index 0000000..278915b
--- /dev/null
+++ b/src/ecs/ecs.zig
@@ -0,0 +1,6 @@
+pub const components = @import("components.zig");
+const entities = @import("entities.zig");
+
+pub const Pool = entities.Pool;
+pub const System = *const fn (*Pool) void;
+pub const SystemGroup = []const System;
diff --git a/src/main.zig b/src/main.zig
index e8ff1d1..fce7776 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -6,14 +6,12 @@ const config = @import("config");
const Renderer = @import("rendering/renderer_vulkan.zig");
const math = @import("math.zig");
const mods = @import("mods");
+const ecs = @import("ecs");
-const components = @import("ecs/components.zig");
-const entities = @import("ecs/entities.zig");
-
-fn testSystem2(pool: *entities.Pool) void {
- for (pool.getQuery(components.Position), 0..) |position, i| {
- const entity = pool.getEntity(i, components.Position);
- if (pool.getComponent(entity, components.Speed)) |speed| {
+fn testSystem2(pool: *ecs.Pool) void {
+ for (pool.getQuery(ecs.components.Position), 0..) |position, i| {
+ const entity = pool.getEntity(i, ecs.components.Position);
+ if (pool.getComponent(entity, ecs.components.Speed)) |speed| {
std.debug.print("entity{d}: {any},{any},{any} {any}\n", .{ i, position.x, position.y, position.z, speed.speed });
}
}
@@ -46,20 +44,20 @@ pub fn main() !void {
const w = try window.Window.create(800, 600, "sideros");
defer w.destroy();
- var pool = try entities.Pool.init(allocator);
+ var pool = try ecs.Pool.init(allocator);
defer pool.deinit(allocator);
//try pool.addSystemGroup(&[_]entities.System{
// testSystem,
//});
- try pool.addSystemGroup(&[_]entities.System{
+ try pool.addSystemGroup(&[_]ecs.System{
testSystem2,
});
for (0..1000) |_| {
const entity = try pool.createEntity();
- try pool.addComponent(entity, components.Position{ .x = 1.0, .y = 0.5, .z = 3.0 });
- try pool.addComponent(entity, components.Speed{ .speed = 5.0 });
+ try pool.addComponent(entity, ecs.components.Position{ .x = 1.0, .y = 0.5, .z = 3.0 });
+ try pool.addComponent(entity, ecs.components.Speed{ .speed = 5.0 });
}
// TODO(luccie-cmd): Renderer.create shouldn't return an error
diff --git a/src/rendering/gltf.zig b/src/rendering/gltf.zig
new file mode 100644
index 0000000..2abeec1
--- /dev/null
+++ b/src/rendering/gltf.zig
@@ -0,0 +1,3 @@
+const std = @import("std");
+const mesh = @import("mesh.zig");
+const Allocator = std.mem.Allocator;