Some refactorings and touch ups.

This commit is contained in:
2014-05-09 11:30:45 -04:30
parent e82d49f1f1
commit 167b5d644b
2 changed files with 42 additions and 18 deletions

View File

@@ -39,12 +39,14 @@ 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.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;
import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture; 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.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
/** /**
* <p>Core of the application.</p> * <p>Core of the application.</p>
@@ -156,13 +158,17 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
Controllers.addListener(state); Controllers.addListener(state);
} }
// Set up fields. // Set up rendering fields and settings.
batch = new SpriteBatch(); batch = new SpriteBatch();
batch.enableBlending();
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
ShaderProgram.pedantic = false;
// Set up the overlay font.
if(ProjectConstants.DEBUG){ if(ProjectConstants.DEBUG){
// Set up the overlay font.
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10; fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10; fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
@@ -317,6 +323,9 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
} }
} }
// TODO: Disable start game button until camera has been sucessfully calibrated.
// TODO: Add calibration listener callback.
@Override @Override
public synchronized void networkStreamConnected(String streamName){ public synchronized void networkStreamConnected(String streamName){
Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected."); Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected.");

View File

@@ -57,7 +57,7 @@ public class InGameState extends BaseState{
private NxtARCore core; private NxtARCore core;
// Background related fields. // Background related fields.
private float u_scaling[]; private float uScaling[];
protected Sprite background; protected Sprite background;
private Texture backgroundTexture; private Texture backgroundTexture;
private ShaderProgram backgroundShader; private ShaderProgram backgroundShader;
@@ -164,9 +164,9 @@ public class InGameState extends BaseState{
backgroundShader = null; backgroundShader = null;
} }
u_scaling = new float[2]; uScaling = new float[2];
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f; uScaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f; uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
// Set up the 3D rendering. // Set up the 3D rendering.
frameBuffer = null; frameBuffer = null;
@@ -184,8 +184,6 @@ public class InGameState extends BaseState{
Gdx.app.error(TAG, CLASS_NAME + ".InGameState(): " + meshShader.getLog()); Gdx.app.error(TAG, CLASS_NAME + ".InGameState(): " + meshShader.getLog());
Gdx.app.exit(); Gdx.app.exit();
} }
// TODO: Move this line to core.
ShaderProgram.pedantic = false;
// Set up Artemis. // Set up Artemis.
gameWorld = new World(); gameWorld = new World();
@@ -212,7 +210,7 @@ public class InGameState extends BaseState{
core.batch.begin();{ core.batch.begin();{
if(backgroundShader != null){ if(backgroundShader != null){
core.batch.setShader(backgroundShader); core.batch.setShader(backgroundShader);
backgroundShader.setUniform2fv("u_scaling", u_scaling, 0, 2); backgroundShader.setUniform2fv("u_scaling", uScaling, 0, 2);
} }
background.draw(core.batch); background.draw(core.batch);
if(backgroundShader != null) core.batch.setShader(null); if(backgroundShader != null) core.batch.setShader(null);
@@ -319,9 +317,6 @@ public class InGameState extends BaseState{
} }
// Render the video frame and the frame buffer. // Render the video frame and the frame buffer.
// TODO: Enable blending only once in core.
core.batch.enableBlending();
core.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
core.batch.begin();{ core.batch.begin();{
renderableVideoFrame.draw(core.batch); renderableVideoFrame.draw(core.batch);
frameBufferSprite.draw(core.batch); frameBufferSprite.draw(core.batch);
@@ -540,9 +535,14 @@ public class InGameState extends BaseState{
event.setPower((byte)0x00); event.setPower((byte)0x00);
queue.addEvent(event); queue.addEvent(event);
} }
}else{
// TODO: Send input to the input handler system.
} }
return true;
} }
return true;
return false;
} }
@Override @Override
@@ -646,9 +646,14 @@ public class InGameState extends BaseState{
motorButtonsPointers[6] = -1; motorButtonsPointers[6] = -1;
motorButtonsTouched[6] = false; motorButtonsTouched[6] = false;
}else{
// TODO: Pass input to the input handler system.
} }
return true;
} }
return true;
return false;
} }
@Override @Override
@@ -749,18 +754,23 @@ public class InGameState extends BaseState{
motorButtonsPointers[6] = -1; motorButtonsPointers[6] = -1;
motorButtonsTouched[6] = false; motorButtonsTouched[6] = false;
}else{
// TODO: Pass input to the input handler system.
} }
return true;
} }
return true;
return false;
} }
@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; core.nextState = game_states_t.MAIN_MENU;
return true; return true;
} }
return false; return false;
} }
@@ -772,7 +782,7 @@ public class InGameState extends BaseState{
public boolean buttonDown(Controller controller, int buttonCode){ public boolean buttonDown(Controller controller, int buttonCode){
MotorEvent event; MotorEvent event;
if(stateActive /*&& Ouya.runningOnOuya*/){ if(stateActive){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode)); Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
if(buttonCode == Ouya.BUTTON_L1){ if(buttonCode == Ouya.BUTTON_L1){
@@ -842,6 +852,8 @@ public class InGameState extends BaseState{
event.setMotor(motor_t.RECENTER); event.setMotor(motor_t.RECENTER);
event.setPower((byte)0x00); event.setPower((byte)0x00);
queue.addEvent(event); queue.addEvent(event);
}else{
// TODO: Pass input to the input handler system.
} }
return true; return true;
@@ -854,7 +866,7 @@ public class InGameState extends BaseState{
public boolean buttonUp(Controller controller, int buttonCode){ public boolean buttonUp(Controller controller, int buttonCode){
MotorEvent event; MotorEvent event;
if(stateActive /*&& Ouya.runningOnOuya*/){ if(stateActive){
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode)); Gdx.app.log(TAG, CLASS_NAME + ".buttonDown() :: " + controller.getName() + " :: " + Integer.toString(buttonCode));
if(buttonCode == Ouya.BUTTON_L1){ if(buttonCode == Ouya.BUTTON_L1){
@@ -917,6 +929,8 @@ public class InGameState extends BaseState{
}else if(buttonCode == Ouya.BUTTON_Y){ }else if(buttonCode == Ouya.BUTTON_Y){
motorGamepadButtonPressed[6] = false; motorGamepadButtonPressed[6] = false;
}else{
// TODO: Pass input to the input handler system.
} }
return true; return true;
@@ -927,6 +941,7 @@ public class InGameState extends BaseState{
@Override @Override
public boolean axisMoved(Controller controller, int axisCode, float value){ public boolean axisMoved(Controller controller, int axisCode, float value){
// TODO: Pass input to the input handler system.
return false; return false;
} }
} }