Assorted fixes for OUYA.

This commit is contained in:
2014-06-26 18:25:28 -04:30
parent a9285a684f
commit 53ae001e59
10 changed files with 159 additions and 105 deletions

View File

@@ -32,7 +32,6 @@ import com.artemis.EntitySystem;
import com.artemis.World;
import com.artemis.managers.GroupManager;
import com.artemis.utils.ImmutableBag;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.utils.Disposable;
@@ -148,7 +147,7 @@ public abstract class ScenarioGlobals{
playerSystem.setCore(core);
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new RobotArmPositioningSystem(), Ouya.runningOnOuya);
gameWorld.setSystem(new RobotArmPositioningSystem());
gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem());
gameWorld.setSystem(new CollisionDetectionSystem());

View File

@@ -22,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
@@ -72,7 +73,10 @@ public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS;
fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
if(!Ouya.runningOnOuya)
fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
else
fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
@@ -122,6 +126,9 @@ public class BombGameAutomaticActionSummaryOverlay extends SummaryOverlayBase{
font.draw(batch, String.format("Combination bombs: %d", bombGameSummary.getNumCombinationBombs()), combinationX, combinationY);
font.draw(batch, String.format("Wire bombs: %d", bombGameSummary.getNumWireBombs()), wireX, wireY);
titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
if(!Ouya.runningOnOuya)
titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
else
titleFont.draw(batch, "Summary", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}
}

View File

