Эх сурвалжийг харах

improved textures, box list and key handler, font and shaders moved to inner resource package, clean up

Kajetan Johannes Hammerle 5 жил өмнө
parent
commit
c25aea3f7d

+ 3 - 8
src/me/hammerle/snuviengine/Main.java

@@ -1,18 +1,13 @@
 package me.hammerle.snuviengine;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.lang.reflect.Field;
 import me.hammerle.snuviengine.game.Game;
-import me.hammerle.snuviengine.game.World;
-import me.hammerle.snuviengine.util.WrappedInputStream;
-import me.hammerle.snuviengine.util.WrappedOutputStream;
 
 public class Main 
 {
     public static void main(String[] args)
     {
-        try(FileOutputStream out = new FileOutputStream(new File("./testworld")))
+        /*try(FileOutputStream out = new FileOutputStream(new File("./testworld")))
         {
             WrappedOutputStream o = new WrappedOutputStream(out);
            
@@ -45,7 +40,7 @@ public class Main
         catch(Exception ex)
         {
             ex.printStackTrace();
-        }
+        }*/
         
         Game game = new Game();
         game.run();

+ 5 - 4
src/me/hammerle/snuviengine/api/Engine.java

@@ -42,6 +42,11 @@ public abstract class Engine
             error.free();
         }
     }
