Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
d481df0f96 | |||
1e2de5ee55 | |||
a37ff0fba5 | |||
ebb943925f | |||
ae93dca1b9 | |||
ddbadba3ea | |||
28be9c8a81 | |||
8ed8be0a29 | |||
c7ee0e0af6 |
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
NxtAR-core
|
||||
==========
|
||||
|
||||
Modulo 2 de mi trabajo especial de grado.
|
@@ -5,7 +5,7 @@ import java.io.Serializable;
|
||||
public class MotorEvent implements Serializable{
|
||||
private static final long serialVersionUID = 9989L;
|
||||
|
||||
public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC};
|
||||
public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC, RECENTER};
|
||||
|
||||
private motor_t motor;
|
||||
private byte power;
|
||||
|
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtar;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor;
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.MulticastEnabler;
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener;
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.Toaster;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
|
||||
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
|
||||
@@ -75,10 +77,12 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
return this.value;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The current application state.
|
||||
*/
|
||||
private game_states_t currState;
|
||||
|
||||
/**
|
||||
* <p>The state to change to.</p>
|
||||
* <p> Usually null. A state change is scheduled by setting this field to a {@link game_states_t} value.</p>
|
||||
@@ -90,6 +94,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
|
||||
// Assorted fields.
|
||||
public SpriteBatch batch;
|
||||
public CVProcessor cvProc;
|
||||
private Toaster toaster;
|
||||
|
||||
// Networking related fields.
|
||||
@@ -98,6 +103,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
private ServiceDiscoveryThread serviceDiscoveryThread;
|
||||
private VideoStreamingThread videoThread;
|
||||
private RobotControlThread robotThread;
|
||||
private SensorReportThread sensorThread;
|
||||
|
||||
// Overlays.
|
||||
private OrthographicCamera pixelPerfectCamera;
|
||||
@@ -130,13 +136,22 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement MulticastEnabler. Quitting.");
|
||||
Gdx.app.exit();
|
||||
}
|
||||
|
||||
try{
|
||||
this.cvProc = (CVProcessor)concreteApp;
|
||||
}catch(ClassCastException cc){
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the CVProcessor interface. Quitting.");
|
||||
Gdx.app.exit();
|
||||
}
|
||||
}
|
||||
|
||||
public void create(){
|
||||
// Create the state objects.
|
||||
states = new BaseState[3];
|
||||
if(Ouya.runningOnOuya)states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
|
||||
else states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
|
||||
if(Ouya.runningOnOuya)
|
||||
states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
|
||||
else
|
||||
states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
|
||||
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
|
||||
states[game_states_t.PAUSED.getValue()] = new PauseState(this);
|
||||
|
||||
@@ -170,6 +185,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
||||
videoThread = VideoStreamingThread.getInstance();
|
||||
robotThread = RobotControlThread.getInstance();
|
||||
sensorThread = SensorReportThread.getInstance();
|
||||
|
||||
serviceDiscoveryThread.start();
|
||||
|
||||
@@ -180,6 +196,9 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
robotThread.addNetworkConnectionListener(this);
|
||||
robotThread.start();
|
||||
|
||||
sensorThread.addNetworkConnectionListener(this);
|
||||
sensorThread.start();
|
||||
|
||||
// Set the current and next states.
|
||||
currState = game_states_t.MAIN_MENU;
|
||||
nextState = null;
|
||||
@@ -204,9 +223,9 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
Controllers.addListener(states[currState.getValue()]);
|
||||
|
||||
// Anything else.
|
||||
Gdx.app.setLogLevel(Application.LOG_INFO);
|
||||
//Gdx.app.setLogLevel(Application.LOG_INFO);
|
||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
//Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||
Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||
}
|
||||
|
||||
public void render(){
|
||||
@@ -266,6 +285,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
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);
|
||||
}batch.end();
|
||||
}
|
||||
}
|
||||
@@ -300,10 +320,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
|
||||
@Override
|
||||
public synchronized void networkStreamConnected(String streamName){
|
||||
//if(streamName.equals(VideoStreamingThread.THREAD_NAME) || streamName.equals(RobotControlThread.THREAD_NAME))
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected.");
|
||||
connections += 1;
|
||||
if(connections >= 2){
|
||||
|
||||
if(connections >= 3){
|
||||
Gdx.app.debug(TAG, CLASS_NAME + ".networkStreamConnected() :: Stopping service broadcast.");
|
||||
serviceDiscoveryThread.finish();
|
||||
mcastEnabler.disableMulticast();
|
||||
|
26
src/ve/ucv/ciens/ccg/nxtar/interfaces/CVProcessor.java
Normal file
26
src/ve/ucv/ciens/ccg/nxtar/interfaces/CVProcessor.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.interfaces;
|
||||
|
||||
public interface CVProcessor {
|
||||
public class CVData{
|
||||
public byte[] outFrame;
|
||||
public int[] markerCodes;
|
||||
// TODO: Add marker location data.
|
||||
}
|
||||
|
||||
public CVData processFrame(byte[] frame, int w, int h);
|
||||
}
|
@@ -96,6 +96,7 @@ public class RobotControlThread extends Thread {
|
||||
|
||||
try{
|
||||
client = server.accept();
|
||||
client.setTcpNoDelay(true);
|
||||
if(netListener != null) netListener.networkStreamConnected(THREAD_NAME);
|
||||
os = new ObjectOutputStream(client.getOutputStream());
|
||||
is = new ObjectInputStream(client.getInputStream());
|
||||
|
@@ -15,10 +15,44 @@
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtar.network;
|
||||
|
||||
import java.io.IOException;
|
||||
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.utils.ProjectConstants;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
public class SensorReportThread extends Thread {
|
||||
public static final String THREAD_NAME = "SensorReportThread";
|
||||
private static final String TAG = "NXTAR_CORE_ROBOTTHREAD";
|
||||
private static final String CLASS_NAME = SensorReportThread.class.getSimpleName();
|
||||
|
||||
private NetworkConnectionListener netListener;
|
||||
private ServerSocket server;
|
||||
private Socket client;
|
||||
private Object pauseMonitor;
|
||||
private boolean paused;
|
||||
private boolean done;
|
||||
private InputStream reader;
|
||||
private Byte lightReading;
|
||||
|
||||
private SensorReportThread(){
|
||||
paused = false;
|
||||
done = false;
|
||||
netListener = null;
|
||||
pauseMonitor = null;
|
||||
client = null;
|
||||
lightReading = -1;
|
||||
|
||||
try{
|
||||
server = new ServerSocket(ProjectConstants.SENSOR_REPORT_PORT);
|
||||
}catch(IOException io){
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".RobotControlThread() :: Error creating server: " + io.getMessage(), io);
|
||||
server = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SingletonHolder{
|
||||
@@ -29,8 +63,64 @@ public class SensorReportThread extends Thread {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public void addNetworkConnectionListener(NetworkConnectionListener listener){
|
||||
netListener = listener;
|
||||
}
|
||||
|
||||
public void pauseThread(){
|
||||
synchronized(pauseMonitor){
|
||||
paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void resumeThread(){
|
||||
synchronized(pauseMonitor){
|
||||
paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void finish(){
|
||||
done = true;
|
||||
}
|
||||
|
||||
public byte getLightSensorReading(){
|
||||
byte data;
|
||||
|
||||
synchronized(lightReading){
|
||||
data = lightReading.byteValue();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
byte[] reading = new byte[1];
|
||||
|
||||
try{
|
||||
client = server.accept();
|
||||
client.setTcpNoDelay(true);
|
||||
if(netListener != null) netListener.networkStreamConnected(THREAD_NAME);
|
||||
reader = client.getInputStream();
|
||||
|
||||
}catch(IOException io){
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".run() :: Error accepting client: " + io.getMessage(), io);
|
||||
return;
|
||||
}
|
||||
|
||||
while(!paused){
|
||||
if(done) break;
|
||||
|
||||
try{
|
||||
reader.read(reading);
|
||||
}catch(IOException io){
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".run() :: IOException during sensor read: " + io.getMessage(), io);
|
||||
break;
|
||||
}
|
||||
|
||||
synchronized (lightReading) {
|
||||
lightReading = reading[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ 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.game_states_t;
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor.CVData;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||
@@ -74,6 +75,7 @@ public class InGameState extends BaseState{
|
||||
private Sprite motorD;
|
||||
private Sprite headA;
|
||||
private Sprite headB;
|
||||
private Sprite headC;
|
||||
|
||||
// Button touch helper fields.
|
||||
private Vector3 win2world;
|
||||
@@ -81,7 +83,6 @@ public class InGameState extends BaseState{
|
||||
private boolean[] motorButtonsTouched;
|
||||
private int[] motorButtonsPointers;
|
||||
private boolean[] motorGamepadButtonPressed;
|
||||
private boolean[] axisStopSent;
|
||||
|
||||
// Monitors.
|
||||
private VideoFrameMonitor frameMonitor;
|
||||
@@ -105,31 +106,32 @@ public class InGameState extends BaseState{
|
||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
touchPointWorldCoords = new Vector2();
|
||||
|
||||
motorButtonsTouched = new boolean[6];
|
||||
motorButtonsTouched = new boolean[7];
|
||||
motorButtonsTouched[0] = false;
|
||||
motorButtonsTouched[1] = false;
|
||||
motorButtonsTouched[2] = false;
|
||||
motorButtonsTouched[3] = false;
|
||||
motorButtonsTouched[4] = false;
|
||||
motorButtonsTouched[5] = false;
|
||||
motorButtonsTouched[6] = false;
|
||||
|
||||
motorButtonsPointers = new int[6];
|
||||
motorButtonsPointers = new int[7];
|
||||
motorButtonsPointers[0] = -1;
|
||||
motorButtonsPointers[1] = -1;
|
||||
motorButtonsPointers[2] = -1;
|
||||
motorButtonsPointers[3] = -1;
|
||||
motorButtonsPointers[4] = -1;
|
||||
motorButtonsPointers[5] = -1;
|
||||
motorButtonsPointers[6] = -1;
|
||||
|
||||
motorGamepadButtonPressed = new boolean[2];
|
||||
motorGamepadButtonPressed = new boolean[7];
|
||||
motorGamepadButtonPressed[0] = false;
|
||||
motorGamepadButtonPressed[1] = false;
|
||||
|
||||
axisStopSent = new boolean[4];
|
||||
axisStopSent[0] = true;
|
||||
axisStopSent[1] = true;
|
||||
axisStopSent[2] = true;
|
||||
axisStopSent[3] = true;
|
||||
motorGamepadButtonPressed[2] = false;
|
||||
motorGamepadButtonPressed[3] = false;
|
||||
motorGamepadButtonPressed[4] = false;
|
||||
motorGamepadButtonPressed[5] = false;
|
||||
motorGamepadButtonPressed[6] = false;
|
||||
|
||||
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
||||
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
||||
@@ -152,9 +154,11 @@ public class InGameState extends BaseState{
|
||||
|
||||
@Override
|
||||
public void render(float delta){
|
||||
int fW, fH;
|
||||
byte[] frame;
|
||||
byte[] prevFrame = null;
|
||||
Size dimensions = null;
|
||||
CVData data;
|
||||
|
||||
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
@@ -170,9 +174,20 @@ public class InGameState extends BaseState{
|
||||
}core.batch.end();
|
||||
|
||||
frame = frameMonitor.getCurrentFrame();
|
||||
if(frame != null && !Arrays.equals(frame, prevFrame)){
|
||||
fW = frameMonitor.getFrameDimensions().getWidth();
|
||||
fH = frameMonitor.getFrameDimensions().getHeight();
|
||||
|
||||
data = core.cvProc.processFrame(frame, fW, fH);
|
||||
|
||||
if(data != null){
|
||||
for(int i = 0; i < data.markerCodes.length; i++){
|
||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".render(): Marker code[%d] = %d", i, data.markerCodes[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if(data != null && data.outFrame != null && !Arrays.equals(frame, prevFrame)){
|
||||
dimensions = frameMonitor.getFrameDimensions();
|
||||
videoFrame = new Pixmap(frame, 0, dimensions.getWidth() * dimensions.getHeight());
|
||||
videoFrame = new Pixmap(data.outFrame, 0, dimensions.getWidth() * dimensions.getHeight());
|
||||
videoFrameTexture = new Texture(videoFrame);
|
||||
videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||
videoFrame.dispose();
|
||||
@@ -213,6 +228,7 @@ public class InGameState extends BaseState{
|
||||
motorD.draw(core.batch);
|
||||
headA.draw(core.batch);
|
||||
headB.draw(core.batch);
|
||||
headC.draw(core.batch);
|
||||
}
|
||||
}core.batch.end();
|
||||
|
||||
@@ -302,6 +318,10 @@ public class InGameState extends BaseState{
|
||||
|
||||
headA.setPosition(-headA.getWidth() - 10, motorA.getY() + (headA.getHeight() / 2));
|
||||
headB.setPosition(10, motorA.getY() + (headA.getHeight() / 2));
|
||||
|
||||
headC = new Sprite(buttonTexture2);
|
||||
headC.setSize(headC.getWidth() * 0.3f, headC.getHeight() * 0.6f);
|
||||
headC.setPosition(-(headC.getWidth() / 2), headA.getY() - headA.getHeight() - 10);
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@@ -327,19 +347,18 @@ public class InGameState extends BaseState{
|
||||
motorButtonsPointers[0] = pointer;
|
||||
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte)100);
|
||||
queue.addEvent(event);
|
||||
|
||||
}else if(motorB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Motor B button pressed");
|
||||
|
||||
|
||||
motorButtonsTouched[1] = true;
|
||||
motorButtonsPointers[1] = pointer;
|
||||
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte)-100);
|
||||
queue.addEvent(event);
|
||||
|
||||
@@ -350,7 +369,7 @@ public class InGameState extends BaseState{
|
||||
motorButtonsPointers[2] = pointer;
|
||||
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte)-100);
|
||||
queue.addEvent(event);
|
||||
|
||||
@@ -361,7 +380,7 @@ public class InGameState extends BaseState{
|
||||
motorButtonsPointers[3] = pointer;
|
||||
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte)100);
|
||||
queue.addEvent(event);
|
||||
|
||||
@@ -387,6 +406,18 @@ public class InGameState extends BaseState{
|
||||
event.setPower((byte)40);
|
||||
queue.addEvent(event);
|
||||
|
||||
}else if(headC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Head C button pressed");
|
||||
|
||||
if(!motorButtonsTouched[4] && !motorButtonsTouched[5]){
|
||||
motorButtonsTouched[6] = true;
|
||||
motorButtonsPointers[6] = pointer;
|
||||
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.RECENTER);
|
||||
event.setPower((byte)0x00);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -413,7 +444,7 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte) 0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
@@ -427,7 +458,7 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte) 0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
@@ -441,7 +472,7 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte) 0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
@@ -455,7 +486,7 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte) 0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
@@ -488,6 +519,11 @@ public class InGameState extends BaseState{
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(headC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head C button released");
|
||||
|
||||
motorButtonsPointers[6] = -1;
|
||||
motorButtonsTouched[6] = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -511,7 +547,7 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte) 0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
@@ -525,7 +561,7 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte) 0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
@@ -539,7 +575,7 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte) 0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
@@ -553,13 +589,13 @@ public class InGameState extends BaseState{
|
||||
// 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.setMotor(motor_t.MOTOR_C);
|
||||
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");
|
||||
}else if(pointer == motorButtonsPointers[4] && !headA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Head A button released");
|
||||
|
||||
motorButtonsPointers[4] = -1;
|
||||
motorButtonsTouched[4] = false;
|
||||
@@ -572,8 +608,8 @@ public class InGameState extends BaseState{
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(pointer == motorButtonsPointers[5] && headB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".touchUp() :: Head B button released");
|
||||
}else if(pointer == motorButtonsPointers[5] && !headB.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Head B button released");
|
||||
|
||||
motorButtonsPointers[5] = -1;
|
||||
motorButtonsTouched[5] = false;
|
||||
@@ -586,6 +622,11 @@ public class InGameState extends BaseState{
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(pointer == motorButtonsPointers[6] && !headC.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Head C button released");
|
||||
|
||||
motorButtonsPointers[6] = -1;
|
||||
motorButtonsTouched[6] = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -609,29 +650,76 @@ public class InGameState extends BaseState{
|
||||
public boolean buttonDown(Controller controller, int buttonCode){
|
||||
MotorEvent event;
|
||||
|
||||
if(stateActive && Ouya.runningOnOuya){
|
||||
if(stateActive /*&& Ouya.runningOnOuya*/){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
|
||||
|
||||
if(buttonCode == Ouya.BUTTON_L1){
|
||||
motorGamepadButtonPressed[0] = true;
|
||||
|
||||
if(!motorGamepadButtonPressed[1]){
|
||||
if(!motorGamepadButtonPressed[4]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_B);
|
||||
event.setPower((byte)100);
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte)-100);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_R1){
|
||||
motorGamepadButtonPressed[1] = true;
|
||||
|
||||
if(!motorGamepadButtonPressed[0]){
|
||||
if(!motorGamepadButtonPressed[5]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_B);
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte)-100);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_DPAD_LEFT){
|
||||
motorGamepadButtonPressed[2] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[3]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_B);
|
||||
event.setPower((byte)-40);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_DPAD_RIGHT){
|
||||
motorGamepadButtonPressed[3] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[2]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_B);
|
||||
event.setPower((byte)40);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_L2){
|
||||
motorGamepadButtonPressed[4] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[0]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte)100);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_R2){
|
||||
motorGamepadButtonPressed[5] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[1]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte)100);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_Y){
|
||||
motorGamepadButtonPressed[6] = true;
|
||||
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.RECENTER);
|
||||
event.setPower((byte)0x00);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -644,29 +732,69 @@ public class InGameState extends BaseState{
|
||||
public boolean buttonUp(Controller controller, int buttonCode){
|
||||
MotorEvent event;
|
||||
|
||||
if(stateActive && Ouya.runningOnOuya){
|
||||
if(stateActive /*&& Ouya.runningOnOuya*/){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
|
||||
|
||||
if(buttonCode == Ouya.BUTTON_L1){
|
||||
if(buttonCode == Ouya.BUTTON_L1){
|
||||
motorGamepadButtonPressed[0] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[1]){
|
||||
if(!motorGamepadButtonPressed[4]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte)0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_R1){
|
||||
motorGamepadButtonPressed[1] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[5]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte)0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_DPAD_LEFT){
|
||||
motorGamepadButtonPressed[2] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[3]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_B);
|
||||
event.setPower((byte)0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
}else if(buttonCode == Ouya.BUTTON_DPAD_RIGHT){
|
||||
motorGamepadButtonPressed[3] = false;
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_R1){
|
||||
motorGamepadButtonPressed[1] = false;
|
||||
if(!motorGamepadButtonPressed[2]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_B);
|
||||
event.setPower((byte)0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
}else if(buttonCode == Ouya.BUTTON_L2){
|
||||
motorGamepadButtonPressed[4] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[0]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_B);
|
||||
event.setMotor(motor_t.MOTOR_A);
|
||||
event.setPower((byte)0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_R2){
|
||||
motorGamepadButtonPressed[5] = false;
|
||||
|
||||
if(!motorGamepadButtonPressed[1]){
|
||||
event = new MotorEvent();
|
||||
event.setMotor(motor_t.MOTOR_C);
|
||||
event.setPower((byte)0);
|
||||
queue.addEvent(event);
|
||||
}
|
||||
|
||||
}else if(buttonCode == Ouya.BUTTON_Y){
|
||||
motorGamepadButtonPressed[6] = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -677,59 +805,7 @@ public class InGameState extends BaseState{
|
||||
|
||||
@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;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -749,47 +825,36 @@ public class InGameState extends BaseState{
|
||||
|
||||
@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 povMoved(Controller controller, int povCode,
|
||||
PovDirection value){
|
||||
// TODO Auto-generated method stub
|
||||
public boolean povMoved(Controller controller, int povCode, PovDirection value){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean xSliderMoved(Controller controller, int sliderCode,
|
||||
boolean value){
|
||||
// TODO Auto-generated method stub
|
||||
public boolean xSliderMoved(Controller controller, int sliderCode, boolean value){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ySliderMoved(Controller controller, int sliderCode,
|
||||
boolean value){
|
||||
// TODO Auto-generated method stub
|
||||
public boolean ySliderMoved(Controller controller, int sliderCode, boolean value){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accelerometerMoved(Controller controller,
|
||||
int accelerometerCode, Vector3 value){
|
||||
// TODO Auto-generated method stub
|
||||
public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scrolled(int amount){
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user