Small Refactors here and there.

This commit is contained in:
Speiger 2021-10-11 00:53:56 +02:00
parent 6577428b1f
commit 161d2a1022
19 changed files with 96 additions and 28 deletions

View File

@ -66,5 +66,5 @@ dependencies {
compile 'com.google.code.gson:gson:2.8.6'
//Primitive Collections
compile 'de.speiger:Primitive-Collections:0.4.1'
compile 'de.speiger:Primitive-Collections:0.4.3'
}

View File

@ -88,6 +88,11 @@ public class MathUtils
return value > 0 ? 1D : (value < 0 ? -1D : 0D);
}
public static int sub(int key, int value)
{
return key - value;
}
public static int ceil(double value)
{
int i = (int)value;

View File

@ -11,6 +11,7 @@ import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.renderer.buffer.RenderBuffer;
import speiger.src.coreengine.rendering.tesselation.Tesselator;
import speiger.src.coreengine.rendering.tesselation.VertexType;
import speiger.src.coreengine.rendering.utils.GLUtils;
public class PieComponent extends GuiComponent
{
@ -76,7 +77,11 @@ public class PieComponent extends GuiComponent
{
float centerX = getBox().getCenterX();
float centerY = getBox().getCenterY();
getRenderer().setBrightness(getActiveBrightness()).translate(centerX, centerY).drawBuffers(buffer, 0F, 0F).translate(-centerX, -centerY).setBrightness(1F);
getRenderer().setBrightness(getActiveBrightness()).translate(centerX, centerY).flush();
GLUtils.DEBTH_TEST.push(true);
getRenderer().drawBuffers(buffer, 0F, 0F).flush();
GLUtils.DEBTH_TEST.pop();
getRenderer().translate(-centerX, -centerY).setBrightness(1F);
return true;
}

View File

@ -48,8 +48,8 @@ public class TreeComponent<T extends ITreeEntry> extends GuiComponent implements
int movement;
Vec2i lastMouse = Vec2i.newMutable();
IButtonComponent customButton;
protected ObjectSet<T> openNodes = new ObjectOpenHashSet<T>();
protected ObjectSet<T> selectedNodes = new ObjectOpenHashSet<T>();
protected ObjectSet<T> openNodes = new ObjectOpenHashSet<>();
protected ObjectSet<T> selectedNodes = new ObjectOpenHashSet<>();
protected int selectionMode = 1;
protected int updateMode = 1;
T node;
@ -304,11 +304,16 @@ public class TreeComponent<T extends ITreeEntry> extends GuiComponent implements
}
public void openNode(T entry, boolean childrenIncluded)
{
openNode(entry, childrenIncluded, Integer.MAX_VALUE);
}
public void openNode(T entry, boolean childrenIncluded, int maxLayers)
{
openNodes.add(entry);
if(childrenIncluded)
{
getNodes(entry, openNodes, false);
getNodes(entry, openNodes, false, maxLayers);
}
listChange = true;
updateScrollBar();
@ -659,6 +664,22 @@ public class TreeComponent<T extends ITreeEntry> extends GuiComponent implements
return MathUtils.clamp(0, visibleNodes.size(), MathUtils.ceil((getBox().getBaseHeight() - (horizontalBar.getRequiredSpace() / getBox().getScale())) / entryHeight) + 1);
}
protected void getNodes(T entry, Collection<T> collection, boolean openOnly, int layers)
{
if(entry != null && layers >= 0)
{
collection.add(entry);
if(!entry.isLeaf() && (!openOnly || openNodes.contains(entry)))
{
for(int i = 0,m=entry.getChildCount();i<m;i++)
{
getNodes((T)entry.getChild(i), collection, openOnly, layers-1);
}
}
}
}
protected void getNodes(T entry, Collection<T> collection, boolean openOnly)
{
if(entry != null)

View File

@ -3,16 +3,16 @@ package speiger.src.coreengine.rendering.gui.components.list;
import speiger.src.coreengine.rendering.gui.components.TextComponent;
import speiger.src.coreengine.rendering.gui.helper.Align;
public class TextEntry extends BaseListEntry
public class TextListEntry extends BaseListEntry
{
TextComponent text = addComponent(new TextComponent().setLimitedBounds(false).setAlignment(Align.LEFT_TOP, Align.LEFT_TOP).setSpecialRendering(true).setComponentPosition(0F, 0F).cast());
public TextEntry(String s)
public TextListEntry(String s)
{
text.setText(s);
}
public TextEntry setScale(float scale)
public TextListEntry setScale(float scale)
{
text.setTextScale(scale);
return this;

View File

@ -12,7 +12,7 @@ import speiger.src.coreengine.rendering.gui.base.IKeyComponent;
import speiger.src.coreengine.rendering.gui.components.ListComponent;
import speiger.src.coreengine.rendering.gui.components.ScrollBarComponent;
import speiger.src.coreengine.rendering.gui.components.TextFieldComponent;
import speiger.src.coreengine.rendering.gui.components.list.TextEntry;
import speiger.src.coreengine.rendering.gui.components.list.TextListEntry;
import speiger.src.coreengine.rendering.gui.helper.constrains.ComponentConstrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.ParentConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.PixelConstrain;
@ -204,7 +204,7 @@ public class ConsoleComponent extends GuiComponent implements IKeyComponent
}
}
private static class MessageEntry extends TextEntry
private static class MessageEntry extends TextListEntry
{
int messageId;

View File

@ -0,0 +1,26 @@
package speiger.src.coreengine.rendering.gui.components.tree;
import speiger.src.coreengine.rendering.gui.components.TextComponent;
import speiger.src.coreengine.rendering.gui.helper.Align;
public class TextTreeEntry extends BaseTreeEntry
{
TextComponent text = addComponent(new TextComponent().setLimitedBounds(false).setAlignment(Align.LEFT_TOP, Align.LEFT_TOP).setSpecialRendering(true).setComponentPosition(0F, 0F).cast());
public TextTreeEntry(String s)
{
text.setText(s);
}
public TextTreeEntry setScale(float scale)
{
text.setTextScale(scale);
return this;
}
public String getText()
{
return text.getText();
}
}

View File

@ -37,13 +37,18 @@ public class Constraints
}
public static ComponentConstrains getSideConstraint(float size, Facing side)
{
return getSideConstraint(size, side, 0F);
}
public static ComponentConstrains getSideConstraint(float size, Facing side, float offset)
{
switch(side)
{
case NORTH: return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(), new ParentConstrain(), new PixelConstrain(size));
case EAST: return new ComponentConstrains(new ParentConstrain(size).invert(), new ParentConstrain(), new PixelConstrain(size), new ParentConstrain());
case SOUTH: return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(size).invert(), new ParentConstrain(), new PixelConstrain(size));
case WEST: return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(), new PixelConstrain(size), new ParentConstrain());
case NORTH: return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(offset), new ParentConstrain(), new PixelConstrain(size));
case EAST: return new ComponentConstrains(new ParentConstrain(size+offset).invert(), new ParentConstrain(), new PixelConstrain(size), new ParentConstrain());
case SOUTH: return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(size+offset).invert(), new ParentConstrain(), new PixelConstrain(size));
case WEST: return new ComponentConstrains(new ParentConstrain(offset), new ParentConstrain(), new PixelConstrain(size), new ParentConstrain());
default: return null;
}
}

