1
0
Fork 0

add option for immediate light updates

This commit is contained in:
Sen 2025-09-01 17:14:34 +02:00
parent 364ada6346
commit 3bc5181273
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
5 changed files with 72 additions and 11 deletions

View file

@ -564,6 +564,8 @@ public class Client implements IThreadListener {
private int lightUpdates = 2048;
@Variable(name = "chunk_light_range", category = CVarCategory.RENDER, min = 5, max = 1024, display = "Radius Licht-Updates")
private int lightRange = 32;
@Variable(name = "chunk_light_onload", category = CVarCategory.RENDER, min = 0, max = 32, display = "Licht-Init. / Tick")
private int lightInit = 0;
@Variable(name = "draw_fov", category = CVarCategory.RENDER, min = 1.0f, max = 179.0f, display = "Sichtfeld (FOV)", unit = "°", precision = 1)
public float fov = 70.0f;
@Variable(name = "draw_wireframe", category = CVarCategory.RENDER, display = "Gitter-Render-Modus")
@ -3645,7 +3647,20 @@ public class Client implements IThreadListener {
}
}
Set<ChunkPos> active = this.world.setActiveChunks(this.renderDistance);
Set<ChunkPos> active = this.world.getActiveChunks();
active.clear();
if(this.player != null) {
int x = ExtMath.floord(this.player.posX / 16.0D);
int z = ExtMath.floord(this.player.posZ / 16.0D);
for(int cx = -this.renderDistance; cx <= this.renderDistance; cx++) {
for(int cz = -this.renderDistance; cz <= this.renderDistance; cz++) {
active.add(new ChunkPos(cx + x, cz + z));
if(this.lightInit > 0)
this.getChunk(cx + x, cz + z).updateLight(this.lightInit);
}
}
}
this.previousActive.retainAll(active);
if (this.previousActive.size() == active.size())
{
@ -3658,8 +3673,6 @@ public class Client implements IThreadListener {
{
if (!this.previousActive.contains(chunkcoordintpair))
{
int j = chunkcoordintpair.x * 16;
int k = chunkcoordintpair.z * 16;
ChunkClient chunk = this.getChunk(chunkcoordintpair.x, chunkcoordintpair.z);
this.previousActive.add(chunkcoordintpair);
++i;

View file

@ -89,19 +89,21 @@ public class GuiGraphics extends GuiOptions {
this.addSelector("chunk_light_range", 0, 75, 240, 0);
this.addSelector("chunk_light_updates", 242, 75, 240, 0);
this.addSelector("chunk_build_time", 0, 95, 240, 0);
this.addSelector("draw_player_firstperson", 242, 95, 240, 0);
this.addSelector("chunk_light_onload", 0, 95, 240, 0);
this.addSelector("chunk_build_time", 242, 95, 240, 0);
this.addSelector("draw_downfall_range", 0, 115, 240, 0);
this.addSelector("draw_rain_particle_range", 242, 115, 240, 0);
this.addSelector("draw_player_firstperson", 0, 115, 240, 0);
this.addSelector("draw_void_particles", 0, 135, 240, 0);
this.addSelector("draw_void_fog", 242, 135, 240, 0);
this.addSelector("draw_downfall_range", 0, 135, 240, 0);
this.addSelector("draw_rain_particle_range", 242, 135, 240, 0);
this.addSelector("draw_void_particles", 0, 155, 240, 0);
this.addSelector("draw_void_fog", 242, 155, 240, 0);
if(this.gm.shaders)
this.addSelector("draw_use_shader", 0, 155, 240, 0);
this.addSelector("draw_use_shader", 0, 175, 240, 0);
else
this.add(new Fill(0, 155, 240, 0, Color.RED + "Shader nicht unterstützt"));
this.add(new Fill(0, 175, 240, 0, Color.RED + "Shader nicht unterstützt"));
super.init(width, height);
}

View file

@ -6,6 +6,7 @@ import common.block.Block;
import common.block.ITileEntityProvider;
import common.init.Blocks;
import common.tileentity.TileEntity;
import common.util.Facing;
import common.util.LocalPos;
import common.world.BlockArray;
import common.world.Chunk;
@ -16,6 +17,8 @@ public class ChunkClient extends Chunk {
private final float[] temperatures = new float[256];
private final float[] offsets = new float[256];
private int lightUpdates = Integer.MAX_VALUE;
public ChunkClient(World world, int x, int z) {
super(world, x, z);
}
@ -113,6 +116,8 @@ public class ChunkClient extends Chunk {
for(TileEntity tile : this.tiles.values()) {
tile.resetBlock();
}
this.lightUpdates = 0;
}
public void setLoaded() {
@ -188,4 +193,38 @@ public class ChunkClient extends Chunk {
stor.setLight(x, y & 15, z, value);
}
public void updateLight(int iters) {
if(this.lightUpdates == Integer.MAX_VALUE)
return;
LocalPos pos = new LocalPos(this.xPos << 4, 0, this.zPos << 4);
for(int n = 0; n < iters; ++n) {
if(this.top == Integer.MIN_VALUE) {
this.lightUpdates = Integer.MAX_VALUE;
return;
}
int h = 1 + (this.top >> 4) - (this.bottom >> 4);
if(this.lightUpdates >= 256 * h) {
this.lightUpdates = Integer.MAX_VALUE;
return;
}
int s = (this.lightUpdates % h) + (this.bottom >> 4);
int x = this.lightUpdates / h % 16;
int z = this.lightUpdates / 512;
++this.lightUpdates;
for(int y = 0; y < 16; ++y) {
LocalPos block = pos.add(x, (s << 4) + y, z);
boolean edge = y == 0 || y == 15 || x == 0 || x == 15 || z == 0 || z == 15;
BlockArray arr = this.getArray(s);
if(arr == null && edge || arr != null && arr.getBlock(x, y, z) == Blocks.air) {
for(Facing face : Facing.values()) {
LocalPos side = block.offset(face);
if(this.world.getState(side).getBlock().getLight() != 0)
this.world.checkBlockLight(side);
}
this.world.checkBlockLight(block);
}
}
}
}
}

View file

@ -152,4 +152,7 @@ public class ChunkEmpty extends ChunkClient {
public int getLowest() {
return 0;
}
public void updateLight(int iters) {
}
}