.registerProvider(new WorldSpawnProvider())
.registerProvider(new SpawningSphereProvider())
.registerProvider(new BeaconProvider())
- .registerProvider(new CustomBoxProvider());
+ .registerProvider(new CustomBoxProvider())
+ .registerProvider(new CacheProvider(this::getCache));
KeyListener.init();
}
public void render(int dimensionId) {
if(!active) return;
- Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxes = getBoundingBoxes(dimensionId);
+ Set<AbstractBoundingBox> boundingBoxes = getBoundingBoxes(dimensionId);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glLineWidth(2.0f);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
}
- Boolean outerBoxesOnly = ConfigManager.outerBoxesOnly.get();
- for (Map.Entry<AbstractBoundingBox, Set<AbstractBoundingBox>> entry : boundingBoxes.entrySet()) {
- AbstractBoundingBox key = entry.getKey();
- if (!key.shouldRender()) continue;
+ for (AbstractBoundingBox key : boundingBoxes) {
+ if (!key.shouldRender() || !isWithinRenderDistance(key)) continue;
AbstractRenderer renderer = boundingBoxRendererMap.get(key.getClass());
if (renderer == null) continue;
- if (!outerBoxesOnly) {
- Set<AbstractBoundingBox> children = entry.getValue();
- if (children != null && children.size() > 0) {
- children.forEach(renderer::render);
- continue;
- }
- }
renderer.render(key);
}
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
- private Map<AbstractBoundingBox, Set<AbstractBoundingBox>> getBoundingBoxes(int dimensionId) {
- Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxes = new HashMap<>();
+ private Set<AbstractBoundingBox> getBoundingBoxes(int dimensionId) {
+ Set<AbstractBoundingBox> boundingBoxes = new HashSet<>();
for(IBoundingBoxProvider<?> provider: providers) {
for (AbstractBoundingBox boundingBox : provider.get(dimensionId)) {
- boundingBoxes.put(boundingBox, null);
- }
- }
-
- BoundingBoxCache cache = getCache.apply(dimensionId);
- if (cache != null) {
- for (Map.Entry<AbstractBoundingBox, Set<AbstractBoundingBox>> entry : cache.getBoundingBoxes().entrySet()) {
- AbstractBoundingBox key = entry.getKey();
- if (key.shouldRender() && isWithinRenderDistance(key)) {
- boundingBoxes.put(key, entry.getValue());
- }
+ boundingBoxes.add(boundingBox);
}
}
return boundingBoxes;
import java.util.function.Function;
-interface GetCache extends Function<Integer, BoundingBoxCache> {
+public interface GetCache extends Function<Integer, BoundingBoxCache> {
}
--- /dev/null
+package com.irtimaled.bbor.client.providers;
+
+import com.irtimaled.bbor.client.GetCache;
+import com.irtimaled.bbor.client.PlayerCoords;
+import com.irtimaled.bbor.client.interop.ClientInterop;
+import com.irtimaled.bbor.common.BoundingBoxCache;
+import com.irtimaled.bbor.common.MathHelper;
+import com.irtimaled.bbor.common.models.AbstractBoundingBox;
+import com.irtimaled.bbor.config.ConfigManager;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class CacheProvider implements IBoundingBoxProvider<AbstractBoundingBox> {
+ private static final int CHUNK_SIZE = 16;
+
+ private final GetCache getCache;
+
+ public CacheProvider(GetCache getCache) {
+ this.getCache = getCache;
+ }
+
+ private static boolean isWithinRenderDistance(AbstractBoundingBox boundingBox) {
+ int renderDistanceBlocks = ClientInterop.getRenderDistanceChunks() * CHUNK_SIZE;
+ int minX = MathHelper.floor(PlayerCoords.getX() - renderDistanceBlocks);
+ int maxX = MathHelper.floor(PlayerCoords.getX() + renderDistanceBlocks);
+ int minZ = MathHelper.floor(PlayerCoords.getZ() - renderDistanceBlocks);
+ int maxZ = MathHelper.floor(PlayerCoords.getZ() + renderDistanceBlocks);
+
+ return boundingBox.intersectsBounds(minX, minZ, maxX, maxZ);
+ }
+
+ @Override
+ public Iterable<AbstractBoundingBox> get(int dimensionId) {
+ Boolean outerBoxesOnly = ConfigManager.outerBoxesOnly.get();
+
+ Set<AbstractBoundingBox> boundingBoxes = new HashSet<>();
+ BoundingBoxCache cache = getCache.apply(dimensionId);
+ if (cache != null) {
+ for (Map.Entry<AbstractBoundingBox, Set<AbstractBoundingBox>> entry : cache.getBoundingBoxes().entrySet()) {
+ AbstractBoundingBox key = entry.getKey();
+ if (key.shouldRender() && isWithinRenderDistance(key)) {
+ if (!outerBoxesOnly) {
+ Set<AbstractBoundingBox> children = entry.getValue();
+ if (children != null && children.size() > 0) {
+ boundingBoxes.addAll(children);
+ continue;
+ }
+ }
+ boundingBoxes.add(key);
+ }
+ }
+ }
+ return boundingBoxes;
+ }
+}