@@ -20,6 +20,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
@@ -70,7 +71,10 @@ public class BombGameInstructionsOverlay extends HintsOverlayBase {
fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS;
fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
if(!Ouya.runningOnOuya)
fontParameters.size = (int)((float)ProjectConstants.MENU_BUTTON_FONT_SIZE * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
else
fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
@@ -115,6 +119,9 @@ public class BombGameInstructionsOverlay extends HintsOverlayBase {
font.draw(batch, "Blue, red, gray and green", combinationX, combinationY);
font.draw(batch, "Cut the blue wire.", wireX, wireY);
titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
if(!Ouya.runningOnOuya)
titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleHeight - 10);
else
titleFont.draw(batch, "Instructions", -(titleWidth / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}
}

View File

@@ -22,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
@@ -44,7 +45,10 @@ public class BombGameScenarioEndingOverlay extends SummaryOverlayBase {
fontParameters = new FreeTypeFontParameter();
fontParameters.characters = ProjectConstants.FONT_CHARS;
fontParameters.size = (int)(65.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
if(!Ouya.runningOnOuya)
fontParameters.size = (int)(65.0f * ((float)Gdx.graphics.getWidth() / CANNONICAL_SCREEN_WIDTH));
else
fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
fontParameters.flip = false;
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
@@ -96,6 +100,10 @@ public class BombGameScenarioEndingOverlay extends SummaryOverlayBase {
else
title = "Game Over";
titleBounds = titleFont.getBounds(title);
titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleBounds.height - 10);
if(!Ouya.runningOnOuya)
titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - titleBounds.height - 10);
else
titleFont.draw(batch, title, -(titleBounds.width / 2), (Utils.getScreenHeightWithOverscan() / 2) - 10);
}
}

View File

@@ -136,6 +136,7 @@ public class AutomaticActionSummaryState extends BaseState{
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false;
}else{
ouyaOButtonTexture = null;

View File

@@ -57,6 +57,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
public class InGameState extends BaseState{
private static final String TAG = "IN_GAME_STATE";
@@ -309,104 +310,108 @@ public class InGameState extends BaseState{
// If a valid frame was fetched.
if(data != null && data.outFrame != null){
// Set the camera to the correct projection.
focalPointX = core.cvProc.getFocalPointX();
focalPointY = core.cvProc.getFocalPointY();
cameraCenterX = core.cvProc.getCameraCenterX();
cameraCenterY = core.cvProc.getCameraCenterY();
perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY, NEAR, FAR, w, h);
perspectiveCamera.update(perspectiveCamera.projection);
try{
// Set the camera to the correct projection.
focalPointX = core.cvProc.getFocalPointX();
focalPointY = core.cvProc.getFocalPointY();
cameraCenterX = core.cvProc.getCameraCenterX();
cameraCenterY = core.cvProc.getCameraCenterY();
perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY, NEAR, FAR, w, h);
perspectiveCamera.update(perspectiveCamera.projection);
// Update the game state.
if(controlMode == robot_control_mode_t.ARM_CONTROL)
gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
else
gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions();
// Update the game state.
if(controlMode == robot_control_mode_t.ARM_CONTROL || Ouya.runningOnOuya)
gameWorld.getSystem(CollisionDetectionSystem.class).enableCollisions();
else
gameWorld.getSystem(CollisionDetectionSystem.class).disableCollisions();
gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
gameWorld.process();
gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
gameWorld.process();
// Decode the video frame.
videoFrame = new Pixmap(data.outFrame, 0, w * h);
videoFrameTexture = new Texture(videoFrame);
videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
videoFrame.dispose();
// Decode the video frame.
videoFrame = new Pixmap(data.outFrame, 0, w * h);
videoFrameTexture = new Texture(videoFrame);
videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
videoFrame.dispose();
// Convert the decoded frame into a renderable texture.
region = new TextureRegion(videoFrameTexture, 0, 0, w, h);
if(renderableVideoFrame == null)
renderableVideoFrame = new Sprite(region);
else
renderableVideoFrame.setRegion(region);
renderableVideoFrame.setOrigin(renderableVideoFrame.getWidth() / 2, renderableVideoFrame.getHeight() / 2);
renderableVideoFrame.setPosition(0, 0);
// Convert the decoded frame into a renderable texture.
region = new TextureRegion(videoFrameTexture, 0, 0, w, h);
if(renderableVideoFrame == null)
renderableVideoFrame = new Sprite(region);
else
renderableVideoFrame.setRegion(region);
renderableVideoFrame.setOrigin(renderableVideoFrame.getWidth() / 2, renderableVideoFrame.getHeight() / 2);
renderableVideoFrame.setPosition(0, 0);
// Set the 3D frame buffer for rendering.
frameBuffer.begin();{
// Set OpenGL state.
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);
// Set the 3D frame buffer for rendering.
frameBuffer.begin();{
// Set OpenGL state.
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);
// Call rendering systems.
markerRenderingSystem.begin(perspectiveCamera);
markerRenderingSystem.process();
markerRenderingSystem.end();
// Call rendering systems.
markerRenderingSystem.begin(perspectiveCamera);
markerRenderingSystem.process();
markerRenderingSystem.end();
if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
objectRenderingSystem.begin(perspectiveCamera);
objectRenderingSystem.process();
objectRenderingSystem.end();
if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){
objectRenderingSystem.begin(perspectiveCamera);
objectRenderingSystem.process();
objectRenderingSystem.end();
}
}frameBuffer.end();
// Set the frame buffer object texture to a renderable sprite.
region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
region.flip(false, true);
if(frameBufferSprite == null)
frameBufferSprite = new Sprite(region);
else
frameBufferSprite.setRegion(region);
frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
frameBufferSprite.setPosition(0, 0);
// Set the position and orientation of the renderable video frame and the frame buffer.
if(!Ouya.runningOnOuya){
renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
renderableVideoFrame.rotate90(true);
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, 0.5f - renderableVideoFrame.getHeight());
frameBufferSprite.setSize(1.0f, frameBufferSprite.getHeight() / frameBufferSprite.getWidth() );
frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
}else{
float xSize = Gdx.graphics.getHeight() * (w / h);
renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
renderableVideoFrame.rotate90(true);
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
}
}frameBuffer.end();
// Set the frame buffer object texture to a renderable sprite.
region = new TextureRegion(frameBuffer.getColorBufferTexture(), 0, 0, frameBuffer.getWidth(), frameBuffer.getHeight());
region.flip(false, true);
if(frameBufferSprite == null)
frameBufferSprite = new Sprite(region);
else
frameBufferSprite.setRegion(region);
frameBufferSprite.setOrigin(frameBufferSprite.getWidth() / 2, frameBufferSprite.getHeight() / 2);
frameBufferSprite.setPosition(0, 0);
// Set the correct camera for the device.
if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
}else{
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
}
// Set the position and orientation of the renderable video frame and the frame buffer.
if(!Ouya.runningOnOuya){
renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
renderableVideoFrame.rotate90(true);
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, 0.5f - renderableVideoFrame.getHeight());
// Render the video frame and the frame buffer.
core.batch.begin();{
renderableVideoFrame.draw(core.batch);
frameBufferSprite.draw(core.batch);
}core.batch.end();
frameBufferSprite.setSize(1.0f, frameBufferSprite.getHeight() / frameBufferSprite.getWidth() );
frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, 0.5f - frameBufferSprite.getHeight());
}else{
float xSize = Gdx.graphics.getHeight() * (w / h);
renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
renderableVideoFrame.rotate90(true);
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
frameBufferSprite.setSize(xSize * ProjectConstants.OVERSCAN, Utils.getScreenHeightWithOverscan());
frameBufferSprite.rotate90(true);
frameBufferSprite.translate(-frameBufferSprite.getWidth() / 2, -frameBufferSprite.getHeight() / 2);
// Clear the video frame from memory.
videoFrameTexture.dispose();
}catch(GdxRuntimeException e){
Gdx.app.error(TAG, CLASS_NAME + ".render(): Runtime exception caught: ", e);
}
// Set the correct camera for the device.
if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
}else{
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
}
// Render the video frame and the frame buffer.
core.batch.begin();{
renderableVideoFrame.draw(core.batch);
frameBufferSprite.draw(core.batch);
}core.batch.end();
// Clear the video frame from memory.
videoFrameTexture.dispose();
}
// Render the interface buttons.

