瀏覽代碼

onStop hook

Kajetan Johannes Hammerle 5 年之前
父節點
當前提交
7f5cd0fef0

+ 0 - 92
src/me/hammerle/snuviengine/Main.java

@@ -1,104 +1,12 @@
 package me.hammerle.snuviengine;
 
-import java.lang.reflect.Field;
 import me.hammerle.snuviengine.game.Game;
 
 public class Main 
 {
     public static void main(String[] args)
     {
-        /*try(FileOutputStream out = new FileOutputStream(new File("./testworld")))
-        {
-            WrappedOutputStream o = new WrappedOutputStream(out);
-           
-            o.writeInt(48);
-            o.writeInt(32);
-            
-            for(int l = 0; l < 24; l++)
-            {
-                for(int i = 0; i < 64; i++)
-                {
-                    o.writeShort(1);
-                }
-                for(int i = 0; i < 64; i++)
-                {
-                    o.writeShort(0);
-                }
-                
-                for(int i = 0; i < 64; i++)
-                {
-                    o.writeShort(14);
-                }
-                for(int i = 0; i < 64; i++)
-                {
-                    o.writeShort(15);
-                }
-            }
-            
-            out.flush();
-        }
-        catch(Exception ex)
-        {
-            ex.printStackTrace();
-        }*/
-        
         Game game = new Game();
         game.run();
-        
-        /*World w = new World();
-        
-        try(FileOutputStream out = new FileOutputStream(new File("./testworld")))
-        {
-            WrappedOutputStream o = new WrappedOutputStream(out);
-           
-            o.writeInt(16);
-            o.writeInt(16);
-            
-            for(int i = 0; i < 256; i++)
-            {
-                o.writeShort(i);
-            }
-            
-            out.flush();
-        }
-        catch(Exception ex)
-        {
-            ex.printStackTrace();
-        }*/
-        
-        //for(int i = 0; i < 736; i++)
-        //{
-        //    System.out.println("public static final TexturedTile OUT_" + i + " = register(" + i + ", new TexturedTile(\"out" + i + ".png\"));");
-        //}
-        
-        /*
-        try
-        {
-            BufferedImage image = ImageIO.read(new File("tileset-blackvolution.png"));
-            int w = image.getWidth();
-            int h = image.getHeight();
-            int counter = 0;
-            
-            for(int iy = 0; iy < h; iy += 16)
-            {
-                for(int ix = 0; ix < w; ix += 16)
-                {
-                    BufferedImage out = new BufferedImage(16, 16, 2);
-                    for(int x = 0; x < 16; x++)
-                    {
-                        for(int y = 0; y < 16; y++)
-                        {
-                            out.setRGB(x, y, image.getRGB(x + ix, y + iy));
-                        }
-                    }
-                    ImageIO.write(out, "png", new File("images/out" + counter + ".png"));
-                    counter++;
-                }
-            }
-        }
-        catch(Exception ex)
-        {
-            ex.printStackTrace();
-        }*/
     }
 }

+ 2 - 0
src/me/hammerle/snuviengine/api/Engine.java

@@ -178,6 +178,7 @@ public abstract class Engine
 
             glfwPollEvents();
         }
+        onStop();
     }
     
     public final void setNanosPerTick(long nanos)
@@ -219,6 +220,7 @@ public abstract class Engine
     public abstract void init();
     public abstract void tick();
     public abstract void renderTick(float lag);
+    public abstract void onStop();
 }
 
 

+ 6 - 2
src/me/hammerle/snuviengine/game/Game.java

@@ -2,7 +2,6 @@ package me.hammerle.snuviengine.game;
 
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.Random;
 import me.hammerle.snuviengine.api.Engine;
 import me.hammerle.snuviengine.api.KeyBinding;
 import me.hammerle.snuviengine.api.KeyHandler;
@@ -59,7 +58,7 @@ 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);
@@ -110,4 +109,9 @@ public class Game extends Engine
         y = Shader.getFontRenderer().drawString(5, y, true, String.valueOf(CLOCK.getTime()));
         y = Shader.getFontRenderer().drawString(5, y, true, String.valueOf(CLOCK.getMinTime()));
     }
+
+    @Override
+    public void onStop()
+    {
+    }
 }