View File

@ -107,7 +107,7 @@ public class FontRenderer implements IFontRenderer
bufferBuilder.finishData();
if(bufferBuilder.getVertexCount() > 0)
{
drawCalls.add(bufferBuilder.getDrawCall(getTexture().getTextureID()));
drawCalls.add(bufferBuilder.getDrawCall(getTexture().getTextureId()));
}
bufferBuilder.setOffset(0F, 0F, 0F);
return drawCalls;
@ -192,7 +192,7 @@ public class FontRenderer implements IFontRenderer
component.getMetadata().addLine(lines.get(i));
}
maxWidth /= 2;
buffer.finishShape(getTexture().getTextureID(), bufferBuilder);
buffer.finishShape(getTexture().getTextureId(), bufferBuilder);
if(lineBuffer.hasData())
{
Tesselator tes = buffer.start(GL11.GL_TRIANGLES, VertexType.UI).offset(0F, 0F, 0.001F);

View File

@ -707,6 +707,6 @@ public class UIRenderer implements IReloadableResource
private int getTextureId(ITexture texture)
{
return texture == null ? 0 : texture.getTextureID();
return texture == null ? 0 : texture.getTextureId();
}
}

View File

@ -34,7 +34,6 @@ public class MergedModelData extends SimpleModelData
public static MergedModelData merge(String newName, int vertexBytes, List<SimpleModelData> data)
{
System.out.println("Test: "+data.size()+", Name="+newName);
ByteList byteData = new ByteArrayList();
IntList indeciesData = new IntArrayList();
int[] offsets = new int[data.size() * 2];

View File

@ -34,7 +34,7 @@ public class UniformTexture extends UniformInt
disable();
return;
}
storeTexture(textureID.getTextureID());
storeTexture(textureID.getTextureId());
}
public void disable()

