Minor refactors and cleanups
This commit is contained in:
@@ -3,7 +3,7 @@ const std = @import("std");
|
||||
|
||||
const stbi = @import("zstbi");
|
||||
|
||||
const atoms = @import("../engine/atoms.zig");
|
||||
const Atom = @import("../engine/Atom.zig").Atom;
|
||||
const Engine = @import("../engine/Engine.zig");
|
||||
const Texture = @import("../engine/Texture.zig");
|
||||
|
||||
@@ -13,7 +13,7 @@ textures: Array,
|
||||
pub const capacity = std.math.maxInt(std.meta.Tag(Id));
|
||||
|
||||
pub const Key = struct {
|
||||
atom: atoms.Atom,
|
||||
atom: Atom,
|
||||
usage: Texture.Usage,
|
||||
};
|
||||
|
||||
@@ -93,7 +93,7 @@ pub fn init(engine: *Engine, allocator: std.mem.Allocator) !Textures {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Textures, engine: *Engine, allocator: std.mem.Allocator) void {
|
||||
std.log.debug("Deinitializing {*} with {*} and Allocator{{{*},{*}}}", .{ self, engine, allocator.ptr, allocator.vtable });
|
||||
std.log.scoped(.deinit).debug("Deinitializing {*} with {*} and Allocator{{{*},{*}}}", .{ self, engine, allocator.ptr, allocator.vtable });
|
||||
|
||||
for (self.textures.items) |*texture| {
|
||||
texture.deinit(engine);
|
||||
@@ -103,13 +103,13 @@ pub fn deinit(self: *Textures, engine: *Engine, allocator: std.mem.Allocator) vo
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
pub fn getAtom(self: *const Textures, atom: atoms.Atom, usage: Texture.Usage) ?Id {
|
||||
pub fn getAtom(self: *const Textures, atom: Atom, usage: Texture.Usage) ?Id {
|
||||
const key: Key = .{ .atom = atom, .usage = usage };
|
||||
return self.map.get(key);
|
||||
}
|
||||
|
||||
pub fn getFilename(self: *const Textures, filename: []const u8, usage: Texture.Usage) ?Id {
|
||||
const atom = atoms.getAtom(filename) orelse return null;
|
||||
const atom = Atom.fromStringIfExists(filename) orelse return null;
|
||||
const key: Key = .{ .atom = atom, .usage = usage };
|
||||
return self.map.get(key);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ pub fn getTexture(self: *const Textures, id: Id) ?*Texture {
|
||||
return if (index < self.textures.items.len) &self.textures.items[index] else null;
|
||||
}
|
||||
|
||||
pub fn getOrLoadAtom(self: *Textures, engine: *Engine, atom: atoms.Atom, usage: Texture.Usage, temp_allocator: std.mem.Allocator) !Id {
|
||||
pub fn getOrLoadAtom(self: *Textures, engine: *Engine, atom: Atom, usage: Texture.Usage, temp_allocator: std.mem.Allocator) !Id {
|
||||
const key: Key = .{ .atom = atom, .usage = usage };
|
||||
const entry = self.map.getOrPutAssumeCapacity(key);
|
||||
|
||||
@@ -127,7 +127,7 @@ pub fn getOrLoadAtom(self: *Textures, engine: *Engine, atom: atoms.Atom, usage:
|
||||
return entry.value_ptr.*;
|
||||
} else {
|
||||
errdefer _ = self.map.remove(key);
|
||||
const texture = try loadTexture(engine, atoms.getString(atom), usage, temp_allocator);
|
||||
const texture = try loadTexture(engine, atom.toString(), usage, temp_allocator);
|
||||
const id = self.nextId();
|
||||
entry.value_ptr.* = id;
|
||||
self.textures.appendAssumeCapacity(texture);
|
||||
@@ -136,7 +136,7 @@ pub fn getOrLoadAtom(self: *Textures, engine: *Engine, atom: atoms.Atom, usage:
|
||||
}
|
||||
|
||||
pub fn getOrLoadFilename(self: *Textures, engine: *Engine, filename: []const u8, usage: Texture.Usage, temp_allocator: std.mem.Allocator) !Id {
|
||||
const atom = try atoms.getOrPutAtom(filename);
|
||||
const atom = try Atom.fromString(filename);
|
||||
const key: Key = .{ .atom = atom, .usage = usage };
|
||||
const entry = self.map.getOrPutAssumeCapacity(key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user