forked from Johni0702/bobby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix chunk flicker with Sodium 0.3.0, release version 2.0.4
They removed the buffering behavior of their ChunkStatusListener which was present in snapshot versions of 0.3.0, so we need to take care of that manually again.
- Loading branch information
Showing
6 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/de/johni0702/minecraft/bobby/ext/ClientChunkManagerExt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
package de.johni0702.minecraft.bobby.ext; | ||
|
||
import de.johni0702.minecraft.bobby.FakeChunkManager; | ||
import me.jellysquid.mods.sodium.client.world.ChunkStatusListener; | ||
|
||
public interface ClientChunkManagerExt { | ||
FakeChunkManager bobby_getFakeChunkManager(); | ||
void bobby_onFakeChunkAdded(int x, int z); | ||
void bobby_onFakeChunkRemoved(int x, int z); | ||
|
||
/** | ||
* Mark Sodium's {@link ChunkStatusListener} as paused. | ||
* This effectively delays all unload notifications until un-paused and most importantly removes redundant (as in | ||
* unload followed by a load) ones. Otherwise Sodium will unload the geometry and the chunk will be missing until | ||
* it is rebuilt. | ||
* | ||
* Has no effect on the vanilla renderer because it polls chunks every frame and gets no intermediate state. | ||
* | ||
* This method is idempotent. | ||
*/ | ||
void bobby_pauseChunkStatusListener(); | ||
|
||
/** | ||
* Resumes Sodium's {@link ChunkStatusListener}, forwarding all updates which are still applicable. | ||
*/ | ||
void bobby_resumeChunkStatusListener(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/de/johni0702/minecraft/bobby/sodium/BufferedChunkStatusListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.johni0702.minecraft.bobby.sodium; | ||
|
||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet; | ||
import it.unimi.dsi.fastutil.longs.LongSet; | ||
import me.jellysquid.mods.sodium.client.world.ChunkStatusListener; | ||
import net.minecraft.util.math.ChunkPos; | ||
|
||
public class BufferedChunkStatusListener implements ChunkStatusListener { | ||
public final ChunkStatusListener delegate; | ||
private final LongSet unloaded = new LongOpenHashSet(); | ||
|
||
public BufferedChunkStatusListener(ChunkStatusListener delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void onChunkAdded(int x, int z) { | ||
if (!this.unloaded.remove(ChunkPos.toLong(x, z))) { | ||
this.delegate.onChunkAdded(x, z); | ||
} | ||
} | ||
|
||
@Override | ||
public void onChunkRemoved(int x, int z) { | ||
this.unloaded.add(ChunkPos.toLong(x, z)); | ||
} | ||
|
||
public void flush() { | ||
for (long pos : this.unloaded) { | ||
this.delegate.onChunkRemoved(ChunkPos.getPackedX(pos), ChunkPos.getPackedZ(pos)); | ||
} | ||
this.unloaded.clear(); | ||
} | ||
} |