Minor refactors and cleanups
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const Blocks = @This();
|
||||
const std = @import("std");
|
||||
|
||||
const atoms = @import("../engine/atoms.zig");
|
||||
const Atom = @import("../engine/Atom.zig").Atom;
|
||||
const Engine = @import("../engine/Engine.zig");
|
||||
const Materials = @import("Materials.zig");
|
||||
const Textures = @import("Textures.zig");
|
||||
@@ -60,7 +60,7 @@ blocks: Array,
|
||||
|
||||
pub const capacity = std.math.maxInt(std.meta.Tag(Id));
|
||||
|
||||
pub const Key = struct { atom: atoms.Atom };
|
||||
pub const Key = struct { atom: Atom };
|
||||
pub const Id = enum(u12) {
|
||||
air = 0,
|
||||
_,
|
||||
@@ -91,20 +91,20 @@ pub fn init(allocator: std.mem.Allocator) !Blocks {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Blocks, allocator: std.mem.Allocator) void {
|
||||
std.log.debug("Deinitializing {*} with Allocator{{{*},{*}}}", .{ self, allocator.ptr, allocator.vtable });
|
||||
std.log.scoped(.deinit).debug("Deinitializing {*} with Allocator{{{*},{*}}}", .{ self, allocator.ptr, allocator.vtable });
|
||||
|
||||
self.blocks.deinit(allocator);
|
||||
self.map.deinit(allocator);
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
pub fn getAtom(self: *const Blocks, atom: atoms.Atom) ?Id {
|
||||
pub fn getAtom(self: *const Blocks, atom: Atom) ?Id {
|
||||
const key: Key = .{ .atom = atom };
|
||||
return self.map.get(key);
|
||||
}
|
||||
|
||||
pub fn getFilename(self: *const Blocks, filename: []const u8) ?Id {
|
||||
const atom = atoms.getAtom(filename) orelse return null;
|
||||
const atom = Atom.fromStringIfExists(filename) orelse return null;
|
||||
const key: Key = .{ .atom = atom };
|
||||
return self.map.get(key);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ pub fn getOrLoadAtom(
|
||||
engine: *Engine,
|
||||
materials: *Materials,
|
||||
textures: *Textures,
|
||||
atom: atoms.Atom,
|
||||
atom: Atom,
|
||||
temp_allocator: std.mem.Allocator,
|
||||
) !Id {
|
||||
const key: Key = .{ .atom = atom };
|
||||
@@ -129,7 +129,7 @@ pub fn getOrLoadAtom(
|
||||
return entry.value_ptr.*;
|
||||
} else {
|
||||
errdefer _ = self.map.remove(key);
|
||||
const block = try loadBlock(engine, materials, textures, atoms.getString(atom), temp_allocator);
|
||||
const block = try loadBlock(engine, materials, textures, Atom.toString(), temp_allocator);
|
||||
const id = self.nextId();
|
||||
entry.value_ptr.* = id;
|
||||
self.blocks.appendAssumeCapacity(block);
|
||||
@@ -145,7 +145,7 @@ pub fn getOrLoadFilename(
|
||||
filename: []const u8,
|
||||
temp_allocator: std.mem.Allocator,
|
||||
) !Id {
|
||||
const atom = try atoms.getOrPutAtom(filename);
|
||||
const atom = try Atom.fromString(filename);
|
||||
const key: Key = .{ .atom = atom };
|
||||
const entry = self.map.getOrPutAssumeCapacity(key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user