Cleanup some TODOs.

This commit is contained in:
IntegratedQuantum 2023-08-05 22:27:06 +02:00
parent 64ec48840d
commit 83e8d52120
15 changed files with 41 additions and 114 deletions

View File

@ -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)) {

View File

@ -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 {

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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.

View File

@ -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 {

View File

@ -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)];
}
};

View File

@ -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;
},

View File

@ -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);
}
}
}

View File

@ -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) {

View File

@ -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);

View File

@ -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 {

View File

@ -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 {

View File

@ -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);
// }
}