Cleaned the code a bit.
This commit is contained in:
@@ -417,11 +417,17 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
|||||||
* <p>Clear graphic resources</p>
|
* <p>Clear graphic resources</p>
|
||||||
*/
|
*/
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
|
// Dispose screens.
|
||||||
|
for(int i = 0; i < states.length; i++){
|
||||||
|
states[i].dispose();
|
||||||
|
}
|
||||||
|
|
||||||
// Finish network threads.
|
// Finish network threads.
|
||||||
serviceDiscoveryThread.finish();
|
serviceDiscoveryThread.finish();
|
||||||
videoThread.finish();
|
videoThread.finish();
|
||||||
robotThread.finish();
|
robotThread.finish();
|
||||||
sensorThread.finish();
|
sensorThread.finish();
|
||||||
|
serviceDiscoveryThread = null;
|
||||||
videoThread = null;
|
videoThread = null;
|
||||||
robotThread = null;
|
robotThread = null;
|
||||||
sensorThread = null;
|
sensorThread = null;
|
||||||
@@ -435,11 +441,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
|||||||
batch.dispose();
|
batch.dispose();
|
||||||
font.dispose();
|
font.dispose();
|
||||||
|
|
||||||
// Dispose screens.
|
|
||||||
for(int i = 0; i < states.length; i++){
|
|
||||||
states[i].dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
GameSettings.clearGameSettings();
|
GameSettings.clearGameSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,7 +93,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
|||||||
private Model wiresBombModelWire1 = null;
|
private Model wiresBombModelWire1 = null;
|
||||||
private Model wiresBombModelWire2 = null;
|
private Model wiresBombModelWire2 = null;
|
||||||
private Model wiresBombModelWire3 = null;
|
private Model wiresBombModelWire3 = null;
|
||||||
private Model monkeyModel = null;
|
private Model monkeyModel = null;
|
||||||
|
|
||||||
// Collision models.
|
// Collision models.
|
||||||
private Model robotArmCollisionModel = null;
|
private Model robotArmCollisionModel = null;
|
||||||
|
@@ -37,7 +37,7 @@ public abstract class EntityCreatorBase implements Disposable{
|
|||||||
* @param world The Artemis {@link World}.
|
* @param world The Artemis {@link World}.
|
||||||
* @throws IllegalArgumentException if world is null.
|
* @throws IllegalArgumentException if world is null.
|
||||||
*/
|
*/
|
||||||
public void setWorld(World world) throws IllegalArgumentException{
|
public final void setWorld(World world) throws IllegalArgumentException{
|
||||||
if(world == null)
|
if(world == null)
|
||||||
throw new IllegalArgumentException("World cannot be 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.
|
* @param core The application core to be used as listener.
|
||||||
* @throws IllegalArgumentException if core is null.
|
* @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.");
|
if(core == null) throw new IllegalArgumentException("Core is null.");
|
||||||
this.core = core;
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
@@ -15,4 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.input;
|
package ve.ucv.ciens.ccg.nxtar.input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag class for different user interaction wrapper classes.
|
||||||
|
*/
|
||||||
public abstract class UserInput{ }
|
public abstract class UserInput{ }
|
||||||
|
@@ -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.TouchUserInput;
|
||||||
import ve.ucv.ciens.ccg.nxtar.input.UserInput;
|
import ve.ucv.ciens.ccg.nxtar.input.UserInput;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
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.MotorEventQueue;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
|
import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
|
||||||
@@ -84,7 +85,7 @@ public class InGameState extends BaseState{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Background related fields.
|
// Background related fields.
|
||||||
private Sprite background;
|
private Sprite background;
|
||||||
private float uScaling[];
|
private float uScaling[];
|
||||||
private Texture backgroundTexture;
|
private Texture backgroundTexture;
|
||||||
private ShaderProgram backgroundShader;
|
private ShaderProgram backgroundShader;
|
||||||
@@ -122,6 +123,7 @@ public class InGameState extends BaseState{
|
|||||||
private Texture armControlButtonTexture;
|
private Texture armControlButtonTexture;
|
||||||
private Texture correctAngleLedOnTexture;
|
private Texture correctAngleLedOnTexture;
|
||||||
private Texture correctAngleLedOffTexture;
|
private Texture correctAngleLedOffTexture;
|
||||||
|
private Texture crossSectionFloorTexture;
|
||||||
private Sprite motorAButton;
|
private Sprite motorAButton;
|
||||||
private Sprite motorBButton;
|
private Sprite motorBButton;
|
||||||
private Sprite motorCButton;
|
private Sprite motorCButton;
|
||||||
@@ -133,6 +135,9 @@ public class InGameState extends BaseState{
|
|||||||
private Sprite armControlButton;
|
private Sprite armControlButton;
|
||||||
private Sprite correctAngleLedOnSprite;
|
private Sprite correctAngleLedOnSprite;
|
||||||
private Sprite correctAngleLedOffSprite;
|
private Sprite correctAngleLedOffSprite;
|
||||||
|
private Sprite crossSectionFloorLed;
|
||||||
|
private Sprite normalFloorLed;
|
||||||
|
private Sprite itemNearbyFloorLed;
|
||||||
|
|
||||||
// Button touch helper fields.
|
// Button touch helper fields.
|
||||||
private boolean[] buttonsTouched;
|
private boolean[] buttonsTouched;
|
||||||
@@ -142,12 +147,14 @@ public class InGameState extends BaseState{
|
|||||||
// Monitors.
|
// Monitors.
|
||||||
private VideoFrameMonitor frameMonitor;
|
private VideoFrameMonitor frameMonitor;
|
||||||
private MotorEventQueue queue;
|
private MotorEventQueue queue;
|
||||||
|
private SensorReportThread sensorThread;
|
||||||
|
|
||||||
public InGameState(final NxtARCore core){
|
public InGameState(final NxtARCore core){
|
||||||
this.core = core;
|
this.core = core;
|
||||||
frameMonitor = VideoFrameMonitor.getInstance();
|
frameMonitor = VideoFrameMonitor.getInstance();
|
||||||
queue = MotorEventQueue.getInstance();
|
queue = MotorEventQueue.getInstance();
|
||||||
controlMode = robot_control_mode_t.WHEEL_CONTROL;
|
controlMode = robot_control_mode_t.WHEEL_CONTROL;
|
||||||
|
sensorThread = SensorReportThread.getInstance();
|
||||||
|
|
||||||
// Set up rendering fields;
|
// Set up rendering fields;
|
||||||
videoFrame = null;
|
videoFrame = null;
|
||||||
@@ -156,8 +163,6 @@ public class InGameState extends BaseState{
|
|||||||
pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
|
unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
|
||||||
|
|
||||||
if(!Ouya.runningOnOuya) setUpButtons();
|
|
||||||
|
|
||||||
// Set up input handling support fields.
|
// Set up input handling support fields.
|
||||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
touchPointWorldCoords = new Vector2();
|
touchPointWorldCoords = new Vector2();
|
||||||
@@ -227,6 +232,26 @@ public class InGameState extends BaseState{
|
|||||||
robotArmFrameBuffer = null;
|
robotArmFrameBuffer = null;
|
||||||
robotArmFrameBufferSprite = 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.
|
// Set up the game world.
|
||||||
gameWorld = GameSettings.getGameWorld();
|
gameWorld = GameSettings.getGameWorld();
|
||||||
|
|
||||||
@@ -454,6 +479,17 @@ public class InGameState extends BaseState{
|
|||||||
}core.batch.end();
|
}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();
|
fadeEffectRenderingSystem.process();
|
||||||
|
|
||||||
data = null;
|
data = null;
|
||||||
@@ -461,6 +497,9 @@ public class InGameState extends BaseState{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
|
SensorReportThread.freeInstance();
|
||||||
|
sensorThread = null;
|
||||||
|
|
||||||
if(modelBatch != null)
|
if(modelBatch != null)
|
||||||
modelBatch.dispose();
|
modelBatch.dispose();
|
||||||
|
|
||||||
@@ -482,6 +521,9 @@ public class InGameState extends BaseState{
|
|||||||
if(backgroundTexture != null)
|
if(backgroundTexture != null)
|
||||||
backgroundTexture.dispose();
|
backgroundTexture.dispose();
|
||||||
|
|
||||||
|
if(crossSectionFloorTexture != null)
|
||||||
|
crossSectionFloorTexture.dispose();
|
||||||
|
|
||||||
if(backgroundShader != null)
|
if(backgroundShader != null)
|
||||||
backgroundShader.dispose();
|
backgroundShader.dispose();
|
||||||
|
|
||||||
@@ -576,9 +618,6 @@ public class InGameState extends BaseState{
|
|||||||
armControlButton.setPosition(-(armControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
|
armControlButton.setPosition(-(armControlButton.getWidth() / 2), headCButton.getY() - headCButton.getHeight() - 15);
|
||||||
|
|
||||||
// Set up the correct angle leds.
|
// 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);
|
correctAngleLedOnSprite = new Sprite(correctAngleLedOnTexture);
|
||||||
correctAngleLedOffSprite = new Sprite(correctAngleLedOffTexture);
|
correctAngleLedOffSprite = new Sprite(correctAngleLedOffTexture);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user