Added comments.
This commit is contained in:
@@ -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;
|
||||
* <li> Starting and destroying the networking threads.</li>
|
||||
* <li> Rendering debug information.</li>
|
||||
* </ul>
|
||||
* @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.
|
||||
/**
|
||||
* <p>The application states.</p>
|
||||
*/
|
||||
private BaseState[] states;
|
||||
|
||||
// Assorted fields.
|
||||
/**
|
||||
* <p>Global sprite batch used for rendering trough the application.</p>
|
||||
*/
|
||||
public SpriteBatch batch;
|
||||
|
||||
/**
|
||||
* <p>The OpenCV wrapper.</p>
|
||||
*/
|
||||
public CVProcessor cvProc;
|
||||
|
||||
/**
|
||||
* <p>Wrapper around the Operating System methods.</p>
|
||||
*/
|
||||
private OSFunctionalityProvider osFunction;
|
||||
|
||||
// Networking related fields.
|
||||
/**
|
||||
* <p>The number of connections successfully established with the NxtAR-cam application.</p>
|
||||
*/
|
||||
private int connections;
|
||||
|
||||
/**
|
||||
* <p>Worker thread used to broadcast this server over the network.</p>
|
||||
*/
|
||||
private ServiceDiscoveryThread serviceDiscoveryThread;
|
||||
|
||||
/**
|
||||
* <p>Worker thread used to receive video frames over UDP.<p>
|
||||
*/
|
||||
private VideoStreamingThread videoThread;
|
||||
|
||||
/**
|
||||
* <p>Worker thread used to send control commands to the NxtAR-cam application.
|
||||
*/
|
||||
private RobotControlThread robotThread;
|
||||
|
||||
/**
|
||||
* <p>Worker thread used to receive sensor data from the NxtAR-cam application.</p>
|
||||
*/
|
||||
private SensorReportThread sensorThread;
|
||||
|
||||
// Overlays.
|
||||
/**
|
||||
* <p>Camera used to render the debugging overlay.</p>
|
||||
*/
|
||||
private OrthographicCamera pixelPerfectCamera;
|
||||
private float fontX;
|
||||
private float fontY;
|
||||
|
||||
/**
|
||||
* <p>The base x coordinate for rendering the debugging overlay.</p>
|
||||
*/
|
||||
private float overlayX;
|
||||
|
||||
/**
|
||||
* <p>The base y coordinate for rendering the debugging overlay.</p>
|
||||
*/
|
||||
private float overlayY;
|
||||
|
||||
/**
|
||||
* <p>The font used to render the debugging overlay.</p>
|
||||
*/
|
||||
private BitmapFont font;
|
||||
|
||||
// Fade in/out effect fields.
|
||||
/**
|
||||
* <p>The graphic used to render the fading effect.</p>
|
||||
*/
|
||||
private Texture fadeTexture;
|
||||
|
||||
/**
|
||||
* <p>The interpolation value for the fading effect.</p>
|
||||
*/
|
||||
private MutableFloat alpha;
|
||||
|
||||
/**
|
||||
* <p>The fade out interpolator.</p>
|
||||
*/
|
||||
private Tween fadeOut;
|
||||
|
||||
/**
|
||||
* <p>The fade in interpolator.</p>
|
||||
*/
|
||||
private Tween fadeIn;
|
||||
|
||||
/**
|
||||
* <p>Flag used to indicate if a fading effect is active.</p>
|
||||
*/
|
||||
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 ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
/**
|
||||
* <p>Initialize the member fields and launch the networking threads. Also creates and
|
||||
* sets the application states.</p>
|
||||
*/
|
||||
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{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Update and render the currently enabled application state. This method
|
||||
* also handles state switching, rendering state transitions and global overlays.</p>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Pause a currently running thread. Pausing an already paused thread is a
|
||||
* no op.</p>
|
||||
*/
|
||||
public void pause(){
|
||||
if(videoThread != null)
|
||||
videoThread.pause();
|
||||
// TODO: Ignore pausing paused threads.
|
||||
// TODO: Pause the other threads.
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Resume a currently paused thread. Resuming an already resumed thread is a
|
||||
* no op.</p>
|
||||
*/
|
||||
public void resume(){
|
||||
if(videoThread != null)
|
||||
videoThread.play();
|
||||
// TODO: Ignore resuming resumed threads.
|
||||
// TODO: Resume the other threads.
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Clear graphic resources</p>
|
||||
*/
|
||||
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.
|
||||
|
||||
/**
|
||||
* <p>Callback used by the networking threads to notify sucessfull connections
|
||||
* to the application</p>
|
||||
*
|
||||
* @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 ;
|
||||
;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
/**
|
||||
* <p>Show a toast message on screen using the O.S. functionality
|
||||
* provider.</p>
|
||||
* @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);
|
||||
|
110
src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
Normal file
110
src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
Normal file
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>A 3D point or directional light source.</p>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@@ -15,6 +15,6 @@
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
||||
|
||||
public interface NetworkConnectionListener {
|
||||
public interface ApplicationEventsListener {
|
||||
public void networkStreamConnected(String streamName);
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
};
|
||||
}
|
||||
|
@@ -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){
|
||||
|
Reference in New Issue
Block a user