From: fred-boy Date: Mon, 23 Dec 2019 14:04:52 +0000 (+0700) Subject: Better handle renderer X-Git-Tag: alpha0.4~18 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=cfadf32a4a39d1e437b141b88e103610561ce6ef;p=cavedroid.git Better handle renderer --- diff --git a/core/src/ru/deadsoftware/cavedroid/GameScreen.java b/core/src/ru/deadsoftware/cavedroid/GameScreen.java index 286ba49..e3278d1 100644 --- a/core/src/ru/deadsoftware/cavedroid/GameScreen.java +++ b/core/src/ru/deadsoftware/cavedroid/GameScreen.java @@ -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; } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java index afd9134..ea5296a 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java @@ -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(); + } } }