Added state transitions with Universal Tween Library.
This commit is contained in:
@@ -29,13 +29,24 @@ 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.TweenEquation;
|
||||||
|
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;
|
||||||
import com.badlogic.gdx.Gdx;
|
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.Color;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
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.Sprite;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,12 +104,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 +152,65 @@ 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()/*.setToaster(toaster)*/;
|
||||||
//robotThread = RobotControlThread.getInstance().setToaster(toaster);
|
//robotThread = RobotControlThread.getInstance().setToaster(toaster);
|
||||||
|
|
||||||
serviceDiscoveryThread.start();
|
serviceDiscoveryThread.start();
|
||||||
videoThread.start();
|
videoThread.start();
|
||||||
videoThread.startStreaming();
|
videoThread.startStreaming();
|
||||||
videoThread.addNetworkConnectionListener(this);
|
videoThread.addNetworkConnectionListener(this);
|
||||||
//robotThread.start();
|
//robotThread.start();
|
||||||
|
|
||||||
// Set the current and next states.
|
// Set the current and next states.
|
||||||
currState = game_states_t.MAIN_MENU;
|
currState = game_states_t.MAIN_MENU;
|
||||||
nextState = null;
|
nextState = null;
|
||||||
this.setScreen(states[currState.getValue()]);
|
this.setScreen(states[currState.getValue()]);
|
||||||
states[currState.getValue()].onStateSet();
|
states[currState.getValue()].onStateSet();
|
||||||
|
|
||||||
// Set initial input handlers.
|
// Prepare the fadeToBlack sprite;
|
||||||
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
|
||||||
Controllers.addListener(states[currState.getValue()]);
|
pixmap.setColor(0, 0, 0, 1);
|
||||||
|
pixmap.fill();
|
||||||
|
fadeTexture = new Texture(pixmap);
|
||||||
|
pixmap.dispose();
|
||||||
|
|
||||||
// Anything else.
|
alpha = new MutableFloat(0.0f);
|
||||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
|
||||||
Gdx.app.setLogLevel(Application.LOG_NONE);
|
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);
|
||||||
|
|
||||||
|
//batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(){
|
public void render(){
|
||||||
@@ -186,18 +220,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,6 +287,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
public void dispose(){
|
public void dispose(){
|
||||||
// Finish network threads.
|
// Finish network threads.
|
||||||
videoThread.finish();
|
videoThread.finish();
|
||||||
|
fadeTexture.dispose();
|
||||||
|
|
||||||
// Dispose graphic objects.
|
// Dispose graphic objects.
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,6 +18,7 @@ package ve.ucv.ciens.ccg.nxtar.states;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
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 ve.ucv.ciens.ccg.nxtar.exceptions.ImageTooBigException;
|
import ve.ucv.ciens.ccg.nxtar.exceptions.ImageTooBigException;
|
||||||
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;
|
||||||
@@ -302,7 +303,7 @@ public class InGameState extends BaseState{
|
|||||||
@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.
|
core.nextState = game_states_t.MAIN_MENU;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -65,7 +65,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{
|
||||||
|
|||||||
@@ -62,7 +62,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{
|
||||||
|
|||||||
Reference in New Issue
Block a user