Globalize textures, materials and gui

This commit is contained in:
2026-05-23 01:37:28 +02:00
parent c971443b02
commit 40fcba9323
13 changed files with 195 additions and 242 deletions

View File

@@ -136,13 +136,7 @@ pub fn getAtom(self: *const Blocks, filename: Atom) ?Id {
});
}
pub fn getOrLoad(
self: *Blocks,
materials: *Materials,
textures: *Textures,
stbi: *media.stbi,
filename: []const u8,
) !Id {
pub fn getOrLoad(self: *Blocks, filename: []const u8) !Id {
const key: Key = .{
// If the material already exists, then the atom must exist and the
// following line will not return any error.
@@ -158,7 +152,7 @@ pub fn getOrLoad(
const id = Id.fromIndexSafe(self.array.items.len) catch |err| switch (err) {
error.Overflow => return error.OutOfBlocks,
};
const def = try loadBlock(materials, textures, stbi, filename);
const def = try loadBlock(filename);
self.map.putAssumeCapacityNoClobber(key, id);
self.array.appendAssumeCapacity(def);
@@ -167,13 +161,7 @@ pub fn getOrLoad(
}
}
pub fn getOrLoadAtom(
self: *Blocks,
materials: *Materials,
textures: *Textures,
stbi: *media.stbi,
filename: Atom,
) !Id {
pub fn getOrLoadAtom(self: *Blocks, filename: Atom) !Id {
const key: Key = .{
.filename = filename,
};
@@ -187,7 +175,7 @@ pub fn getOrLoadAtom(
const id = Id.fromIndexSafe(self.array.items.len) catch |err| switch (err) {
error.Overflow => return error.OutOfBlocks,
};
const def = try loadBlock(materials, textures, stbi, filename.toString());
const def = try loadBlock(filename.toString());
self.map.putAssumeCapacityNoClobber(key, id);
self.array.appendAssumeCapacity(def);
@@ -196,12 +184,7 @@ pub fn getOrLoadAtom(
}
}
pub fn loadAll(
self: *Blocks,
materials: *Materials,
textures: *Textures,
stbi: *media.stbi,
) void {
pub fn loadAll(self: *Blocks) void {
const io = ctx.io;
const cwd = std.Io.Dir.cwd();
@@ -222,20 +205,16 @@ pub fn loadAll(
continue;
}
_ = self.getOrLoad(materials, textures, stbi, entry.name) catch |err| {
_ = self.getOrLoad(entry.name) catch |err| {
std.log.err("Error while loading block definition entry {s}: {s}", .{ entry.name, @errorName(err) });
};
}
}
fn loadBlock(
materials: *Materials,
textures: *Textures,
stbi: *media.stbi,
filename: []const u8,
) !Definition {
fn loadBlock(filename: []const u8) !Definition {
const allocator_frame = ctx.allocator_frame;
const io = ctx.io;
const materials = ctx.materials;
const DefinitionJson = struct {
pub const Wall = struct {
@@ -278,7 +257,7 @@ fn loadBlock(
return error.ParseError;
}
const material = try materials.getOrLoad(textures, stbi, name);
const material = try materials.getOrLoad(name);
break :blk .initUniform(material);
}
@@ -288,7 +267,7 @@ fn loadBlock(
var ret: Definition.Walls = undefined;
inline for (@typeInfo(voxels.Orientation).@"enum".fields) |field| {
@field(ret, field.name) = .{
.material = try materials.getOrLoad(textures, stbi, @field(walls, field.name).material),
.material = try materials.getOrLoad(@field(walls, field.name).material),
.transform = @field(walls, field.name).transform,
};
}