diff --git a/com/danitheskunk/skunkworks/Color.java b/com/danitheskunk/skunkworks/Color.java index bc895d8..7b33b46 100644 --- a/com/danitheskunk/skunkworks/Color.java +++ b/com/danitheskunk/skunkworks/Color.java @@ -1,7 +1,7 @@ package com.danitheskunk.skunkworks; public final class Color { - final int r, g, b, a; + private final int r, g, b, a; public final static Color WHITE = new Color(255, 255, 255); public Color(int r, int g, int b) { diff --git a/com/danitheskunk/skunkworks/Engine.java b/com/danitheskunk/skunkworks/Engine.java index 4bf4fc1..327867d 100644 --- a/com/danitheskunk/skunkworks/Engine.java +++ b/com/danitheskunk/skunkworks/Engine.java @@ -10,7 +10,7 @@ import java.nio.ByteBuffer; import static com.danitheskunk.skunkworks.GraphicsBackend.*; public class Engine { - GraphicsBackend graphicsBackend; + private GraphicsBackend graphicsBackend; //Constructors public Engine() { diff --git a/com/danitheskunk/skunkworks/GLTexture.java b/com/danitheskunk/skunkworks/GLTexture.java index f873c26..f0aa3d7 100644 --- a/com/danitheskunk/skunkworks/GLTexture.java +++ b/com/danitheskunk/skunkworks/GLTexture.java @@ -2,7 +2,9 @@ package com.danitheskunk.skunkworks; class GLTexture implements ITexture { private Recti texArea; - Image img; //for re-blitting onto texture atlas + + + private Image img; //for re-blitting onto texture atlas GLTexture(Recti texArea, Image img) { this.texArea = texArea; @@ -10,6 +12,9 @@ class GLTexture implements ITexture { } //setters + Image getImg() { + return img; + } @Override public Vec2i getSize() { return this.img.getSize(); } void setTexArea(Recti texArea) { @@ -17,7 +22,7 @@ class GLTexture implements ITexture { } - public Recti getTexArea() { + Recti getTexArea() { return texArea; } } diff --git a/com/danitheskunk/skunkworks/GLTextureAtlas.java b/com/danitheskunk/skunkworks/GLTextureAtlas.java index b0cd16a..350e0d4 100644 --- a/com/danitheskunk/skunkworks/GLTextureAtlas.java +++ b/com/danitheskunk/skunkworks/GLTextureAtlas.java @@ -14,7 +14,7 @@ import static org.lwjgl.opengl.GL11.*; class GLTextureAtlas { private GLTexture atlasTexture; //for debugging private Image img; - boolean shouldUpdate; + private boolean shouldUpdate; private int textureID; private List textures; @@ -59,11 +59,12 @@ class GLTextureAtlas { int height; textures.sort(new TextureHeightComparator().reversed()); - height = textures.get(0).img.getHeight(); + height = textures.get(0).getImg().getHeight(); for(var tex : textures) { + var teximg = tex.getImg(); //texture larger than atlas? resize atlas and try again - if(tex.img.getHeight() > img.getHeight() || tex.img.getWidth() > img.getWidth()) { + if(teximg.getHeight() > img.getHeight() || teximg.getWidth() > img.getWidth()) { System.out.println("Texture too large"); doubleAtlasSize(); repack(); @@ -71,10 +72,10 @@ class GLTextureAtlas { } //row full? start the next row - if(img.getWidth() - x < tex.img.getWidth()) { + if(img.getWidth() - x < teximg.getWidth()) { x = 0; y += height; - height = tex.img.getHeight(); + height = teximg.getHeight(); //not enough space for new row? resize atlas and try again if(y + height > img.getHeight()) { @@ -86,14 +87,14 @@ class GLTextureAtlas { } //take space, advance to right - tex.setTexArea(new Recti(new Vec2i(x, y), tex.img.getSize())); - x += tex.img.getWidth(); + tex.setTexArea(new Recti(new Vec2i(x, y), teximg.getSize())); + x += teximg.getWidth(); } } void updateImage() { for(var tex : textures) { - img.drawImage(tex.img, tex.getTexArea().getPos()); + img.drawImage(tex.getImg(), tex.getTexArea().getPos()); } } @@ -126,7 +127,7 @@ class GLTextureAtlas { private class TextureHeightComparator implements Comparator { @Override public int compare(GLTexture o1, GLTexture o2) { - return o1.img.getHeight() - o2.img.getHeight(); + return o1.getImg().getHeight() - o2.getImg().getHeight(); } } } diff --git a/com/danitheskunk/skunkworks/Image.java b/com/danitheskunk/skunkworks/Image.java index 641ce41..a99b1f7 100644 --- a/com/danitheskunk/skunkworks/Image.java +++ b/com/danitheskunk/skunkworks/Image.java @@ -5,12 +5,12 @@ import org.lwjgl.stb.STBImage; import java.nio.ByteBuffer; public class Image { - byte[] data; - Vec2i size; + private byte[] data; + private Vec2i size; //constructors Image(ByteBuffer buffer) { - //todo: resorce system + //todo: resource system int[] x = {0}, y = {0}, n = {0}; var img = STBImage.stbi_load_from_memory(buffer, x, y, n, 4); size = new Vec2i(x[0], y[0]); @@ -20,7 +20,7 @@ public class Image { Image(Vec2i size) { this.size = size; - data = new byte[size.x * size.y * 4]; + data = new byte[size.getX() * size.getY() * 4]; } //getters @@ -52,10 +52,10 @@ 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.r & 0xFF); - data[i + 1] = (byte) (col.g & 0xFF); - data[i + 2] = (byte) (col.b & 0xFF); - data[i + 3] = (byte) (col.a & 0xFF); + data[i + 0] = (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); } public void drawImage(Image srcImage, Vec2i destPos) { diff --git a/com/danitheskunk/skunkworks/Recti.java b/com/danitheskunk/skunkworks/Recti.java index c82ff93..ab36b29 100644 --- a/com/danitheskunk/skunkworks/Recti.java +++ b/com/danitheskunk/skunkworks/Recti.java @@ -1,7 +1,7 @@ package com.danitheskunk.skunkworks; public final class Recti { - final Vec2i pos, size; + private final Vec2i pos, size; //constructors public Recti(int x, int y, int width, int height) { diff --git a/com/danitheskunk/skunkworks/Vec2f.java b/com/danitheskunk/skunkworks/Vec2f.java index 94f0645..293f979 100644 --- a/com/danitheskunk/skunkworks/Vec2f.java +++ b/com/danitheskunk/skunkworks/Vec2f.java @@ -1,7 +1,7 @@ package com.danitheskunk.skunkworks; public final class Vec2f { - final double x, y; + private final double x, y; //constructors public Vec2f(double x, double y) { diff --git a/com/danitheskunk/skunkworks/Vec2i.java b/com/danitheskunk/skunkworks/Vec2i.java index f52d45a..f5d5802 100644 --- a/com/danitheskunk/skunkworks/Vec2i.java +++ b/com/danitheskunk/skunkworks/Vec2i.java @@ -1,7 +1,7 @@ package com.danitheskunk.skunkworks; public final class Vec2i { - final int x, y; + private final int x, y; public final static Vec2i ZERO = new Vec2i(0, 0); @@ -57,7 +57,7 @@ public final class Vec2i { return new Vec2f(a.x / b, a.y / b); } public static Vec2f divf(Vec2i a, Vec2f b) { - return new Vec2f(a.x / b.x, a.y / b.y); + return new Vec2f(a.x / b.getX(), a.y / b.getY()); } public static Vec2f divf(Vec2i a, int b) { return new Vec2f(a.x / (double)b, a.y / (double)b);