diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..c241077
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 07115cd..aa305f6 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Test.java b/Test.java
index 4376a3b..ec78b78 100644
--- a/Test.java
+++ b/Test.java
@@ -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
diff --git a/com/danitheskunk/skunkworks/Engine.java b/com/danitheskunk/skunkworks/Engine.java
index 327867d..eb59559 100644
--- a/com/danitheskunk/skunkworks/Engine.java
+++ b/com/danitheskunk/skunkworks/Engine.java
@@ -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);
}
diff --git a/com/danitheskunk/skunkworks/GLRenderContext.java b/com/danitheskunk/skunkworks/GLRenderContext.java
index eaef04d..88269ee 100644
--- a/com/danitheskunk/skunkworks/GLRenderContext.java
+++ b/com/danitheskunk/skunkworks/GLRenderContext.java
@@ -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());
diff --git a/com/danitheskunk/skunkworks/GLTexture.java b/com/danitheskunk/skunkworks/GLTexture.java
index f0aa3d7..602c17e 100644
--- a/com/danitheskunk/skunkworks/GLTexture.java
+++ b/com/danitheskunk/skunkworks/GLTexture.java
@@ -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;
diff --git a/com/danitheskunk/skunkworks/GLTextureAtlas.java b/com/danitheskunk/skunkworks/GLTextureAtlas.java
index 350e0d4..c164851 100644
--- a/com/danitheskunk/skunkworks/GLTextureAtlas.java
+++ b/com/danitheskunk/skunkworks/GLTextureAtlas.java
@@ -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 textures;
+ private final List 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 {
+ private static class TextureHeightComparator implements Comparator {
@Override
public int compare(GLTexture o1, GLTexture o2) {
return o1.getImg().getHeight() - o2.getImg().getHeight();
diff --git a/com/danitheskunk/skunkworks/GLWindow.java b/com/danitheskunk/skunkworks/GLWindow.java
index 5b3d7d6..9c4bbed 100644
--- a/com/danitheskunk/skunkworks/GLWindow.java
+++ b/com/danitheskunk/skunkworks/GLWindow.java
@@ -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();
diff --git a/com/danitheskunk/skunkworks/Image.java b/com/danitheskunk/skunkworks/Image.java
index a99b1f7..cb62cf4 100644
--- a/com/danitheskunk/skunkworks/Image.java
+++ b/com/danitheskunk/skunkworks/Image.java
@@ -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);
diff --git a/com/danitheskunk/skunkworks/Recti.java b/com/danitheskunk/skunkworks/Recti.java
index ab36b29..71f2df8 100644
--- a/com/danitheskunk/skunkworks/Recti.java
+++ b/com/danitheskunk/skunkworks/Recti.java
@@ -1,5 +1,6 @@
package com.danitheskunk.skunkworks;
+@SuppressWarnings("SpellCheckingInspection")
public final class Recti {
private final Vec2i pos, size;
diff --git a/com/danitheskunk/skunkworks/Vec2i.java b/com/danitheskunk/skunkworks/Vec2i.java
index f5d5802..caba1b7 100644
--- a/com/danitheskunk/skunkworks/Vec2i.java
+++ b/com/danitheskunk/skunkworks/Vec2i.java
@@ -1,5 +1,6 @@
package com.danitheskunk.skunkworks;
+@SuppressWarnings("SpellCheckingInspection")
public final class Vec2i {
private final int x, y;