general cleanup

This commit is contained in:
DaniTheSkunk 2022-09-18 19:38:02 +02:00
parent 287d5482e2
commit 7a792c2a46
11 changed files with 52 additions and 37 deletions

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClassCanBeRecord" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@ -1,5 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<pattern value="com.danitheskunk.skunkworks.IRenderContext" method="drawRectangle" />
<pattern value="com.danitheskunk.skunkworks.IRenderContext" method="drawTextureRectangle" />
<pattern value="com.danitheskunk.skunkworks.IRenderContext" />
<pattern value="com.danitheskunk.skunkworks.IWindow" method="loadTextureArray" />
<pattern value="com.danitheskunk.skunkworks.Recti" method="getX" />
<pattern value="com.danitheskunk.skunkworks.Recti" method="getY" />
<pattern value="com.danitheskunk.skunkworks.Recti" />
<pattern value="com.danitheskunk.skunkworks.Vec2f" method="add" />
<pattern value="com.danitheskunk.skunkworks.Vec2f" method="div" />
<pattern value="com.danitheskunk.skunkworks.Vec2f" method="mul" />
<pattern value="com.danitheskunk.skunkworks.Vec2f" method="sub" />
<pattern value="com.danitheskunk.skunkworks.Vec2i" method="add" />
<pattern value="com.danitheskunk.skunkworks.Vec2i" method="div" />
<pattern value="com.danitheskunk.skunkworks.Vec2i" method="divf" />
<pattern value="com.danitheskunk.skunkworks.Vec2i" method="sub" />
<pattern value="com.danitheskunk.skunkworks.GLRenderContext" method="drawRectangle" />
<pattern value="com.danitheskunk.skunkworks.GLRenderContext" method="drawTextureRectangle" />
<pattern value="com.danitheskunk.skunkworks.GLWindow" method="loadTextureArray" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>

View File

