Add a LodStorage object for all LOD objects
This commit is contained in:
+5
-5
@@ -5,13 +5,13 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.DimensionType;
|
||||
|
||||
/**
|
||||
* This object holds the regions
|
||||
* currently needed by the LodRenderer.
|
||||
* This object holds the LOD regions
|
||||
* of a given dimension.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 1-27-2021
|
||||
* @version 01-30-2021
|
||||
*/
|
||||
public class LoadedRegions
|
||||
public class LodDimensionalStorage
|
||||
{
|
||||
public final DimensionType dimension;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class LoadedRegions
|
||||
|
||||
private LodRegionFileHandler rfHandler;
|
||||
|
||||
public LoadedRegions(DimensionType newDimension, int newMaxWidth)
|
||||
public LodDimensionalStorage(DimensionType newDimension, int newMaxWidth)
|
||||
{
|
||||
dimension = newDimension;
|
||||
width = newMaxWidth;
|
||||
@@ -0,0 +1,38 @@
|
||||
package backsun.lod.objects;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* This stores all LODs for a given world.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 01-30-2021
|
||||
*/
|
||||
public class LodStorage
|
||||
{
|
||||
/**
|
||||
* Key = Dimension id (as an int)
|
||||
*/
|
||||
private Dictionary<Integer, LodDimensionalStorage> LodDimensions;
|
||||
|
||||
public String worldName;
|
||||
|
||||
|
||||
public LodStorage()
|
||||
{
|
||||
LodDimensions = new Hashtable<Integer, LodDimensionalStorage>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addLodDimensionalStorage(LodDimensionalStorage newStorage)
|
||||
{
|
||||
LodDimensions.put(newStorage.dimension.getId(), newStorage);
|
||||
}
|
||||
|
||||
public LodDimensionalStorage getLodDimensionalStorage(int dimensionId)
|
||||
{
|
||||
return LodDimensions.get(dimensionId);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,10 @@ package backsun.lod.proxy;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import backsun.lod.objects.LoadedRegions;
|
||||
import backsun.lod.objects.LodChunk;
|
||||
import backsun.lod.objects.LodDimensionalStorage;
|
||||
import backsun.lod.objects.LodRegion;
|
||||
import backsun.lod.objects.LodStorage;
|
||||
import backsun.lod.renderer.LodRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
@@ -26,7 +27,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
private LodRenderer renderer;
|
||||
private LoadedRegions regions;
|
||||
private LodStorage lodStorage;
|
||||
private ExecutorService lodGenThreadPool = Executors.newFixedThreadPool(1);
|
||||
|
||||
// TODO make this change dynamically based on the render distance
|
||||
@@ -47,12 +48,17 @@ public class ClientProxy extends CommonProxy
|
||||
@SubscribeEvent
|
||||
public void renderWorldLastEvent(RenderWorldLastEvent event)
|
||||
{
|
||||
// We can't render anything if the loaded regions is null
|
||||
if (regions == null)
|
||||
// We can't render anything if the lodStorage is null
|
||||
if (lodStorage == null)
|
||||
return;
|
||||
|
||||
double playerX = Minecraft.getMinecraft().player.posX;
|
||||
double playerZ = Minecraft.getMinecraft().player.posZ;
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
int dimId = mc.player.dimension;
|
||||
LodDimensionalStorage regions = lodStorage.getLodDimensionalStorage(dimId);
|
||||
|
||||
|
||||
double playerX = mc.player.posX;
|
||||
double playerZ = mc.player.posZ;
|
||||
|
||||
int xOffset = ((int)playerX / (LodChunk.WIDTH * LodRegion.SIZE)) - regions.getCenterX();
|
||||
int zOffset = ((int)playerZ / (LodChunk.WIDTH * LodRegion.SIZE)) - regions.getCenterZ();
|
||||
@@ -127,22 +133,34 @@ public class ClientProxy extends CommonProxy
|
||||
|
||||
private void generateLodChunk(Chunk chunk)
|
||||
{
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
// don't try to create an LOD object
|
||||
// if for some reason we aren't
|
||||
// given a valid chunk object
|
||||
// (Minecraft often gives back empty
|
||||
// or null chunks in this method)
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc != null && mc.world != null && chunk != null && isValidChunk(chunk))
|
||||
{
|
||||
int dimId = mc.player.dimension;
|
||||
|
||||
Thread thread = new Thread(() ->
|
||||
{
|
||||
{
|
||||
LodChunk lod = new LodChunk(chunk, mc.world);
|
||||
LodDimensionalStorage regions;
|
||||
|
||||
if (regions == null)
|
||||
if (lodStorage == null)
|
||||
lodStorage = new LodStorage();
|
||||
|
||||
if (lodStorage.getLodDimensionalStorage(dimId) == null)
|
||||
{
|
||||
DimensionType dim = DimensionType.getById(chunk.getWorld().provider.getDimension());
|
||||
regions = new LoadedRegions(dim, regionWidth);
|
||||
regions = new LodDimensionalStorage(dim, regionWidth);
|
||||
lodStorage.addLodDimensionalStorage(regions);
|
||||
}
|
||||
else
|
||||
{
|
||||
regions = lodStorage.getLodDimensionalStorage(dimId);
|
||||
}
|
||||
|
||||
regions.addLod(lod);
|
||||
@@ -177,11 +195,4 @@ public class ClientProxy extends CommonProxy
|
||||
}
|
||||
|
||||
|
||||
private double distanceToPlayer(int x, int y, int z, double cameraX, double cameraY, double cameraZ)
|
||||
{
|
||||
if(cameraY == y)
|
||||
return Math.sqrt(Math.pow((x - cameraX),2) + Math.pow((z - cameraZ),2));
|
||||
|
||||
return Math.sqrt(Math.pow((x - cameraX),2) + Math.pow((y - cameraY),2) + Math.pow((z - cameraZ),2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.awt.Color;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.Project;
|
||||
|
||||
import backsun.lod.objects.LoadedRegions;
|
||||
import backsun.lod.objects.LodDimensionalStorage;
|
||||
import backsun.lod.objects.LodChunk;
|
||||
import backsun.lod.util.OfConfig;
|
||||
import backsun.lod.util.enums.ColorDirection;
|
||||
@@ -42,7 +42,7 @@ public class LodRenderer
|
||||
|
||||
private OfConfig ofConfig;
|
||||
|
||||
public LoadedRegions regions = null;
|
||||
public LodDimensionalStorage regions = null;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.io.IOException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import backsun.lod.objects.LoadedRegions;
|
||||
import backsun.lod.objects.LodDimensionalStorage;
|
||||
import backsun.lod.objects.LodChunk;
|
||||
import backsun.lod.objects.LodRegion;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -24,7 +24,7 @@ import net.minecraft.world.storage.ISaveHandler;
|
||||
*/
|
||||
public class LodRegionFileHandler
|
||||
{
|
||||
private LoadedRegions loadedRegion = null;
|
||||
private LodDimensionalStorage loadedRegion = null;
|
||||
public long regionLastWriteTime[][];
|
||||
|
||||
// String s = Minecraft.getMinecraftDir().getCanonicalPath() + "/saves/" + world.getSaveHandler().getSaveDirectoryName() + "/data/AA/World" + world.provider.dimensionId + ".dat";
|
||||
@@ -39,7 +39,7 @@ public class LodRegionFileHandler
|
||||
private boolean waitingToSaveRegions = false;
|
||||
|
||||
|
||||
public LodRegionFileHandler(ISaveHandler newSaveHandler, LoadedRegions newLoadedRegion)
|
||||
public LodRegionFileHandler(ISaveHandler newSaveHandler, LodDimensionalStorage newLoadedRegion)
|
||||
{
|
||||
saveHandler = newSaveHandler;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class LodRegionFileHandler
|
||||
}
|
||||
|
||||
loadedRegion = newLoadedRegion;
|
||||
// these two variable are used in sync with the LoadedRegions
|
||||
// these two variable are used in sync with the LodDimensionalStorage
|
||||
regionLastWriteTime = new long[loadedRegion.getWidth()][loadedRegion.getWidth()];
|
||||
for(int i = 0; i < loadedRegion.getWidth(); i++)
|
||||
for(int j = 0; j < loadedRegion.getWidth(); j++)
|
||||
|
||||
Reference in New Issue
Block a user