+    
+    public final void stop()
+    {
+        glfwSetWindowShouldClose(window, true);
+    }
 
     private void initGLFW()
     {
@@ -67,10 +72,6 @@ public abstract class Engine
             if(action == GLFW_RELEASE)
             {
                 KeyHandler.onKeyUpEvent(key);
-                if(key == GLFW_KEY_ESCAPE)
-                {
-                    glfwSetWindowShouldClose(window, true);
-                }
             }
             else if(action == GLFW_PRESS)
             {

+ 7 - 2
src/me/hammerle/snuviengine/api/FontRenderer.java

@@ -11,7 +11,7 @@ import static org.lwjgl.opengl.GL30.*;
 
 public class FontRenderer
 {
-    private final static Texture FONT_TEXTURE = new Texture("font.png");
+    private final static Texture FONT_TEXTURE = new Texture("font.png", true);
     
     public static final char COLOR_CHAR = '&';
     
@@ -165,13 +165,18 @@ public class FontRenderer
         glUnmapBuffer(GL_ARRAY_BUFFER);
         
         GLHelper.glBindVertexArray(vao);
-        FONT_TEXTURE.bindTexture();
+        FONT_TEXTURE.bind();
         
         glDrawArrays(GL_TRIANGLES, offset / 20, buffer.limit() / 20);
 
         buffer.limit(buffer.capacity());
         return y;
     }
+    
+    public float drawString(float x, float y, String s)
+    {
+        return drawString(x, y, true, s);
+    }
 
     private float addString(float x, float y, float[] colors, String s)
     {

+ 0 - 11
src/me/hammerle/snuviengine/api/GLHelper.java

@@ -1,6 +1,5 @@
 package me.hammerle.snuviengine.api;
 
-import org.lwjgl.opengl.GL11;
 import org.lwjgl.opengl.GL15;
 import org.lwjgl.opengl.GL30;
 
@@ -8,7 +7,6 @@ public class GLHelper
 {
     private static int currentVao = -1;
     private static int currentVbo = -1;
-    private static int currentTexture = -1;
         
     protected static void glBindVertexArray(int vao)
     {
@@ -27,13 +25,4 @@ public class GLHelper
             GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
         }
     }
-    
-    protected static void glBindTexture(int texture)
-    {
-        if(texture != currentTexture)
-        {
-            currentTexture = texture;
-            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
-        }
-    }
 }

+ 61 - 7
src/me/hammerle/snuviengine/api/KeyBinding.java

@@ -1,16 +1,59 @@
 package me.hammerle.snuviengine.api;
 
+import static org.lwjgl.glfw.GLFW.*;
+
 public final class KeyBinding
 {
-    private boolean isDown;
-    private int time;
-    private boolean isReleased;
+    private boolean isDown = false;
+    private int time = 0;
+    private boolean isReleased = false;
+    private int key;
+    private boolean isRebinding = false;
+    private String name = null;
+    
+    protected KeyBinding(int key)
+    {
+        this.key = key;
+    }
+    
+    public boolean isRebinding()
+    {
+        return isRebinding;
+    }
+    
+    public String getName()
+    {
+        if(name == null)
+        {
+            switch(key)
+            {
+                case GLFW_KEY_UP: name = "Up"; break;
+                case GLFW_KEY_DOWN: name = "Down"; break;
+                case GLFW_KEY_LEFT: name = "Left"; break;
+                case GLFW_KEY_RIGHT: name = "Right"; break;
+                case GLFW_KEY_LEFT_SHIFT: name = "L-Shift"; break;
+                case GLFW_KEY_RIGHT_SHIFT: name = "R-Shift"; break;
+                case GLFW_KEY_ESCAPE: name = "Escape"; break;
+                case GLFW_KEY_ENTER: name = "Enter"; break;
+                case GLFW_KEY_SPACE: name = "Space"; break;
+                default:
+                    name = glfwGetKeyName(key, glfwGetKeyScancode(key));
+                    if(name != null)
+                    {
+                        name = name.substring(0, 1).toUpperCase() + name.substring(1);
+                    }
+            }
+            if(name == null)
+            {
+                name = "Unknown";
+            }
+        }
+        return name;
+    }
     
-    protected KeyBinding()
+    protected void setIsRebinding(boolean b)
     {
-        isDown = false;
-        time = 0;
-        isReleased = false;
+        isRebinding = b;
     }
     
     protected void onKeyDownEvent()
@@ -64,4 +107,15 @@ public final class KeyBinding
     {
         this.time = time;
     }
+    
+    protected void setKey(int key)
+    {
+        this.key = key;
+        name = null;
+    }
+    
+    public int getKey()
+    {
+        return key;
+    }
 }

+ 29 - 1
src/me/hammerle/snuviengine/api/KeyHandler.java

@@ -5,19 +5,47 @@ import java.util.HashMap;
 public final class KeyHandler
 {
     private final static HashMap<Integer, KeyBinding> BINDINGS = new HashMap<>();
+    private static KeyBinding rebind = null;
     
     public static KeyBinding register(int key) throws KeyDuplicateException
     {
-        KeyBinding binding = new KeyBinding();
+        KeyBinding binding = new KeyBinding(key);
         if(BINDINGS.putIfAbsent(key, binding) != null)
         {
             throw new KeyDuplicateException("the key '" + key + "' has already been registered");
         }
         return binding;
     }
+    
+    public static void rebind(KeyBinding binding)
+    {
+        rebind = binding;
+        if(binding != null)
+        {
+            binding.setIsRebinding(true);
+        }
+    }
+    
+    public static void rebind(KeyBinding binding, int key)
+    {
+        if(BINDINGS.containsKey(key))
+        {
+            return;
+        }
+        BINDINGS.remove(binding.getKey());
+        binding.setKey(key);
+        BINDINGS.put(key, binding);
+    }
 
     protected static void onKeyDownEvent(int key) 
     {
+        if(rebind != null)
+        {
+            rebind.setIsRebinding(false);
+            rebind(rebind, key);
+            rebind = null;
+            return;
+        }
         KeyBinding binding = BINDINGS.get(key);
         if(binding != null)
         {

+ 0 - 9
src/me/hammerle/snuviengine/api/MapException.java

@@ -1,9 +0,0 @@
-package me.hammerle.snuviengine.api;
-
-public class MapException extends RuntimeException
-{
-    public MapException(String message)
-    {
-        super(message);
-    }
-}

+ 23 - 10
src/me/hammerle/snuviengine/api/Shader.java

@@ -1,11 +1,12 @@
 package me.hammerle.snuviengine.api;
 
-import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.nio.FloatBuffer;
-import java.nio.file.Files;
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Scanner;
 import org.lwjgl.BufferUtils;
 import static org.lwjgl.opengl.GL11.*;
 import static org.lwjgl.opengl.GL14.*;
@@ -40,7 +41,7 @@ public final class Shader
     
     protected static void init()
     {
-        program = createShaderProgram("shaders/vertex.vs", "shaders/fragment.fs");
+        program = createShaderProgram("vertex.vs", "fragment.fs");
         glUseProgram(program);
         
         unifViewMatrix = glGetUniformLocation(program, "viewMatrix");
@@ -77,6 +78,11 @@ public final class Shader
         initDone = true;
     }
     
+    protected static int getProgram()
+    {
+        return program;
+    }
+    
     protected static void addTask(Runnable r)
     {
         TASKS.add(r);
@@ -271,18 +277,25 @@ public final class Shader
     // general stuff
     // -------------------------------------------------------------------------
     
-    private static String[] readFile(String path)
+    private static String[] readFile(String name)
     {
-        try
+        URL url = Shader.class.getClassLoader().getResource("me/hammerle/snuviengine/shader/" + name);
+        if(url == null)
+        {
+            throw new ShaderException("failed reading shader '" + name + "'");
+        }
+        ArrayList<String> strings = new ArrayList<>();
+        try(Scanner scanner = new Scanner(url.openStream()))
         {
-            File f = new File(path);
-            List<String> list = Files.readAllLines(f.toPath());
-            list.replaceAll(s -> s + "\n");
-            return list.toArray(new String[list.size()]);
+            while(scanner.hasNext())
+            {
+                strings.add(scanner.nextLine() + "\n");
+            }
+            return strings.toArray(new String[strings.size()]);
         }
         catch(IOException ex)
         {
-            throw new ShaderException("failed reading shader file '" + path + "'");
+            throw new ShaderException("failed reading shader '" + name + "'");
         }
     }
     

+ 40 - 7
src/me/hammerle/snuviengine/api/Texture.java

@@ -8,7 +8,10 @@ import javax.imageio.ImageIO;
 import org.lwjgl.BufferUtils;
 import static org.lwjgl.opengl.GL11.*;
 import static org.lwjgl.opengl.GL12.*;
+import static org.lwjgl.opengl.GL13.*;
+import static org.lwjgl.opengl.GL20.*;
 import static org.lwjgl.opengl.GL30.*;
+import static org.lwjgl.opengl.GL33.*;
 
 public class Texture
 {
@@ -67,7 +70,7 @@ public class Texture
         
         public void nextFrame()
         {
-            GLHelper.glBindTexture(texture);
+            glActiveTexture(GL_TEXTURE0 + textureUnit);
             glTexSubImage2D(GL_TEXTURE_2D, 0, offsetX, offsetY, wi[index], he[index], GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, data[index]);
             index = (index + 1) % data.length;
         }
@@ -79,14 +82,27 @@ public class Texture
     private final int h;
     private IntBuffer buffer;
     
-    public Texture(String path)
+    private static int textureUnits = 1;
+    private int textureUnit = -1;
+    private static int boundSampler = -1;
+    private int sampler = -1;
+    private int sampLoc = -1;
+    
+    public Texture(String path, boolean internal)
     {
         this.path = path;
         
         BufferedImage image;
         try
         {
-            image = ImageIO.read(new File(path));
+            if(internal)
+            {
+                image = ImageIO.read(Texture.class.getClassLoader().getResource("me/hammerle/snuviengine/resources/" + path));
+            }
+            else
+            {
+                image = ImageIO.read(new File(path));
+            }
         }
         catch(IOException | IllegalArgumentException ex)
         {
@@ -109,6 +125,11 @@ public class Texture
         Shader.addTask(() -> loadTexture());
     }
     
+    public Texture(String path)
+    {
+        this(path, false);
+    }
+    
     public Animation addAnimation(int offsetX, int offsetY, String... paths)
     {
         return new Animation(offsetX, offsetY, paths);
@@ -121,9 +142,17 @@ public class Texture
             throw new TextureException("a texture is already loaded");
         }
         
-        texture = glGenTextures();
+        sampler = glGenSamplers();
+        sampLoc = glGetUniformLocation(Shader.getProgram(), "samp");
+        glUniform1i(sampLoc, sampler);
+
+        textureUnit = textureUnits;
+        textureUnits++;
+        glBindSampler(GL_TEXTURE0 + textureUnit, sampler);
         
-        GLHelper.glBindTexture(texture);
+        glActiveTexture(GL_TEXTURE0 + textureUnit);
+        texture = glGenTextures();
+        glBindTexture(GL_TEXTURE_2D, texture);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -133,13 +162,17 @@ public class Texture
         glGenerateMipmap(GL_TEXTURE_2D);
     }    
 
-    public void bindTexture()
+    public void bind()
     {
         if(texture == -1)
         {
             throw new TextureException("cannot load non loaded texture");
         }
-        GLHelper.glBindTexture(texture);
+        if(boundSampler != sampler)
+        {
+            boundSampler = sampler; 
+            glUniform1i(sampLoc, sampler);
+        }
     }
 }
 

+ 0 - 187
src/me/hammerle/snuviengine/api/TextureAtlas.java

@@ -1,187 +0,0 @@
-package me.hammerle.snuviengine.api;
-
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-import java.nio.IntBuffer;
-import javax.imageio.ImageIO;
-import org.lwjgl.BufferUtils;
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL12.*;
-import static org.lwjgl.opengl.GL13.*;
-
-public class TextureAtlas 
-{
-    private static final Texture NULL_TEXTURE = new Texture(0.0f, 0.0f, 0.0f, 0.0f);
-    
-    private static class Texture
-    {
-        private final float minX;
-        private final float minY;
-        private final float maxX;
-        private final float maxY;
-
-        private Texture(float minX, float minY, float maxX, float maxY)
-        {
-            this.minX = minX;
-            this.minY = minY;
-            this.maxX = maxX;
-            this.maxY = maxY;
-        }
-    }
-    
-    private final int tileWidth;
-    private final int tileHeight;
-    private final int width;    
-    private final int height;
-    
-    private Texture[] textures;
-    private int textureIndex = 0;
-    private final int[][] data;
-    
-    private int texture = -1; 
-    
-    private boolean generated = false;
-    
-    protected TextureAtlas(int tileWidth, int tileHeight, int width, int height)
-    {
-        this.tileWidth = tileWidth;
-        this.tileHeight = tileHeight;
-        this.width = width * tileWidth;
-        this.height = height * tileHeight;
-        
-        textures = new Texture[width * height];
-        for(int i = 0; i < textures.length; i++)
-        {
-            textures[i] = NULL_TEXTURE;
-        }
-        
-        data = new int[this.width][this.height];
-        
-        for(int x = 0; x < this.width; x++)
-        {
-            for(int y = 0; y < this.height; y++)
-            {
-               data[x][y] = 0xFF0000FF;
-            }
-        }
-    }
-    
-    protected void generateTexture()
-    {
-        if(generated)
-        {
-            throw new TextureException("the texture is already generated");
-        }
-        generated = true;
-        
-        texture = glGenTextures();
-        glBindTexture(GL_TEXTURE_2D, texture);
-
-        IntBuffer buffer = BufferUtils.createIntBuffer(width * height);       
-        for(int y = 0; y < height; y++)
-        {
-            for(int x = 0; x < width; x++)
-            {
-                buffer.put(data[x][y]);
-            }
-        }
-        buffer.flip();
-        
-        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, buffer);
-    }    
-
-    protected void bindTexture()
-    {
-        glActiveTexture(GL_TEXTURE0);
-        glBindTexture(GL_TEXTURE_2D, texture);
-        
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-    }
-    
-    private int convertColor(int c)
-    {
-        return (c << 8) | ((c >> 24) & 0xFF);
-    }
-    
-    public int addTexture(String path)
-    {
-        if(generated)
-        {
-            throw new TextureException("cannot add a texture to an already generated texture atlas");
-        }
-        else if(textureIndex == textures.length)
-        {
-            throw new TextureException("the texture atlas is full");
-        }
-        
-        BufferedImage image;
-        try
-        {
-            image = ImageIO.read(new File(path));
-        }
-        catch(IOException | IllegalArgumentException ex)
-        {
-            throw new TextureException("cannot add texture '" + path + "'");
-        }
-        
-        if(image.getWidth() != tileWidth || image.getHeight() != tileHeight)
-        {
-            throw new TextureException("size of '" + path + "' is " + image.getWidth() + "x" + image.getHeight() + ", expected is " + tileWidth + "x" + tileHeight);
-        }
-
-        int x = (textureIndex % width) * tileWidth;
-        int y = (textureIndex / height) * tileHeight;           
-        textures[textureIndex] = new Texture(((float) x) / width, ((float) y) / height, ((float) (x + tileWidth)) / width, ((float) (y + tileHeight)) / height);
-        textureIndex++;
-
-        for(int ix = 0; ix < image.getWidth(); ix++)
-        {
-            for(int iy = 0; iy < image.getHeight(); iy++)
-            {
-                data[ix + x][iy + y] = convertColor(image.getRGB(ix, image.getHeight() - iy - 1));
-            }
-        }
-        return textureIndex - 1;
-    }
-    
-    protected float getTextureMinX(int index, boolean hFlip)
-    {
-        if(hFlip)
-        {
-            return textures[index].maxX;
-        }
-        return textures[index].minX;
-    }
-    
-    protected float getTextureMaxX(int index, boolean hFlip)
-    {
-        if(hFlip)
-        {
-            return textures[index].minX;
-        }
-        return textures[index].maxX;
-    }
-    
-    protected float getTextureMinY(int index, boolean vFlip)
-    {
-        if(vFlip)
-        {
-            return textures[index].maxY;
-        }
-        return textures[index].minY;
-    }
-    
-    protected float getTextureMaxY(int index, boolean vFlip)
-    {
-        if(vFlip)
-        {
-            return textures[index].minY;
-        }
-        return textures[index].maxY;
-    }
-}
-

+ 3 - 2
src/me/hammerle/snuviengine/api/TextureRenderer.java

@@ -12,12 +12,13 @@ public class TextureRenderer
     private int vao;
     private int vbo;
     
-    private FloatBuffer buffer = BufferUtils.createFloatBuffer(12);
+    private FloatBuffer buffer;
     
     private boolean built = false;
     
-    public TextureRenderer()
+    public TextureRenderer(int triangles)
     {
+        buffer = BufferUtils.createFloatBuffer(triangles * 12);
         Shader.addTask(() -> 
         {
             vao = glGenVertexArrays();

+ 32 - 22
src/me/hammerle/snuviengine/game/BoxList.java

@@ -5,12 +5,13 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.function.Consumer;
 
-public class BoxList
+public class BoxList<T extends IBoxListEntry>
 {
-    private static final double MAX_SIZE = 2.5;
+    private double maxWidth = 0;
+    private double maxHeight = 0;
     
-    private final Entity[] entities = new Entity[70000];
-    private int lastFreeEntity = entities.length - 1;
+    private final T[] entities;
+    private int lastFreeEntity;
     public boolean isIterating = false;
     
     public static class Node
@@ -36,7 +37,7 @@ public class BoxList
     
     public int amount = 0;
         
-    public BoxList(double x1, double y1, double x2, double y2, double size)
+    public BoxList(int maxObjects, double x1, double y1, double x2, double y2, double size)
     {
         this.size = size;
         
@@ -49,24 +50,33 @@ public class BoxList
         boxMaxX = partionX * size;
         boxMaxY = partionY * size;
         
-        System.out.println(boxMinX + " " + boxMaxX);
-        System.out.println(boxMinY + " " + boxMaxY);
-        System.out.println(partionX + " " + partionY);
-        
         nodes = new Node[partionX][partionY];
+        
+        entities = (T[]) new IBoxListEntry[maxObjects];
+        lastFreeEntity = entities.length - 1;
     }
     
-    public Node add(Entity ent)
+    public Node add(T ent)
     {
         if(isIterating)
         {
             throw new ConcurrentModificationException();
         }
         
+        if(maxHeight < ent.getHeight() / 2)
+        {
+            maxHeight = ent.getHeight() / 2;
+        }
+        
+        if(maxWidth < ent.getWidth() / 2)
+        {
+            maxWidth = ent.getWidth() / 2;
+        }
+        
         amount++;
         
-        int x = Math.max(Math.min((int) (((ent.xPos + ent.width / 2) + boxMinX) / size), partionX - 1), 0);
-        int y = Math.max(Math.min((int) (((ent.yPos + ent.height / 2) + boxMinY) / size), partionY - 1), 0);
+        int x = Math.max(Math.min((int) ((ent.getCenterX() + boxMinX) / size), partionX - 1), 0);
+        int y = Math.max(Math.min((int) ((ent.getCenterY() + boxMinY) / size), partionY - 1), 0);
         
         Node n = new Node();
         n.index = lastFreeEntity;
@@ -117,9 +127,9 @@ public class BoxList
         else
         {
             lastFreeEntity++;
-            Entity ent = entities[lastFreeEntity];
+            T ent = entities[lastFreeEntity];
             entities[n.index] = ent;
-            ent.node.index = n.index;
+            ent.getNode().index = n.index;
             entities[lastFreeEntity] = null;
         }
         
@@ -171,14 +181,14 @@ public class BoxList
         }
     }
     
-    public List<Entity> getAllEntitiesAt(Entity not, double minX, double minY, double maxX, double maxY)
+    public List<T> getAllEntitiesAt(T not, double minX, double minY, double maxX, double maxY)
     {
-        int sx = Math.max(Math.min((int) ((minX + boxMinX - MAX_SIZE) / size), partionX - 1), 0);
-        int sy = Math.max(Math.min((int) ((minY + boxMinY - MAX_SIZE) / size), partionY - 1), 0);
-        int ex = Math.max(Math.min((int) ((maxX + boxMinX + MAX_SIZE) / size), partionX - 1), 0);
-        int ey = Math.max(Math.min((int) ((maxY + boxMinY + MAX_SIZE) / size), partionY - 1), 0);
+        int sx = Math.max(Math.min((int) ((minX + boxMinX - maxWidth) / size), partionX - 1), 0);
+        int sy = Math.max(Math.min((int) ((minY + boxMinY - maxHeight) / size), partionY - 1), 0);
+        int ex = Math.max(Math.min((int) ((maxX + boxMinX + maxWidth) / size), partionX - 1), 0);
+        int ey = Math.max(Math.min((int) ((maxY + boxMinY + maxHeight) / size), partionY - 1), 0);
         
-        List<Entity> list = new LinkedList<>();
+        List<T> list = new LinkedList<>();
         
         for(int x = sx; x <= ex; x++)
         {
@@ -199,7 +209,7 @@ public class BoxList
         return list;
     } 
     
-    public void forEach(Consumer<Entity> c)
+    public void forEach(Consumer<T> c)
     {
         isIterating = true;
         for(int i = lastFreeEntity + 1; i < entities.length; i++)
@@ -213,7 +223,7 @@ public class BoxList
     public String toString()
     {
         StringBuilder sb = new StringBuilder();
-        for(Entity ent : entities)
+        for(T ent : entities)
         {
             sb.append(ent);
             sb.append(", ");

+ 32 - 1
src/me/hammerle/snuviengine/game/Entity.java

@@ -5,7 +5,7 @@ import me.hammerle.snuviengine.api.Shader;
 import me.hammerle.snuviengine.game.BoxList.Node;
 import me.hammerle.snuviengine.util.Face;
 
-public class Entity
+public class Entity implements IBoxListEntry
 {
     private static final double STEP = 0.0625;
     
@@ -43,6 +43,7 @@ public class Entity
                 yPos + height > ent.yPos && ent.yPos + ent.height > yPos;
     }
     
+    @Override
     public boolean isColliding(double minX, double minY, double maxX, double maxY)
     {
         return xPos + width > minX && maxX > xPos &&
@@ -231,4 +232,34 @@ public class Entity
         xPos = x;
         yPos = y;
     }
+
+    @Override
+    public double getCenterX()
+    {
+        return xPos + width / 2;
+    }
+
+    @Override
+    public double getCenterY()
+    {
+        return yPos + height / 2;
+    }
+
+    @Override
+    public double getWidth()
+    {
+        return width;
+    }
+
+    @Override
+    public double getHeight()
+    {
+        return height;
+    }
+
+    @Override
+    public Node getNode()
+    {
+        return node;
+    }
 }

+ 13 - 9
src/me/hammerle/snuviengine/game/Game.java

@@ -2,13 +2,11 @@ package me.hammerle.snuviengine.game;
 
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Random;
 import me.hammerle.snuviengine.api.Engine;
 import me.hammerle.snuviengine.api.KeyBinding;
 import me.hammerle.snuviengine.api.KeyHandler;
 import me.hammerle.snuviengine.api.Shader;
-import me.hammerle.snuviengine.api.Texture;
 import me.hammerle.snuviengine.api.TextureRenderer;
 import me.hammerle.snuviengine.util.Clock;
 import me.hammerle.snuviengine.util.WrappedInputStream;
@@ -26,18 +24,18 @@ public class Game extends Engine
     public final static KeyBinding KEY_T = KeyHandler.register(GLFW_KEY_T);
     private boolean toogleTps = false;
     
-    private final TextureRenderer tr = new TextureRenderer();
+    private final TextureRenderer tr = new TextureRenderer(12);
     
-    public BoxList entities = new BoxList(0.0, 0.0, 400.0, 300.0, 1.0);
+    public BoxList<Entity> entities = new BoxList<>(5000, 0.0, 0.0, 400.0, 300.0, 1.0);
     
     private World w;
     
     public Game()
     {
         /*Random r = new Random(200);
-        for(int i = 0; i < 128; i++)
+        for(int i = 0; i < 4096; i++)
         {
-            Entity ent = new Entity(this, 5.0, 5.0);
+            Entity ent = new Entity(this, 2.0, 2.0);
             ent.setPosition((int) (r.nextDouble() * 400.0), (int) (r.nextDouble() * 300));
             ent.node = entities.add(ent);
         }*/
@@ -61,14 +59,18 @@ public class Game extends Engine
     public void init()
     {
         setNanosPerTick(50_000_000);
-        setMaxFps(120);
+        //setMaxFps(120);
+        
+        //Shader.setAmbientLight(0.5f, 0.5f, 0.5f);
+        Shader.setLightColor(0, 1f, 0.75f, 0.5f);
+        Shader.setLightStrength(0, 0.01f);
     }
 
     @Override
     public void tick()
     {        
         w.tick();
-        /*CLOCK.start();
+        CLOCK.start();
         entities.forEach(ent -> ent.tick());
         CLOCK.stop();
         CLOCK.calculate();
@@ -82,7 +84,7 @@ public class Game extends Engine
         {
             toogleTps = !toogleTps;
             setRenderTps(toogleTps);
-        }*/
+        }
     }
     
     private static final Clock CLOCK = new Clock(250);
@@ -90,7 +92,9 @@ public class Game extends Engine
     @Override
     public void renderTick(float lag)
     {
+        Shader.setLightEnabled(true);  
         w.renderTick(lag);
+        
         /*Shader.setTextureEnabled(false);
         Shader.setColorEnabled(true);
         Shader.getColorRenderer().drawRectangle(0, 299, 400, 300, 0xFFFFFFFF);

+ 13 - 0
src/me/hammerle/snuviengine/game/IBoxListEntry.java

@@ -0,0 +1,13 @@
+package me.hammerle.snuviengine.game;
+
+import me.hammerle.snuviengine.game.BoxList.Node;
+
+public interface IBoxListEntry
+{
+    public double getCenterX();
+    public double getCenterY();
+    public double getWidth();
+    public double getHeight();
+    public Node getNode();
+    public boolean isColliding(double minX, double minY, double maxX, double maxY);
+}

+ 4 - 2
src/me/hammerle/snuviengine/game/World.java

@@ -72,9 +72,11 @@ public class World
     {
         Shader.translateTo(lastCameraX + (cameraX - lastCameraX) * lag, lastCameraY + (cameraY - lastCameraY) * lag);
         
+        Shader.setLightLocation(0, 100 + lastCameraX + (cameraX - lastCameraX) * lag, 100 + lastCameraY + (cameraY - lastCameraY) * lag);
+        
         Shader.setColorEnabled(false);
         Shader.setTextureEnabled(true);
-        tiles.bindTexture();
+        tiles.bind();
         for(Chunk[] chunk : chunks)
         {
             for(Chunk c : chunk)
@@ -90,7 +92,7 @@ public class World
         
         Shader.setColorEnabled(false);
         Shader.setTextureEnabled(true);
-        tiles.bindTexture();
+        tiles.bind();
         for(Chunk[] chunk : chunks)
         {
             for(Chunk c : chunk)

+ 0 - 0
font.png → src/me/hammerle/snuviengine/resources/font.png


+ 1 - 1
shaders/fragment.fs → src/me/hammerle/snuviengine/shader/fragment.fs

@@ -4,7 +4,7 @@ layout (location = 0) in vec3 pos;
 layout (location = 1) in vec2 tex;
 layout (location = 2) in vec4 vertexColor;
 
-layout (binding = 0) uniform sampler2D samp;
+uniform sampler2D samp;
 
 uniform mat4 viewMatrix;
 uniform mat4 modelMatrix;

+ 1 - 1
shaders/vertex.vs → src/me/hammerle/snuviengine/shader/vertex.vs

@@ -29,7 +29,7 @@ out vec4 vColor;
 
 void main(void)
 { 
-    loc = pos.xy;
+    loc = (modelMatrix * vec4(pos, 1.0)).xy;
 
     gl_Position = viewMatrix * modelMatrix * vec4(pos, 1.0);