|
|
|
|
@@ -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,48 +152,65 @@ 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());{
|
|
|
|
|
// Set up the overlay font.
|
|
|
|
|
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
|
|
|
|
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
|
|
|
|
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
if(ProjectConstants.DEBUG){
|
|
|
|
|
// Set up the overlay font.
|
|
|
|
|
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
|
|
|
|
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
mcastEnabler.enableMulticast();
|
|
|
|
|
// Start networking.
|
|
|
|
|
mcastEnabler.enableMulticast();
|
|
|
|
|
|
|
|
|
|
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
|
|
|
|
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
|
|
|
|
videoThread = VideoStreamingThread.getInstance()/*.setToaster(toaster)*/;
|
|
|
|
|
//robotThread = RobotControlThread.getInstance().setToaster(toaster);
|
|
|
|
|
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
|
|
|
|
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
|
|
|
|
videoThread = VideoStreamingThread.getInstance()/*.setToaster(toaster)*/;
|
|
|
|
|
//robotThread = RobotControlThread.getInstance().setToaster(toaster);
|
|
|
|
|
|
|
|
|
|
serviceDiscoveryThread.start();
|
|
|
|
|
videoThread.start();
|
|
|
|
|
videoThread.startStreaming();
|
|
|
|
|
videoThread.addNetworkConnectionListener(this);
|
|
|
|
|
//robotThread.start();
|
|
|
|
|
serviceDiscoveryThread.start();
|
|
|
|
|
videoThread.start();
|
|
|
|
|
videoThread.startStreaming();
|
|
|
|
|
videoThread.addNetworkConnectionListener(this);
|
|
|
|
|
//robotThread.start();
|
|
|
|
|
|
|
|
|
|
// Set the current and next states.
|
|
|
|
|
currState = game_states_t.MAIN_MENU;
|
|
|
|
|
nextState = null;
|
|
|
|
|
this.setScreen(states[currState.getValue()]);
|
|
|
|
|
states[currState.getValue()].onStateSet();
|
|
|
|
|
// Set the current and next states.
|
|
|
|
|
currState = game_states_t.MAIN_MENU;
|
|
|
|
|
nextState = null;
|
|
|
|
|
this.setScreen(states[currState.getValue()]);
|
|
|
|
|
states[currState.getValue()].onStateSet();
|
|
|
|
|
|
|
|
|
|
// Set initial input handlers.
|
|
|
|
|
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
|
|
|
|
Controllers.addListener(states[currState.getValue()]);
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
// Anything else.
|
|
|
|
|
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
|
|
|
|
Gdx.app.setLogLevel(Application.LOG_NONE);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
|
|
|
|
|
currState = nextState;
|
|
|
|
|
nextState = null;
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
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){
|
|
|
|
|
// 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();
|
|
|
|
|
|