DEADSOFTWARE

Better handle renderer
authorfred-boy <fredboy@protonmail.com>
Mon, 23 Dec 2019 14:04:52 +0000 (21:04 +0700)
committerfred-boy <fredboy@protonmail.com>
Mon, 23 Dec 2019 14:04:52 +0000 (21:04 +0700)
core/src/ru/deadsoftware/cavedroid/GameScreen.java
core/src/ru/deadsoftware/cavedroid/game/GameProc.java

index 286ba49ed846779c741b282246d9f3bbb9e0e6ef..e3278d1bf4c92eb973439dafe1178e9f2a3e8107 100644 (file)
@@ -13,6 +13,8 @@ import ru.deadsoftware.cavedroid.misc.states.AppState;
 import ru.deadsoftware.cavedroid.misc.states.GameState;
 import ru.deadsoftware.cavedroid.misc.states.MenuState;
 
+import javax.annotation.Nullable;
+
 public class GameScreen implements Screen {
 
     public static GameProc GP;
@@ -24,7 +26,7 @@ public class GameScreen implements Screen {
     private Renderer renderer;
     private MenuProc menuProc;
 
-    private InputHandlerGame inputHandlerGame;
+    @Nullable private InputHandlerGame inputHandlerGame;
 
     public GameScreen() {
         Assets.load();
@@ -66,8 +68,7 @@ public class GameScreen implements Screen {
                 break;
 
             case LOAD:
-                GP.resetRenderer();
-                renderer = GP.renderer;
+                renderer = GP.resetRenderer();
                 if (inputHandlerGame == null) {
                     inputHandlerGame = new InputHandlerGame();
                 }
@@ -97,8 +98,7 @@ public class GameScreen implements Screen {
                 renderer = menuProc;
                 break;
             case GAME:
-                GP.resetRenderer();
-                renderer = GP.renderer;
+                renderer = GP.resetRenderer();
                 break;
         }
     }
index afd91343eeda6c06ce04cd02c0a3c4ed68830956..ea5296a4f226aa93c4d3bb594d0071de41c8ec91 100644 (file)
@@ -10,6 +10,7 @@ import ru.deadsoftware.cavedroid.game.mobs.Player;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 
+import javax.annotation.Nullable;
 import java.io.Serializable;
 import java.util.LinkedList;
 
@@ -31,7 +32,7 @@ public class GameProc implements Serializable, Disposable {
     public transient GameInput input;
     public ControlMode controlMode;
     transient GamePhysics physics;
-    private transient GameFluidsThread fluidThread;
+    @Nullable private transient GameFluidsThread fluidThread;
 
     public GameProc(int gameMode) {
         world = new GameWorld(WORLD_WIDTH, WORLD_HEIGHT);
@@ -41,13 +42,14 @@ public class GameProc implements Serializable, Disposable {
         physics = new GamePhysics();
         input = new GameInput();
         controlMode = CaveGame.TOUCH ? ControlMode.WALK : ControlMode.CURSOR;
-        resetRenderer();
+        renderer = resetRenderer();
         startFluidThread();
     }
 
-    public void resetRenderer() {
+    public GameRenderer resetRenderer() {
         int scale = CaveGame.TOUCH ? 320 : 480;
-        renderer = new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth());
+        renderer =  new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth());
+        return renderer;
     }
 
     private void startFluidThread() {
@@ -109,6 +111,8 @@ public class GameProc implements Serializable, Disposable {
 
     @Override
     public void dispose() {
-        fluidThread.interrupt();
+        if (fluidThread != null) {
+            fluidThread.interrupt();
+        }
     }
 }