This commit is contained in:
s809
2023-11-11 19:20:33 +05:00
16 changed files with 161 additions and 45 deletions
@@ -40,6 +40,20 @@ import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue;
public interface IDhApiFogConfig extends IDhApiConfigGroup
{
//===============//
// inner configs //
//===============//
/**
* The advanced fog config.
*/
IDhApiFarFogConfig farFog();
/**
* The height fog config.
*/
IDhApiHeightFogConfig heightFog();
//====================//
// basic fog settings //
//====================//
@@ -41,7 +41,9 @@ public class DhApiFogConfig implements IDhApiFogConfig
// inner configs //
//===============//
@Override
public IDhApiFarFogConfig farFog() { return DhApiFarFogConfig.INSTANCE; }
@Override
public IDhApiHeightFogConfig heightFog() { return DhApiHeightFogConfig.INSTANCE; }
@@ -51,8 +51,8 @@ public abstract class AbstractScreen
/** Called every time the window gets re-sized */
public void onResize() { }
;
/** What happens when the user closes the screen */
/** What happens when the user closes the screen */
public void onClose() { }
// ---------- Random stuff that might be needed later on ---------- //
@@ -21,8 +21,10 @@ package com.seibel.distanthorizons.core.config.gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class ConfigScreen extends JFrame
public class ConfigScreen extends JComponent
{
public ConfigScreen()
@@ -33,6 +35,8 @@ public class ConfigScreen extends JFrame
constraints.weightx = 0.5;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = new Insets(10, 10, 0, 10);
add(new JLabel("Hello World!"), constraints);
}
@@ -40,8 +44,12 @@ public class ConfigScreen extends JFrame
public static void main(String[] args)
{
SwingUtilities.invokeLater(() -> {
JFrame frame = new ConfigScreen();
JFrame frame = new JFrame();
frame.add(new ConfigScreen());
frame.setSize(300, 200);
frame.setLocationRelativeTo(null); // Makes the window open at the center of the screen
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
@@ -39,7 +39,7 @@ import static org.lwjgl.system.macosx.ObjCRuntime.*;
// which is licensed under https://www.lwjgl.org/license
/**
* Some utils for embeding awt and swing items into lwjgl windows
* Some utils for embedding awt and swing items into lwjgl windows
*
* @author Ran
* @author coolGi
@@ -23,6 +23,8 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/**
*
@@ -52,6 +54,23 @@ public class JavaScreenHandlerScreen extends AbstractScreen
frame.add(jComponent);
JavaScreenHandlerScreen thiss = this;
frame.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent)
{
System.out.println("Key pressed code=" + keyEvent.getKeyCode() + ", char=" + keyEvent.getKeyChar());
if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE)
thiss.close = true;
}
@Override
public void keyTyped(KeyEvent keyEvent) { }
@Override
public void keyReleased(KeyEvent keyEvent) { }
});
if (firstRun)
{
EmbeddedFrameUtil.embeddedFrameSetBounds(frame, 0, 0, this.width, this.height);
@@ -80,7 +80,8 @@ public class FullDataPointIdMap
// getters //
//=========//
private Entry getEntry(int id)
/** @throws IndexOutOfBoundsException if the given ID isn't in the {@link FullDataPointIdMap#entryList} */
private Entry getEntry(int id) throws IndexOutOfBoundsException
{
try
{
@@ -92,8 +93,7 @@ public class FullDataPointIdMap
}
catch (IndexOutOfBoundsException e)
{
LOGGER.error("FullData ID Map out of sync for pos: " + this.pos + ". ID: [" + id + "] greater than the number of known ID's: [" + this.entryList.size() + "].");
throw e;
throw new IndexOutOfBoundsException("FullData ID Map out of sync for pos: "+this.pos+". ID: ["+id+"] greater than the number of known ID's: ["+this.entryList.size()+"].");
}
return entry;
@@ -104,8 +104,16 @@ public class FullDataPointIdMap
}
}
public IBiomeWrapper getBiomeWrapper(int id) { return this.getEntry(id).biome; }
public IBlockStateWrapper getBlockStateWrapper(int id) { return this.getEntry(id).blockState; }
/** @see FullDataPointIdMap#getEntry(int) */
public IBiomeWrapper getBiomeWrapper(int id) throws IndexOutOfBoundsException { return this.getEntry(id).biome; }
/** @see FullDataPointIdMap#getEntry(int) */
public IBlockStateWrapper getBlockStateWrapper(int id) throws IndexOutOfBoundsException { return this.getEntry(id).blockState; }
/** @return -1 if the list is empty */
public int getMaxValidId() { return this.entryList.size() - 1; }
public DhSectionPos getPos() { return this.pos; }
@@ -143,7 +143,8 @@ public class SingleColumnFullDataAccessor implements IFullDataAccessor
{
int[] remappedEntryIds = target.mapping.mergeAndReturnRemappedEntityIds(this.mapping);
long[] sourceData = this.dataArrays[this.dataArrayIndex];
if (sourceData != null)
// FIXME sourceData.length != 0 may not be a good solution and may end up breaking issues down the line, but fixes exceptions being fired here
if (sourceData != null && sourceData.length != 0)
{
long[] newData = new long[sourceData.length];
for (int i = 0; i < newData.length; i++)
@@ -214,7 +214,7 @@ public class LodQuadBuilder
// add vertices //
//==============//
private static void putQuad(ByteBuffer bb, BufferQuad quad)
private void putQuad(ByteBuffer bb, BufferQuad quad)
{
int[][] quadBase = DIRECTION_VERTEX_IBO_QUAD[quad.direction.ordinal()];
short widthEastWest = quad.widthEastWest;
@@ -261,7 +261,7 @@ public class LodQuadBuilder
}
}
private static void putVertex(ByteBuffer bb, short x, short y, short z, int color, byte skylight, byte blocklight, int mx, int my, int mz)
private void putVertex(ByteBuffer bb, short x, short y, short z, int color, byte skylight, byte blocklight, int mx, int my, int mz)
{
skylight %= 16;
blocklight %= 16;
@@ -287,7 +287,7 @@ public class LodQuadBuilder
byte r = (byte) ColorUtil.getRed(color);
byte g = (byte) ColorUtil.getGreen(color);
byte b = (byte) ColorUtil.getBlue(color);
byte a = (byte) ColorUtil.getAlpha(color);
byte a = this.doTransparency ? (byte) ColorUtil.getAlpha(color) : (byte) 255; // TODO should this be called here or happen somewhere else?
bb.put(r);
bb.put(g);
bb.put(b);
@@ -21,7 +21,6 @@ package com.seibel.distanthorizons.core.dataObjects.transformers;
import com.seibel.distanthorizons.api.enums.config.EBlocksToAvoid;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener;
import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap;
import com.seibel.distanthorizons.core.dataObjects.fullData.accessor.ChunkSizedFullDataAccessor;
import com.seibel.distanthorizons.core.dataObjects.fullData.accessor.SingleColumnFullDataAccessor;
@@ -29,7 +28,6 @@ import com.seibel.distanthorizons.core.dataObjects.fullData.sources.CompleteFull
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.interfaces.IFullDataSource;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.interfaces.IIncompleteFullDataSource;
import com.seibel.distanthorizons.core.dataObjects.render.ColumnRenderSource;
import com.seibel.distanthorizons.core.dataObjects.render.bufferBuilding.ColumnRenderBufferBuilder;
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.level.IDhClientLevel;
@@ -39,7 +37,6 @@ import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.FullDataPointUtil;
import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
import com.seibel.distanthorizons.core.util.ThreadUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
@@ -47,8 +44,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
import org.apache.logging.log4j.Logger;
import java.util.HashSet;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
/**
* Handles converting {@link ChunkSizedFullDataAccessor}, {@link IIncompleteFullDataSource},
@@ -230,6 +225,8 @@ public class FullDataToRenderDataTransformer
}
}
private static HashSet<DhSectionPos> brokenPos = new HashSet<>();
// TODO what does this mean?
private static void iterateAndConvert(IDhClientLevel level, int blockX, int blockZ, int genMode, ColumnArrayView column, SingleColumnFullDataAccessor data)
@@ -252,8 +249,28 @@ public class FullDataToRenderDataTransformer
int blockHeight = FullDataPointUtil.getHeight(fullData);
int id = FullDataPointUtil.getId(fullData);
int light = FullDataPointUtil.getLight(fullData);
IBiomeWrapper biome = fullDataMapping.getBiomeWrapper(id);
IBlockStateWrapper block = fullDataMapping.getBlockStateWrapper(id);
IBiomeWrapper biome;
IBlockStateWrapper block;
try
{
biome = fullDataMapping.getBiomeWrapper(id);
block = fullDataMapping.getBlockStateWrapper(id);
}
catch (IndexOutOfBoundsException e)
{
// FIXME sometimes the data map has a length of 0
if (!brokenPos.contains(fullDataMapping.getPos()))
{
brokenPos.add(fullDataMapping.getPos());
String dimName = level.getLevelWrapper().getDimensionType().getDimensionName();
LOGGER.warn("Unable to get data point with id ["+id+"] (Max possible ID: ["+fullDataMapping.getMaxValidId()+"]) for pos ["+fullDataMapping.getPos()+"] in dimension ["+dimName+"]. Error: ["+e.getMessage()+"]. Further errors for this position won't be logged.");
}
// skip rendering broken data
continue;
}
if (blockStatesToIgnore.contains(block))
{
@@ -619,7 +619,7 @@ public class LodRenderer
if (GLProxy.getInstance() == null)
{
// shouldn't normally happen, but just in case
EVENT_LOGGER.warn("Renderer Cleanup called but the GLProxy has never been initalized!");
EVENT_LOGGER.warn("Renderer Cleanup called but the GLProxy has never been initialized!");
return;
}
@@ -41,10 +41,6 @@ public class DhApplyShader extends AbstractShaderRenderer
public int gDhColorTextureUniform;
public int gDepthMapUniform;
public int tempFramebufferId;
public int tempColorTextureId;
public int tempDepthTextureId;
private DhApplyShader() { }
@@ -62,28 +58,26 @@ public class DhApplyShader extends AbstractShaderRenderer
this.gDhColorTextureUniform = this.shader.getUniformLocation("gDhColorTexture");
this.gDepthMapUniform = this.shader.getUniformLocation("gDhDepthTexture");
this.tempFramebufferId = GL32.glGenFramebuffers();
this.tempColorTextureId = GL32.glGenTextures();
this.tempDepthTextureId = GL32.glGenTextures();
}
@Override
protected void onApplyUniforms(float partialTicks)
{
}
protected void onApplyUniforms(float partialTicks) { }
//========//
// render //
//========//
private boolean texturesCreated = false;
@Override
protected void onRender()
{
int targetFrameBuffer = MC_RENDER.getTargetFrameBuffer();
if (targetFrameBuffer == -1)
{
return;
}
GL32.glDisable(GL32.GL_DEPTH_TEST);
GL32.glEnable(GL32.GL_BLEND);
@@ -99,8 +93,9 @@ public class DhApplyShader extends AbstractShaderRenderer
GL32.glUniform1i(this.gDepthMapUniform, 1);
// Copy to MC's framebuffer
GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, MC_RENDER.getTargetFrameBuffer());
GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, targetFrameBuffer);
ScreenQuad.INSTANCE.render();
}
}
@@ -126,6 +126,9 @@ public abstract class AbstractDhRepo<TDTO extends IBaseDTO>
{
this.query(statement);
}
catch (DbConnectionClosedException ignored)
{
}
catch (SQLException e)
{
String message = "Unexpected insert statement error: ["+e.getMessage()+"].";
@@ -139,6 +142,9 @@ public abstract class AbstractDhRepo<TDTO extends IBaseDTO>
{
this.query(statement);
}
catch (DbConnectionClosedException ignored)
{
}
catch (SQLException e)
{
String message = "Unexpected update statement error: ["+e.getMessage()+"].";
@@ -172,17 +178,34 @@ public abstract class AbstractDhRepo<TDTO extends IBaseDTO>
// low level DB //
//==============//
public List<Map<String, Object>> queryDictionary(String sql) { return this.query(sql); }
public List<Map<String, Object>> queryDictionary(String sql)
{
try
{
return this.query(sql);
}
catch (DbConnectionClosedException e)
{
return new ArrayList<>();
}
}
@Nullable
public Map<String, Object> queryDictionaryFirst(String sql)
{
List<Map<String, Object>> objectList = this.query(sql);
return !objectList.isEmpty() ? objectList.get(0) : null;
try
{
List<Map<String, Object>> objectList = this.query(sql);
return !objectList.isEmpty() ? objectList.get(0) : null;
}
catch (DbConnectionClosedException e)
{
return null;
}
}
/** note: this can only handle 1 command at a time */
private List<Map<String, Object>> query(PreparedStatement statement) throws RuntimeException
private List<Map<String, Object>> query(PreparedStatement statement) throws RuntimeException, DbConnectionClosedException
{
try
{
@@ -200,13 +223,16 @@ public abstract class AbstractDhRepo<TDTO extends IBaseDTO>
// SQL exceptions generally only happen when something is wrong with
// the database or the query and should cause the system to blow up to notify the developer
if (e.toString().equals("database connection closed"))
throw new DbConnectionClosedException(e);
String message = "Unexpected Query error: ["+e.getMessage()+"], for prepared statement: ["+statement+"].";
LOGGER.error(message);
throw new RuntimeException(message, e);
}
}
/** note: this can only handle 1 command at a time */
private List<Map<String, Object>> query(String sql) throws RuntimeException
private List<Map<String, Object>> query(String sql) throws RuntimeException, DbConnectionClosedException
{
try (Statement statement = this.connection.createStatement())
{
@@ -224,6 +250,9 @@ public abstract class AbstractDhRepo<TDTO extends IBaseDTO>
// SQL exceptions generally only happen when something is wrong with
// the database or the query and should cause the system to blow up to notify the developer
if (e.toString().equals("database connection closed"))
throw new DbConnectionClosedException(e);
String message = "Unexpected Query error: ["+e.getMessage()+"], for script: ["+sql+"].";
LOGGER.error(message);
throw new RuntimeException(message, e);
@@ -0,0 +1,20 @@
package com.seibel.distanthorizons.core.sql;
public class DbConnectionClosedException extends Exception
{
public DbConnectionClosedException() {
super("The database connection is closed.");
}
public DbConnectionClosedException(String message) {
super(message);
}
public DbConnectionClosedException(String message, Throwable cause) {
super(message, cause);
}
public DbConnectionClosedException(Throwable cause) {
super(cause);
}
}
@@ -75,7 +75,7 @@ public class ThreadPools
/** how many total worker threads can be used */
private static int workerThreadSemaphoreCount = 0;
private static int workerThreadSemaphoreCount = Config.Client.Advanced.MultiThreading.numberOfLodBuilderThreads.get();
public static int getWorkerThreadCount() { return workerThreadSemaphoreCount; }
private static Semaphore workerThreadSemaphore = null;
@@ -141,9 +141,12 @@ public class ThreadPools
ThreadPools.bufferBuilderThreadPool.shutdownExecutorService();
workerThreadSemaphore = null;
workerThreadSemaphoreConfigListener.close();
workerThreadSemaphoreConfigListener = null;
if (workerThreadSemaphoreConfigListener != null)
{
workerThreadSemaphoreConfigListener.close();
workerThreadSemaphoreConfigListener = null;
}
}
}