diff --git a/assets/cubyz/blocks/baobab_branch.zig.zon b/assets/cubyz/blocks/baobab_branch.zig.zon index 94d8a0f6..95a91314 100644 --- a/assets/cubyz/blocks/baobab_branch.zig.zon +++ b/assets/cubyz/blocks/baobab_branch.zig.zon @@ -9,12 +9,12 @@ .model = .{ .radius = 4, }, - .texture_top = "cubyz:branch/baobab/dot", - .texture_bottom = "cubyz:branch/baobab/half_line", - .texture_right = "cubyz:branch/baobab/line", - .texture_left = "cubyz:branch/baobab/bend", - .texture_front = "cubyz:branch/baobab/intersection", - .texture_back = "cubyz:branch/baobab/cross", + .texture0 = "cubyz:branch/baobab/dot", + .texture1 = "cubyz:branch/baobab/half_line", + .texture2 = "cubyz:branch/baobab/line", + .texture3 = "cubyz:branch/baobab/bend", + .texture4 = "cubyz:branch/baobab/intersection", + .texture5 = "cubyz:branch/baobab/cross", .item = .{ .material = .{ .density = 0.2, diff --git a/assets/cubyz/blocks/birch_branch.zig.zon b/assets/cubyz/blocks/birch_branch.zig.zon index 639b5c05..5fe7035f 100644 --- a/assets/cubyz/blocks/birch_branch.zig.zon +++ b/assets/cubyz/blocks/birch_branch.zig.zon @@ -9,12 +9,12 @@ .model = .{ .radius = 4, }, - .texture_top = "cubyz:branch/birch/dot", - .texture_bottom = "cubyz:branch/birch/half_line", - .texture_right = "cubyz:branch/birch/line", - .texture_left = "cubyz:branch/birch/bend", - .texture_front = "cubyz:branch/birch/intersection", - .texture_back = "cubyz:branch/birch/cross", + .texture0 = "cubyz:branch/birch/dot", + .texture1 = "cubyz:branch/birch/half_line", + .texture2 = "cubyz:branch/birch/line", + .texture3 = "cubyz:branch/birch/bend", + .texture4 = "cubyz:branch/birch/intersection", + .texture5 = "cubyz:branch/birch/cross", .item = .{ .material = .{ .density = 0.3, diff --git a/assets/cubyz/blocks/cactus_arm.zig.zon b/assets/cubyz/blocks/cactus_arm.zig.zon index ce1857e4..d1b2ae9e 100644 --- a/assets/cubyz/blocks/cactus_arm.zig.zon +++ b/assets/cubyz/blocks/cactus_arm.zig.zon @@ -9,12 +9,12 @@ .model = .{ .radius = 4, }, - .texture_top = "cubyz:branch/cactus/dot", - .texture_bottom = "cubyz:branch/cactus/half_line", - .texture_right = "cubyz:branch/cactus/line", - .texture_left = "cubyz:branch/cactus/bend", - .texture_front = "cubyz:branch/cactus/intersection", - .texture_back = "cubyz:branch/cactus/cross", + .texture0 = "cubyz:branch/cactus/dot", + .texture1 = "cubyz:branch/cactus/half_line", + .texture2 = "cubyz:branch/cactus/line", + .texture3 = "cubyz:branch/cactus/bend", + .texture4 = "cubyz:branch/cactus/intersection", + .texture5 = "cubyz:branch/cactus/cross", .item = .{ .material = .{ .density = 0.8, diff --git a/assets/cubyz/blocks/mahogany_branch.zig.zon b/assets/cubyz/blocks/mahogany_branch.zig.zon index 74074274..71534471 100644 --- a/assets/cubyz/blocks/mahogany_branch.zig.zon +++ b/assets/cubyz/blocks/mahogany_branch.zig.zon @@ -9,12 +9,12 @@ .model = .{ .radius = 4, }, - .texture_top = "cubyz:branch/mahogany/dot", - .texture_bottom = "cubyz:branch/mahogany/half_line", - .texture_right = "cubyz:branch/mahogany/line", - .texture_left = "cubyz:branch/mahogany/bend", - .texture_front = "cubyz:branch/mahogany/intersection", - .texture_back = "cubyz:branch/mahogany/cross", + .texture0 = "cubyz:branch/mahogany/dot", + .texture1 = "cubyz:branch/mahogany/half_line", + .texture2 = "cubyz:branch/mahogany/line", + .texture3 = "cubyz:branch/mahogany/bend", + .texture4 = "cubyz:branch/mahogany/intersection", + .texture5 = "cubyz:branch/mahogany/cross", .item = .{ .material = .{ .density = 0.5, diff --git a/assets/cubyz/blocks/oak_branch.zig.zon b/assets/cubyz/blocks/oak_branch.zig.zon index dcc08545..03014557 100644 --- a/assets/cubyz/blocks/oak_branch.zig.zon +++ b/assets/cubyz/blocks/oak_branch.zig.zon @@ -9,12 +9,12 @@ .model = .{ .radius = 4, }, - .texture_top = "cubyz:branch/oak/dot", - .texture_bottom = "cubyz:branch/oak/half_line", - .texture_right = "cubyz:branch/oak/line", - .texture_left = "cubyz:branch/oak/bend", - .texture_front = "cubyz:branch/oak/intersection", - .texture_back = "cubyz:branch/oak/cross", + .texture0 = "cubyz:branch/oak/dot", + .texture1 = "cubyz:branch/oak/half_line", + .texture2 = "cubyz:branch/oak/line", + .texture3 = "cubyz:branch/oak/bend", + .texture4 = "cubyz:branch/oak/intersection", + .texture5 = "cubyz:branch/oak/cross", .item = .{ .material = .{ .density = 0.25, diff --git a/assets/cubyz/blocks/pine_branch.zig.zon b/assets/cubyz/blocks/pine_branch.zig.zon index a21a878e..c1a33001 100644 --- a/assets/cubyz/blocks/pine_branch.zig.zon +++ b/assets/cubyz/blocks/pine_branch.zig.zon @@ -9,12 +9,12 @@ .model = .{ .radius = 4, }, - .texture_top = "cubyz:branch/pine/dot", - .texture_bottom = "cubyz:branch/pine/half_line", - .texture_right = "cubyz:branch/pine/line", - .texture_left = "cubyz:branch/pine/bend", - .texture_front = "cubyz:branch/pine/intersection", - .texture_back = "cubyz:branch/pine/cross", + .texture0 = "cubyz:branch/pine/dot", + .texture1 = "cubyz:branch/pine/half_line", + .texture2 = "cubyz:branch/pine/line", + .texture3 = "cubyz:branch/pine/bend", + .texture4 = "cubyz:branch/pine/intersection", + .texture5 = "cubyz:branch/pine/cross", .item = .{ .material = .{ .density = 0.25, diff --git a/assets/cubyz/blocks/willow_branch.zig.zon b/assets/cubyz/blocks/willow_branch.zig.zon index 8826f043..8a7f5f12 100644 --- a/assets/cubyz/blocks/willow_branch.zig.zon +++ b/assets/cubyz/blocks/willow_branch.zig.zon @@ -9,12 +9,12 @@ .model = .{ .radius = 4, }, - .texture_top = "cubyz:branch/willow/dot", - .texture_bottom = "cubyz:branch/willow/half_line", - .texture_right = "cubyz:branch/willow/line", - .texture_left = "cubyz:branch/willow/bend", - .texture_front = "cubyz:branch/willow/intersection", - .texture_back = "cubyz:branch/willow/cross", + .texture0 = "cubyz:branch/willow/dot", + .texture1 = "cubyz:branch/willow/half_line", + .texture2 = "cubyz:branch/willow/line", + .texture3 = "cubyz:branch/willow/bend", + .texture4 = "cubyz:branch/willow/intersection", + .texture5 = "cubyz:branch/willow/cross", .item = .{ .material = .{ .density = 0.5, diff --git a/src/blocks.zig b/src/blocks.zig index 963dea1a..8c04acb5 100644 --- a/src/blocks.zig +++ b/src/blocks.zig @@ -429,16 +429,13 @@ pub const meshes = struct { // MARK: meshes time: u32, }; - const TextureData = extern struct { - textureIndices: [6]u16, - }; const FogData = extern struct { fogDensity: f32, fogColor: u32, }; var size: u32 = 0; var _modelIndex: [maxBlockCount]ModelIndex = undefined; - var textureData: [maxBlockCount]TextureData = undefined; + var textureIndices: [maxBlockCount][16]u16 = undefined; /// Stores the number of textures after each block was added. Used to clean additional textures when the world is switched. var maxTextureCount: [maxBlockCount]u32 = undefined; /// Number of loaded meshes. Used to determine if an update is needed. @@ -556,11 +553,11 @@ pub const meshes = struct { // MARK: meshes } pub inline fn fogDensity(block: Block) f32 { - return textureFogData.items[animation.items[textureData[block.typ].textureIndices[0]].startFrame].fogDensity; + return textureFogData.items[animation.items[textureIndices[block.typ][0]].startFrame].fogDensity; } pub inline fn fogColor(block: Block) u32 { - return textureFogData.items[animation.items[textureData[block.typ].textureIndices[0]].startFrame].fogColor; + return textureFogData.items[animation.items[textureIndices[block.typ][0]].startFrame].fogColor; } pub inline fn hasFog(block: Block) bool { @@ -569,9 +566,9 @@ pub const meshes = struct { // MARK: meshes pub inline fn textureIndex(block: Block, orientation: usize) u16 { if(orientation < 16) { - return textureData[block.typ].textureIndices[orientation]; + return textureIndices[block.typ][orientation]; } else { - return textureData[block.data].textureIndices[orientation - 16]; + return textureIndices[block.data][orientation - 16]; } } @@ -657,10 +654,13 @@ pub const meshes = struct { // MARK: meshes return result; } - pub fn getTextureIndices(zon: ZonElement, assetFolder: []const u8, textureIndicesRef: []u16) void { + pub fn getTextureIndices(zon: ZonElement, assetFolder: []const u8, textureIndicesRef: *[16]u16) void { const defaultIndex = readTexture(zon.get(?[]const u8, "texture", null), assetFolder) catch 0; - for(textureIndicesRef, sideNames) |*ref, name| { - const textureId = zon.get(?[]const u8, name, null); + inline for(textureIndicesRef, 0..) |*ref, i| { + var textureId = zon.get(?[]const u8, std.fmt.comptimePrint("texture{}", .{i}), null); + if(i < sideNames.len) { + textureId = zon.get(?[]const u8, sideNames[i], textureId); + } ref.* = readTexture(textureId, assetFolder) catch defaultIndex; } } @@ -671,7 +671,7 @@ pub const meshes = struct { // MARK: meshes // The actual model is loaded later, in the rendering thread. // But textures can be loaded here: - getTextureIndices(zon, assetFolder, &textureData[meshes.size].textureIndices); + getTextureIndices(zon, assetFolder, &textureIndices[meshes.size]); maxTextureCount[meshes.size] = @intCast(textureIDs.items.len);