@ -1,11 +1,9 @@
import com.danitheskunk.skunkworks.*;
import org.w3c.dom.css.Rect;
public class Test {
public static void main(String[] args) {
var engine = new Engine();
var window = engine.openWindow(new Vec2i(1280, 720), "Skunkworks");
var img2 = engine.loadImage("C:\\art\\pixel stuff.png");
var img = engine.loadImage("C:\\Users\\dani\\Videos\\Screenshot 2022-06-25 17-00-59.png");
var tex2 = window.loadTexture("C:\\art\\pixel stuff.png");
var tileset = window.loadTextureArray("C:\\stream\\coding\\rlc\\tilemap.png", new Vec2i(16, 16));
@ -16,10 +14,6 @@ public class Test {
while(!window.shouldClose()) {
window.tick();
var renderContext = window.renderStart();
//renderContext.drawRectangle(
// new Recti(100, 100, 100, 100),
// new Color(150, 200, 250)
//);
renderContext.drawTextureRectangle(
new Recti(0, 0, 1280, 720),
tex

View File

@ -3,14 +3,13 @@ package com.danitheskunk.skunkworks;
import org.lwjgl.BufferUtils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import static com.danitheskunk.skunkworks.GraphicsBackend.*;
public class Engine {
private GraphicsBackend graphicsBackend;
private final GraphicsBackend graphicsBackend;
//Constructors
public Engine() {
@ -27,8 +26,6 @@ public class Engine {
byte[] bytes;
try(FileInputStream fis = new FileInputStream(path)) {
bytes = fis.readAllBytes();
} catch(FileNotFoundException e) {
throw new RuntimeException(e);
} catch(IOException e) {
throw new RuntimeException(e);
}

View File

@ -3,7 +3,7 @@ package com.danitheskunk.skunkworks;
import static org.lwjgl.opengl.GL11.*;
class GLRenderContext implements IRenderContext{
private GLTextureAtlas atlas;
private final GLTextureAtlas atlas;
public GLRenderContext(GLTextureAtlas atlas) {
this.atlas = atlas;
@ -24,7 +24,7 @@ class GLRenderContext implements IRenderContext{
color.getA() / 255.0f
);
//counter clockwise triangles
//counterclockwise triangles
glVertex2i(bl.getX(), bl.getY());
glVertex2i(tr.getX(), tr.getY());
glVertex2i(tl.getX(), tl.getY());
@ -60,7 +60,7 @@ class GLRenderContext implements IRenderContext{
color.getA() / 255.0f
);
//counter clockwise triangles
//counterclockwise triangles
glTexCoord2d(tbl.getX(), tbl.getY());
glVertex2i(bl.getX(), bl.getY());
glTexCoord2d(ttr.getX(), ttr.getY());

View File

@ -4,7 +4,7 @@ class GLTexture implements ITexture {
private Recti texArea;
private Image img; //for re-blitting onto texture atlas
private final Image img; //for re-blitting onto texture atlas
GLTexture(Recti texArea, Image img) {
this.texArea = texArea;

View File

@ -1,10 +1,7 @@
package com.danitheskunk.skunkworks;
import org.lwjgl.BufferUtils;
import org.lwjgl.stb.STBRPContext;
import org.lwjgl.stb.STBRectPack;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@ -15,12 +12,11 @@ class GLTextureAtlas {
private GLTexture atlasTexture; //for debugging
private Image img;
private boolean shouldUpdate;
private int textureID;
private List<GLTexture> textures;
private final List<GLTexture> textures;
GLTextureAtlas() {
img = new Image(new Vec2i(32, 32));
textureID = glGenTextures();
int textureID = glGenTextures();
textures = new ArrayList<>();
shouldUpdate = true;
@ -62,9 +58,9 @@ class GLTextureAtlas {
height = textures.get(0).getImg().getHeight();
for(var tex : textures) {
var teximg = tex.getImg();
var texImg = tex.getImg();
//texture larger than atlas? resize atlas and try again
if(teximg.getHeight() > img.getHeight() || teximg.getWidth() > img.getWidth()) {
if(texImg.getHeight() > img.getHeight() || texImg.getWidth() > img.getWidth()) {
System.out.println("Texture too large");
doubleAtlasSize();
repack();
@ -72,10 +68,10 @@ class GLTextureAtlas {
}
//row full? start the next row
if(img.getWidth() - x < teximg.getWidth()) {
if(img.getWidth() - x < texImg.getWidth()) {
x = 0;
y += height;
height = teximg.getHeight();
height = texImg.getHeight();
//not enough space for new row? resize atlas and try again
if(y + height > img.getHeight()) {
@ -87,8 +83,8 @@ class GLTextureAtlas {
}
//take space, advance to right
tex.setTexArea(new Recti(new Vec2i(x, y), teximg.getSize()));
x += teximg.getWidth();
tex.setTexArea(new Recti(new Vec2i(x, y), texImg.getSize()));
x += texImg.getWidth();
}
}
@ -124,7 +120,7 @@ class GLTextureAtlas {
return img.getSize();
}
private class TextureHeightComparator implements Comparator<GLTexture> {
private static class TextureHeightComparator implements Comparator<GLTexture> {
@Override
public int compare(GLTexture o1, GLTexture o2) {
return o1.getImg().getHeight() - o2.getImg().getHeight();

View File

@ -3,7 +3,6 @@ package com.danitheskunk.skunkworks;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.stb.STBRectPack;
import java.util.ArrayList;
import java.util.List;
@ -14,12 +13,12 @@ import static org.lwjgl.system.MemoryUtil.NULL;
class GLWindow implements IWindow {
private boolean debug;
private Engine engine;
private GLRenderContext renderContext;
private final Engine engine;
private final GLRenderContext renderContext;
private boolean shouldClose;
private Vec2i size;
private GLTextureAtlas textureAtlas;
private long window;
private final Vec2i size;
private final GLTextureAtlas textureAtlas;
private final long window;
public GLWindow(Vec2i size, String title, Engine engine) {
GLFWErrorCallback.createPrint(System.err).set();

View File

@ -5,8 +5,8 @@ import org.lwjgl.stb.STBImage;
import java.nio.ByteBuffer;
public class Image {
private byte[] data;
private Vec2i size;
private final byte[] data;
private final Vec2i size;
//constructors
Image(ByteBuffer buffer) {
@ -15,6 +15,7 @@ public class Image {
var img = STBImage.stbi_load_from_memory(buffer, x, y, n, 4);
size = new Vec2i(x[0], y[0]);
data = new byte[x[0] * y[0] * 4];
assert img != null;
img.get(data);
}
@ -43,7 +44,7 @@ public class Image {
public Color getPixel(Vec2i pos) {
int i = pos.getX() * 4 + pos.getY() * 4 * size.getX();
return new Color(
((int) data[i + 0]) & 0xFF,
((int) data[i]) & 0xFF,
((int) data[i + 1]) & 0xFF,
((int) data[i + 2]) & 0xFF,
((int) data[i + 3]) & 0xFF
@ -52,7 +53,7 @@ public class Image {
public void setPixel(Vec2i pos, Color col) {
int i = pos.getX() * 4 + pos.getY() * 4 * size.getX();
data[i + 0] = (byte) (col.getR() & 0xFF);
data[i] = (byte) (col.getR() & 0xFF);
data[i + 1] = (byte) (col.getG() & 0xFF);
data[i + 2] = (byte) (col.getB() & 0xFF);
data[i + 3] = (byte) (col.getA() & 0xFF);

View File

@ -1,5 +1,6 @@
package com.danitheskunk.skunkworks;
@SuppressWarnings("SpellCheckingInspection")
public final class Recti {
private final Vec2i pos, size;

View File

@ -1,5 +1,6 @@
package com.danitheskunk.skunkworks;
@SuppressWarnings("SpellCheckingInspection")
public final class Vec2i {
private final int x, y;