-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace chunk tracker --------- Co-authored-by: Jason Mitchell <mitchej@gmail.com>
- Loading branch information
1 parent
9e1fa7b
commit 8c5f4d2
Showing
8 changed files
with
183 additions
and
38 deletions.
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
7 changes: 7 additions & 0 deletions
7
src/main/java/me/jellysquid/mods/sodium/client/render/chunk/map/ChunkStatus.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,7 @@ | ||
package me.jellysquid.mods.sodium.client.render.chunk.map; | ||
|
||
public class ChunkStatus { | ||
public static final int FLAG_HAS_BLOCK_DATA = 1; | ||
public static final int FLAG_HAS_LIGHT_DATA = 2; | ||
public static final int FLAG_ALL = FLAG_HAS_BLOCK_DATA | FLAG_HAS_LIGHT_DATA; | ||
} |
125 changes: 125 additions & 0 deletions
125
src/main/java/me/jellysquid/mods/sodium/client/render/chunk/map/ChunkTracker.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,125 @@ | ||
package me.jellysquid.mods.sodium.client.render.chunk.map; | ||
|
||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; | ||
import it.unimi.dsi.fastutil.longs.LongCollection; | ||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet; | ||
import it.unimi.dsi.fastutil.longs.LongSet; | ||
import it.unimi.dsi.fastutil.longs.LongSets; | ||
import net.minecraft.world.ChunkCoordIntPair; | ||
|
||
public class ChunkTracker implements ClientChunkEventListener { | ||
private final Long2IntOpenHashMap chunkStatus = new Long2IntOpenHashMap(); | ||
private final LongOpenHashSet chunkReady = new LongOpenHashSet(); | ||
|
||
private final LongSet unloadQueue = new LongOpenHashSet(); | ||
private final LongSet loadQueue = new LongOpenHashSet(); | ||
|
||
public ChunkTracker() { | ||
|
||
} | ||
|
||
@Override | ||
public void updateMapCenter(int chunkX, int chunkZ) { | ||
|
||
} | ||
|
||
@Override | ||
public void updateLoadDistance(int loadDistance) { | ||
|
||
} | ||
|
||
@Override | ||
public void onChunkStatusAdded(int x, int z, int flags) { | ||
var key = ChunkCoordIntPair.chunkXZ2Int(x, z); | ||
|
||
var prev = this.chunkStatus.get(key); | ||
var cur = prev | flags; | ||
|
||
if (prev == cur) { | ||
return; | ||
} | ||
|
||
this.chunkStatus.put(key, cur); | ||
|
||
this.updateNeighbors(x, z); | ||
} | ||
|
||
@Override | ||
public void onChunkStatusRemoved(int x, int z, int flags) { | ||
var key = ChunkCoordIntPair.chunkXZ2Int(x, z); | ||
|
||
var prev = this.chunkStatus.get(key); | ||
int cur = prev & ~flags; | ||
|
||
if (prev == cur) { | ||
return; | ||
} | ||
|
||
if (cur == this.chunkStatus.defaultReturnValue()) { | ||
this.chunkStatus.remove(key); | ||
} else { | ||
this.chunkStatus.put(key, cur); | ||
} | ||
|
||
this.updateNeighbors(x, z); | ||
} | ||
|
||
private void updateNeighbors(int x, int z) { | ||
for (int ox = -1; ox <= 1; ox++) { | ||
for (int oz = -1; oz <= 1; oz++) { | ||
this.updateMerged(ox + x, oz + z); | ||
} | ||
} | ||
} | ||
|
||
private void updateMerged(int x, int z) { | ||
long key = ChunkCoordIntPair.chunkXZ2Int(x, z); | ||
|
||
int flags = this.chunkStatus.get(key); | ||
|
||
for (int ox = -1; ox <= 1; ox++) { | ||
for (int oz = -1; oz <= 1; oz++) { | ||
flags &= this.chunkStatus.get(ChunkCoordIntPair.chunkXZ2Int(ox + x, oz + z)); | ||
} | ||
} | ||
|
||
if (flags == ChunkStatus.FLAG_ALL) { | ||
if (this.chunkReady.add(key) && !this.unloadQueue.remove(key)) { | ||
this.loadQueue.add(key); | ||
} | ||
} else { | ||
if (this.chunkReady.remove(key) && !this.loadQueue.remove(key)) { | ||
this.unloadQueue.add(key); | ||
} | ||
} | ||
} | ||
|
||
public LongCollection getReadyChunks() { | ||
return LongSets.unmodifiable(this.chunkReady); | ||
} | ||
|
||
public void forEachEvent(ChunkEventHandler loadEventHandler, ChunkEventHandler unloadEventHandler) { | ||
forEachChunk(this.unloadQueue, unloadEventHandler); | ||
this.unloadQueue.clear(); | ||
|
||
forEachChunk(this.loadQueue, loadEventHandler); | ||
this.loadQueue.clear(); | ||
} | ||
|
||
public static void forEachChunk(LongCollection queue, ChunkEventHandler handler) { | ||
var iterator = queue.iterator(); | ||
|
||
while (iterator.hasNext()) { | ||
var pos = iterator.nextLong(); | ||
|
||
var x = (int)(pos & 4294967295L); | ||
var z = (int)((pos >> 32L) & 4294967295L); | ||
|
||
handler.apply(x, z); | ||
} | ||
} | ||
|
||
public interface ChunkEventHandler { | ||
void apply(int x, int z); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/me/jellysquid/mods/sodium/client/render/chunk/map/ChunkTrackerHolder.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,11 @@ | ||
package me.jellysquid.mods.sodium.client.render.chunk.map; | ||
|
||
import net.minecraft.client.multiplayer.WorldClient; | ||
|
||
public interface ChunkTrackerHolder { | ||
static ChunkTracker get(WorldClient world) { | ||
return ((ChunkTrackerHolder) world).sodium$getTracker(); | ||
} | ||
|
||
ChunkTracker sodium$getTracker(); | ||
} |
10 changes: 10 additions & 0 deletions
10
...main/java/me/jellysquid/mods/sodium/client/render/chunk/map/ClientChunkEventListener.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,10 @@ | ||
package me.jellysquid.mods.sodium.client.render.chunk.map; | ||
|
||
public interface ClientChunkEventListener { | ||
void updateMapCenter(int chunkX, int chunkZ); | ||
|
||
void updateLoadDistance(int loadDistance); | ||
|
||
void onChunkStatusAdded(int x, int z, int flags); | ||
void onChunkStatusRemoved(int x, int z, int flags); | ||
} |
18 changes: 0 additions & 18 deletions
18
src/mixin/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinChunkProviderClient.java
This file was deleted.
Oops, something went wrong.
19 changes: 16 additions & 3 deletions
19
src/mixin/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinWorldClient.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,17 +1,30 @@ | ||
package com.gtnewhorizons.angelica.mixins.early.sodium; | ||
|
||
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer; | ||
import me.jellysquid.mods.sodium.client.render.chunk.map.ChunkStatus; | ||
import me.jellysquid.mods.sodium.client.render.chunk.map.ChunkTracker; | ||
import me.jellysquid.mods.sodium.client.render.chunk.map.ChunkTrackerHolder; | ||
import net.minecraft.client.multiplayer.WorldClient; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(WorldClient.class) | ||
public class MixinWorldClient { | ||
public class MixinWorldClient implements ChunkTrackerHolder { | ||
private final ChunkTracker angelica$tracker = new ChunkTracker(); | ||
|
||
@Inject(method = "doPreChunk", at = @At("TAIL")) | ||
private void sodium$loadChunk(int x, int z, boolean load, CallbackInfo ci) { | ||
if(load) | ||
SodiumWorldRenderer.getInstance().onChunkAdded(x, z); | ||
if(load) { | ||
this.angelica$tracker.onChunkStatusAdded(x, z, ChunkStatus.FLAG_ALL); | ||
} else { | ||
this.angelica$tracker.onChunkStatusRemoved(x, z, ChunkStatus.FLAG_ALL); | ||
} | ||
} | ||
|
||
@Override | ||
public ChunkTracker sodium$getTracker() { | ||
return this.angelica$tracker; | ||
} | ||
} |