make source files and build file compatible with current zig compiler 0.11.0-dev.1580+a5b34a61a
This commit is contained in:
parent
e0eb68dd5b
commit
94f38a3d89
@ -3,7 +3,10 @@ const Builder = std.build.Builder;
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
const build_mode = b.standardReleaseOptions();
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const ecs_module = b.createModule(.{
|
||||
.source_file = std.build.FileSource{ .path = "src/ecs.zig" },
|
||||
});
|
||||
|
||||
// use a different cache folder for macos arm builds
|
||||
b.cache_root = if (builtin.os.tag == .macos and builtin.target.cpu.arch == .aarch64) "zig-arm-cache" else "zig-cache";
|
||||
@ -18,11 +21,14 @@ pub fn build(b: *Builder) void {
|
||||
const name = if (i == 0) "ecs" else example[0];
|
||||
const source = example[1];
|
||||
|
||||
var exe = b.addExecutable(name, source);
|
||||
exe.setBuildMode(b.standardReleaseOptions());
|
||||
var exe = b.addExecutable(.{
|
||||
.name = name,
|
||||
.root_source_file = std.build.FileSource{ .path = source },
|
||||
.optimize = optimize,
|
||||
});
|
||||
exe.setOutputDir(std.fs.path.join(b.allocator, &[_][]const u8{ b.cache_root, "bin" }) catch unreachable);
|
||||
exe.addPackagePath("ecs", "src/ecs.zig");
|
||||
exe.linkSystemLibrary("c");
|
||||
exe.addModule("ecs", ecs_module);
|
||||
exe.linkLibC();
|
||||
|
||||
const docs = exe;
|
||||
docs.emit_docs = .emit;
|
||||
@ -42,13 +48,17 @@ pub fn build(b: *Builder) void {
|
||||
}
|
||||
|
||||
// internal tests
|
||||
const internal_test_step = b.addTest("src/tests.zig");
|
||||
internal_test_step.setBuildMode(build_mode);
|
||||
const internal_test_step = b.addTest(.{
|
||||
.root_source_file = std.build.FileSource{ .path = "src/tests.zig" },
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
// public api tests
|
||||
const test_step = b.addTest("tests/tests.zig");
|
||||
test_step.addPackagePath("ecs", "src/ecs.zig");
|
||||
test_step.setBuildMode(build_mode);
|
||||
const test_step = b.addTest(.{
|
||||
.root_source_file = std.build.FileSource{ .path = "tests/tests.zig" },
|
||||
.optimize = optimize,
|
||||
});
|
||||
test_step.addModule("ecs", ecs_module);
|
||||
|
||||
const test_cmd = b.step("test", "Run the tests");
|
||||
test_cmd.dependOn(&internal_test_step.step);
|
||||
@ -61,7 +71,7 @@ pub const LibType = enum(i32) {
|
||||
exe_compiled,
|
||||
};
|
||||
|
||||
pub fn getPackage(comptime prefix_path: []const u8) std.build.Pkg {
|
||||
pub fn getModule(comptime prefix_path: []const u8) std.build.Module {
|
||||
return .{
|
||||
.name = "ecs",
|
||||
.path = .{ .path = prefix_path ++ "src/ecs.zig" },
|
||||
@ -70,18 +80,16 @@ pub fn getPackage(comptime prefix_path: []const u8) std.build.Pkg {
|
||||
|
||||
/// prefix_path is used to add package paths. It should be the the same path used to include this build file
|
||||
pub fn linkArtifact(b: *Builder, artifact: *std.build.LibExeObjStep, _: std.build.Target, lib_type: LibType, comptime prefix_path: []const u8) void {
|
||||
const build_mode = b.standardReleaseOptions();
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
switch (lib_type) {
|
||||
.static => {
|
||||
const lib = b.addStaticLibrary("ecs", "ecs.zig");
|
||||
lib.setBuildMode(build_mode);
|
||||
const lib = b.addStaticLibrary(.{ .name = "ecs", .root_source_file = "ecs.zig", .optimize = optimize });
|
||||
lib.install();
|
||||
|
||||
artifact.linkLibrary(lib);
|
||||
},
|
||||
.dynamic => {
|
||||
const lib = b.addSharedLibrary("ecs", "ecs.zig", .unversioned);
|
||||
lib.setBuildMode(build_mode);
|
||||
const lib = b.addSharedLibrary(.{ .name = "ecs", .root_source_file = "ecs.zig", .optimize = optimize });
|
||||
lib.install();
|
||||
|
||||
artifact.linkLibrary(lib);
|
||||
@ -89,5 +97,5 @@ pub fn linkArtifact(b: *Builder, artifact: *std.build.LibExeObjStep, _: std.buil
|
||||
else => {},
|
||||
}
|
||||
|
||||
artifact.addPackage(getPackage(prefix_path));
|
||||
artifact.addModule(getModule(prefix_path));
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ pub const OwningGroup = struct {
|
||||
|
||||
var component_ptrs: [component_info.fields.len][*]u8 = undefined;
|
||||
inline for (component_info.fields) |field, i| {
|
||||
const storage = group.registry.assure(@typeInfo(field.field_type).Pointer.child);
|
||||
const storage = group.registry.assure(@typeInfo(field.type).Pointer.child);
|
||||
component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr);
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ pub const OwningGroup = struct {
|
||||
// fill and return the struct
|
||||
var comps: Components = undefined;
|
||||
inline for (@typeInfo(Components).Struct.fields) |field, i| {
|
||||
const typed_ptr = @ptrCast([*]@typeInfo(field.field_type).Pointer.child, @alignCast(@alignOf(@typeInfo(field.field_type).Pointer.child), it.component_ptrs[i]));
|
||||
const typed_ptr = @ptrCast([*]@typeInfo(field.type).Pointer.child, @alignCast(@alignOf(@typeInfo(field.type).Pointer.child), it.component_ptrs[i]));
|
||||
@field(comps, field.name) = &typed_ptr[it.index];
|
||||
}
|
||||
return comps;
|
||||
@ -161,8 +161,8 @@ pub const OwningGroup = struct {
|
||||
std.debug.assert(@typeInfo(Components) == .Struct);
|
||||
|
||||
inline for (@typeInfo(Components).Struct.fields) |field| {
|
||||
std.debug.assert(@typeInfo(field.field_type) == .Pointer);
|
||||
const found = std.mem.indexOfScalar(u32, self.group_data.owned, utils.typeId(std.meta.Child(field.field_type)));
|
||||
std.debug.assert(@typeInfo(field.type) == .Pointer);
|
||||
const found = std.mem.indexOfScalar(u32, self.group_data.owned, utils.typeId(std.meta.Child(field.type)));
|
||||
std.debug.assert(found != null);
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ pub const OwningGroup = struct {
|
||||
|
||||
var component_ptrs: [component_info.fields.len][*]u8 = undefined;
|
||||
inline for (component_info.fields) |field, i| {
|
||||
const storage = self.registry.assure(std.meta.Child(field.field_type));
|
||||
const storage = self.registry.assure(std.meta.Child(field.type));
|
||||
component_ptrs[i] = @ptrCast([*]u8, storage.instances.items.ptr);
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ pub const OwningGroup = struct {
|
||||
const index = self.firstOwnedStorage().set.index(entity);
|
||||
var comps: Components = undefined;
|
||||
inline for (component_info.fields) |field, i| {
|
||||
const typed_ptr = @ptrCast([*]std.meta.Child(field.field_type), @alignCast(@alignOf(std.meta.Child(field.field_type)), component_ptrs[i]));
|
||||
const typed_ptr = @ptrCast([*]std.meta.Child(field.type), @alignCast(@alignOf(std.meta.Child(field.type)), component_ptrs[i]));
|
||||
@field(comps, field.name) = &typed_ptr[index];
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ pub const OwningGroup = struct {
|
||||
// optionally we could just use an Iterator here and pay for some slight indirection for code sharing
|
||||
var iter = self.iterator(Components);
|
||||
while (iter.next()) |comps| {
|
||||
@call(.{ .modifier = .always_inline }, func, .{comps});
|
||||
@call(.always_inline, func, .{comps});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ pub fn Cache(comptime T: type) type {
|
||||
pub fn remove(self: *@This(), id: u32) void {
|
||||
if (self.resources.fetchRemove(id)) |kv| {
|
||||
if (@hasDecl(T, "deinit")) {
|
||||
@call(.{ .modifier = .always_inline }, @field(kv.value, "deinit"), .{});
|
||||
@call(.always_inline, @field(kv.value, "deinit"), .{});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,7 @@ pub fn Cache(comptime T: type) type {
|
||||
if (@hasDecl(T, "deinit")) {
|
||||
var iter = self.resources.iterator();
|
||||
while (iter.next()) |kv| {
|
||||
@call(.{ .modifier = .always_inline }, @field(kv.value_ptr.*, "deinit"), .{});
|
||||
@call(.always_inline, @field(kv.value_ptr.*, "deinit"), .{});
|
||||
}
|
||||
}
|
||||
self.resources.clearAndFree();
|
||||
|
@ -22,7 +22,7 @@ pub fn Delegate(comptime Event: type) type {
|
||||
.callback = .{
|
||||
.bound = struct {
|
||||
fn cb(self: usize, param: Event) void {
|
||||
@call(.{ .modifier = .always_inline }, @field(@intToPtr(T, self), fn_name), .{param});
|
||||
@call(.always_inline, @field(@intToPtr(T, self), fn_name), .{param});
|
||||
}
|
||||
}.cb,
|
||||
},
|
||||
@ -38,8 +38,8 @@ pub fn Delegate(comptime Event: type) type {
|
||||
|
||||
pub fn trigger(self: Self, param: Event) void {
|
||||
switch (self.callback) {
|
||||
.free => |func| @call(.{}, func, .{param}),
|
||||
.bound => |func| @call(.{}, func, .{ self.ctx_ptr_address, param }),
|
||||
.free => |func| @call(.auto, func, .{param}),
|
||||
.bound => |func| @call(.auto, func, .{ self.ctx_ptr_address, param }),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user