View File

@@ -133,6 +133,7 @@ public class InstructionsState extends BaseState {
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false;
}else{
ouyaOButtonTexture = null;

View File

@@ -150,10 +150,10 @@ public class OuyaMainMenuState extends MainMenuStateBase{
}
}else if(buttonCode == Ouya.BUTTON_DPAD_UP){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
}else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
}
return true;
@@ -189,4 +189,21 @@ public class OuyaMainMenuState extends MainMenuStateBase{
return false;
}
}
@Override
public boolean axisMoved(Controller controller, int axisCode, float value){
if(Math.abs(value) > 0.99f){
if(axisCode == Ouya.AXIS_LEFT_Y && value < 0.0f){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
}else if(axisCode == Ouya.AXIS_LEFT_Y && value >= 0.0f){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
}
return true;
}
return false;
}
}

View File

@@ -136,6 +136,7 @@ public class ScenarioEndSummaryState extends BaseState {
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
ouyaOButton = new Sprite(ouyaOButtonTexture);
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
ouyaOButton.setPosition(continueButton.getX() - ouyaOButton.getWidth() - 20, continueButton.getY() + (ouyaOButton.getHeight() / 2));
oButtonPressed = false;
}else{
ouyaOButtonTexture = null;

View File

@@ -82,9 +82,7 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
}else autoMove(geometry, auto, collision);
input = null;
}else if(input instanceof GamepadUserInput){
tempGP = (GamepadUserInput) input;
@@ -92,18 +90,22 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
if(!tempGP.oButton){
geometry.position.x += -tempGP.axisLeftY * STEP_SIZE;
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
if(Math.abs(tempGP.axisLeftX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisLeftY) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisRightX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisRightY) < Ouya.STICK_DEADZONE)
if(Math.abs(tempGP.axisLeftX) < Ouya.STICK_DEADZONE && Math.abs(tempGP.axisLeftY) < Ouya.STICK_DEADZONE)
input = null;
else
input = (UserInput)tempGP;
}else{
endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
auto.startPoint.set(geometry.position);
auto.endPoint.set(endPoint);
auto.moving = true;
auto.forward = true;
input = null;
}
}else autoMove(geometry, auto, collision);
}else{
autoMove(geometry, auto, collision);
input = null;
}
}else if(input instanceof KeyboardUserInput){
tempKey = (KeyboardUserInput) input;
@@ -114,20 +116,26 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f;
geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
if(!tempKey.keyUp && !tempKey.keyUp && !tempKey.keyUp && !tempKey.keyUp)
input = null;
else
input = (UserInput)tempKey;
}else{
endPoint = new Vector3(geometry.position.x, geometry.position.y, MAX_Z);
auto.startPoint.set(geometry.position);
auto.endPoint.set(endPoint);
auto.moving = true;
auto.forward = true;
input = null;
}
}else autoMove(geometry, auto, collision);
input = null;
}else{
autoMove(geometry, auto, collision);
input = null;
}
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
}
}
private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){