Skip to content
Snippets Groups Projects
Commit 2538b34b authored by Mads Hermansen's avatar Mads Hermansen
Browse files

feat(GameManager): :bug: fix Statemanager, Gamemanager bugs and performance changes

parent 0efb03ce
Branches
No related tags found
1 merge request!11Draft: Resolve "Slight Controller Logic implementation"
...@@ -19,8 +19,10 @@ public class ChessGame extends ApplicationAdapter { ...@@ -19,8 +19,10 @@ public class ChessGame extends ApplicationAdapter {
@Override @Override
public void render () { public void render () {
ScreenUtils.clear(1, 0, 0, 1); ScreenUtils.clear(1, 0, 0, 1);
batch.begin();
GameManager.getInstance().render(batch); GameManager.getInstance().render(batch);
GameManager.getInstance().update(Gdx.graphics.getDeltaTime()); GameManager.getInstance().update(Gdx.graphics.getDeltaTime());
batch.end();
} }
@Override @Override
......
...@@ -29,6 +29,8 @@ public class GameManager { ...@@ -29,6 +29,8 @@ public class GameManager {
private GameManager(GameState gameState) { private GameManager(GameState gameState) {
viewStateManager = new ViewStateManager();
controllerStateManager = new ControllerStateManager();
setStateManagers(gameState); setStateManagers(gameState);
} }
...@@ -54,10 +56,8 @@ public class GameManager { ...@@ -54,10 +56,8 @@ public class GameManager {
} }
private void setStates(ViewState viewState, ControllerState controllerState) { private void setStates(ViewState viewState, ControllerState controllerState) {
viewStateManager = new ViewStateManager(); viewStateManager.set(viewState);
controllerStateManager = new ControllerStateManager(); controllerStateManager.set(controllerState);
viewStateManager.push(viewState);
controllerStateManager.push(controllerState);
} }
public void render(SpriteBatch batch) { public void render(SpriteBatch batch) {
......
...@@ -18,7 +18,6 @@ public abstract class ControllerState extends InputAdapter { ...@@ -18,7 +18,6 @@ public abstract class ControllerState extends InputAdapter {
Gdx.input.setInputProcessor(this); Gdx.input.setInputProcessor(this);
} }
public ControllerStateManager getControllerStateManager() { public ControllerStateManager getControllerStateManager() {
return controllerStateManager; return controllerStateManager;
} }
......
...@@ -28,7 +28,9 @@ public class ControllerStateManager { ...@@ -28,7 +28,9 @@ public class ControllerStateManager {
} }
public void set(ControllerState state) { public void set(ControllerState state) {
if (!controller.isEmpty()) {
controller.pop(); controller.pop();
}
controller.push(state); controller.push(state);
} }
......
package com.mygdx.game.controller;
public class MultiplayerController extends ControllerState {
public MultiplayerController(ControllerStateManager controllerStateManager) {
super(controllerStateManager);
//TODO Auto-generated constructor stub
}
}
package com.mygdx.game.controller;
public class TutorialController extends ControllerState {
public TutorialController(ControllerStateManager controllerStateManager) {
super(controllerStateManager);
//TODO Auto-generated constructor stub
}
}
...@@ -13,9 +13,7 @@ public class InGameView extends ViewState { ...@@ -13,9 +13,7 @@ public class InGameView extends ViewState {
@Override @Override
public void render(SpriteBatch batch) { public void render(SpriteBatch batch) {
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
batch.begin();
font.draw(batch, "Playing", ChessGame.WIDTH / 2 - 100, ChessGame.HEIGHT - 100); font.draw(batch, "Playing", ChessGame.WIDTH / 2 - 100, ChessGame.HEIGHT - 100);
batch.end();
} }
@Override @Override
......
...@@ -23,10 +23,8 @@ public class MainMenuView extends ViewState { ...@@ -23,10 +23,8 @@ public class MainMenuView extends ViewState {
@Override @Override
public void render(SpriteBatch batch) { public void render(SpriteBatch batch) {
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(backgroundTexture, 0, 0, ChessGame.WIDTH, ChessGame.HEIGHT); batch.draw(backgroundTexture, 0, 0, ChessGame.WIDTH, ChessGame.HEIGHT);
font.draw(batch, "Chess 2", ChessGame.WIDTH / 2 - 100, ChessGame.HEIGHT - 100); font.draw(batch, "Chess 2", ChessGame.WIDTH / 2 - 100, ChessGame.HEIGHT - 100);
batch.end();
} }
......
...@@ -26,7 +26,9 @@ public class ViewStateManager { ...@@ -26,7 +26,9 @@ public class ViewStateManager {
} }
public void set(ViewState view) { public void set(ViewState view) {
if (!views.isEmpty()) {
views.pop(); views.pop();
}
views.push(view); views.push(view);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment