Have the stored regions size change based on view distance

also fix/improve the profiler
This commit is contained in:
James Seibel
2021-02-01 08:38:30 -06:00
parent d9ce8e24ea
commit b2417957d6
4 changed files with 68 additions and 16 deletions
@@ -9,14 +9,14 @@ import net.minecraft.world.DimensionType;
* for a given dimension.
*
* @author James Seibel
* @version 01-30-2021
* @version 01-31-2021
*/
public class LodDimension
{
public final DimensionType dimension;
private int width; // if this ever changes make sure to update the halfWidth too
private int halfWidth;
private volatile int width; // if this ever changes make sure to update the halfWidth too
private volatile int halfWidth;
public LodRegion regions[][];
public boolean isRegionDirty[][];
@@ -295,6 +295,20 @@ public class LodDimension
{
return width;
}
public void setRegionWidth(int newWidth)
{
width = newWidth;
halfWidth = (int)Math.floor(width / 2);
regions = new LodRegion[width][width];
isRegionDirty = new boolean[width][width];
// populate isRegionDirty
for(int i = 0; i < width; i++)
for(int j = 0; j < width; j++)
isRegionDirty[i][j] = false;
}
}
@@ -1,13 +1,14 @@
package backsun.lod.objects;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* This stores all LODs for a given world.
*
* @author James Seibel
* @version 01-30-2021
* @version 01-31-2021
*/
public class LodWorld
{
@@ -16,24 +17,33 @@ public class LodWorld
/**
* Key = Dimension id (as an int)
*/
private Dictionary<Integer, LodDimension> LodDimensions;
private Dictionary<Integer, LodDimension> lodDimensions;
public LodWorld(String newWorldName)
{
worldName = newWorldName;
LodDimensions = new Hashtable<Integer, LodDimension>();
lodDimensions = new Hashtable<Integer, LodDimension>();
}
public void addLodDimension(LodDimension newStorage)
{
LodDimensions.put(newStorage.dimension.getId(), newStorage);
lodDimensions.put(newStorage.dimension.getId(), newStorage);
}
public LodDimension getLodDimension(int dimensionId)
{
return LodDimensions.get(dimensionId);
return lodDimensions.get(dimensionId);
}
public void resizeDimensionRegionWidth(int newWidth)
{
Enumeration<Integer> keys = lodDimensions.keys();
while(keys.hasMoreElements())
lodDimensions.get(keys.nextElement()).setRegionWidth(newWidth);
}
}
@@ -15,6 +15,7 @@ import net.minecraft.world.DimensionType;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -23,7 +24,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
* This is used by the client.
*
* @author James_Seibel
* @version 01-30-2021
* @version 01-31-2021
*/
public class ClientProxy extends CommonProxy
{
@@ -31,7 +32,6 @@ public class ClientProxy extends CommonProxy
private LodWorld lodWorld;
private ExecutorService lodGenThreadPool = Executors.newFixedThreadPool(1);
// TODO make this change dynamically based on the render distance
private int regionWidth = 5;
public ClientProxy()
@@ -46,9 +46,35 @@ public class ClientProxy extends CommonProxy
// render event //
//==============//
/** prevent LODs from being rendered multiple times */
private boolean frameRendered = false;
@SubscribeEvent
public void onRenderTick(RenderWorldLastEvent event)
{
frameRendered = false;
}
@SubscribeEvent
public void onRenderTick(EntityViewRenderEvent.FogDensity event)
{
// this event is called 5 times every frame
// but we only need to render the LODs once
if (frameRendered)
return;
frameRendered = true;
// int newWidth = Math.max(3, (Minecraft.getMinecraft().gameSettings.renderDistanceChunks * LodRenderer.VIEW_DISTANCE_MULTIPLIER) / LodRegion.SIZE);
// if (lodWorld != null && regionWidth != newWidth)
// {
// lodWorld.resizeDimensionRegionWidth(newWidth);
// regionWidth = newWidth;
//
// // skip this frame, hopefully the lodWorld
// // should have everything set up by then
// return;
// }
Minecraft mc = Minecraft.getMinecraft();
int dimId = mc.player.dimension;
LodDimension lodDim = lodWorld.getLodDimension(dimId);
@@ -81,7 +81,9 @@ public class LodRenderer
// used for debugging and viewing how long different processes take
mc.world.profiler.startSection("LOD setup");
mc.mcProfiler.endSection();
mc.mcProfiler.startSection("LOD");
mc.mcProfiler.startSection("LOD setup");
@SuppressWarnings("unused")
long startTime = System.nanoTime();
@@ -150,7 +152,7 @@ public class LodRenderer
// create the LODs //
//=================//
mc.world.profiler.endStartSection("LOD generation");
mc.mcProfiler.endStartSection("LOD generation");
// TODO multithread this
@@ -263,7 +265,7 @@ public class LodRenderer
// rendering //
//===========//
mc.world.profiler.endStartSection("LOD build buffer");
mc.mcProfiler.endStartSection("LOD build buffer");
// send the LODs over to the GPU
sendToGPUAndDraw(lodArray, colorArray, cameraX, cameraY ,cameraZ);
@@ -278,7 +280,7 @@ public class LodRenderer
// cleanup //
//=========//
mc.world.profiler.endStartSection("LOD cleanup");
mc.mcProfiler.endStartSection("LOD cleanup");
// this must be done otherwise other parts of the screen may be drawn with a fog effect
@@ -299,7 +301,7 @@ public class LodRenderer
long endTime = System.nanoTime();
// end of profiler tracking
mc.world.profiler.endSection();
mc.mcProfiler.endSection();
}
@@ -415,7 +417,7 @@ public class LodRenderer
colorIndex++;
}
mc.world.profiler.endStartSection("LOD draw");
mc.mcProfiler.endStartSection("LOD draw");
// draw the LODs
tessellator.draw();