mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Improve priority calculation for light maps so it always generates the light maps before the contained terrain.
Fixes #243
This commit is contained in:
parent
f774ccf370
commit
4330f33d36
@ -7,6 +7,7 @@ const Chunk = main.chunk.Chunk;
|
||||
const ChunkPosition = main.chunk.ChunkPosition;
|
||||
const Cache = main.utils.Cache;
|
||||
const JsonElement = main.JsonElement;
|
||||
const Vec3d = main.vec.Vec3d;
|
||||
|
||||
const terrain = @import("terrain.zig");
|
||||
const TerrainGenerationProfile = terrain.TerrainGenerationProfile;
|
||||
@ -39,6 +40,19 @@ pub const MapFragmentPosition = struct {
|
||||
pub fn hashCode(self: MapFragmentPosition) u32 {
|
||||
return @bitCast((self.wx >> (MapFragment.mapShift + self.voxelSizeShift))*%33 +% (self.wz >> (MapFragment.mapShift + self.voxelSizeShift)) ^ self.voxelSize);
|
||||
}
|
||||
|
||||
pub fn getMinDistanceSquared(self: MapFragmentPosition, playerPosition: Vec3d, comptime width: comptime_int) f64 {
|
||||
const halfWidth: f64 = @floatFromInt(self.voxelSize*@divExact(width, 2));
|
||||
var dx = @abs(@as(f64, @floatFromInt(self.wx)) + halfWidth - playerPosition[0]);
|
||||
var dz = @abs(@as(f64, @floatFromInt(self.wz)) + halfWidth - playerPosition[2]);
|
||||
dx = @max(0, dx - halfWidth);
|
||||
dz = @max(0, dz - halfWidth);
|
||||
return dx*dx + dz*dz;
|
||||
}
|
||||
|
||||
pub fn getPriority(self: MapFragmentPosition, playerPos: Vec3d, comptime width: comptime_int) f32 {
|
||||
return -@as(f32, @floatCast(self.getMinDistanceSquared(playerPos, width)))/@as(f32, @floatFromInt(self.voxelSize*self.voxelSize)) + 2*@as(f32, @floatFromInt(std.math.log2_int(u31, self.voxelSize)))*width*width;
|
||||
}
|
||||
};
|
||||
|
||||
/// Generates and stores the height and Biome maps of the planet.
|
||||
|
@ -127,8 +127,7 @@ const ChunkManager = struct {
|
||||
|
||||
pub fn getPriority(self: *LightMapLoadTask) f32 {
|
||||
if(self.source) |user| {
|
||||
const pos = ChunkPosition{.wx = self.pos.wx, .wy = @intFromFloat(user.player.pos[1]), .wz = self.pos.wz, .voxelSize = self.pos.voxelSize};
|
||||
return pos.getPriority(user.player.pos) + 100000;
|
||||
return self.pos.getPriority(user.player.pos, terrain.LightMap.LightMapFragment.mapSize) + 100;
|
||||
} else {
|
||||
return std.math.floatMax(f32);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user