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.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.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.controllers.Controllers;
|
||||
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.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.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
/**
|
||||
@@ -93,12 +104,18 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
private VideoStreamingThread videoThread;
|
||||
private RobotControlThread robotThread;
|
||||
|
||||
// Overlay font.
|
||||
// Overlays.
|
||||
private OrthographicCamera pixelPerfectCamera;
|
||||
private float fontX;
|
||||
private float fontY;
|
||||
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>
|
||||
*/
|
||||
@@ -135,8 +152,9 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
// Set up fields.
|
||||
batch = new SpriteBatch();
|
||||
|
||||
if(ProjectConstants.DEBUG)
|
||||
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());{
|
||||
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
|
||||
if(ProjectConstants.DEBUG){
|
||||
// Set up the overlay font.
|
||||
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
||||
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
||||
@@ -170,13 +188,29 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
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);
|
||||
//Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||
|
||||
//batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
public void render(){
|
||||
@@ -186,18 +220,53 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
if(nextState != null){
|
||||
states[currState.getValue()].onStateUnset();
|
||||
|
||||
if(!fadeOut.isStarted()){
|
||||
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());
|
||||
|
||||
if(fadeOut.isFinished()){
|
||||
currState = nextState;
|
||||
nextState = null;
|
||||
|
||||
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){
|
||||
// Draw the FPS overlay.
|
||||
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||
batch.begin();{
|
||||
// Draw the FPS overlay.
|
||||
font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), fontX, fontY);
|
||||
font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), fontX, fontY - font.getCapHeight() - 5);
|
||||
font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), fontX, fontY - (2 * font.getCapHeight()) - 10);
|
||||
@@ -218,6 +287,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
||||
public void dispose(){
|
||||
// Finish network threads.
|
||||
videoThread.finish();
|
||||
fadeTexture.dispose();
|
||||
|
||||
// Dispose graphic objects.
|
||||
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 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.network.monitors.VideoFrameMonitor;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||
@@ -302,7 +303,7 @@ public class InGameState extends BaseState{
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
if(keycode == Input.Keys.BACK){
|
||||
// TODO: Go to pause state.
|
||||
core.nextState = game_states_t.MAIN_MENU;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -65,7 +65,9 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
||||
|
||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||
core.batch.begin();{
|
||||
core.batch.disableBlending();
|
||||
drawBackground(core.batch);
|
||||
core.batch.enableBlending();
|
||||
if(clientConnected){
|
||||
clientConnectedLedOn.draw(core.batch);
|
||||
}else{
|
||||
|
||||
@@ -62,7 +62,10 @@ public class TabletMainMenuState extends MainMenuStateBase{
|
||||
|
||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||
core.batch.begin();{
|
||||
core.batch.disableBlending();
|
||||
drawBackground(core.batch);
|
||||
core.batch.enableBlending();
|
||||
|
||||
if(clientConnected){
|
||||
clientConnectedLedOn.draw(core.batch);
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user