View File

@ -17,7 +17,7 @@ public abstract class AbstractTexture implements ITexture
}
@Override
public int getTextureID()
public int getTextureId()
{
return textureID;
}

View File

@ -12,7 +12,7 @@ import speiger.src.coreengine.rendering.textures.stb.STBTexture;
public interface ITexture extends IReloadableResource
{
public int getTextureID();
public int getTextureId();
public void bindTexture();
public void deleteTexture();

View File

@ -51,7 +51,7 @@ public class TextureManager implements IReloadableResource
{
if(texture != null)
{
GL11.glDeleteTextures(texture.getTextureID());
GL11.glDeleteTextures(texture.getTextureId());
reloader.removeReloadableResource(texture);
}
}

View File

@ -21,7 +21,7 @@ public class WrappedTexture implements ITexture
}
@Override
public int getTextureID()
public int getTextureId()
{
return textureId;
}

View File

@ -3,6 +3,8 @@ package speiger.src.coreengine.rendering.textures.normal;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.lwjgl.opengl.GL11;
import org.lwjgl.system.MemoryStack;
@ -29,6 +31,7 @@ public class DynamicTexture extends AbstractTexture implements IDynamicTexture
public static final int B = 0xFF;
public static final int A = 0xFF << 24;
Int2ObjectMap<IntSet> dirtyChunks = new Int2ObjectLinkedOpenHashMap<IntSet>();
Lock lock = new ReentrantLock();
int[] data;
int width;
int height;
@ -56,6 +59,7 @@ public class DynamicTexture extends AbstractTexture implements IDynamicTexture
@Override
public void markDirty(int x, int z)
{
lock.lock();
int chunkIndex = BitUtil.toInt(x >> 4, z >> 4);
IntSet set = dirtyChunks.get(chunkIndex);
if(set == null)
@ -64,6 +68,7 @@ public class DynamicTexture extends AbstractTexture implements IDynamicTexture
dirtyChunks.put(chunkIndex, set);
}
set.add((x & 15) << 4 | (z & 15));
lock.unlock();
}
@Override
@ -144,6 +149,7 @@ public class DynamicTexture extends AbstractTexture implements IDynamicTexture
@Override
public void processChanges(boolean full)
{
lock.lock();
if(full)
{
ByteBuffer buffer = MemoryUtil.memAlloc(data.length * 4);
@ -206,12 +212,13 @@ public class DynamicTexture extends AbstractTexture implements IDynamicTexture
{
((ITrimmable)dirtyChunks).trim();
}
lock.unlock();
}
@Override
public void reload()
{
int old = getTextureID();
int old = getTextureId();
setTextureID(GL11.glGenTextures());
TextureManager.INSTANCE.removeTexture(old);
processChanges(true);

View File

@ -83,8 +83,8 @@ public class GPUProfilerEntry implements IProfilerEntry
currentTime = 0;
if(end && totalTicks++ >= 10)
{
minTime = Long.MAX_VALUE;
maxTime = Long.MIN_VALUE;
minTime = currentTime;
maxTime = currentTime;
totalTicks = 0;
}
}

View File

@ -84,8 +84,8 @@ public class ProfilerEntry implements IProfilerEntry
currentTime = 0;
if(end && totalTicks++ >= 10)
{
minTime = Long.MAX_VALUE;
maxTime = Long.MIN_VALUE;
minTime = currentTime;
maxTime = currentTime;
totalTicks = 0;
}
}