From 83199df36dbb41f7842911e311281f9422f6873c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jun 2014 18:27:30 -0430 Subject: [PATCH] Cleaned the code a bit. --- src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 11 ++-- .../nxtar/entities/BombGameEntityCreator.java | 2 +- .../ccg/nxtar/entities/EntityCreatorBase.java | 4 +- .../ucv/ciens/ccg/nxtar/input/UserInput.java | 3 ++ .../ciens/ccg/nxtar/states/InGameState.java | 51 ++++++++++++++++--- 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java index 7a22d53..3d866b4 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java +++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java @@ -417,11 +417,17 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ *

Clear graphic resources

*/ public void dispose(){ + // Dispose screens. + for(int i = 0; i < states.length; i++){ + states[i].dispose(); + } + // Finish network threads. serviceDiscoveryThread.finish(); videoThread.finish(); robotThread.finish(); sensorThread.finish(); + serviceDiscoveryThread = null; videoThread = null; robotThread = null; sensorThread = null; @@ -435,11 +441,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{ batch.dispose(); font.dispose(); - // Dispose screens. - for(int i = 0; i < states.length; i++){ - states[i].dispose(); - } - GameSettings.clearGameSettings(); } diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java index fc4e6f4..030c03e 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java +++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java @@ -93,7 +93,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{ private Model wiresBombModelWire1 = null; private Model wiresBombModelWire2 = null; private Model wiresBombModelWire3 = null; - private Model monkeyModel = null; + private Model monkeyModel = null; // Collision models. private Model robotArmCollisionModel = null; diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java index 4c37fd5..8063e26 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java +++ b/src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java @@ -37,7 +37,7 @@ public abstract class EntityCreatorBase implements Disposable{ * @param world The Artemis {@link World}. * @throws IllegalArgumentException if world is null. */ - public void setWorld(World world) throws IllegalArgumentException{ + public final void setWorld(World world) throws IllegalArgumentException{ if(world == null) throw new IllegalArgumentException("World cannot be null."); @@ -50,7 +50,7 @@ public abstract class EntityCreatorBase implements Disposable{ * @param core The application core to be used as listener. * @throws IllegalArgumentException if core is null. */ - public void setCore(NxtARCore core) throws IllegalArgumentException{ + public final void setCore(NxtARCore core) throws IllegalArgumentException{ if(core == null) throw new IllegalArgumentException("Core is null."); this.core = core; } diff --git a/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java b/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java index 6e38daa..b1ac203 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java +++ b/src/ve/ucv/ciens/ccg/nxtar/input/UserInput.java @@ -15,4 +15,7 @@ */ package ve.ucv.ciens.ccg.nxtar.input; +/** + * Tag class for different user interaction wrapper classes. + */ public abstract class UserInput{ } diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java index ab8529a..c9fc8bb 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java @@ -25,6 +25,7 @@ import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput; import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput; import ve.ucv.ciens.ccg.nxtar.input.UserInput; import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData; +import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread; import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue; import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor; import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem; @@ -84,7 +85,7 @@ public class InGameState extends BaseState{ } // Background related fields. - private Sprite background; + private Sprite background; private float uScaling[]; private Texture backgroundTexture; private ShaderProgram backgroundShader; @@ -122,6 +123,7 @@ public class InGameState extends BaseState{ private Texture armControlButtonTexture; private Texture correctAngleLedOnTexture; private Texture correctAngleLedOffTexture; + private Texture crossSectionFloorTexture; private Sprite motorAButton; private Sprite motorBButton; private Sprite motorCButton; @@ -133,6 +135,9 @@ public class InGameState extends BaseState{ private Sprite armControlButton; private Sprite correctAngleLedOnSprite; private Sprite correctAngleLedOffSprite; + private Sprite crossSectionFloorLed; + private Sprite normalFloorLed; + private Sprite itemNearbyFloorLed; // Button touch helper fields. private boolean[] buttonsTouched; @@ -142,12 +147,14 @@ public class InGameState extends BaseState{ // Monitors. private VideoFrameMonitor frameMonitor; private MotorEventQueue queue; + private SensorReportThread sensorThread; public InGameState(final NxtARCore core){ this.core = core; frameMonitor = VideoFrameMonitor.getInstance(); queue = MotorEventQueue.getInstance(); controlMode = robot_control_mode_t.WHEEL_CONTROL; + sensorThread = SensorReportThread.getInstance(); // Set up rendering fields; videoFrame = null; @@ -156,8 +163,6 @@ public class InGameState extends BaseState{ pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth()); - if(!Ouya.runningOnOuya) setUpButtons(); - // Set up input handling support fields. win2world = new Vector3(0.0f, 0.0f, 0.0f); touchPointWorldCoords = new Vector2(); @@ -227,6 +232,26 @@ public class InGameState extends BaseState{ robotArmFrameBuffer = null; robotArmFrameBufferSprite = null; + // Set up floor leds and possibly the buttons. + correctAngleLedOnTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Green.png")); + correctAngleLedOffTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Red.png")); + crossSectionFloorTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Cyan.png")); + + crossSectionFloorLed = new Sprite(crossSectionFloorTexture); + normalFloorLed = new Sprite(correctAngleLedOffTexture); + itemNearbyFloorLed = new Sprite(correctAngleLedOnTexture); + + crossSectionFloorLed.setSize(crossSectionFloorLed.getWidth() * 0.25f, crossSectionFloorLed.getHeight() * 0.25f); + normalFloorLed.setSize(normalFloorLed.getWidth() * 0.25f, normalFloorLed.getHeight() * 0.25f); + itemNearbyFloorLed.setSize(itemNearbyFloorLed.getWidth() * 0.25f, itemNearbyFloorLed.getHeight() * 0.25f); + + crossSectionFloorLed.setPosition(-(crossSectionFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - crossSectionFloorLed.getHeight() - 5); + normalFloorLed.setPosition(-(normalFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - normalFloorLed.getHeight() - 5); + itemNearbyFloorLed.setPosition(-(itemNearbyFloorLed.getWidth() / 2), Gdx.graphics.getHeight() / 2 - itemNearbyFloorLed.getHeight() - 5); + + if(!Ouya.runningOnOuya) + setUpButtons(); + // Set up the game world. gameWorld = GameSettings.getGameWorld(); @@ -454,6 +479,17 @@ public class InGameState extends BaseState{ }core.batch.end(); } + core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined); + core.batch.begin();{ + if(sensorThread.getLightSensorReading() < 40){ + normalFloorLed.draw(core.batch); + }else if(sensorThread.getLightSensorReading() >= 40 && sensorThread.getLightSensorReading() <= 80){ + itemNearbyFloorLed.draw(core.batch); + }else{ + crossSectionFloorLed.draw(core.batch); + } + }core.batch.end(); + fadeEffectRenderingSystem.process(); data = null; @@ -461,6 +497,9 @@ public class InGameState extends BaseState{ @Override public void dispose(){ + SensorReportThread.freeInstance(); + sensorThread = null; + if(modelBatch != null) modelBatch.dispose(); @@ -482,6 +521,9 @@ public class InGameState extends BaseState{ if(backgroundTexture != null) backgroundTexture.dispose(); + if(crossSectionFloorTexture != null) + crossSectionFloorTexture.dispose(); + if(backgroundShader != null) backgroundShader.dispose(); @@ -576,9 +618,6 @@ public class InGameState extends BaseState{ armControlButton.setPosition(-(armControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15); // Set up the correct angle leds. - correctAngleLedOnTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Green.png")); - correctAngleLedOffTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Button_Red.png")); - correctAngleLedOnSprite = new Sprite(correctAngleLedOnTexture); correctAngleLedOffSprite = new Sprite(correctAngleLedOffTexture);