From 386ff639034653cfb58b14080825b3927e410c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Wi=C5=9Bniewski?= Date: Wed, 23 Apr 2025 15:36:22 +0200 Subject: [PATCH] Unify 'Registered x' log message format (#1335) * Unify 'Registered x' log message format * Apply review change requests --- src/blocks.zig | 6 ++++-- src/items.zig | 11 +++++++---- src/server/command/_command.zig | 2 +- src/server/terrain/biomes.zig | 3 ++- src/server/terrain/structure_building_blocks.zig | 7 ++++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/blocks.zig b/src/blocks.zig index 306d7f14..11ef3e53 100644 --- a/src/blocks.zig +++ b/src/blocks.zig @@ -93,6 +93,7 @@ pub fn register(_: []const u8, id: []const u8, zon: ZonElement) u16 { if(reverseIndices.contains(id)) { std.log.err("Registered block with id {s} twice!", .{id}); } + _id[size] = allocator.dupe(u8, id); reverseIndices.put(_id[size], @intCast(size)) catch unreachable; @@ -140,8 +141,9 @@ pub fn register(_: []const u8, id: []const u8, zon: ZonElement) u16 { }); } - size += 1; - return @intCast(size - 1); + defer size += 1; + std.log.debug("Registered block: {d: >5} '{s}'", .{size, id}); + return @intCast(size); } fn registerBlockDrop(typ: u16, zon: ZonElement) void { diff --git a/src/items.zig b/src/items.zig index 83cb57d4..44574d12 100644 --- a/src/items.zig +++ b/src/items.zig @@ -850,14 +850,16 @@ pub fn globalInit() void { } pub fn register(_: []const u8, texturePath: []const u8, replacementTexturePath: []const u8, id: []const u8, zon: ZonElement) *BaseItem { - std.log.info("{s}", .{id}); if(reverseIndices.contains(id)) { - std.log.err("Registered item with id {s} twice!", .{id}); + std.log.err("Registered item with id '{s}' twice!", .{id}); } const newItem = &itemList[itemListSize]; + defer itemListSize += 1; + newItem.init(arena.allocator(), texturePath, replacementTexturePath, id, zon); reverseIndices.put(newItem.id, newItem) catch unreachable; - itemListSize += 1; + + std.log.debug("Registered item: {d: >5} '{s}'", .{itemListSize, id}); return newItem; } @@ -897,7 +899,6 @@ fn loadPixelSources(assetFolder: []const u8, id: []const u8, layerPostfix: []con } pub fn registerTool(assetFolder: []const u8, id: []const u8, zon: ZonElement) void { - std.log.info("Registering tool type {s}", .{id}); if(toolTypes.contains(id)) { std.log.err("Registered tool type with id {s} twice!", .{id}); } @@ -942,6 +943,8 @@ pub fn registerTool(assetFolder: []const u8, id: []const u8, zon: ZonElement) vo .pixelSources = pixelSources, .pixelSourcesOverlay = pixelSourcesOverlay, }) catch unreachable; + + std.log.debug("Registered tool: '{s}'", .{id}); } fn parseRecipeItem(zon: ZonElement) !ItemStack { diff --git a/src/server/command/_command.zig b/src/server/command/_command.zig index 5d95c997..7ed24e51 100644 --- a/src/server/command/_command.zig +++ b/src/server/command/_command.zig @@ -22,7 +22,7 @@ pub fn init() void { .usage = @field(commandList, decl.name).usage, .exec = &@field(commandList, decl.name).execute, }) catch unreachable; - std.log.info("Registered Command: /{s}", .{decl.name}); + std.log.debug("Registered command: '/{s}'", .{decl.name}); } } diff --git a/src/server/terrain/biomes.zig b/src/server/terrain/biomes.zig index fa7b98f2..7fb6fa5d 100644 --- a/src/server/terrain/biomes.zig +++ b/src/server/terrain/biomes.zig @@ -666,14 +666,15 @@ pub fn deinit() void { } pub fn register(id: []const u8, paletteId: u32, zon: ZonElement) void { - std.log.debug("Registered biome: {s}", .{id}); std.debug.assert(!finishedLoading); var biome: Biome = undefined; biome.init(id, paletteId, zon); if(biome.isCave) { caveBiomes.append(biome); + std.log.debug("Registered cave biome: {d: >5} '{s}'", .{paletteId, id}); } else { biomes.append(biome); + std.log.debug("Registered surface biome: {d: >5} '{s}'", .{paletteId, id}); } } diff --git a/src/server/terrain/structure_building_blocks.zig b/src/server/terrain/structure_building_blocks.zig index 188341f1..186d6607 100644 --- a/src/server/terrain/structure_building_blocks.zig +++ b/src/server/terrain/structure_building_blocks.zig @@ -200,20 +200,21 @@ pub fn registerSBB(structures: *std.StringHashMap(ZonElement)) !void { } pub fn registerChildBlock(numericId: u16, stringId: []const u8) void { + std.debug.assert(numericId != 0); + const index: u16 = @intCast(childBlockNumericIdMap.count()); childBlockNumericIdMap.put(arenaAllocator.allocator, numericId, index) catch unreachable; // Take only color name from the ID. var iterator = std.mem.splitBackwardsScalar(u8, stringId, '/'); const colorName = iterator.first(); childBlockStringId.append(arenaAllocator, arenaAllocator.dupe(u8, colorName)); - std.log.debug("Structure child block '{s}' {} ('{s}' {}) ", .{colorName, index, stringId, numericId}); } pub fn registerBlueprints(blueprints: *std.StringHashMap([]u8)) !void { std.debug.assert(blueprintCache.capacity() == 0); originBlockNumericId = main.blocks.parseBlock(originBlockStringId).typ; - std.log.debug("Origin block numeric id: {}", .{originBlockNumericId}); + std.debug.assert(originBlockNumericId != 0); blueprintCache.ensureTotalCapacity(arenaAllocator.allocator, blueprints.count()) catch unreachable; @@ -234,7 +235,7 @@ pub fn registerBlueprints(blueprints: *std.StringHashMap([]u8)) !void { }; blueprintCache.put(arenaAllocator.allocator, arenaAllocator.dupe(u8, stringId), rotatedBlueprints) catch unreachable; - std.log.debug("Registered blueprint: {s}", .{stringId}); + std.log.debug("Registered blueprint: '{s}'", .{stringId}); } }