Merge branch 'robot_control' into develop
This commit is contained in:
32
src/ve/ucv/ciens/ccg/networkdata/MotorEventACK.java
Normal file
32
src/ve/ucv/ciens/ccg/networkdata/MotorEventACK.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.networkdata;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class MotorEventACK implements Serializable {
|
||||||
|
private static final long serialVersionUID = 9989L;
|
||||||
|
|
||||||
|
private boolean clientQueueIsFull;
|
||||||
|
|
||||||
|
public MotorEventACK(boolean isQueueFull){
|
||||||
|
this.clientQueueIsFull = isQueueFull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClientQueueFull(){
|
||||||
|
return this.clientQueueIsFull;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,9 @@ import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
|
|||||||
import ve.ucv.ciens.ccg.nxtar.states.PauseState;
|
import ve.ucv.ciens.ccg.nxtar.states.PauseState;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState;
|
import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
import aurelienribon.tweenengine.Tween;
|
||||||
|
import aurelienribon.tweenengine.TweenEquations;
|
||||||
|
import aurelienribon.tweenengine.primitives.MutableFloat;
|
||||||
|
|
||||||
import com.badlogic.gdx.Application;
|
import com.badlogic.gdx.Application;
|
||||||
import com.badlogic.gdx.Game;
|
import com.badlogic.gdx.Game;
|
||||||
@@ -35,6 +38,9 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.controllers.Controllers;
|
import com.badlogic.gdx.controllers.Controllers;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
|
||||||
@@ -93,12 +99,18 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
private VideoStreamingThread videoThread;
|
private VideoStreamingThread videoThread;
|
||||||
private RobotControlThread robotThread;
|
private RobotControlThread robotThread;
|
||||||
|
|
||||||
// Overlay font.
|
// Overlays.
|
||||||
private OrthographicCamera pixelPerfectCamera;
|
private OrthographicCamera pixelPerfectCamera;
|
||||||
private float fontX;
|
private float fontX;
|
||||||
private float fontY;
|
private float fontY;
|
||||||
private BitmapFont font;
|
private BitmapFont font;
|
||||||
|
|
||||||
|
private Texture fadeTexture;
|
||||||
|
private MutableFloat alpha;
|
||||||
|
private Tween fadeOut;
|
||||||
|
private Tween fadeIn;
|
||||||
|
private boolean fading;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Set up the basic application fields.</p>
|
* <p>Set up the basic application fields.</p>
|
||||||
*/
|
*/
|
||||||
@@ -135,48 +147,66 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
// Set up fields.
|
// Set up fields.
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
|
|
||||||
if(ProjectConstants.DEBUG)
|
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());{
|
|
||||||
// Set up the overlay font.
|
|
||||||
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
|
||||||
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
|
||||||
|
|
||||||
font = new BitmapFont();
|
if(ProjectConstants.DEBUG){
|
||||||
font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
|
// Set up the overlay font.
|
||||||
if(!Ouya.runningOnOuya){
|
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
||||||
font.setScale(1.0f);
|
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
||||||
}else{
|
|
||||||
font.setScale(2.5f);
|
font = new BitmapFont();
|
||||||
}
|
font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
|
font.setScale(1.0f);
|
||||||
|
}else{
|
||||||
|
font.setScale(2.5f);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start networking.
|
// Start networking.
|
||||||
mcastEnabler.enableMulticast();
|
mcastEnabler.enableMulticast();
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
||||||
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
||||||
videoThread = VideoStreamingThread.getInstance()/*.setToaster(toaster)*/;
|
videoThread = VideoStreamingThread.getInstance();
|
||||||
//robotThread = RobotControlThread.getInstance().setToaster(toaster);
|
robotThread = RobotControlThread.getInstance();
|
||||||
|
|
||||||
serviceDiscoveryThread.start();
|
serviceDiscoveryThread.start();
|
||||||
videoThread.start();
|
|
||||||
videoThread.startStreaming();
|
|
||||||
videoThread.addNetworkConnectionListener(this);
|
|
||||||
//robotThread.start();
|
|
||||||
|
|
||||||
// Set the current and next states.
|
videoThread.start();
|
||||||
currState = game_states_t.MAIN_MENU;
|
videoThread.startStreaming();
|
||||||
nextState = null;
|
videoThread.addNetworkConnectionListener(this);
|
||||||
this.setScreen(states[currState.getValue()]);
|
|
||||||
states[currState.getValue()].onStateSet();
|
|
||||||
|
|
||||||
// Set initial input handlers.
|
robotThread.addNetworkConnectionListener(this);
|
||||||
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
robotThread.start();
|
||||||
Controllers.addListener(states[currState.getValue()]);
|
|
||||||
|
|
||||||
// Anything else.
|
// Set the current and next states.
|
||||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
currState = game_states_t.MAIN_MENU;
|
||||||
Gdx.app.setLogLevel(Application.LOG_NONE);
|
nextState = null;
|
||||||
|
this.setScreen(states[currState.getValue()]);
|
||||||
|
states[currState.getValue()].onStateSet();
|
||||||
|
|
||||||
|
// Prepare the fadeToBlack sprite;
|
||||||
|
Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
|
||||||
|
pixmap.setColor(0, 0, 0, 1);
|
||||||
|
pixmap.fill();
|
||||||
|
fadeTexture = new Texture(pixmap);
|
||||||
|
pixmap.dispose();
|
||||||
|
|
||||||
|
alpha = new MutableFloat(0.0f);
|
||||||
|
fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
|
||||||
|
fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
|
||||||
|
|
||||||
|
fading = false;
|
||||||
|
|
||||||
|
// Set initial input handlers.
|
||||||
|
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
||||||
|
Controllers.addListener(states[currState.getValue()]);
|
||||||
|
|
||||||
|
// Anything else.
|
||||||
|
Gdx.app.setLogLevel(Application.LOG_INFO);
|
||||||
|
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||||
|
//Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(){
|
public void render(){
|
||||||
@@ -186,18 +216,53 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
if(nextState != null){
|
if(nextState != null){
|
||||||
states[currState.getValue()].onStateUnset();
|
states[currState.getValue()].onStateUnset();
|
||||||
|
|
||||||
currState = nextState;
|
if(!fadeOut.isStarted()){
|
||||||
nextState = null;
|
Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Starting fade out.");
|
||||||
|
fadeOut.start();
|
||||||
|
fading = true;
|
||||||
|
}else{
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Updating fade out.");
|
||||||
|
fadeOut.update(Gdx.graphics.getDeltaTime());
|
||||||
|
|
||||||
states[currState.getValue()].onStateSet();
|
if(fadeOut.isFinished()){
|
||||||
|
currState = nextState;
|
||||||
|
nextState = null;
|
||||||
|
|
||||||
setScreen(states[currState.getValue()]);
|
states[currState.getValue()].onStateSet();
|
||||||
|
|
||||||
|
setScreen(states[currState.getValue()]);
|
||||||
|
|
||||||
|
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);
|
||||||
|
fadeIn.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fadeIn.isStarted()){
|
||||||
|
if(!fadeIn.isFinished()){
|
||||||
|
fadeIn.update(Gdx.graphics.getDeltaTime());
|
||||||
|
}else{
|
||||||
|
fading = false;
|
||||||
|
fadeIn.free();
|
||||||
|
fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fading){
|
||||||
|
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
|
batch.begin();{
|
||||||
|
batch.setColor(1, 1, 1, alpha.floatValue());
|
||||||
|
batch.draw(fadeTexture, -(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
|
||||||
|
batch.setColor(1, 1, 1, 1);
|
||||||
|
}batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ProjectConstants.DEBUG){
|
if(ProjectConstants.DEBUG){
|
||||||
// Draw the FPS overlay.
|
|
||||||
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
batch.begin();{
|
batch.begin();{
|
||||||
|
// Draw the FPS overlay.
|
||||||
font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), fontX, fontY);
|
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("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("Lost stream FPS: %d", videoThread.getLostFrames()), fontX, fontY - (2 * font.getCapHeight()) - 10);
|
||||||
@@ -218,8 +283,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
public void dispose(){
|
public void dispose(){
|
||||||
// Finish network threads.
|
// Finish network threads.
|
||||||
videoThread.finish();
|
videoThread.finish();
|
||||||
|
robotThread.finish();
|
||||||
|
|
||||||
// Dispose graphic objects.
|
// Dispose graphic objects.
|
||||||
|
fadeTexture.dispose();
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
if(ProjectConstants.DEBUG){
|
if(ProjectConstants.DEBUG){
|
||||||
font.dispose();
|
font.dispose();
|
||||||
@@ -233,9 +300,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void networkStreamConnected(String streamName){
|
public synchronized void networkStreamConnected(String streamName){
|
||||||
if(streamName.equals(VideoStreamingThread.THREAD_NAME) || streamName.equals(RobotControlThread.THREAD_NAME))
|
//if(streamName.equals(VideoStreamingThread.THREAD_NAME) || streamName.equals(RobotControlThread.THREAD_NAME))
|
||||||
connections += 1;
|
Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected.");
|
||||||
if(connections >= 1){
|
connections += 1;
|
||||||
|
if(connections >= 2){
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".networkStreamConnected() :: Stopping service broadcast.");
|
Gdx.app.debug(TAG, CLASS_NAME + ".networkStreamConnected() :: Stopping service broadcast.");
|
||||||
serviceDiscoveryThread.finish();
|
serviceDiscoveryThread.finish();
|
||||||
mcastEnabler.disableMulticast();
|
mcastEnabler.disableMulticast();
|
||||||
|
|||||||
@@ -16,11 +16,16 @@
|
|||||||
package ve.ucv.ciens.ccg.nxtar.network;
|
package ve.ucv.ciens.ccg.nxtar.network;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InvalidClassException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
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.NetworkConnectionListener;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.Toaster;
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
@@ -33,15 +38,24 @@ public class RobotControlThread extends Thread {
|
|||||||
private NetworkConnectionListener netListener;
|
private NetworkConnectionListener netListener;
|
||||||
private ServerSocket server;
|
private ServerSocket server;
|
||||||
private Socket client;
|
private Socket client;
|
||||||
private Toaster toaster;
|
private MotorEventQueue queue;
|
||||||
|
private Object pauseMonitor;
|
||||||
|
private boolean paused;
|
||||||
|
private boolean done;
|
||||||
|
private ObjectOutputStream os;
|
||||||
|
private ObjectInputStream is;
|
||||||
|
|
||||||
private RobotControlThread(){
|
private RobotControlThread(){
|
||||||
super(THREAD_NAME);
|
super(THREAD_NAME);
|
||||||
|
|
||||||
netListener = null;
|
netListener = null;
|
||||||
|
queue = MotorEventQueue.getInstance();
|
||||||
|
pauseMonitor = new Object();
|
||||||
|
paused = false;
|
||||||
|
done = false;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
server = new ServerSocket(ProjectConstants.SERVER_TCP_PORT_2);
|
server = new ServerSocket(ProjectConstants.MOTOR_CONTROL_PORT);
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".RobotControlThread() :: Error creating server: " + io.getMessage(), io);
|
Gdx.app.error(TAG, CLASS_NAME + ".RobotControlThread() :: Error creating server: " + io.getMessage(), io);
|
||||||
}
|
}
|
||||||
@@ -55,25 +69,109 @@ public class RobotControlThread extends Thread {
|
|||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RobotControlThread setToaster(Toaster toaster){
|
|
||||||
this.toaster = toaster;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addNetworkConnectionListener(NetworkConnectionListener listener){
|
public void addNetworkConnectionListener(NetworkConnectionListener listener){
|
||||||
netListener = listener;
|
netListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pauseThread(){
|
||||||
|
synchronized(pauseMonitor){
|
||||||
|
paused = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resumeThread(){
|
||||||
|
synchronized(pauseMonitor){
|
||||||
|
paused = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finish(){
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
|
MotorEvent message;
|
||||||
|
MotorEventACK ack;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
client = server.accept();
|
client = server.accept();
|
||||||
if(netListener != null)
|
if(netListener != null) netListener.networkStreamConnected(THREAD_NAME);
|
||||||
netListener.networkStreamConnected(THREAD_NAME);
|
os = new ObjectOutputStream(client.getOutputStream());
|
||||||
toaster.showShortToast("Client connected to RobotControlThread");
|
is = new ObjectInputStream(client.getInputStream());
|
||||||
client.close();
|
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error accepting client: " + io.getMessage(), io);
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error accepting client: " + io.getMessage(), io);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!paused){
|
||||||
|
if(done){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the motor event.
|
||||||
|
try{
|
||||||
|
message = queue.getNextEvent();
|
||||||
|
os.writeObject(message);
|
||||||
|
message = null;
|
||||||
|
|
||||||
|
}catch(InvalidClassException ic){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: InvalidClassException during transmission: " + ic.getMessage(), ic);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}catch(IOException io){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: IOException during transmission: " + io.getMessage(), io);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receive ack.
|
||||||
|
try{
|
||||||
|
ack = (MotorEventACK)is.readObject();
|
||||||
|
}catch(ClassNotFoundException cn){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: InvalidClassException during reception: " + cn.getMessage(), cn);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}catch(ClassCastException cc){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: InvalidClassException during reception: " + cc.getMessage(), cc);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}catch(IOException io){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: InvalidClassException during reception: " + io.getMessage(), io);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ack.isClientQueueFull()){
|
||||||
|
// Wait for client to notify.
|
||||||
|
// A client will never send two queue full acks in a row.
|
||||||
|
try{
|
||||||
|
ack = (MotorEventACK)is.readObject();
|
||||||
|
}catch(ClassNotFoundException cn){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: InvalidClassException during reception: " + cn.getMessage(), cn);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}catch(ClassCastException cc){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: InvalidClassException during reception: " + cc.getMessage(), cc);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}catch(IOException io){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: InvalidClassException during reception: " + io.getMessage(), io);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
// Clean and continue.
|
||||||
|
ack = null;
|
||||||
|
message = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try{
|
||||||
|
client.close();
|
||||||
|
}catch(IOException io){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error closing client: " + io.getMessage(), io);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import com.badlogic.gdx.Gdx;
|
|||||||
* <p> This thread performs an ad hoc service discovery protocol. A multicast datagram packet is sent every
|
* <p> This thread performs an ad hoc service discovery protocol. A multicast datagram packet is sent every
|
||||||
* 250 miliseconds carrying the string "NxtAR server is here!" on the multicast address defined
|
* 250 miliseconds carrying the string "NxtAR server is here!" on the multicast address defined
|
||||||
* in {@link ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants#MULTICAST_ADDRESS}. The port defined in
|
* in {@link ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants#MULTICAST_ADDRESS}. The port defined in
|
||||||
* {@link ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants#SERVER_UDP_PORT} is used for the transmissions. The server stops
|
* {@link ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants#SERVICE_DISCOVERY_PORT} is used for the transmissions. The server stops
|
||||||
* when another thread calls the {@link #finish()} method or the server fails to transmit {@link #MAX_RETRIES} packets in
|
* when another thread calls the {@link #finish()} method or the server fails to transmit {@link #MAX_RETRIES} packets in
|
||||||
* a row, whichever happens first.</p>
|
* a row, whichever happens first.</p>
|
||||||
*
|
*
|
||||||
@@ -89,7 +89,7 @@ public class ServiceDiscoveryThread extends Thread {
|
|||||||
// Create a UDP socket at the port defined in ProjectConstants.SERVER_UDP_PORT.
|
// Create a UDP socket at the port defined in ProjectConstants.SERVER_UDP_PORT.
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".ServiceDiscoveryThread() :: Creating multicast server.");
|
Gdx.app.debug(TAG, CLASS_NAME + ".ServiceDiscoveryThread() :: Creating multicast server.");
|
||||||
try{
|
try{
|
||||||
udpServer = new DatagramSocket(ProjectConstants.SERVER_UDP_PORT);
|
udpServer = new DatagramSocket(ProjectConstants.SERVICE_DISCOVERY_PORT);
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".ServiceDiscoveryThread() :: Error creating UDP socket: " + io.getMessage());
|
Gdx.app.error(TAG, CLASS_NAME + ".ServiceDiscoveryThread() :: Error creating UDP socket: " + io.getMessage());
|
||||||
udpServer = null;
|
udpServer = null;
|
||||||
@@ -150,10 +150,11 @@ public class ServiceDiscoveryThread extends Thread {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Send the packet and reset the retry counter.
|
// Send the packet and reset the retry counter.
|
||||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, ProjectConstants.SERVER_UDP_PORT);
|
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, group, ProjectConstants.SERVICE_DISCOVERY_PORT);
|
||||||
udpServer.send(packet);
|
udpServer.send(packet);
|
||||||
retries = 0;
|
retries = 0;
|
||||||
try{ sleep(250L); }catch(InterruptedException ie){ }
|
try{ sleep(250L); }catch(InterruptedException ie){ }
|
||||||
|
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error sending packet: " + io.getMessage());
|
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error sending packet: " + io.getMessage());
|
||||||
retries += 1;
|
retries += 1;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
|
||||||
public class VideoStreamingThread extends Thread {
|
public class VideoStreamingThread extends Thread{
|
||||||
public static final String THREAD_NAME = "VideoStreamingThread";
|
public static final String THREAD_NAME = "VideoStreamingThread";
|
||||||
private static final String TAG = "NXTAR_CORE_VIDEOTHREAD";
|
private static final String TAG = "NXTAR_CORE_VIDEOTHREAD";
|
||||||
private static final String CLASS_NAME = VideoStreamingThread.class.getSimpleName();
|
private static final String CLASS_NAME = VideoStreamingThread.class.getSimpleName();
|
||||||
@@ -65,7 +65,7 @@ public class VideoStreamingThread extends Thread {
|
|||||||
frameMonitor = VideoFrameMonitor.getInstance();
|
frameMonitor = VideoFrameMonitor.getInstance();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
socket = new DatagramSocket(ProjectConstants.SERVER_TCP_PORT_1);
|
socket = new DatagramSocket(ProjectConstants.VIDEO_STREAMING_PORT);
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".VideoStreamingThread() :: Error creating server: " + io.getMessage(), io);
|
Gdx.app.error(TAG, CLASS_NAME + ".VideoStreamingThread() :: Error creating server: " + io.getMessage(), io);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* 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.network.monitors;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A simple monitor class that encapsulates a queue.</p>
|
||||||
|
* <p>As it name says it stores motor events to be forwarded to the NXT robot.</p>
|
||||||
|
* <p>This class implements the singleton design pattern.<p>
|
||||||
|
*
|
||||||
|
* @author Miguel Angel Astor Romero
|
||||||
|
*/
|
||||||
|
public class MotorEventQueue{
|
||||||
|
/**
|
||||||
|
* The event queue implemented as a linked list.
|
||||||
|
*/
|
||||||
|
private Queue<MotorEvent> motorEvents;
|
||||||
|
|
||||||
|
private MotorEventQueue(){
|
||||||
|
motorEvents = new LinkedList<MotorEvent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder{
|
||||||
|
public static final MotorEventQueue instance = new MotorEventQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the singleton instance of this class.
|
||||||
|
* @return The singleton instance.
|
||||||
|
*/
|
||||||
|
public static MotorEventQueue getInstance(){
|
||||||
|
return SingletonHolder.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Get the first event on the queue.</p>
|
||||||
|
* <p> If there are no events to return this method blocks until some thread calls the addEvent() method.</p>
|
||||||
|
* @return The event at the front of the queue.
|
||||||
|
*/
|
||||||
|
public synchronized MotorEvent getNextEvent(){
|
||||||
|
while(motorEvents.size() == 0){
|
||||||
|
try{ wait(); }catch(InterruptedException ie){ }
|
||||||
|
}
|
||||||
|
return motorEvents.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Adds an event to the back of the queue.</p>
|
||||||
|
* @param event The event to add.
|
||||||
|
*/
|
||||||
|
public synchronized void addEvent(MotorEvent event){
|
||||||
|
motorEvents.add(event);
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2013 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.network.protocols;
|
|
||||||
|
|
||||||
public final class VideoStreamingProtocol{
|
|
||||||
public static final byte STREAM_CONTROL_END = 0x10;
|
|
||||||
public static final byte ACK_SEND_NEXT = 0x20;
|
|
||||||
public static final byte ACK_WAIT = 0x30;
|
|
||||||
public static final byte FLOW_CONTROL_WAIT = 0x40;
|
|
||||||
public static final byte FLOW_CONTROL_CONTINUE = 0x50;
|
|
||||||
public static final byte IMAGE_DATA = 0x60;
|
|
||||||
public static final byte UNRECOGNIZED = (byte)0xFF;
|
|
||||||
|
|
||||||
public static boolean checkValidityOfMessage(byte message){
|
|
||||||
boolean validity;
|
|
||||||
|
|
||||||
switch(message){
|
|
||||||
case STREAM_CONTROL_END:
|
|
||||||
case ACK_SEND_NEXT:
|
|
||||||
case ACK_WAIT:
|
|
||||||
case FLOW_CONTROL_WAIT:
|
|
||||||
case FLOW_CONTROL_CONTINUE:
|
|
||||||
case IMAGE_DATA:
|
|
||||||
case UNRECOGNIZED:
|
|
||||||
validity = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
validity = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return validity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,8 +17,11 @@ package ve.ucv.ciens.ccg.nxtar.states;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
||||||
|
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
|
||||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||||
import ve.ucv.ciens.ccg.nxtar.exceptions.ImageTooBigException;
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
||||||
|
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.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.Size;
|
import ve.ucv.ciens.ccg.nxtar.utils.Size;
|
||||||
@@ -64,22 +67,30 @@ public class InGameState extends BaseState{
|
|||||||
|
|
||||||
// Interface buttons.
|
// Interface buttons.
|
||||||
private Texture buttonTexture;
|
private Texture buttonTexture;
|
||||||
|
private Texture buttonTexture2;
|
||||||
private Sprite motorA;
|
private Sprite motorA;
|
||||||
private Sprite motorB;
|
private Sprite motorB;
|
||||||
private Sprite motorC;
|
private Sprite motorC;
|
||||||
private Sprite motorD;
|
private Sprite motorD;
|
||||||
|
private Sprite headA;
|
||||||
|
private Sprite headB;
|
||||||
|
|
||||||
// Button touch helper fields.
|
// Button touch helper fields.
|
||||||
private Vector3 win2world;
|
private Vector3 win2world;
|
||||||
private Vector2 touchPointWorldCoords;
|
private Vector2 touchPointWorldCoords;
|
||||||
private boolean[] motorButtonsTouched;
|
private boolean[] motorButtonsTouched;
|
||||||
private int[] motorButtonsPointers;
|
private int[] motorButtonsPointers;
|
||||||
|
private boolean[] motorGamepadButtonPressed;
|
||||||
|
private boolean[] axisStopSent;
|
||||||
|
|
||||||
|
// Monitors.
|
||||||
private VideoFrameMonitor frameMonitor;
|
private VideoFrameMonitor frameMonitor;
|
||||||
|
private MotorEventQueue queue;
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
// Set up rendering fields;
|
// Set up rendering fields;
|
||||||
videoFrame = null;
|
videoFrame = null;
|
||||||
@@ -93,17 +104,32 @@ public class InGameState extends BaseState{
|
|||||||
// 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();
|
||||||
motorButtonsTouched = new boolean[4];
|
|
||||||
|
motorButtonsTouched = new boolean[6];
|
||||||
motorButtonsTouched[0] = false;
|
motorButtonsTouched[0] = false;
|
||||||
motorButtonsTouched[1] = false;
|
motorButtonsTouched[1] = false;
|
||||||
motorButtonsTouched[2] = false;
|
motorButtonsTouched[2] = false;
|
||||||
motorButtonsTouched[3] = false;
|
motorButtonsTouched[3] = false;
|
||||||
|
motorButtonsTouched[4] = false;
|
||||||
|
motorButtonsTouched[5] = false;
|
||||||
|
|
||||||
motorButtonsPointers = new int[4];
|
motorButtonsPointers = new int[6];
|
||||||
motorButtonsPointers[0] = -1;
|
motorButtonsPointers[0] = -1;
|
||||||
motorButtonsPointers[1] = -1;
|
motorButtonsPointers[1] = -1;
|
||||||
motorButtonsPointers[2] = -1;
|
motorButtonsPointers[2] = -1;
|
||||||
motorButtonsPointers[3] = -1;
|
motorButtonsPointers[3] = -1;
|
||||||
|
motorButtonsPointers[4] = -1;
|
||||||
|
motorButtonsPointers[5] = -1;
|
||||||
|
|
||||||
|
motorGamepadButtonPressed = new boolean[2];
|
||||||
|
motorGamepadButtonPressed[0] = false;
|
||||||
|
motorGamepadButtonPressed[1] = false;
|
||||||
|
|
||||||
|
axisStopSent = new boolean[4];
|
||||||
|
axisStopSent[0] = true;
|
||||||
|
axisStopSent[1] = true;
|
||||||
|
axisStopSent[2] = true;
|
||||||
|
axisStopSent[3] = true;
|
||||||
|
|
||||||
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
||||||
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
||||||
@@ -125,8 +151,7 @@ public class InGameState extends BaseState{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float delta) {
|
public void render(float delta){
|
||||||
Pixmap temp;
|
|
||||||
byte[] frame;
|
byte[] frame;
|
||||||
byte[] prevFrame = null;
|
byte[] prevFrame = null;
|
||||||
Size dimensions = null;
|
Size dimensions = null;
|
||||||
@@ -147,20 +172,10 @@ public class InGameState extends BaseState{
|
|||||||
frame = frameMonitor.getCurrentFrame();
|
frame = frameMonitor.getCurrentFrame();
|
||||||
if(frame != null && !Arrays.equals(frame, prevFrame)){
|
if(frame != null && !Arrays.equals(frame, prevFrame)){
|
||||||
dimensions = frameMonitor.getFrameDimensions();
|
dimensions = frameMonitor.getFrameDimensions();
|
||||||
temp = new Pixmap(frame, 0, dimensions.getWidth() * dimensions.getHeight());
|
videoFrame = new Pixmap(frame, 0, dimensions.getWidth() * dimensions.getHeight());
|
||||||
if(videoFrame == null){
|
|
||||||
try{
|
|
||||||
videoFrame = new Pixmap(getOptimalTextureSize(dimensions.getWidth()), getOptimalTextureSize(dimensions.getHeight()), temp.getFormat());
|
|
||||||
}catch(ImageTooBigException e){
|
|
||||||
core.toast("Cannot display received frame.\n" + e.getMessage(), true);
|
|
||||||
Gdx.app.exit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
videoFrame.drawPixmap(temp, 0, 0);
|
|
||||||
temp.dispose();
|
|
||||||
videoFrameTexture = new Texture(videoFrame);
|
videoFrameTexture = new Texture(videoFrame);
|
||||||
videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||||
|
videoFrame.dispose();
|
||||||
|
|
||||||
TextureRegion region = new TextureRegion(videoFrameTexture, 0, 0, dimensions.getWidth(), dimensions.getHeight());
|
TextureRegion region = new TextureRegion(videoFrameTexture, 0, 0, dimensions.getWidth(), dimensions.getHeight());
|
||||||
|
|
||||||
@@ -196,61 +211,44 @@ public class InGameState extends BaseState{
|
|||||||
motorB.draw(core.batch);
|
motorB.draw(core.batch);
|
||||||
motorC.draw(core.batch);
|
motorC.draw(core.batch);
|
||||||
motorD.draw(core.batch);
|
motorD.draw(core.batch);
|
||||||
|
headA.draw(core.batch);
|
||||||
|
headB.draw(core.batch);
|
||||||
}
|
}
|
||||||
}core.batch.end();
|
}core.batch.end();
|
||||||
|
|
||||||
prevFrame = frame;
|
prevFrame = frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height){
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show(){ }
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hide() {
|
public void hide(){ }
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pause() {
|
public void pause(){ }
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resume() {
|
public void resume(){ }
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose(){
|
||||||
if(videoFrameTexture != null)
|
if(videoFrameTexture != null)
|
||||||
videoFrameTexture.dispose();
|
videoFrameTexture.dispose();
|
||||||
if(buttonTexture != null)
|
if(buttonTexture != null)
|
||||||
buttonTexture.dispose();
|
buttonTexture.dispose();
|
||||||
if(videoFrame != null)
|
if(buttonTexture2 != null)
|
||||||
videoFrame.dispose();
|
buttonTexture2.dispose();
|
||||||
backgroundTexture.dispose();
|
backgroundTexture.dispose();
|
||||||
if(backgroundShader != null) backgroundShader.dispose();
|
if(backgroundShader != null) backgroundShader.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getOptimalTextureSize(int imageSideLength) throws ImageTooBigException{
|
|
||||||
for(int po2: ProjectConstants.POWERS_OF_2){
|
|
||||||
if(imageSideLength < po2) return po2;
|
|
||||||
}
|
|
||||||
throw new ImageTooBigException("No valid texture size found. Image too large.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
; HELPER METHODS ;
|
; HELPER METHODS ;
|
||||||
;;;;;;;;;;;;;;;;;;*/
|
;;;;;;;;;;;;;;;;;;*/
|
||||||
@@ -293,6 +291,17 @@ public class InGameState extends BaseState{
|
|||||||
motorB.setPosition(-(Gdx.graphics.getWidth() / 2) + 20 + (motorA.getWidth() / 2), -(Gdx.graphics.getHeight() / 2) + 10);
|
motorB.setPosition(-(Gdx.graphics.getWidth() / 2) + 20 + (motorA.getWidth() / 2), -(Gdx.graphics.getHeight() / 2) + 10);
|
||||||
motorC.setPosition((Gdx.graphics.getWidth() / 2) - (1.5f * (motorD.getWidth())) - 20, -(Gdx.graphics.getHeight() / 2) + 10);
|
motorC.setPosition((Gdx.graphics.getWidth() / 2) - (1.5f * (motorD.getWidth())) - 20, -(Gdx.graphics.getHeight() / 2) + 10);
|
||||||
motorD.setPosition((Gdx.graphics.getWidth() / 2) - motorD.getWidth() - 10, -(Gdx.graphics.getHeight() / 2) + 20 + motorC.getHeight());
|
motorD.setPosition((Gdx.graphics.getWidth() / 2) - motorD.getWidth() - 10, -(Gdx.graphics.getHeight() / 2) + 20 + motorC.getHeight());
|
||||||
|
|
||||||
|
buttonTexture2 = new Texture(Gdx.files.internal("data/gfx/gui/orange_glowy_button.png"));
|
||||||
|
|
||||||
|
headA = new Sprite(buttonTexture2);
|
||||||
|
headA.setSize(headA.getWidth() * 0.3f, headA.getHeight() * 0.6f);
|
||||||
|
|
||||||
|
headB = new Sprite(buttonTexture2);
|
||||||
|
headB.setSize(headB.getWidth() * 0.3f, headB.getHeight() * 0.6f);
|
||||||
|
|
||||||
|
headA.setPosition(-headA.getWidth() - 10, motorA.getY() + (headA.getHeight() / 2));
|
||||||
|
headB.setPosition(10, motorA.getY() + (headA.getHeight() / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@@ -300,28 +309,9 @@ public class InGameState extends BaseState{
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyDown(int keycode) {
|
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||||
if(keycode == Input.Keys.BACK){
|
MotorEvent event;
|
||||||
// TODO: Go to pause state.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyUp(int keycode) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyTyped(char character) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
|
||||||
if(!Ouya.runningOnOuya){
|
if(!Ouya.runningOnOuya){
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
camera.unproject(win2world);
|
camera.unproject(win2world);
|
||||||
@@ -332,27 +322,80 @@ public class InGameState extends BaseState{
|
|||||||
|
|
||||||
if(motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
if(motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor A button pressed");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor A button pressed");
|
||||||
|
|
||||||
motorButtonsTouched[0] = true;
|
motorButtonsTouched[0] = true;
|
||||||
motorButtonsPointers[0] = pointer;
|
motorButtonsPointers[0] = pointer;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte)100);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
}else if(motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor B button pressed");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor B button pressed");
|
||||||
|
|
||||||
|
|
||||||
motorButtonsTouched[1] = true;
|
motorButtonsTouched[1] = true;
|
||||||
motorButtonsPointers[1] = pointer;
|
motorButtonsPointers[1] = pointer;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte)-100);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
}else if(motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor C button pressed");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor C button pressed");
|
||||||
|
|
||||||
motorButtonsTouched[2] = true;
|
motorButtonsTouched[2] = true;
|
||||||
motorButtonsPointers[2] = pointer;
|
motorButtonsPointers[2] = pointer;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte)-100);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
}else if(motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor D button pressed");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor D button pressed");
|
||||||
|
|
||||||
motorButtonsTouched[3] = true;
|
motorButtonsTouched[3] = true;
|
||||||
motorButtonsPointers[3] = pointer;
|
motorButtonsPointers[3] = pointer;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte)100);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
|
}else if(headA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Head A button pressed");
|
||||||
|
|
||||||
|
motorButtonsTouched[4] = true;
|
||||||
|
motorButtonsPointers[4] = pointer;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte)-40);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
|
}else if(headB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Head B button pressed");
|
||||||
|
|
||||||
|
motorButtonsTouched[5] = true;
|
||||||
|
motorButtonsPointers[5] = pointer;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte)40);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||||
|
MotorEvent event;
|
||||||
|
|
||||||
if(!Ouya.runningOnOuya){
|
if(!Ouya.runningOnOuya){
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
camera.unproject(win2world);
|
camera.unproject(win2world);
|
||||||
@@ -363,27 +406,97 @@ public class InGameState extends BaseState{
|
|||||||
|
|
||||||
if(motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
if(motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor A button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor A button released");
|
||||||
|
|
||||||
motorButtonsPointers[0] = -1;
|
motorButtonsPointers[0] = -1;
|
||||||
motorButtonsTouched[0] = false;
|
motorButtonsTouched[0] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[1]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}else if(motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor B button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor B button released");
|
||||||
|
|
||||||
motorButtonsPointers[1] = -1;
|
motorButtonsPointers[1] = -1;
|
||||||
motorButtonsTouched[1] = false;
|
motorButtonsTouched[1] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[0]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}else if(motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor C button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor C button released");
|
||||||
|
|
||||||
motorButtonsPointers[2] = -1;
|
motorButtonsPointers[2] = -1;
|
||||||
motorButtonsTouched[2] = false;
|
motorButtonsTouched[2] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[3]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}else if(motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor D button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Motor D button released");
|
||||||
|
|
||||||
motorButtonsPointers[3] = -1;
|
motorButtonsPointers[3] = -1;
|
||||||
motorButtonsTouched[3] = false;
|
motorButtonsTouched[3] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[2]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(headA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head A button released");
|
||||||
|
|
||||||
|
motorButtonsPointers[4] = -1;
|
||||||
|
motorButtonsTouched[4] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[5]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(headB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head B button released");
|
||||||
|
|
||||||
|
motorButtonsPointers[5] = -1;
|
||||||
|
motorButtonsTouched[5] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[4]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
public boolean touchDragged(int screenX, int screenY, int pointer){
|
||||||
|
MotorEvent event;
|
||||||
|
|
||||||
if(!Ouya.runningOnOuya){
|
if(!Ouya.runningOnOuya){
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
camera.unproject(win2world);
|
camera.unproject(win2world);
|
||||||
@@ -391,28 +504,100 @@ public class InGameState extends BaseState{
|
|||||||
|
|
||||||
if(pointer == motorButtonsPointers[0] && !motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
if(pointer == motorButtonsPointers[0] && !motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor A button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor A button released");
|
||||||
|
|
||||||
motorButtonsPointers[0] = -1;
|
motorButtonsPointers[0] = -1;
|
||||||
motorButtonsTouched[0] = false;
|
motorButtonsTouched[0] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[1]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}else if(pointer == motorButtonsPointers[1] && !motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(pointer == motorButtonsPointers[1] && !motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor B button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor B button released");
|
||||||
|
|
||||||
motorButtonsPointers[1] = -1;
|
motorButtonsPointers[1] = -1;
|
||||||
motorButtonsTouched[1] = false;
|
motorButtonsTouched[1] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[0]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}else if(pointer == motorButtonsPointers[2] && !motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(pointer == motorButtonsPointers[2] && !motorC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor C button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor C button released");
|
||||||
|
|
||||||
motorButtonsPointers[2] = -1;
|
motorButtonsPointers[2] = -1;
|
||||||
motorButtonsTouched[2] = false;
|
motorButtonsTouched[2] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[3]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}else if(pointer == motorButtonsPointers[3] && !motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
|
}else if(pointer == motorButtonsPointers[3] && !motorD.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor D button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor D button released");
|
||||||
|
|
||||||
motorButtonsPointers[3] = -1;
|
motorButtonsPointers[3] = -1;
|
||||||
motorButtonsTouched[3] = false;
|
motorButtonsTouched[3] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[2]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(pointer == motorButtonsPointers[4] && headA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head A button released");
|
||||||
|
|
||||||
|
motorButtonsPointers[4] = -1;
|
||||||
|
motorButtonsTouched[4] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[5]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(pointer == motorButtonsPointers[5] && headB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head B button released");
|
||||||
|
|
||||||
|
motorButtonsPointers[5] = -1;
|
||||||
|
motorButtonsTouched[5] = false;
|
||||||
|
|
||||||
|
// Enqueue the event corresponding to releasing this button if the opposing button is not pressed already.
|
||||||
|
if(!motorButtonsTouched[4]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte) 0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseMoved(int screenX, int screenY) {
|
public boolean keyDown(int keycode){
|
||||||
// TODO Auto-generated method stub
|
if(keycode == Input.Keys.BACK){
|
||||||
|
// TODO: Go to pause state.
|
||||||
|
core.nextState = game_states_t.MAIN_MENU;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,34 +606,124 @@ public class InGameState extends BaseState{
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean buttonDown(Controller controller, int buttonCode) {
|
public boolean buttonDown(Controller controller, int buttonCode){
|
||||||
if(stateActive){
|
MotorEvent event;
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if(stateActive && Ouya.runningOnOuya){
|
||||||
public boolean buttonUp(Controller controller, int buttonCode) {
|
|
||||||
if(stateActive){
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if(buttonCode == Ouya.BUTTON_L1){
|
||||||
public boolean axisMoved(Controller controller, int axisCode, float value) {
|
motorGamepadButtonPressed[0] = true;
|
||||||
if(stateActive){
|
|
||||||
if(value >= Ouya.STICK_DEADZONE){
|
if(!motorGamepadButtonPressed[1]){
|
||||||
if(axisCode == Ouya.AXIS_LEFT_TRIGGER){
|
event = new MotorEvent();
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".axisMoved() :: LEFT TRIGGER pressed.");
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte)100);
|
||||||
|
queue.addEvent(event);
|
||||||
}
|
}
|
||||||
if(axisCode == Ouya.AXIS_RIGHT_TRIGGER){
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".axisMoved() :: RIGHT TRIGGER pressed.");
|
}else if(buttonCode == Ouya.BUTTON_R1){
|
||||||
|
motorGamepadButtonPressed[1] = true;
|
||||||
|
|
||||||
|
if(!motorGamepadButtonPressed[0]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte)-100);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean buttonUp(Controller controller, int buttonCode){
|
||||||
|
MotorEvent event;
|
||||||
|
|
||||||
|
if(stateActive && Ouya.runningOnOuya){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
|
||||||
|
|
||||||
|
if(buttonCode == Ouya.BUTTON_L1){
|
||||||
|
motorGamepadButtonPressed[0] = false;
|
||||||
|
|
||||||
|
if(!motorGamepadButtonPressed[1]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte)0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(buttonCode == Ouya.BUTTON_R1){
|
||||||
|
motorGamepadButtonPressed[1] = false;
|
||||||
|
|
||||||
|
if(!motorGamepadButtonPressed[0]){
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_B);
|
||||||
|
event.setPower((byte)0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean axisMoved(Controller controller, int axisCode, float value){
|
||||||
|
MotorEvent event;
|
||||||
|
|
||||||
|
if(stateActive && Ouya.runningOnOuya){
|
||||||
|
if(Math.abs(value) >= Ouya.STICK_DEADZONE * 3.0f){
|
||||||
|
|
||||||
|
if(axisCode == Ouya.AXIS_LEFT_Y){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".axisMoved() :: LEFT Y moved: "+ Float.toString(value));
|
||||||
|
|
||||||
|
axisStopSent[0] = false;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte)(100.0f * -value));
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
|
}else if(axisCode == Ouya.AXIS_RIGHT_Y){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".axisMoved() :: RIGHT Y moved: "+ Float.toString(value));
|
||||||
|
|
||||||
|
axisStopSent[1] = false;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte)(100.0f * -value));
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
if(axisCode == Ouya.AXIS_LEFT_Y && !axisStopSent[0]){
|
||||||
|
|
||||||
|
axisStopSent[0] = true;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_A);
|
||||||
|
event.setPower((byte)0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
|
}else if(axisCode == Ouya.AXIS_RIGHT_Y && !axisStopSent[1]){
|
||||||
|
|
||||||
|
axisStopSent[1] = true;
|
||||||
|
|
||||||
|
event = new MotorEvent();
|
||||||
|
event.setMotor(motor_t.MOTOR_C);
|
||||||
|
event.setPower((byte)0);
|
||||||
|
queue.addEvent(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -458,47 +733,62 @@ public class InGameState extends BaseState{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean scrolled(int amount) {
|
public void connected(Controller controller){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnected(Controller controller){ }
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; UNUSED LISTENER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseMoved(int screenX, int screenY){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyUp(int keycode){
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected(Controller controller) {
|
public boolean keyTyped(char character){
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disconnected(Controller controller) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean povMoved(Controller controller, int povCode,
|
public boolean povMoved(Controller controller, int povCode,
|
||||||
PovDirection value) {
|
PovDirection value){
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean xSliderMoved(Controller controller, int sliderCode,
|
public boolean xSliderMoved(Controller controller, int sliderCode,
|
||||||
boolean value) {
|
boolean value){
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ySliderMoved(Controller controller, int sliderCode,
|
public boolean ySliderMoved(Controller controller, int sliderCode,
|
||||||
boolean value) {
|
boolean value){
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accelerometerMoved(Controller controller,
|
public boolean accelerometerMoved(Controller controller,
|
||||||
int accelerometerCode, Vector3 value) {
|
int accelerometerCode, Vector3 value){
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean scrolled(int amount){
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.states;
|
package ve.ucv.ciens.ccg.nxtar.states;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
@@ -23,6 +24,7 @@ import com.badlogic.gdx.controllers.Controller;
|
|||||||
import com.badlogic.gdx.controllers.PovDirection;
|
import com.badlogic.gdx.controllers.PovDirection;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
||||||
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
||||||
@@ -34,6 +36,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|||||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||||
@@ -49,6 +52,7 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
// Helper fields.
|
// Helper fields.
|
||||||
protected boolean clientConnected;
|
protected boolean clientConnected;
|
||||||
private float u_scaling[];
|
private float u_scaling[];
|
||||||
|
protected OrthographicCamera pixelPerfectCamera;
|
||||||
|
|
||||||
// Buttons and other gui components.
|
// Buttons and other gui components.
|
||||||
protected TextButton startButton;
|
protected TextButton startButton;
|
||||||
@@ -72,9 +76,17 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
private Texture backgroundTexture;
|
private Texture backgroundTexture;
|
||||||
private ShaderProgram backgroundShader;
|
private ShaderProgram backgroundShader;
|
||||||
|
|
||||||
|
// Button touch helper fields.
|
||||||
|
private Vector3 win2world;
|
||||||
|
protected Vector2 touchPointWorldCoords;
|
||||||
|
protected boolean startButtonTouched;
|
||||||
|
protected int startButtonTouchPointer;
|
||||||
|
|
||||||
public MainMenuStateBase(){
|
public MainMenuStateBase(){
|
||||||
TextureRegion region;
|
TextureRegion region;
|
||||||
|
|
||||||
|
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
|
||||||
// Create the start button background.
|
// Create the start button background.
|
||||||
startButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
startButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
||||||
startButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0, startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
startButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0, startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
||||||
@@ -131,6 +143,12 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
|
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
|
||||||
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||||
|
|
||||||
|
|
||||||
|
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
|
touchPointWorldCoords = new Vector2();
|
||||||
|
startButtonTouched = false;
|
||||||
|
startButtonTouchPointer = -1;
|
||||||
|
|
||||||
clientConnected = false;
|
clientConnected = false;
|
||||||
stateActive = false;
|
stateActive = false;
|
||||||
}
|
}
|
||||||
@@ -139,18 +157,18 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
public abstract void render(float delta);
|
public abstract void render(float delta);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void resize(int width, int height);
|
public void resize(int width, int height){ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void show();
|
public void show(){ }
|
||||||
@Override
|
@Override
|
||||||
public abstract void hide();
|
public void hide(){ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void pause();
|
public void pause(){ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void resume();
|
public void resume(){ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
@@ -194,19 +212,82 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
startButton.setDisabled(false);
|
startButton.setDisabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
; INPUT LISTENER METHOD STUBS ;
|
; HELPER METHODS ;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
protected void unprojectTouch(int screenX, int screenY){
|
||||||
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
|
pixelPerfectCamera.unproject(win2world);
|
||||||
|
touchPointWorldCoords.set(win2world.x, win2world.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; INPUT LISTENER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||||
|
unprojectTouch(screenX, screenY);
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
|
|
||||||
|
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
||||||
|
startButton.setChecked(true);
|
||||||
|
startButtonTouched = true;
|
||||||
|
startButtonTouchPointer = pointer;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||||
|
unprojectTouch(screenX, screenY);
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
|
|
||||||
|
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
||||||
|
startButton.setChecked(false);
|
||||||
|
startButtonTouched = false;
|
||||||
|
startButtonTouchPointer = -1;
|
||||||
|
core.nextState = game_states_t.IN_GAME;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDragged(int screenX, int screenY, int pointer){
|
||||||
|
unprojectTouch(screenX, screenY);
|
||||||
|
|
||||||
|
if(!startButton.isDisabled() && startButtonTouched && pointer == startButtonTouchPointer && !startButtonBBox.contains(touchPointWorldCoords)){
|
||||||
|
startButtonTouchPointer = -1;
|
||||||
|
startButtonTouched = false;
|
||||||
|
startButton.setChecked(false);
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyDown(int keycode){
|
public boolean keyDown(int keycode){
|
||||||
if(keycode == Input.Keys.BACK){
|
if(keycode == Input.Keys.BACK){
|
||||||
// TODO: Go to pause state.
|
// Ignore.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; INPUT LISTENER METHOD STUBS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keycode){
|
public boolean keyUp(int keycode){
|
||||||
return false;
|
return false;
|
||||||
@@ -217,21 +298,6 @@ public abstract class MainMenuStateBase extends BaseState{
|
|||||||
return false;
|
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
|
@Override
|
||||||
public boolean mouseMoved(int screenX, int screenY){
|
public boolean mouseMoved(int screenX, int screenY){
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.controllers.Controller;
|
import com.badlogic.gdx.controllers.Controller;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
@@ -30,14 +29,12 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|||||||
public class OuyaMainMenuState extends MainMenuStateBase{
|
public class OuyaMainMenuState extends MainMenuStateBase{
|
||||||
private static final String CLASS_NAME = OuyaMainMenuState.class.getSimpleName();
|
private static final String CLASS_NAME = OuyaMainMenuState.class.getSimpleName();
|
||||||
|
|
||||||
private OrthographicCamera pixelPerfectCamera;
|
|
||||||
private Texture ouyaOButtonTexture;
|
private Texture ouyaOButtonTexture;
|
||||||
private Sprite ouyaOButton;
|
private Sprite ouyaOButton;
|
||||||
private boolean oButtonPressed;
|
private boolean oButtonPressed;
|
||||||
|
|
||||||
public OuyaMainMenuState(final NxtARCore core){
|
public OuyaMainMenuState(final NxtARCore core){
|
||||||
this.core = core;
|
this.core = core;
|
||||||
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
||||||
|
|
||||||
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
||||||
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
||||||
@@ -53,7 +50,7 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
|
TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
|
||||||
ouyaOButton = new Sprite(region);
|
ouyaOButton = new Sprite(region);
|
||||||
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
|
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
|
||||||
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY());
|
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
|
||||||
|
|
||||||
oButtonPressed = false;
|
oButtonPressed = false;
|
||||||
}
|
}
|
||||||
@@ -65,7 +62,9 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
|
|
||||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
core.batch.begin();{
|
core.batch.begin();{
|
||||||
|
core.batch.disableBlending();
|
||||||
drawBackground(core.batch);
|
drawBackground(core.batch);
|
||||||
|
core.batch.enableBlending();
|
||||||
if(clientConnected){
|
if(clientConnected){
|
||||||
clientConnectedLedOn.draw(core.batch);
|
clientConnectedLedOn.draw(core.batch);
|
||||||
}else{
|
}else{
|
||||||
@@ -76,36 +75,6 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
}core.batch.end();
|
}core.batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resize(int width, int height) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void show() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hide() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pause() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resume() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|||||||
@@ -16,37 +16,16 @@
|
|||||||
package ve.ucv.ciens.ccg.nxtar.states;
|
package ve.ucv.ciens.ccg.nxtar.states;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
|
||||||
import com.badlogic.gdx.math.Vector3;
|
|
||||||
|
|
||||||
public class TabletMainMenuState extends MainMenuStateBase{
|
public class TabletMainMenuState extends MainMenuStateBase{
|
||||||
private static final String CLASS_NAME = TabletMainMenuState.class.getSimpleName();
|
|
||||||
|
|
||||||
private OrthographicCamera pixelPerfectCamera;
|
|
||||||
|
|
||||||
// Button touch helper fields.
|
|
||||||
private Vector3 win2world;
|
|
||||||
private Vector2 touchPointWorldCoords;
|
|
||||||
private boolean startButtonTouched;
|
|
||||||
private int startButtonTouchPointer;
|
|
||||||
|
|
||||||
public TabletMainMenuState(final NxtARCore core){
|
public TabletMainMenuState(final NxtARCore core){
|
||||||
this.core = core;
|
this.core = core;
|
||||||
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
||||||
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
||||||
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
||||||
|
|
||||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
|
||||||
touchPointWorldCoords = new Vector2();
|
|
||||||
|
|
||||||
startButtonTouched = false;
|
|
||||||
startButtonTouchPointer = -1;
|
|
||||||
|
|
||||||
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (startButton.getY() * 0.5f);
|
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (startButton.getY() * 0.5f);
|
||||||
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
||||||
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
||||||
@@ -62,7 +41,10 @@ public class TabletMainMenuState extends MainMenuStateBase{
|
|||||||
|
|
||||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
core.batch.begin();{
|
core.batch.begin();{
|
||||||
|
core.batch.disableBlending();
|
||||||
drawBackground(core.batch);
|
drawBackground(core.batch);
|
||||||
|
core.batch.enableBlending();
|
||||||
|
|
||||||
if(clientConnected){
|
if(clientConnected){
|
||||||
clientConnectedLedOn.draw(core.batch);
|
clientConnectedLedOn.draw(core.batch);
|
||||||
}else{
|
}else{
|
||||||
@@ -71,87 +53,4 @@ public class TabletMainMenuState extends MainMenuStateBase{
|
|||||||
startButton.draw(core.batch, 1.0f);
|
startButton.draw(core.batch, 1.0f);
|
||||||
}core.batch.end();
|
}core.batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(){
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;
|
|
||||||
; HELPER METHODS ;
|
|
||||||
;;;;;;;;;;;;;;;;;;*/
|
|
||||||
|
|
||||||
private void unprojectTouch(int screenX, int screenY){
|
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
|
||||||
pixelPerfectCamera.unproject(win2world);
|
|
||||||
touchPointWorldCoords.set(win2world.x, win2world.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
; INPUT LISTENER METHODS ;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
|
||||||
unprojectTouch(screenX, screenY);
|
|
||||||
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
|
||||||
|
|
||||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
|
||||||
startButton.setChecked(true);
|
|
||||||
startButtonTouched = true;
|
|
||||||
startButtonTouchPointer = pointer;
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
|
||||||
unprojectTouch(screenX, screenY);
|
|
||||||
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
|
||||||
|
|
||||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
|
||||||
startButton.setChecked(false);
|
|
||||||
startButtonTouched = false;
|
|
||||||
startButtonTouchPointer = -1;
|
|
||||||
core.nextState = game_states_t.IN_GAME;
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean touchDragged(int screenX, int screenY, int pointer){
|
|
||||||
unprojectTouch(screenX, screenY);
|
|
||||||
|
|
||||||
if(!startButton.isDisabled() && startButtonTouched && pointer == startButtonTouchPointer && !startButtonBBox.contains(touchPointWorldCoords)){
|
|
||||||
startButtonTouchPointer = -1;
|
|
||||||
startButtonTouched = false;
|
|
||||||
startButton.setChecked(false);
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,15 @@ package ve.ucv.ciens.ccg.nxtar.utils;
|
|||||||
|
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
|
|
||||||
public abstract class ProjectConstants {
|
public abstract class ProjectConstants{
|
||||||
public static final int SERVER_UDP_PORT = 8889;
|
public static final int SERVICE_DISCOVERY_PORT = 9988;
|
||||||
public static final int SERVER_TCP_PORT_1 = 9989;
|
public static final int VIDEO_STREAMING_PORT = 9989;
|
||||||
public static final int SERVER_TCP_PORT_2 = 9990;
|
public static final int MOTOR_CONTROL_PORT = 9990;
|
||||||
|
public static final int SENSOR_REPORT_PORT = 9991;
|
||||||
|
public static final int APP_CONTROL_PORT = 9992;
|
||||||
|
|
||||||
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
||||||
|
|
||||||
public static final int EXIT_SUCCESS = 0;
|
public static final int EXIT_SUCCESS = 0;
|
||||||
public static final int EXIT_FAILURE = 1;
|
public static final int EXIT_FAILURE = 1;
|
||||||
|
|
||||||
@@ -31,8 +35,8 @@ public abstract class ProjectConstants {
|
|||||||
|
|
||||||
public static final float OVERSCAN;
|
public static final float OVERSCAN;
|
||||||
|
|
||||||
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.,:;!?";
|
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||||||
|
|
||||||
static{
|
static{
|
||||||
OVERSCAN = Ouya.runningOnOuya ? 0.9f : 1.0f;
|
OVERSCAN = Ouya.runningOnOuya ? 0.9f : 1.0f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user