mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-10 21:07:54 -04:00
parent
eaaf524f99
commit
df99bfc804
@ -27,6 +27,7 @@ pub const Assets = struct {
|
|||||||
blocks: ZonHashMap,
|
blocks: ZonHashMap,
|
||||||
blockMigrations: AddonNameToZonMap,
|
blockMigrations: AddonNameToZonMap,
|
||||||
items: ZonHashMap,
|
items: ZonHashMap,
|
||||||
|
itemMigrations: ZonHashMap,
|
||||||
tools: ZonHashMap,
|
tools: ZonHashMap,
|
||||||
biomes: ZonHashMap,
|
biomes: ZonHashMap,
|
||||||
biomeMigrations: AddonNameToZonMap,
|
biomeMigrations: AddonNameToZonMap,
|
||||||
@ -41,6 +42,7 @@ pub const Assets = struct {
|
|||||||
.blocks = .{},
|
.blocks = .{},
|
||||||
.blockMigrations = .{},
|
.blockMigrations = .{},
|
||||||
.items = .{},
|
.items = .{},
|
||||||
|
.itemMigrations = .{},
|
||||||
.tools = .{},
|
.tools = .{},
|
||||||
.biomes = .{},
|
.biomes = .{},
|
||||||
.biomeMigrations = .{},
|
.biomeMigrations = .{},
|
||||||
@ -55,6 +57,7 @@ pub const Assets = struct {
|
|||||||
self.blocks.deinit(allocator.allocator);
|
self.blocks.deinit(allocator.allocator);
|
||||||
self.blockMigrations.deinit(allocator.allocator);
|
self.blockMigrations.deinit(allocator.allocator);
|
||||||
self.items.deinit(allocator.allocator);
|
self.items.deinit(allocator.allocator);
|
||||||
|
self.itemMigrations.deinit(allocator.allocator);
|
||||||
self.tools.deinit(allocator.allocator);
|
self.tools.deinit(allocator.allocator);
|
||||||
self.biomes.deinit(allocator.allocator);
|
self.biomes.deinit(allocator.allocator);
|
||||||
self.biomeMigrations.deinit(allocator.allocator);
|
self.biomeMigrations.deinit(allocator.allocator);
|
||||||
@ -69,6 +72,7 @@ pub const Assets = struct {
|
|||||||
.blocks = self.blocks.clone(allocator.allocator) catch unreachable,
|
.blocks = self.blocks.clone(allocator.allocator) catch unreachable,
|
||||||
.blockMigrations = self.blockMigrations.clone(allocator.allocator) catch unreachable,
|
.blockMigrations = self.blockMigrations.clone(allocator.allocator) catch unreachable,
|
||||||
.items = self.items.clone(allocator.allocator) catch unreachable,
|
.items = self.items.clone(allocator.allocator) catch unreachable,
|
||||||
|
.itemMigrations = self.itemMigrations.clone(allocator.allocator) catch unreachable,
|
||||||
.tools = self.tools.clone(allocator.allocator) catch unreachable,
|
.tools = self.tools.clone(allocator.allocator) catch unreachable,
|
||||||
.biomes = self.biomes.clone(allocator.allocator) catch unreachable,
|
.biomes = self.biomes.clone(allocator.allocator) catch unreachable,
|
||||||
.biomeMigrations = self.biomeMigrations.clone(allocator.allocator) catch unreachable,
|
.biomeMigrations = self.biomeMigrations.clone(allocator.allocator) catch unreachable,
|
||||||
@ -86,7 +90,7 @@ pub const Assets = struct {
|
|||||||
|
|
||||||
for(addons.items) |addon| {
|
for(addons.items) |addon| {
|
||||||
addon.readAllZon(allocator, "blocks", true, &self.blocks, &self.blockMigrations);
|
addon.readAllZon(allocator, "blocks", true, &self.blocks, &self.blockMigrations);
|
||||||
addon.readAllZon(allocator, "items", true, &self.items, null);
|
addon.readAllZon(allocator, "items", true, &self.items, &self.itemMigrations);
|
||||||
addon.readAllZon(allocator, "tools", true, &self.tools, null);
|
addon.readAllZon(allocator, "tools", true, &self.tools, null);
|
||||||
addon.readAllZon(allocator, "biomes", true, &self.biomes, &self.biomeMigrations);
|
addon.readAllZon(allocator, "biomes", true, &self.biomes, &self.biomeMigrations);
|
||||||
addon.readAllZon(allocator, "recipes", false, &self.recipes, null);
|
addon.readAllZon(allocator, "recipes", false, &self.recipes, null);
|
||||||
@ -98,8 +102,8 @@ pub const Assets = struct {
|
|||||||
}
|
}
|
||||||
fn log(self: *Assets, typ: enum {common, world}) void {
|
fn log(self: *Assets, typ: enum {common, world}) void {
|
||||||
std.log.info(
|
std.log.info(
|
||||||
"Finished {s} assets reading with {} blocks ({} migrations), {} items, {} tools, {} biomes ({} migrations), {} recipes, {} structure building blocks, {} blueprints and {} particles",
|
"Finished {s} assets reading with {} blocks ({} migrations), {} items ({} migrations), {} tools, {} biomes ({} migrations), {} recipes, {} structure building blocks, {} blueprints and {} particles",
|
||||||
.{@tagName(typ), self.blocks.count(), self.blockMigrations.count(), self.items.count(), self.tools.count(), self.biomes.count(), self.biomeMigrations.count(), self.recipes.count(), self.structureBuildingBlocks.count(), self.blueprints.count(), self.particles.count()},
|
.{@tagName(typ), self.blocks.count(), self.blockMigrations.count(), self.items.count(), self.itemMigrations.count(), self.tools.count(), self.biomes.count(), self.biomeMigrations.count(), self.recipes.count(), self.structureBuildingBlocks.count(), self.blueprints.count(), self.particles.count()},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +327,7 @@ fn createAssetStringID(
|
|||||||
pub fn init() void {
|
pub fn init() void {
|
||||||
biomes_zig.init();
|
biomes_zig.init();
|
||||||
blocks_zig.init();
|
blocks_zig.init();
|
||||||
|
migrations_zig.init();
|
||||||
|
|
||||||
commonAssetArena = .init(main.globalAllocator);
|
commonAssetArena = .init(main.globalAllocator);
|
||||||
commonAssetAllocator = commonAssetArena.allocator();
|
commonAssetAllocator = commonAssetArena.allocator();
|
||||||
@ -494,6 +499,9 @@ pub fn loadWorldAssets(assetFolder: []const u8, blockPalette: *Palette, itemPale
|
|||||||
migrations_zig.registerAll(.block, &worldAssets.blockMigrations);
|
migrations_zig.registerAll(.block, &worldAssets.blockMigrations);
|
||||||
migrations_zig.apply(.block, blockPalette);
|
migrations_zig.apply(.block, blockPalette);
|
||||||
|
|
||||||
|
migrations_zig.registerAll(.item, &worldAssets.itemMigrations);
|
||||||
|
migrations_zig.apply(.item, itemPalette);
|
||||||
|
|
||||||
migrations_zig.registerAll(.biome, &worldAssets.biomeMigrations);
|
migrations_zig.registerAll(.biome, &worldAssets.biomeMigrations);
|
||||||
migrations_zig.apply(.biome, biomePalette);
|
migrations_zig.apply(.biome, biomePalette);
|
||||||
|
|
||||||
@ -653,6 +661,7 @@ pub fn unloadAssets() void { // MARK: unloadAssets()
|
|||||||
sbb.reset();
|
sbb.reset();
|
||||||
blocks_zig.reset();
|
blocks_zig.reset();
|
||||||
items_zig.reset();
|
items_zig.reset();
|
||||||
|
migrations_zig.reset();
|
||||||
biomes_zig.reset();
|
biomes_zig.reset();
|
||||||
migrations_zig.reset();
|
migrations_zig.reset();
|
||||||
main.models.reset();
|
main.models.reset();
|
||||||
|
@ -5,14 +5,16 @@ const ZonElement = @import("zon.zig").ZonElement;
|
|||||||
const Palette = @import("assets.zig").Palette;
|
const Palette = @import("assets.zig").Palette;
|
||||||
const Assets = main.assets.Assets;
|
const Assets = main.assets.Assets;
|
||||||
|
|
||||||
var arenaAllocator = main.heap.NeverFailingArenaAllocator.init(main.globalAllocator);
|
var arenaAllocator: main.heap.NeverFailingArenaAllocator = undefined;
|
||||||
const migrationAllocator = arenaAllocator.allocator();
|
const migrationAllocator: main.heap.NeverFailingAllocator = arenaAllocator.allocator();
|
||||||
|
|
||||||
var blockMigrations: std.StringHashMap([]const u8) = .init(migrationAllocator.allocator);
|
var blockMigrations: std.StringHashMapUnmanaged([]const u8) = undefined;
|
||||||
var biomeMigrations: std.StringHashMap([]const u8) = .init(migrationAllocator.allocator);
|
var itemMigrations: std.StringHashMapUnmanaged([]const u8) = undefined;
|
||||||
|
var biomeMigrations: std.StringHashMapUnmanaged([]const u8) = undefined;
|
||||||
|
|
||||||
const MigrationType = enum {
|
const MigrationType = enum {
|
||||||
block,
|
block,
|
||||||
|
item,
|
||||||
biome,
|
biome,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,6 +22,7 @@ pub fn registerAll(comptime typ: MigrationType, migrations: *Assets.AddonNameToZ
|
|||||||
std.log.info("Registering {} {s} migrations", .{migrations.count(), @tagName(typ)});
|
std.log.info("Registering {} {s} migrations", .{migrations.count(), @tagName(typ)});
|
||||||
const collection = switch(typ) {
|
const collection = switch(typ) {
|
||||||
.block => &blockMigrations,
|
.block => &blockMigrations,
|
||||||
|
.item => &itemMigrations,
|
||||||
.biome => &biomeMigrations,
|
.biome => &biomeMigrations,
|
||||||
};
|
};
|
||||||
var migrationIterator = migrations.iterator();
|
var migrationIterator = migrations.iterator();
|
||||||
@ -30,7 +33,7 @@ pub fn registerAll(comptime typ: MigrationType, migrations: *Assets.AddonNameToZ
|
|||||||
|
|
||||||
fn register(
|
fn register(
|
||||||
comptime typ: MigrationType,
|
comptime typ: MigrationType,
|
||||||
collection: *std.StringHashMap([]const u8),
|
collection: *std.StringHashMapUnmanaged([]const u8),
|
||||||
addonName: []const u8,
|
addonName: []const u8,
|
||||||
migrationZon: ZonElement,
|
migrationZon: ZonElement,
|
||||||
) void {
|
) void {
|
||||||
@ -65,7 +68,7 @@ fn register(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const oldAssetId = std.fmt.allocPrint(migrationAllocator.allocator, "{s}:{s}", .{addonName, oldZon}) catch unreachable;
|
const oldAssetId = std.fmt.allocPrint(migrationAllocator.allocator, "{s}:{s}", .{addonName, oldZon}) catch unreachable;
|
||||||
const result = collection.getOrPut(oldAssetId) catch unreachable;
|
const result = collection.getOrPut(migrationAllocator.allocator, oldAssetId) catch unreachable;
|
||||||
|
|
||||||
if(result.found_existing) {
|
if(result.found_existing) {
|
||||||
std.log.err("Skipping name collision in {s} migration: '{s}' -> '{s}:{s}'", .{@tagName(typ), oldAssetId, addonName, newZon});
|
std.log.err("Skipping name collision in {s} migration: '{s}' -> '{s}:{s}'", .{@tagName(typ), oldAssetId, addonName, newZon});
|
||||||
@ -86,6 +89,7 @@ fn register(
|
|||||||
pub fn apply(comptime typ: MigrationType, palette: *Palette) void {
|
pub fn apply(comptime typ: MigrationType, palette: *Palette) void {
|
||||||
const migrations = switch(typ) {
|
const migrations = switch(typ) {
|
||||||
.block => blockMigrations,
|
.block => blockMigrations,
|
||||||
|
.item => itemMigrations,
|
||||||
.biome => biomeMigrations,
|
.biome => biomeMigrations,
|
||||||
};
|
};
|
||||||
std.log.info("Applying {} migrations to {s} palette", .{migrations.count(), @tagName(typ)});
|
std.log.info("Applying {} migrations to {s} palette", .{migrations.count(), @tagName(typ)});
|
||||||
@ -97,12 +101,23 @@ pub fn apply(comptime typ: MigrationType, palette: *Palette) void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn init() void {
|
||||||
|
biomeMigrations = .{};
|
||||||
|
blockMigrations = .{};
|
||||||
|
itemMigrations = .{};
|
||||||
|
arenaAllocator = .init(main.globalAllocator);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn reset() void {
|
pub fn reset() void {
|
||||||
blockMigrations.clearAndFree();
|
biomeMigrations = .{};
|
||||||
biomeMigrations.clearAndFree();
|
blockMigrations = .{};
|
||||||
|
itemMigrations = .{};
|
||||||
_ = arenaAllocator.reset(.free_all);
|
_ = arenaAllocator.reset(.free_all);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit() void {
|
pub fn deinit() void {
|
||||||
|
biomeMigrations = undefined;
|
||||||
|
blockMigrations = undefined;
|
||||||
|
itemMigrations = undefined;
|
||||||
arenaAllocator.deinit();
|
arenaAllocator.deinit();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user