Simpler renderer but same issue

This commit is contained in:
Player Name 2026-06-27 19:46:41 +02:00
parent 97afdb4bb0
commit 5f00844221
3 changed files with 37 additions and 60 deletions

View file

@ -93,6 +93,7 @@ import static core.api.utils.PermadeathKt.permadeath;
import static core.game.system.command.sets.StatAttributeKeysKt.STATS_BASE;
import static core.game.system.command.sets.StatAttributeKeysKt.STATS_DEATHS;
import static core.tools.GlobalsKt.colorize;
import static java.util.Collections.emptySet;
import static org.rs09.consts.Items.BONES_526;
/**
@ -856,7 +857,7 @@ public class Player extends Entity {
getZoneMonitor().getZones().clear();
playerFlags.setLastSceneGraph(null);
playerFlags.setUpdateSceneGraph(false);
playerFlags.setLastViewport(new RegionChunk[13][13]);
playerFlags.setLastViewport(emptySet());
renderInfo.getLocalNpcs().clear();
renderInfo.getLocalPlayers().clear();
renderInfo.setLastLocation(null);

View file

@ -23,66 +23,37 @@ object MapChunkRenderer {
*/
@JvmStatic
fun render(player: Player) {
val last = player.playerFlags.lastViewport
val updated: MutableList<RegionChunk> = ArrayList()
val current: MutableList<MutableList<RegionChunk>> = ArrayList()
for (dcx in -buildAreaDepth..+buildAreaDepth) {
val addX = ArrayList<RegionChunk>()
for (dcy in -buildAreaDepth..+buildAreaDepth) {
val newloc = player.location.transform(dcx*8, dcy*8, 0)
addX.add(newloc.chunk)
val lastSet = player.playerFlags.lastViewport
val currentSet = HashSet<RegionChunk>()
for (dcx in -buildAreaDepth..buildAreaDepth) {
for (dcy in -buildAreaDepth..buildAreaDepth) {
val loc = player.location.transform(dcx * 8, dcy * 8, 0)
currentSet.add(loc.chunk)
}
current.add(addX)
}
var sizeX = last.size
for (x in 0 until sizeX) {
val sizeY: Int = last[x].size
for (y in 0 until sizeY) {
val previous = last[x][y] ?: continue
if (containsChunk(current, previous)) {
updated.add(previous)
continue
}
if (previous.region is DynamicRegion) {
continue //dynamic regions do not need a clear packet and briefly flash their cached states (e.g. POH with only hotspots) if you do send one
}
PacketRepository.send(ClearRegionChunk::class.java, ClearChunkContext(player, previous))
}
}
sizeX = current.size
for (x in 0 until sizeX) {
val sizeY: Int = current[x].size
for (y in 0 until sizeY) {
val chunk = current[x][y]
if (updated.contains(chunk)) {
chunk.update(player)
} else {
println("Syncing ${chunk.currentBase}")
chunk.synchronize(player)
}
last[x][y] = chunk
}
}
}
// Compute diffs
val entered = currentSet - lastSet
val stayed = currentSet intersect lastSet
val exited = lastSet - currentSet
/**
* Checks if the chunks list contains the specified region chunk.
* @param list The list to search.
* @param c The region chunk.
* @return `True` if so.
*/
private fun containsChunk(list: MutableList<MutableList<RegionChunk>>, c: RegionChunk): Boolean {
val sizeList = list.size
for (x in 0 until sizeList) {
val chunkSize: Int = list[x].size
for (y in 0 until chunkSize) {
if (list[x][y] === c) {
return true
}
// 1. New chunks → synchronize
for (c in entered) {
c.synchronize(player)
}
// 2. Existing chunks → update
for (c in stayed) {
c.update(player)
}
// 3. Exited chunks → clear
for (c in exited) {
if (c.region !is DynamicRegion) {
PacketRepository.send(ClearRegionChunk::class.java, ClearChunkContext(player, c))
}
}
return false
player.playerFlags.lastViewport = currentSet
}
}

View file

@ -1,7 +1,13 @@
package core.game.world.update.flag;
import core.game.world.map.Location;
import core.game.world.map.Region;
import core.game.world.map.RegionChunk;
import core.game.world.update.MapChunkRenderer;
import java.util.Set;
import static java.util.Collections.emptySet;
/**
* A class holding a player's updating flags.
@ -17,7 +23,7 @@ public final class PlayerFlags {
/**
* The last viewport.
*/
private RegionChunk[][] lastViewport = new RegionChunk[13][13];
private Set<RegionChunk> lastViewport = emptySet();
/**
* The location the player was standing on when last scene graph update
@ -70,7 +76,7 @@ public final class PlayerFlags {
* Gets the lastViewport.
* @return The lastViewport.
*/
public RegionChunk[][] getLastViewport() {
public Set<RegionChunk> getLastViewport() {
return lastViewport;
}
@ -78,8 +84,7 @@ public final class PlayerFlags {
* Sets the lastViewport.
* @param lastViewport The lastViewport to set.
*/
public void setLastViewport(RegionChunk[][] lastViewport) {
public void setLastViewport(Set<RegionChunk> lastViewport) {
this.lastViewport = lastViewport;
}
}