From e6ea6ab4a115c0635943972d14f9b70fddf293d8 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 9 May 2014 17:00:21 -0430 Subject: [PATCH] Added comments. --- src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java | 165 ++++++++- .../ciens/ccg/nxtar/graphics/LightSource.java | 110 ++++++ ...er.java => ApplicationEventsListener.java} | 2 +- .../ccg/nxtar/network/RobotControlThread.java | 6 +- .../ccg/nxtar/network/SensorReportThread.java | 6 +- .../nxtar/network/VideoStreamingThread.java | 6 +- .../ucv/ciens/ccg/nxtar/states/BaseState.java | 316 +++++++++--------- .../ciens/ccg/nxtar/states/InGameState.java | 34 +- 8 files changed, 445 insertions(+), 200 deletions(-) create mode 100644 src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java rename src/ve/ucv/ciens/ccg/nxtar/interfaces/{NetworkConnectionListener.java => ApplicationEventsListener.java} (94%) diff --git a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java index 3af4f70..1fa7fe5 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java +++ b/src/ve/ucv/ciens/ccg/nxtar/NxtARCore.java @@ -16,7 +16,7 @@ package ve.ucv.ciens.ccg.nxtar; import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor; -import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener; +import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener; import ve.ucv.ciens.ccg.nxtar.interfaces.OSFunctionalityProvider; import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread; import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread; @@ -57,10 +57,16 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram; *
  • Starting and destroying the networking threads.
  • *
  • Rendering debug information.
  • * - * @author Miguel Angel Astor Romero */ -public class NxtARCore extends Game implements NetworkConnectionListener{ +public class NxtARCore extends Game implements ApplicationEventsListener{ + /** + * Tag used for logging. + */ private static final String TAG = "NXTAR_CORE_MAIN"; + + /** + * Class name used for logging. + */ private static final String CLASS_NAME = NxtARCore.class.getSimpleName(); /** @@ -96,30 +102,98 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ public game_states_t nextState; // Screens. + /** + *

    The application states.

    + */ private BaseState[] states; // Assorted fields. + /** + *

    Global sprite batch used for rendering trough the application.

    + */ public SpriteBatch batch; + + /** + *

    The OpenCV wrapper.

    + */ public CVProcessor cvProc; + + /** + *

    Wrapper around the Operating System methods.

    + */ private OSFunctionalityProvider osFunction; // Networking related fields. + /** + *

    The number of connections successfully established with the NxtAR-cam application.

    + */ private int connections; + + /** + *

    Worker thread used to broadcast this server over the network.

    + */ private ServiceDiscoveryThread serviceDiscoveryThread; + + /** + *

    Worker thread used to receive video frames over UDP.

    + */ private VideoStreamingThread videoThread; + + /** + *

    Worker thread used to send control commands to the NxtAR-cam application. + */ private RobotControlThread robotThread; + + /** + *

    Worker thread used to receive sensor data from the NxtAR-cam application.

    + */ private SensorReportThread sensorThread; // Overlays. + /** + *

    Camera used to render the debugging overlay.

    + */ private OrthographicCamera pixelPerfectCamera; - private float fontX; - private float fontY; + + /** + *

    The base x coordinate for rendering the debugging overlay.

    + */ + private float overlayX; + + /** + *

    The base y coordinate for rendering the debugging overlay.

    + */ + private float overlayY; + + /** + *

    The font used to render the debugging overlay.

    + */ private BitmapFont font; + // Fade in/out effect fields. + /** + *

    The graphic used to render the fading effect.

    + */ private Texture fadeTexture; + + /** + *

    The interpolation value for the fading effect.

    + */ private MutableFloat alpha; + + /** + *

    The fade out interpolator.

    + */ private Tween fadeOut; + + /** + *

    The fade in interpolator.

    + */ private Tween fadeIn; + + /** + *

    Flag used to indicate if a fading effect is active.

    + */ private boolean fading; /** @@ -127,7 +201,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ */ public NxtARCore(Application concreteApp){ super(); + connections = 0; + + // Check if the concrete application implements all required interfaces. try{ this.osFunction = (OSFunctionalityProvider)concreteApp; }catch(ClassCastException cc){ @@ -143,6 +220,14 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ } } + /*;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; GAME SUPERCLASS METHODS ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ + + /** + *

    Initialize the member fields and launch the networking threads. Also creates and + * sets the application states.

    + */ public void create(){ // Create the state objects. states = new BaseState[game_states_t.getNumStates()]; @@ -154,6 +239,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ states[game_states_t.PAUSED.getValue()] = new PauseState(this); states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this); + // Register controller listeners. for(BaseState state : states){ Controllers.addListener(state); } @@ -169,8 +255,8 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ // Set up the overlay font. if(ProjectConstants.DEBUG){ - fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10; - fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10; + overlayX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10; + overlayY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10; font = new BitmapFont(); font.setColor(1.0f, 1.0f, 0.0f, 1.0f); @@ -190,6 +276,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ robotThread = RobotControlThread.getInstance(); sensorThread = SensorReportThread.getInstance(); + // Launch networking threads. serviceDiscoveryThread.start(); videoThread.start(); @@ -208,7 +295,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ this.setScreen(states[currState.getValue()]); states[currState.getValue()].onStateSet(); - // Prepare the fadeToBlack sprite; + // Prepare the fading effect. Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444); pixmap.setColor(0, 0, 0, 1); pixmap.fill(); @@ -233,6 +320,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ } } + /** + *

    Update and render the currently enabled application state. This method + * also handles state switching, rendering state transitions and global overlays.

    + */ public void render(){ super.render(); @@ -241,21 +332,23 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ states[currState.getValue()].onStateUnset(); if(!fadeOut.isStarted()){ - Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Starting fade out."); + // Start the fade out effect. fadeOut.start(); fading = true; }else{ - Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Updating fade out."); + // Update the fade out effect. fadeOut.update(Gdx.graphics.getDeltaTime()); + // When the fade out effect finishes, change to the requested state + // and launh the fade in effect. if(fadeOut.isFinished()){ + // Change to the requested state. currState = nextState; nextState = null; - states[currState.getValue()].onStateSet(); - setScreen(states[currState.getValue()]); + // Reset the fade out effect and launch the fade in. Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Freeing fade out."); fadeOut.free(); fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint); @@ -264,16 +357,20 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ } } + // If there is a fade in effect in progress. if(fadeIn.isStarted()){ if(!fadeIn.isFinished()){ + // Update it until finished. fadeIn.update(Gdx.graphics.getDeltaTime()); }else{ + // Stop and reset it when done. fading = false; fadeIn.free(); fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint); } } + // Render the fading sprite with alpha blending. if(fading){ batch.setProjectionMatrix(pixelPerfectCamera.combined); batch.begin();{ @@ -283,28 +380,44 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ }batch.end(); } + // Render the debug overlay. if(ProjectConstants.DEBUG){ batch.setProjectionMatrix(pixelPerfectCamera.combined); batch.begin();{ // Draw the FPS overlay. - font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), fontX, fontY); - font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), fontX, fontY - font.getCapHeight() - 5); - font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), fontX, fontY - (2 * font.getCapHeight()) - 10); - font.draw(batch, String.format("Light sensor data: %d", sensorThread.getLightSensorReading()), fontX, fontY - (3 * font.getCapHeight()) - 15); + font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY); + font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5); + font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), overlayX, overlayY - (2 * font.getCapHeight()) - 10); + font.draw(batch, String.format("Light sensor data: %d", sensorThread.getLightSensorReading()), overlayX, overlayY - (3 * font.getCapHeight()) - 15); }batch.end(); } } + /** + *

    Pause a currently running thread. Pausing an already paused thread is a + * no op.

    + */ public void pause(){ if(videoThread != null) videoThread.pause(); + // TODO: Ignore pausing paused threads. + // TODO: Pause the other threads. } + /** + *

    Resume a currently paused thread. Resuming an already resumed thread is a + * no op.

    + */ public void resume(){ if(videoThread != null) videoThread.play(); + // TODO: Ignore resuming resumed threads. + // TODO: Resume the other threads. } + /** + *

    Clear graphic resources

    + */ public void dispose(){ // Finish network threads. videoThread.finish(); @@ -323,9 +436,19 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ } } + /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; APPLICATION EVENTS LISTENER INTERFACE METHODS ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ + // TODO: Disable start game button until camera has been sucessfully calibrated. // TODO: Add calibration listener callback. + /** + *

    Callback used by the networking threads to notify sucessfull connections + * to the application

    + * + * @param streamName The name of the thread notifying a connection. + */ @Override public synchronized void networkStreamConnected(String streamName){ Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected."); @@ -340,6 +463,16 @@ public class NxtARCore extends Game implements NetworkConnectionListener{ } } + /*;;;;;;;;;;;;;;;;;; + ; HELPER METHODS ; + ;;;;;;;;;;;;;;;;;;*/ + + /** + *

    Show a toast message on screen using the O.S. functionality + * provider.

    + * @param msg The message to show. + * @param longToast True for a lasting toast. False for a short toast. + */ public void toast(String msg, boolean longToast){ if(osFunction != null){ if(longToast) osFunction.showLongToast(msg); diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java new file mode 100644 index 0000000..5eb5521 --- /dev/null +++ b/src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2014 Miguel Angel Astor Romero + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ve.ucv.ciens.ccg.nxtar.graphics; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.math.Vector3; + +/** + *

    A 3D point or directional light source.

    + */ +public class LightSource{ + private Vector3 position; + private Color ambientColor; + private Color diffuseColor; + private Color specularColor; + private float shinyness; + + public LightSource(){ + position = new Vector3(0.0f, 0.0f, 0.0f); + ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f); + diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); + ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); + shinyness = 10.0f; + } + + public LightSource(Vector3 position){ + this.position.set(position); + ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f); + diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); + ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); + shinyness = 10.0f; + } + + public LightSource(Vector3 position, Color ambientColor, Color diffuseColor, Color specularColor, float shinyness){ + this.position.set(position); + this.ambientColor.set(ambientColor); + this.diffuseColor.set(diffuseColor); + this.specularColor.set(specularColor); + this.shinyness = shinyness; + } + + public void setPosition(float x, float y, float z){ + position.set(x, y, z); + } + + public void setPosition(Vector3 position){ + this.position.set(position); + } + + public void setAmbientColor(float r, float g, float b, float a){ + ambientColor.set(r, g, b, a); + } + + public void setAmbientColor(Color ambientColor){ + this.ambientColor.set(ambientColor); + } + + public void setDiffuseColor(float r, float g, float b, float a){ + diffuseColor.set(r, g, b, a); + } + + public void setdiffuseColor(Color diffuseColor){ + this.diffuseColor.set(diffuseColor); + } + + public void setSpecularColor(float r, float g, float b, float a){ + specularColor.set(r, g, b, a); + } + + public void setSpecularColor(Color specularColor){ + this.specularColor.set(specularColor); + } + + public void setShinyness(float shinyness){ + this.shinyness = shinyness; + } + + public Vector3 getPosition(){ + return position; + } + + public Color getAmbientColor(){ + return ambientColor; + } + + public Color getDiffuseColor(){ + return diffuseColor; + } + + public Color getSpecularColor(){ + return specularColor; + } + + public float getShinyness(){ + return shinyness; + } +} diff --git a/src/ve/ucv/ciens/ccg/nxtar/interfaces/NetworkConnectionListener.java b/src/ve/ucv/ciens/ccg/nxtar/interfaces/ApplicationEventsListener.java similarity index 94% rename from src/ve/ucv/ciens/ccg/nxtar/interfaces/NetworkConnectionListener.java rename to src/ve/ucv/ciens/ccg/nxtar/interfaces/ApplicationEventsListener.java index a5629f4..f759925 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/interfaces/NetworkConnectionListener.java +++ b/src/ve/ucv/ciens/ccg/nxtar/interfaces/ApplicationEventsListener.java @@ -15,6 +15,6 @@ */ package ve.ucv.ciens.ccg.nxtar.interfaces; -public interface NetworkConnectionListener { +public interface ApplicationEventsListener { public void networkStreamConnected(String streamName); } diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java index 9250ae2..52bfa8e 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java +++ b/src/ve/ucv/ciens/ccg/nxtar/network/RobotControlThread.java @@ -24,7 +24,7 @@ import java.net.Socket; import ve.ucv.ciens.ccg.networkdata.MotorEvent; import ve.ucv.ciens.ccg.networkdata.MotorEventACK; -import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener; +import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener; import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; @@ -35,7 +35,7 @@ public class RobotControlThread extends Thread { private static final String TAG = "NXTAR_CORE_ROBOTTHREAD"; private static final String CLASS_NAME = RobotControlThread.class.getSimpleName(); - private NetworkConnectionListener netListener; + private ApplicationEventsListener netListener; private ServerSocket server; private Socket client; private MotorEventQueue queue; @@ -69,7 +69,7 @@ public class RobotControlThread extends Thread { return SingletonHolder.INSTANCE; } - public void addNetworkConnectionListener(NetworkConnectionListener listener){ + public void addNetworkConnectionListener(ApplicationEventsListener listener){ netListener = listener; } diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java index a30ff01..f980e63 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java +++ b/src/ve/ucv/ciens/ccg/nxtar/network/SensorReportThread.java @@ -20,7 +20,7 @@ import java.io.InputStream; import java.net.ServerSocket; import java.net.Socket; -import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener; +import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; import com.badlogic.gdx.Gdx; @@ -30,7 +30,7 @@ public class SensorReportThread extends Thread { private static final String TAG = "NXTAR_CORE_ROBOTTHREAD"; private static final String CLASS_NAME = SensorReportThread.class.getSimpleName(); - private NetworkConnectionListener netListener; + private ApplicationEventsListener netListener; private ServerSocket server; private Socket client; private Object pauseMonitor; @@ -63,7 +63,7 @@ public class SensorReportThread extends Thread { return SingletonHolder.INSTANCE; } - public void addNetworkConnectionListener(NetworkConnectionListener listener){ + public void addNetworkConnectionListener(ApplicationEventsListener listener){ netListener = listener; } diff --git a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java index a8c12f2..629ad22 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java +++ b/src/ve/ucv/ciens/ccg/nxtar/network/VideoStreamingThread.java @@ -23,7 +23,7 @@ import java.net.DatagramSocket; import java.net.Socket; import ve.ucv.ciens.ccg.networkdata.VideoFrameDataMessage; -import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener; +import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener; import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; @@ -34,7 +34,7 @@ public class VideoStreamingThread extends Thread{ private static final String TAG = "NXTAR_CORE_VIDEOTHREAD"; private static final String CLASS_NAME = VideoStreamingThread.class.getSimpleName(); - private NetworkConnectionListener netListener; + private ApplicationEventsListener netListener; private DatagramSocket socket; private boolean protocolStarted; private boolean done; @@ -79,7 +79,7 @@ public class VideoStreamingThread extends Thread{ return SingletonHolder.INSTANCE; } - public void addNetworkConnectionListener(NetworkConnectionListener listener){ + public void addNetworkConnectionListener(ApplicationEventsListener listener){ netListener = listener; } diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/BaseState.java b/src/ve/ucv/ciens/ccg/nxtar/states/BaseState.java index 3886705..b0c2be1 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/BaseState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/BaseState.java @@ -1,151 +1,165 @@ -/* - * Copyright (C) 2014 Miguel Angel Astor Romero - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ve.ucv.ciens.ccg.nxtar.states; - -import ve.ucv.ciens.ccg.nxtar.NxtARCore; - -import com.badlogic.gdx.InputProcessor; -import com.badlogic.gdx.Screen; -import com.badlogic.gdx.controllers.Controller; -import com.badlogic.gdx.controllers.ControllerListener; -import com.badlogic.gdx.controllers.PovDirection; -import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.math.Vector3; - -public abstract class BaseState implements Screen, ControllerListener, InputProcessor { - protected NxtARCore core; - protected boolean stateActive; - protected OrthographicCamera pixelPerfectCamera; - protected Vector3 win2world; - protected Vector2 touchPointWorldCoords; - - /* STATE METHODS */ - public abstract void onStateSet(); - public abstract void onStateUnset(); - - /* SCREEN METHODS*/ - @Override - public abstract void render(float delta); - - @Override - public abstract void resize(int width, int height); - - @Override - public abstract void show(); - - @Override - public abstract void hide(); - - @Override - public abstract void pause(); - - @Override - public abstract void resume(); - - @Override - public abstract void dispose(); - - /* HELPER METHODS */ - - protected final void unprojectTouch(int screenX, int screenY){ - win2world.set(screenX, screenY, 0.0f); - pixelPerfectCamera.unproject(win2world); - touchPointWorldCoords.set(win2world.x, win2world.y); - } - - /* INPUT PROCESSOR METHODS. */ - @Override - public boolean keyDown(int keycode){ - return false; - }; - - @Override - public boolean keyUp(int keycode){ - return false; - }; - - @Override - public boolean keyTyped(char character){ - return false; - }; - - @Override - public boolean touchDown(int screenX, int screenY, int pointer, int button){ - return false; - }; - - @Override - public boolean touchUp(int screenX, int screenY, int pointer, int button){ - return false; - }; - - @Override - public boolean touchDragged(int screenX, int screenY, int pointer){ - return false; - }; - - @Override - public boolean mouseMoved(int screenX, int screenY){ - return false; - }; - - @Override - public boolean scrolled(int amount){ - return false; - }; - - /* CONTROLLER LISTENER METHODS. */ - @Override - public void connected(Controller controller){ }; - - @Override - public void disconnected(Controller controller){ }; - - @Override - public boolean buttonDown(Controller controller, int buttonCode){ - return false; - }; - - @Override - public boolean buttonUp(Controller controller, int buttonCode){ - return false; - }; - @Override - public boolean axisMoved(Controller controller, int axisCode, float value){ - return false; - }; - - @Override - public boolean povMoved(Controller controller, int povCode, PovDirection value){ - return false; - }; - - @Override - public boolean xSliderMoved(Controller controller, int sliderCode, boolean value){ - return false; - }; - - @Override - public boolean ySliderMoved(Controller controller, int sliderCode, boolean value){ - return false; - }; - - @Override - public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value){ - return false; - }; -} +/* + * Copyright (C) 2014 Miguel Angel Astor Romero + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ve.ucv.ciens.ccg.nxtar.states; + +import ve.ucv.ciens.ccg.nxtar.NxtARCore; + +import com.badlogic.gdx.InputProcessor; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.controllers.Controller; +import com.badlogic.gdx.controllers.ControllerListener; +import com.badlogic.gdx.controllers.PovDirection; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; + +public abstract class BaseState implements Screen, ControllerListener, InputProcessor{ + protected NxtARCore core; + protected boolean stateActive; + protected OrthographicCamera pixelPerfectCamera; + protected Vector3 win2world; + protected Vector2 touchPointWorldCoords; + + /*;;;;;;;;;;;;;;;;; + ; STATE METHODS ; + ;;;;;;;;;;;;;;;;;*/ + + public abstract void onStateSet(); + public abstract void onStateUnset(); + + /*;;;;;;;;;;;;;;;;;; + ; SCREEN METHODS ; + ;;;;;;;;;;;;;;;;;;*/ + + @Override + public abstract void render(float delta); + + @Override + public abstract void dispose(); + + @Override + public void resize(int width, int height){ } + + @Override + public void show(){ } + + @Override + public void hide(){ } + + @Override + public void pause(){ } + + @Override + public void resume(){ } + + /*;;;;;;;;;;;;;;;;;; + ; HELPER METHODS ; + ;;;;;;;;;;;;;;;;;;*/ + + protected final void unprojectTouch(int screenX, int screenY){ + win2world.set(screenX, screenY, 0.0f); + pixelPerfectCamera.unproject(win2world); + touchPointWorldCoords.set(win2world.x, win2world.y); + } + + /*;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; INPUT PROCESSOR METHODS ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ + + @Override + public boolean keyDown(int keycode){ + return false; + }; + + @Override + public boolean keyUp(int keycode){ + return false; + }; + + @Override + public boolean keyTyped(char character){ + return false; + }; + + @Override + public boolean touchDown(int screenX, int screenY, int pointer, int button){ + return false; + }; + + @Override + public boolean touchUp(int screenX, int screenY, int pointer, int button){ + return false; + }; + + @Override + public boolean touchDragged(int screenX, int screenY, int pointer){ + return false; + }; + + @Override + public boolean mouseMoved(int screenX, int screenY){ + return false; + }; + + @Override + public boolean scrolled(int amount){ + return false; + }; + + /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; CONTROLLER LISTENER METHODS ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ + + @Override + public void connected(Controller controller){ }; + + @Override + public void disconnected(Controller controller){ }; + + @Override + public boolean buttonDown(Controller controller, int buttonCode){ + return false; + }; + + @Override + public boolean buttonUp(Controller controller, int buttonCode){ + return false; + }; + @Override + public boolean axisMoved(Controller controller, int axisCode, float value){ + return false; + }; + + @Override + public boolean povMoved(Controller controller, int povCode, PovDirection value){ + return false; + }; + + @Override + public boolean xSliderMoved(Controller controller, int sliderCode, boolean value){ + return false; + }; + + @Override + public boolean ySliderMoved(Controller controller, int sliderCode, boolean value){ + return false; + }; + + @Override + public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value){ + return false; + }; +} diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java index f763661..a731ca3 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java @@ -54,8 +54,6 @@ public class InGameState extends BaseState{ private static final String CLASS_NAME = InGameState.class.getSimpleName(); private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg"; - private NxtARCore core; - // Background related fields. private float uScaling[]; protected Sprite background; @@ -188,8 +186,13 @@ public class InGameState extends BaseState{ // Set up Artemis. gameWorld = new World(); // TODO: Create entities and systems. + gameWorld.initialize(); } + /*;;;;;;;;;;;;;;;;;;;;;; + ; BASE STATE METHODS ; + ;;;;;;;;;;;;;;;;;;;;;;*/ + @Override public void render(float delta){ int w, h; @@ -341,21 +344,6 @@ public class InGameState extends BaseState{ } } - @Override - public void resize(int width, int height){ } - - @Override - public void show(){ } - - @Override - public void hide(){ } - - @Override - public void pause(){ } - - @Override - public void resume(){ } - @Override public void dispose(){ if(videoFrameTexture != null) @@ -441,9 +429,9 @@ public class InGameState extends BaseState{ headC.setPosition(-(headC.getWidth() / 2), headA.getY() - headA.getHeight() - 10); } - /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - ; BEGIN INPUT PROCESSOR METHODS ; - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ + /*;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; INPUT PROCESSOR METHODS ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ @Override public boolean touchDown(int screenX, int screenY, int pointer, int button){ @@ -774,9 +762,9 @@ public class InGameState extends BaseState{ return false; } - /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - ; BEGIN CONTROLLER LISTENER METHODS ; - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ + /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; CONTROLLER LISTENER METHODS ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/ @Override public boolean buttonDown(Controller controller, int buttonCode){