diff --git a/src/assets.zig b/src/assets.zig index e5005622..028cf364 100644 --- a/src/assets.zig +++ b/src/assets.zig @@ -122,7 +122,7 @@ fn registerItem(assetFolder: []const u8, id: []const u8, json: JsonElement) !*it } fn registerBlock(assetFolder: []const u8, id: []const u8, json: JsonElement) !void { - const block = try blocks_zig.register(assetFolder, id, json); // TODO: Modded block registries + const block = try blocks_zig.register(assetFolder, id, json); try blocks_zig.meshes.register(assetFolder, id, json); if(json.get(bool, "hasItem", true)) { diff --git a/src/blocks.zig b/src/blocks.zig index 3cd6ac3c..d05960f0 100644 --- a/src/blocks.zig +++ b/src/blocks.zig @@ -215,68 +215,68 @@ pub const Block = packed struct { return Block{.typ=@truncate(self), .data=@intCast(self>>16)}; } pub inline fn lightingTransparent(self: Block) bool { - return (&_lightingTransparent)[self.typ]; // TODO: #15685 + return _lightingTransparent[self.typ]; } pub inline fn transparent(self: Block) bool { - return (&_transparent)[self.typ]; // TODO: #15685 + return _transparent[self.typ]; } pub inline fn id(self: Block) []u8 { - return (&_id)[self.typ]; // TODO: #15685 + return _id[self.typ]; } /// Time in seconds to break this block by hand. pub inline fn hardness(self: Block) f32 { - return (&_hardness)[self.typ]; // TODO: #15685 + return _hardness[self.typ]; } /// Minimum pickaxe/axe/shovel power required. pub inline fn breakingPower(self: Block) f32 { - return (&_breakingPower)[self.typ]; // TODO: #15685 + return _breakingPower[self.typ]; } pub inline fn solid(self: Block) bool { - return (&_solid)[self.typ]; // TODO: #15685 + return _solid[self.typ]; } pub inline fn selectable(self: Block) bool { - return (&_selectable)[self.typ]; // TODO: #15685 + return _selectable[self.typ]; } pub inline fn blockDrops(self: Block) []BlockDrop { - return (&_blockDrops)[self.typ]; // TODO: #15685 + return _blockDrops[self.typ]; } /// Meaning undegradable parts of trees or other structures can grow through this block. pub inline fn degradable(self: Block) bool { - return (&_degradable)[self.typ]; // TODO: #15685 + return _degradable[self.typ]; } pub inline fn viewThrough(self: Block) bool { - return (&_viewThrough)[self.typ]; // TODO: #15685 + return _viewThrough[self.typ]; } pub inline fn blockClass(self: Block) BlockClass { - return (&_blockClass)[self.typ]; // TODO: #15685 + return _blockClass[self.typ]; } pub inline fn light(self: Block) u32 { - return (&_light)[self.typ]; // TODO: #15685 + return _light[self.typ]; } /// How much light this block absorbs if it is transparent. pub inline fn absorption(self: Block) u32 { - return (&_absorption)[self.typ]; // TODO: #15685 + return _absorption[self.typ]; } /// GUI that is opened on click. pub inline fn gui(self: Block) []u8 { - return (&_gui)[self.typ]; // TODO: #15685 + return _gui[self.typ]; } pub inline fn mode(self: Block) *RotationMode { - return (&_mode)[self.typ]; // TODO: #15685 + return _mode[self.typ]; } // TODO: @@ -386,7 +386,7 @@ pub const meshes = struct { } pub inline fn modelIndexStart(block: Block) u16 { - return (&_modelIndex)[block.typ]; // TODO: #15685 + return _modelIndex[block.typ]; } pub fn readTexture(textureInfo: JsonElement, assetFolder: []const u8) !?u31 { diff --git a/src/chunk.zig b/src/chunk.zig index d2f12f10..91aa1735 100644 --- a/src/chunk.zig +++ b/src/chunk.zig @@ -310,24 +310,6 @@ pub const Chunk = struct { } } - // Create updated meshes and send to client: - // TODO: - //for(int x = 0; x <= 2*xOffset; x += chunkSize) { - // for(int y = 0; y <= 2*yOffset; y += chunkSize) { - // for(int z = 0; z <= 2*zOffset; z += chunkSize) { - // int wx = this.wx + x*voxelSize - Chunk.chunkSize; - // int wy = this.wy + y*voxelSize - Chunk.chunkSize; - // int wz = this.wz + z*voxelSize - Chunk.chunkSize; - // if(voxelSize == 32) { - // wx -= chunkSize*voxelSize/2; - // wy -= chunkSize*voxelSize/2; - // wz -= chunkSize*voxelSize/2; - // } - // world.queueChunks(new ChunkData[] {new ChunkData(wx, wy, wz, voxelSize)}); - // } - // } - //} - self.setChanged(); } @@ -746,7 +728,7 @@ pub const meshing = struct { } } - pub fn updateBlock(self: *ChunkMesh, _x: i32, _y: i32, _z: i32, newBlock: Block) !void { // TODO: Investigate bug when placing blocks. + pub fn updateBlock(self: *ChunkMesh, _x: i32, _y: i32, _z: i32, newBlock: Block) !void { const x = _x & chunkMask; const y = _y & chunkMask; const z = _z & chunkMask; diff --git a/src/items.zig b/src/items.zig index 88141840..a6b96fe2 100644 --- a/src/items.zig +++ b/src/items.zig @@ -1249,16 +1249,6 @@ pub const ItemStack = struct { try self.storeToJson(result); return result; } - -// TODO: Check if/how this is needed: -// public int getBlock() { -// if(item == null) -// return 0; -// if(item instanceof ItemBlock) -// return ((ItemBlock) item).getBlock(); -// else -// return 0; -// } }; pub const Inventory = struct { @@ -1310,11 +1300,6 @@ pub const Inventory = struct { return false; } -// TODO: Check if/how this is needed: -// public int getBlock(int slot) { -// return items[slot].getBlock(); -// } - pub fn getItem(self: Inventory, slot: usize) ?Item { return self.items[slot].item; } diff --git a/src/renderer.zig b/src/renderer.zig index a9f39dba..41d116d9 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -143,7 +143,7 @@ pub fn updateViewport(width: u31, height: u31, fov: f32) void { pub fn render(playerPosition: Vec3d) !void { var startTime = std.time.milliTimestamp(); -// TODO: BlockMeshes.loadMeshes(); // Loads all meshes that weren't loaded yet +// TODO: // if (Cubyz.player != null) { // if (Cubyz.playerInc.x != 0 || Cubyz.playerInc.z != 0) { // while walking // if (bobbingUp) { @@ -165,10 +165,6 @@ pub fn render(playerPosition: Vec3d) !void { // Cubyz.player.vx = Cubyz.playerInc.x; // } // playerPosition.y += Player.cameraHeight + playerBobbing; -// } -// -// while (!Cubyz.renderDeque.isEmpty()) { -// Cubyz.renderDeque.pop().run(); // } if(game.world) |world| { // // TODO: Handle colors and sun position in the world. @@ -747,8 +743,6 @@ pub const MeshSelection = struct { lastPos = pos; var dir = vec.floatCast(f64, _dir); lastDir = _dir; -//TODO: -// intersection.set(0, 0, 0, dir.x, dir.y, dir.z); // Test blocks: const closestDistance: f64 = 6.0; // selection now limited @@ -980,7 +974,7 @@ pub const RenderStructure = struct { if(yIndex < 0 or yIndex >= (&lastSize[lod]).*) return null; if(zIndex < 0 or zIndex >= (&lastSize[lod]).*) return null; var index = (xIndex*(&lastSize[lod]).* + yIndex)*(&lastSize[lod]).* + zIndex; - return (&storageLists[lod]).*[@intCast(index)]; // TODO: Wait for #12205 to be fixed and remove the weird (&...).* workaround. + return storageLists[lod][@intCast(index)]; } pub fn getChunk(x: i32, y: i32, z: i32) ?*chunk.Chunk { diff --git a/src/rotation.zig b/src/rotation.zig index 53b37b01..e14e402d 100644 --- a/src/rotation.zig +++ b/src/rotation.zig @@ -119,7 +119,7 @@ pub const RotatedModel = struct { permutation: Permutation = Permutation{}, }; -// TODO: Why not just use a tageed union? +// TODO: Why not just use a tagged union? /// Each block gets 16 bit of additional storage(apart from the reference to the block type). /// These 16 bits are accessed and interpreted by the `RotationMode`. /// With the `RotationMode` interface there is almost no limit to what can be done with those 16 bit. diff --git a/src/server/terrain/CaveMap.zig b/src/server/terrain/CaveMap.zig index 06929807..cf65a316 100644 --- a/src/server/terrain/CaveMap.zig +++ b/src/server/terrain/CaveMap.zig @@ -66,7 +66,7 @@ pub const CaveMapFragment = struct { const relZ = _relZ >> self.voxelShift; const start = _start >> self.voxelShift; const end = _end >> self.voxelShift; - (&self.data)[getIndex(relX, relZ)] |= ~getMask(start, end); // TODO: #13938 + self.data[getIndex(relX, relZ)] |= ~getMask(start, end); } pub fn removeRange(self: *CaveMapFragment, _relX: i32, _relZ: i32, _start: i32, _end: i32) void { @@ -74,7 +74,7 @@ pub const CaveMapFragment = struct { const relZ = _relZ >> self.voxelShift; const start = _start >> self.voxelShift; const end = _end >> self.voxelShift; - (&self.data)[getIndex(relX, relZ)] &= getMask(start, end); // TODO: #13938 + self.data[getIndex(relX, relZ)] &= getMask(start, end); } pub fn getColumnData(self: *CaveMapFragment, _relX: i32, _relZ: i32) u64 { diff --git a/src/server/terrain/SurfaceMap.zig b/src/server/terrain/SurfaceMap.zig index 9a17eaad..9049fcab 100644 --- a/src/server/terrain/SurfaceMap.zig +++ b/src/server/terrain/SurfaceMap.zig @@ -73,13 +73,13 @@ pub const MapFragment = struct { pub fn getBiome(self: *MapFragment, wx: i32, wz: i32) *const Biome { const xIndex = wx>>self.pos.voxelSizeShift & mapMask; const zIndex = wz>>self.pos.voxelSizeShift & mapMask; - return (&self.biomeMap[@intCast(xIndex)])[@intCast(zIndex)]; // TODO: #15685 + return self.biomeMap[@intCast(xIndex)][@intCast(zIndex)]; } pub fn getHeight(self: *MapFragment, wx: i32, wz: i32) f32 { const xIndex = wx>>self.pos.voxelSizeShift & mapMask; const zIndex = wz>>self.pos.voxelSizeShift & mapMask; - return (&self.heightMap[@intCast(xIndex)])[@intCast(zIndex)]; // TODO: #15685 + return self.heightMap[@intCast(xIndex)][@intCast(zIndex)]; } }; diff --git a/src/server/terrain/biomes.zig b/src/server/terrain/biomes.zig index 1f28139c..157b365d 100644 --- a/src/server/terrain/biomes.zig +++ b/src/server/terrain/biomes.zig @@ -90,7 +90,7 @@ pub const Biome = struct { properties: GenerationProperties, isCave: bool, radius: f32, - minHeight: i32, // TODO: Use only one base height. + minHeight: i32, maxHeight: i32, interpolation: Interpolation, roughness: f32, @@ -108,7 +108,7 @@ pub const Biome = struct { subBiomes: main.utils.AliasTable(*const Biome) = undefined, maxSubBiomeCount: f32, subBiomeTotalChance: f32 = 0, - preferredMusic: []const u8, // TODO: Support multiple possibilities that are chose based on time and danger. + preferredMusic: []const u8, // TODO: Support multiple possibilities that are chosen based on time and danger. isValidPlayerSpawn: bool, chance: f32, @@ -333,7 +333,7 @@ pub const TreeNode = union(enum) { pub fn getBiome(self: *const TreeNode, seed: *u64, x: f32, y: f32) *const Biome { switch(self.*) { .leaf => |leaf| { - var biomeSeed = seed.* ^ @as(u64, 5624786589461)*%@as(u32, @bitCast(@as(i32, @intFromFloat(x)))) ^ @as(u64, 897650786185)*%@as(u32, @bitCast(@as(i32, @intFromFloat(y)))); // TODO: Use random.initSeed + var biomeSeed = main.random.initSeed2D(seed.*, main.vec.Vec2i{@intFromFloat(x), @intFromFloat(y)}); const result = leaf.aliasTable.sample(&biomeSeed); return result; }, diff --git a/src/server/terrain/cavegen/SurfaceGenerator.zig b/src/server/terrain/cavegen/SurfaceGenerator.zig index 24438915..0927125b 100644 --- a/src/server/terrain/cavegen/SurfaceGenerator.zig +++ b/src/server/terrain/cavegen/SurfaceGenerator.zig @@ -30,22 +30,13 @@ pub fn deinit() void { pub fn generate(map: *CaveMapFragment, worldSeed: u64) Allocator.Error!void { _ = worldSeed; - var x0: u31 = 0; - while(x0 < CaveMapFragment.width*map.pos.voxelSize) : (x0 += MapFragment.mapSize*map.pos.voxelSize) { - var z0: u31 = 0; - while(z0 < CaveMapFragment.width*map.pos.voxelSize) : (z0 += MapFragment.mapSize*map.pos.voxelSize) { - if(x0 != 0 or z0 != 0) { - std.log.err("TODO: Remove this print when it's printed. Otherwise remove the extra for loops. They are likely obsolete, but just to be sure it should be kept for a while.", .{}); - } - const mapFragment = try SurfaceMap.getOrGenerateFragment(map.pos.wx + x0, map.pos.wz + z0, map.pos.voxelSize); - defer mapFragment.deinit(); - var x: u31 = 0; - while(x < @min(CaveMapFragment.width*map.pos.voxelSize, MapFragment.mapSize*map.pos.voxelSize)) : (x += map.pos.voxelSize) { - var z: u31 = 0; - while(z < @min(CaveMapFragment.width*map.pos.voxelSize, MapFragment.mapSize*map.pos.voxelSize)) : (z += map.pos.voxelSize) { - map.addRange(x0 + x, z0 + z, 0, @as(i32, @intFromFloat(mapFragment.getHeight(map.pos.wx + x + x0, map.pos.wz + z + z0))) - map.pos.wy); - } - } + const mapFragment = try SurfaceMap.getOrGenerateFragment(map.pos.wx, map.pos.wz, map.pos.voxelSize); + defer mapFragment.deinit(); + var x: u31 = 0; + while(x < CaveMapFragment.width*map.pos.voxelSize) : (x += map.pos.voxelSize) { + var z: u31 = 0; + while(z < CaveMapFragment.width*map.pos.voxelSize) : (z += map.pos.voxelSize) { + map.addRange(x, z, 0, @as(i32, @intFromFloat(mapFragment.getHeight(map.pos.wx + x, map.pos.wz + z))) - map.pos.wy); } } } diff --git a/src/server/terrain/climategen/NoiseBasedVoronoi.zig b/src/server/terrain/climategen/NoiseBasedVoronoi.zig index 020f7c38..b6369b4a 100644 --- a/src/server/terrain/climategen/NoiseBasedVoronoi.zig +++ b/src/server/terrain/climategen/NoiseBasedVoronoi.zig @@ -80,7 +80,7 @@ const Chunk = struct { maxBiomeRadius: f32, fn getStartCoordinate(minX: f32, biomesSortedByX: []BiomePoint) usize { - // TODO: Should this by vectorized by storing the x-coordinate in a seperate []u8? + // TODO: Should this be vectorized by storing the x-coordinate in a seperate []u8? var start: usize = 0; var end: usize = biomesSortedByX.len; while(end - start > 16) { diff --git a/src/server/terrain/mapgen/MapGenV1.zig b/src/server/terrain/mapgen/MapGenV1.zig index 421338fc..f1996169 100644 --- a/src/server/terrain/mapgen/MapGenV1.zig +++ b/src/server/terrain/mapgen/MapGenV1.zig @@ -54,10 +54,9 @@ pub fn generateMapFragment(map: *MapFragment, worldSeed: u64) Allocator.Error!vo const offset = 8; const biomePositions = try terrain.ClimateMap.getBiomeMap(main.threadAllocator, map.pos.wx - offset*biomeSize, map.pos.wz - offset*biomeSize, mapSize + 2*offset*biomeSize, mapSize + 2*offset*biomeSize); defer biomePositions.deinit(main.threadAllocator); - var seed = worldSeed; - random.scrambleSeed(&seed); - seed = @as(u32, @bitCast((random.nextInt(i32, &seed) | 1)*%map.pos.wx ^ (random.nextInt(i32, &seed) | 1)*%map.pos.wz)); // TODO: Use random.initSeed2D(); + var seed = random.initSeed2D(worldSeed, .{map.pos.wx, map.pos.wz}); random.scrambleSeed(&seed); + seed ^= seed >> 16; const xOffsetMap = try Array2D(f32).init(main.threadAllocator, scaledSize, scaledSize); defer xOffsetMap.deinit(main.threadAllocator); diff --git a/src/server/terrain/noise/FractalNoise.zig b/src/server/terrain/noise/FractalNoise.zig index e8beb294..4b776388 100644 --- a/src/server/terrain/noise/FractalNoise.zig +++ b/src/server/terrain/noise/FractalNoise.zig @@ -4,12 +4,7 @@ const main = @import("root"); const Array2D = main.utils.Array2D; fn setSeed(x: i32, z: i32, offsetX: i32, offsetZ: i32, seed: *u64, worldSeed: u64, scale: u31, maxResolution: u31) void { - seed.* = worldSeed*%(scale*maxResolution | 1); - main.random.scrambleSeed(seed); - const l1 = main.random.nextInt(i64, seed); - const l2 = main.random.nextInt(i64, seed); - seed.* = @as(u64, @bitCast(((offsetX +% x)*%maxResolution*%l1) ^ ((offsetZ +% z)*%maxResolution*%l2))) ^ worldSeed; // TODO: Use random.initSeed2D(); - main.random.scrambleSeed(seed); + seed.* = main.random.initSeed2D(worldSeed*%(scale*maxResolution | 1), .{(offsetX +% x)*%maxResolution, (offsetZ +% z)*%maxResolution}); } pub fn generateFractalTerrain(wx: i32, wz: i32, x0: u31, z0: u31, width: u32, height: u32, scale: u31, worldSeed: u64, map: Array2D(f32), maxResolution: u31) !void { diff --git a/src/server/terrain/noise/RandomlyWeightedFractalNoise.zig b/src/server/terrain/noise/RandomlyWeightedFractalNoise.zig index e6c40733..bcce384c 100644 --- a/src/server/terrain/noise/RandomlyWeightedFractalNoise.zig +++ b/src/server/terrain/noise/RandomlyWeightedFractalNoise.zig @@ -4,12 +4,7 @@ const main = @import("root"); const Array2D = main.utils.Array2D; fn setSeed(x: i32, z: i32, offsetX: i32, offsetZ: i32, seed: *u64, worldSeed: u64, scale: u31, maxResolution: u31) void { - seed.* = worldSeed*%(scale*maxResolution | 1); - main.random.scrambleSeed(seed); - const l1 = main.random.nextInt(i64, seed); - const l2 = main.random.nextInt(i64, seed); - seed.* = @as(u64, @bitCast(((offsetX +% x)*%maxResolution*%l1) ^ ((offsetZ +% z)*%maxResolution*%l2))) ^ worldSeed; // TODO: Use random.initSeed2D(); - main.random.scrambleSeed(seed); + seed.* = main.random.initSeed2D(worldSeed*%(scale*maxResolution | 1), .{(offsetX +% x)*%maxResolution, (offsetZ +% z)*%maxResolution}); } pub fn generateFractalTerrain(wx: i32, wz: i32, x0: u31, z0: u31, width: u32, height: u32, scale: u31, worldSeed: u64, map: Array2D(f32), maxResolution: u31) !void { diff --git a/src/settings.zig b/src/settings.zig index 17724993..6f9f3d96 100644 --- a/src/settings.zig +++ b/src/settings.zig @@ -119,18 +119,4 @@ pub fn deinit() void { std.log.err("Error in settings.deinit(): {s}", .{@errorName(err)}); return; }; -} - -// TODO: Check if/how these are needed: -// static Side currentSide = null; -// -// private static Language currentLanguage = null; -// -// public static boolean musicOnOff = true; //Turn on or off the music -// -// /**Not actually a setting, but stored here anyways.*/ -// public static int EFFECTIVE_RENDER_DISTANCE = calculatedEffectiveRenderDistance(); -// -// public static int calculatedEffectiveRenderDistance() { -// return RENDER_DISTANCE + (((int)(RENDER_DISTANCE*LOD_FACTOR) & ~1) << Constants.HIGHEST_LOD); -// } \ No newline at end of file +} \ No newline at end of file