VampireSurvivors/src/resource/textures.zig

70 lines
1.5 KiB
Zig
Raw Normal View History

2026-07-13 01:33:26 +01:00
// --- # ---
const std = @import("std");
const gtl = @import("gtl");
const sdl = @import("sdl");
const Self = @This();
//
//
//
pub const Player = struct {};
/// ----------------------------------------------------
/// ----------------------------------------------------
pub const Texture = struct { id: u64 };
/// ----------------------------------------------------
/// ----------------------------------------------------
pub const GPUTexture = struct {
path: []const u8,
raw: ?*sdl.SDL_Texture,
size: [2]i32 = .{ 0, 0 },
};
//
// FIELDS
//
data: gtl.KeyedSlotMap(Texture, GPUTexture),
/// ----------------------------------------------------
/// ----------------------------------------------------
pub fn init(alloc: std.mem.Allocator) Self {
return .{
.data = .init(alloc),
};
}
/// ----------------------------------------------------
/// ----------------------------------------------------
pub fn deinit(self: *Self) void {
for (self.data.items()) |entry| {
if (entry.value.raw) |raw| {
sdl.SDL_DestroyTexture(raw);
}
}
self.data.deinit();
}
/// ----------------------------------------------------
/// ----------------------------------------------------
pub fn load(
self: *Self,
comptime T: type,
path: []const u8,
) !gtl.Handle(Texture) {
// --- ID ---
const id = gtl.TypeID(T);
// --- # ---
if (self.data.getHandle(.{ .id = id })) |h| {
return h;
}
return try self.data.put(.{ .id = id }, .{
.path = path,
.raw = null,
});
}