fixed member variable visibility

This commit is contained in:
DaniTheSkunk 2022-09-18 19:11:23 +02:00
parent db785d7bca
commit 287d5482e2
8 changed files with 31 additions and 25 deletions

View File

@ -1,7 +1,7 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
public final class Color { 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 final static Color WHITE = new Color(255, 255, 255);
public Color(int r, int g, int b) { public Color(int r, int g, int b) {

View File

@ -10,7 +10,7 @@ import java.nio.ByteBuffer;
import static com.danitheskunk.skunkworks.GraphicsBackend.*; import static com.danitheskunk.skunkworks.GraphicsBackend.*;
public class Engine { public class Engine {
GraphicsBackend graphicsBackend; private GraphicsBackend graphicsBackend;
//Constructors //Constructors
public Engine() { public Engine() {

View File

@ -2,7 +2,9 @@ package com.danitheskunk.skunkworks;
class GLTexture implements ITexture { class GLTexture implements ITexture {
private Recti texArea; 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) { GLTexture(Recti texArea, Image img) {
this.texArea = texArea; this.texArea = texArea;
@ -10,6 +12,9 @@ class GLTexture implements ITexture {
} }
//setters //setters
Image getImg() {
return img;
}
@Override @Override
public Vec2i getSize() { return this.img.getSize(); } public Vec2i getSize() { return this.img.getSize(); }
void setTexArea(Recti texArea) { void setTexArea(Recti texArea) {
@ -17,7 +22,7 @@ class GLTexture implements ITexture {
} }
public Recti getTexArea() { Recti getTexArea() {
return texArea; return texArea;
} }
} }

View File

@ -14,7 +14,7 @@ import static org.lwjgl.opengl.GL11.*;
class GLTextureAtlas { class GLTextureAtlas {
private GLTexture atlasTexture; //for debugging private GLTexture atlasTexture; //for debugging
private Image img; private Image img;
boolean shouldUpdate; private boolean shouldUpdate;
private int textureID; private int textureID;
private List<GLTexture> textures; private List<GLTexture> textures;
@ -59,11 +59,12 @@ class GLTextureAtlas {
int height; int height;
textures.sort(new TextureHeightComparator().reversed()); textures.sort(new TextureHeightComparator().reversed());
height = textures.get(0).img.getHeight(); height = textures.get(0).getImg().getHeight();
for(var tex : textures) { for(var tex : textures) {
var teximg = tex.getImg();
//texture larger than atlas? resize atlas and try again //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"); System.out.println("Texture too large");
doubleAtlasSize(); doubleAtlasSize();
repack(); repack();
@ -71,10 +72,10 @@ class GLTextureAtlas {
} }
//row full? start the next row //row full? start the next row
if(img.getWidth() - x < tex.img.getWidth()) { if(img.getWidth() - x < teximg.getWidth()) {
x = 0; x = 0;
y += height; y += height;
height = tex.img.getHeight(); height = teximg.getHeight();
//not enough space for new row? resize atlas and try again //not enough space for new row? resize atlas and try again
if(y + height > img.getHeight()) { if(y + height > img.getHeight()) {
@ -86,14 +87,14 @@ class GLTextureAtlas {
} }
//take space, advance to right //take space, advance to right
tex.setTexArea(new Recti(new Vec2i(x, y), tex.img.getSize())); tex.setTexArea(new Recti(new Vec2i(x, y), teximg.getSize()));
x += tex.img.getWidth(); x += teximg.getWidth();
} }
} }
void updateImage() { void updateImage() {
for(var tex : textures) { 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<GLTexture> { private class TextureHeightComparator implements Comparator<GLTexture> {
@Override @Override
public int compare(GLTexture o1, GLTexture o2) { public int compare(GLTexture o1, GLTexture o2) {
return o1.img.getHeight() - o2.img.getHeight(); return o1.getImg().getHeight() - o2.getImg().getHeight();
} }
} }
} }

View File

@ -5,12 +5,12 @@ import org.lwjgl.stb.STBImage;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public class Image { public class Image {
byte[] data; private byte[] data;
Vec2i size; private Vec2i size;
//constructors //constructors
Image(ByteBuffer buffer) { Image(ByteBuffer buffer) {
//todo: resorce system //todo: resource system
int[] x = {0}, y = {0}, n = {0}; int[] x = {0}, y = {0}, n = {0};
var img = STBImage.stbi_load_from_memory(buffer, x, y, n, 4); var img = STBImage.stbi_load_from_memory(buffer, x, y, n, 4);
size = new Vec2i(x[0], y[0]); size = new Vec2i(x[0], y[0]);
@ -20,7 +20,7 @@ public class Image {
Image(Vec2i size) { Image(Vec2i size) {
this.size = size; this.size = size;
data = new byte[size.x * size.y * 4]; data = new byte[size.getX() * size.getY() * 4];
} }
//getters //getters
@ -52,10 +52,10 @@ public class Image {
public void setPixel(Vec2i pos, Color col) { public void setPixel(Vec2i pos, Color col) {
int i = pos.getX() * 4 + pos.getY() * 4 * size.getX(); int i = pos.getX() * 4 + pos.getY() * 4 * size.getX();
data[i + 0] = (byte) (col.r & 0xFF); data[i + 0] = (byte) (col.getR() & 0xFF);
data[i + 1] = (byte) (col.g & 0xFF); data[i + 1] = (byte) (col.getG() & 0xFF);
data[i + 2] = (byte) (col.b & 0xFF); data[i + 2] = (byte) (col.getB() & 0xFF);
data[i + 3] = (byte) (col.a & 0xFF); data[i + 3] = (byte) (col.getA() & 0xFF);
} }
public void drawImage(Image srcImage, Vec2i destPos) { public void drawImage(Image srcImage, Vec2i destPos) {

View File

@ -1,7 +1,7 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
public final class Recti { public final class Recti {
final Vec2i pos, size; private final Vec2i pos, size;
//constructors //constructors
public Recti(int x, int y, int width, int height) { public Recti(int x, int y, int width, int height) {

View File

@ -1,7 +1,7 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
public final class Vec2f { public final class Vec2f {
final double x, y; private final double x, y;
//constructors //constructors
public Vec2f(double x, double y) { public Vec2f(double x, double y) {

View File

@ -1,7 +1,7 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
public final class Vec2i { public final class Vec2i {
final int x, y; private final int x, y;
public final static Vec2i ZERO = new Vec2i(0, 0); 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); return new Vec2f(a.x / b, a.y / b);
} }
public static Vec2f divf(Vec2i a, Vec2f 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) { public static Vec2f divf(Vec2i a, int b) {
return new Vec2f(a.x / (double)b, a.y / (double)b); return new Vec2f(a.x / (double)b, a.y / (double)b);