Bomb game assets loaded with asset manager. Camera calibration is automagic.
This commit is contained in:
@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
|
||||
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
|
||||
import ve.ucv.ciens.ccg.nxtar.states.PauseState;
|
||||
import ve.ucv.ciens.ccg.nxtar.states.TabletMainMenuState;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
|
||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||
import aurelienribon.tweenengine.Tween;
|
||||
import aurelienribon.tweenengine.TweenEquations;
|
||||
@@ -121,7 +122,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
/**
|
||||
* <p>Wrapper around the Operating System methods.</p>
|
||||
*/
|
||||
private ActionResolver osFunction;
|
||||
private ActionResolver actionResolver;
|
||||
|
||||
// Networking related fields.
|
||||
/**
|
||||
@@ -206,10 +207,10 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
|
||||
// Check if the concrete application implements all required interfaces.
|
||||
try{
|
||||
this.osFunction = (ActionResolver)concreteApp;
|
||||
this.actionResolver = (ActionResolver)concreteApp;
|
||||
}catch(ClassCastException cc){
|
||||
Gdx.app.debug(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the Toaster interface. Toasting disabled.");
|
||||
this.osFunction = null;
|
||||
this.actionResolver = null;
|
||||
}
|
||||
|
||||
try{
|
||||
@@ -229,6 +230,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
* sets the application states.</p>
|
||||
*/
|
||||
public void create(){
|
||||
GameSettings.initGameSettings(this);
|
||||
|
||||
// Create the state objects.
|
||||
states = new BaseState[game_states_t.getNumStates()];
|
||||
if(Ouya.runningOnOuya)
|
||||
@@ -268,7 +271,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
}
|
||||
|
||||
// Start networking.
|
||||
osFunction.enableMulticast();
|
||||
actionResolver.enableMulticast();
|
||||
|
||||
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
||||
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
||||
@@ -327,6 +330,10 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
public void render(){
|
||||
super.render();
|
||||
|
||||
// Load the assets.
|
||||
if(!GameSettings.getEntityCreator().areEntitiesCreated())
|
||||
GameSettings.getEntityCreator().updateAssetManager();
|
||||
|
||||
// If the current state set a value for nextState then switch to that state.
|
||||
if(nextState != null){
|
||||
states[currState.getValue()].onStateUnset();
|
||||
@@ -430,6 +437,9 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
font.dispose();
|
||||
}
|
||||
|
||||
if(GameSettings.getEntityCreator() != null)
|
||||
GameSettings.getEntityCreator().dispose();
|
||||
|
||||
// Dispose screens.
|
||||
for(int i = 0; i < states.length; i++){
|
||||
states[i].dispose();
|
||||
@@ -440,29 +450,32 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
; APPLICATION EVENTS LISTENER INTERFACE METHODS ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
// TODO: Disable start game button until camera has been sucessfully calibrated.
|
||||
// TODO: Add calibration listener callback.
|
||||
|
||||
/**
|
||||
* <p>Callback used by the networking threads to notify sucessfull connections
|
||||
* to the application</p>
|
||||
*
|
||||
* @param streamName The name of the thread notifying a connection.
|
||||
*/
|
||||
@Override
|
||||
public synchronized void networkStreamConnected(String streamName){
|
||||
public synchronized void onNetworkStreamConnected(String streamName){
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected.");
|
||||
connections += 1;
|
||||
|
||||
if(connections >= 3){
|
||||
Gdx.app.debug(TAG, CLASS_NAME + ".networkStreamConnected() :: Stopping service broadcast.");
|
||||
serviceDiscoveryThread.finish();
|
||||
osFunction.disableMulticast();
|
||||
osFunction.showShortToast("Client connected");
|
||||
if(actionResolver != null) actionResolver.disableMulticast();
|
||||
if(actionResolver != null) actionResolver.showShortToast("Client connected");
|
||||
((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onClientConnected();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssetsLoaded(){
|
||||
if(actionResolver != null) actionResolver.showShortToast("All assets sucessfully loaded.");
|
||||
((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onAssetsLoaded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraCalibrated(){
|
||||
if(actionResolver != null) actionResolver.showShortToast("Camera successfully calibrated.");
|
||||
((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onCameraCalibrated();
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;
|
||||
; HELPER METHODS ;
|
||||
;;;;;;;;;;;;;;;;;;*/
|
||||
@@ -474,9 +487,9 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
* @param longToast True for a lasting toast. False for a short toast.
|
||||
*/
|
||||
public void toast(String msg, boolean longToast){
|
||||
if(osFunction != null){
|
||||
if(longToast) osFunction.showLongToast(msg);
|
||||
else osFunction.showShortToast(msg);
|
||||
if(actionResolver != null){
|
||||
if(longToast) actionResolver.showLongToast(msg);
|
||||
else actionResolver.showShortToast(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
|
||||
|
||||
import com.artemis.Entity;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g3d.Environment;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
@@ -36,11 +37,9 @@ import com.badlogic.gdx.graphics.g3d.ModelInstance;
|
||||
import com.badlogic.gdx.graphics.g3d.Shader;
|
||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
|
||||
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
|
||||
import com.badlogic.gdx.math.Matrix3;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.badlogic.gdx.utils.UBJsonReader;
|
||||
|
||||
public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
private static final String TAG = "BOMB_ENTITY_CREATOR";
|
||||
@@ -83,7 +82,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
private Model wiresBombModelWire1 = null;
|
||||
private Model wiresBombModelWire2 = null;
|
||||
private Model wiresBombModelWire3 = null;
|
||||
private Model easterEggModel = null;
|
||||
// private Model easterEggModel = null;
|
||||
|
||||
// Collision models.
|
||||
private Model doorCollisionModel = null;
|
||||
@@ -99,11 +98,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
private Model wiresBombCollisionModelWire1 = null;
|
||||
private Model wiresBombCollisionModelWire2 = null;
|
||||
private Model wiresBombCollisionModelWire3 = null;
|
||||
private Model easterEggCollisionModel = null;
|
||||
// private Model easterEggCollisionModel = null;
|
||||
|
||||
public BombGameEntityCreator(){
|
||||
G3dModelLoader loader = new G3dModelLoader(new UBJsonReader());
|
||||
currentBombId = 0;
|
||||
manager = new AssetManager();
|
||||
|
||||
// Create and set the lighting.
|
||||
parameters = new EntityParameters();
|
||||
@@ -121,42 +120,42 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
parameters.shader = shader;
|
||||
|
||||
// Load the render models.
|
||||
doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
|
||||
doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
|
||||
manager.load("models/render_models/bomb_game/door.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/door_frame1.g3db", Model.class);
|
||||
|
||||
combinationBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_body.g3db"));
|
||||
combinationButton1Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_1.g3db"));
|
||||
combinationButton2Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_2.g3db"));
|
||||
combinationButton3Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_3.g3db"));
|
||||
combinationButton4Model = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_3_btn_4.g3db"));
|
||||
manager.load("models/render_models/bomb_game/bomb_3_body.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/bomb_3_btn_1.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/bomb_3_btn_2.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/bomb_3_btn_3.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/bomb_3_btn_4.g3db", Model.class);
|
||||
|
||||
inclinationBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_2_body.g3db"));
|
||||
inclinationBombButtonModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/big_btn.g3db"));
|
||||
manager.load("models/render_models/bomb_game/bomb_2_body.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/big_btn.g3db", Model.class);
|
||||
|
||||
wiresBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
|
||||
wiresBombModelWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
|
||||
wiresBombModelWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
|
||||
wiresBombModelWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
|
||||
// easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
|
||||
manager.load("models/render_models/bomb_game/bomb_1_body.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/cable_1.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/cable_2.g3db", Model.class);
|
||||
manager.load("models/render_models/bomb_game/cable_3.g3db", Model.class);
|
||||
// manager.load("models/render_models/bomb_game/", Model.class);
|
||||
|
||||
// Load the collision models.
|
||||
doorCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_col.g3db"));
|
||||
doorFrameCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_frame1_col.g3db"));
|
||||
manager.load("models/collision_models/bomb_game/door_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);
|
||||
|
||||
combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_body_col.g3db"));
|
||||
combinationButton1CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_1_col.g3db"));
|
||||
combinationButton2CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_2_col.g3db"));
|
||||
combinationButton3CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_3_col.g3db"));
|
||||
combinationButton4CollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_3_btn_4_col.g3db"));
|
||||
manager.load("models/collision_models/bomb_game/bomb_3_body_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/bomb_3_btn_1_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/bomb_3_btn_2_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/bomb_3_btn_3_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/bomb_3_btn_4_col.g3db", Model.class);
|
||||
|
||||
inclinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_2_body_col.g3db"));
|
||||
inclinationBombButtonCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/big_btn_col.g3db"));
|
||||
manager.load("models/collision_models/bomb_game/bomb_2_body_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/big_btn_col.g3db", Model.class);
|
||||
|
||||
wiresBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_1_body_col.g3db"));
|
||||
wiresBombCollisionModelWire1 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_1_col.g3db"));
|
||||
wiresBombCollisionModelWire2 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_2_col.g3db"));
|
||||
wiresBombCollisionModelWire3 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_3_col.g3db"));
|
||||
// easterEggCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
|
||||
manager.load("models/collision_models/bomb_game/bomb_1_body_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/cable_1_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/cable_2_col.g3db", Model.class);
|
||||
manager.load("models/collision_models/bomb_game/cable_3_col.g3db", Model.class);
|
||||
// manager.load("models/collision_models/bomb_game/door.g3db", Model.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,41 +182,14 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
addDoor(parameters);
|
||||
|
||||
// TODO: Add easter egg.
|
||||
|
||||
entitiesCreated = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if(shader != null) shader.dispose();
|
||||
|
||||
// Dispose of the render models.
|
||||
if(doorModel != null) doorModel.dispose();
|
||||
if(doorFrameModel != null) doorFrameModel.dispose();
|
||||
if(combinationBombModel != null) combinationBombModel.dispose();
|
||||
if(combinationButton1Model != null) combinationButton1Model.dispose();
|
||||
if(combinationButton2Model != null) combinationButton2Model.dispose();
|
||||
if(combinationButton3Model != null) combinationButton3Model.dispose();
|
||||
if(combinationButton4Model != null) combinationButton4Model.dispose();
|
||||
if(inclinationBombModel != null) inclinationBombModel.dispose();
|
||||
if(wiresBombModel != null) wiresBombModel.dispose();
|
||||
if(wiresBombModelWire1 != null) wiresBombModelWire1.dispose();
|
||||
if(wiresBombModelWire2 != null) wiresBombModelWire2.dispose();
|
||||
if(wiresBombModelWire3 != null) wiresBombModelWire3.dispose();
|
||||
if(easterEggModel != null) easterEggModel.dispose();
|
||||
|
||||
// Dispose of the collision models.
|
||||
if(doorCollisionModel != null) doorCollisionModel.dispose();
|
||||
if(doorFrameCollisionModel != null) doorFrameCollisionModel.dispose();
|
||||
if(combinationBombCollisionModel != null) combinationBombCollisionModel.dispose();
|
||||
if(combinationButton1CollisionModel != null) combinationButton1CollisionModel.dispose();
|
||||
if(combinationButton2CollisionModel != null) combinationButton2CollisionModel.dispose();
|
||||
if(combinationButton3CollisionModel != null) combinationButton3CollisionModel.dispose();
|
||||
if(combinationButton4CollisionModel != null) combinationButton4CollisionModel.dispose();
|
||||
if(inclinationBombCollisionModel != null) inclinationBombCollisionModel.dispose();
|
||||
if(wiresBombCollisionModel != null) wiresBombCollisionModel.dispose();
|
||||
if(wiresBombCollisionModelWire1 != null) wiresBombCollisionModelWire1.dispose();
|
||||
if(wiresBombCollisionModelWire2 != null) wiresBombCollisionModelWire2.dispose();
|
||||
if(wiresBombCollisionModelWire3 != null) wiresBombCollisionModelWire3.dispose();
|
||||
if(easterEggCollisionModel != null) easterEggCollisionModel.dispose();
|
||||
manager.dispose();
|
||||
}
|
||||
|
||||
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
|
||||
@@ -371,4 +343,61 @@ public class BombGameEntityCreator extends EntityCreatorBase{
|
||||
}
|
||||
thing.addToWorld();
|
||||
}
|
||||
|
||||
private void getModels(){
|
||||
// Load the render models.
|
||||
doorModel = manager.get("models/render_models/bomb_game/door.g3db", Model.class);
|
||||
doorFrameModel = manager.get("models/render_models/bomb_game/door_frame1.g3db", Model.class);
|
||||
|
||||
combinationBombModel = manager.get("models/render_models/bomb_game/bomb_3_body.g3db", Model.class);
|
||||
combinationButton1Model = manager.get("models/render_models/bomb_game/bomb_3_btn_1.g3db", Model.class);
|
||||
combinationButton2Model = manager.get("models/render_models/bomb_game/bomb_3_btn_2.g3db", Model.class);
|
||||
combinationButton3Model = manager.get("models/render_models/bomb_game/bomb_3_btn_3.g3db", Model.class);
|
||||
combinationButton4Model = manager.get("models/render_models/bomb_game/bomb_3_btn_4.g3db", Model.class);
|
||||
|
||||
inclinationBombModel = manager.get("models/render_models/bomb_game/bomb_2_body.g3db", Model.class);
|
||||
inclinationBombButtonModel = manager.get("models/render_models/bomb_game/big_btn.g3db", Model.class);
|
||||
|
||||
wiresBombModel = manager.get("models/render_models/bomb_game/bomb_1_body.g3db", Model.class);
|
||||
wiresBombModelWire1 = manager.get("models/render_models/bomb_game/cable_1.g3db", Model.class);
|
||||
wiresBombModelWire2 = manager.get("models/render_models/bomb_game/cable_2.g3db", Model.class);
|
||||
wiresBombModelWire3 = manager.get("models/render_models/bomb_game/cable_3.g3db", Model.class);
|
||||
// easterEggModel = manager.get("models/render_models/bomb_game/", Model.class);
|
||||
|
||||
// Load the collision models.
|
||||
doorCollisionModel = manager.get("models/collision_models/bomb_game/door_col.g3db", Model.class);
|
||||
doorFrameCollisionModel = manager.get("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);
|
||||
|
||||
combinationBombCollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_body_col.g3db", Model.class);
|
||||
combinationButton1CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_1_col.g3db", Model.class);
|
||||
combinationButton2CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_2_col.g3db", Model.class);
|
||||
combinationButton3CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_3_col.g3db", Model.class);
|
||||
combinationButton4CollisionModel = manager.get("models/collision_models/bomb_game/bomb_3_btn_4_col.g3db", Model.class);
|
||||
|
||||
inclinationBombCollisionModel = manager.get("models/collision_models/bomb_game/bomb_2_body_col.g3db", Model.class);
|
||||
inclinationBombButtonCollisionModel = manager.get("models/collision_models/bomb_game/big_btn_col.g3db", Model.class);
|
||||
|
||||
wiresBombCollisionModel = manager.get("models/collision_models/bomb_game/bomb_1_body_col.g3db", Model.class);
|
||||
wiresBombCollisionModelWire1 = manager.get("models/collision_models/bomb_game/cable_1_col.g3db", Model.class);
|
||||
wiresBombCollisionModelWire2 = manager.get("models/collision_models/bomb_game/cable_2_col.g3db", Model.class);
|
||||
wiresBombCollisionModelWire3 = manager.get("models/collision_models/bomb_game/cable_3_col.g3db", Model.class);
|
||||
// easterEggCollisionModel = manager.get("models/collision_models/bomb_game/door.g3db", Model.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateAssetManager(){
|
||||
boolean doneLoading;
|
||||
|
||||
if(core == null)
|
||||
throw new NullPointerException("Core has not been set.");
|
||||
|
||||
doneLoading = manager.update();
|
||||
if(doneLoading){
|
||||
getModels();
|
||||
createAllEntities();
|
||||
core.onAssetsLoaded();
|
||||
}
|
||||
|
||||
return doneLoading;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,28 @@
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtar.entities;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
||||
|
||||
import com.artemis.World;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class EntityCreatorBase implements Disposable{
|
||||
protected World world;
|
||||
protected World world = null;
|
||||
protected ApplicationEventsListener core = null;
|
||||
protected boolean entitiesCreated = false;
|
||||
protected AssetManager manager = null;
|
||||
|
||||
/**
|
||||
* <p>Sets the Artemis {@link World} to use to create entities.</p>
|
||||
*
|
||||
* @param world The Artemis {@link World}.
|
||||
* @throws IllegalArgumentException if world is null.
|
||||
*/
|
||||
public void setWorld(World world) throws IllegalArgumentException{
|
||||
if(world == null)
|
||||
throw new IllegalArgumentException("World cannot be null.");
|
||||
@@ -28,7 +44,38 @@ public abstract class EntityCreatorBase implements Disposable{
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public abstract void createAllEntities();
|
||||
/**
|
||||
* <p>Sets the application core to listen for asset loading events.</p>
|
||||
*
|
||||
* @param core The application core to be used as listener.
|
||||
* @throws IllegalArgumentException if core is null.
|
||||
*/
|
||||
public void setCore(NxtARCore core) throws IllegalArgumentException{
|
||||
if(core == null) throw new IllegalArgumentException("Core is null.");
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Updates the state of the {@link AssetManager}.</p>
|
||||
*
|
||||
* @return true if the {@link AssetManager} has finished loading.
|
||||
*/
|
||||
public abstract boolean updateAssetManager();
|
||||
|
||||
/**
|
||||
* <p>Unloads all assets loaded for the scenario.</p>
|
||||
*/
|
||||
public abstract void dispose();
|
||||
|
||||
/**
|
||||
* @return true if the createAllEntities method has been called.
|
||||
*/
|
||||
public boolean areEntitiesCreated(){
|
||||
return entitiesCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Creates all entities for a game scenario.</p>
|
||||
*/
|
||||
protected abstract void createAllEntities();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
private DirectionalLightPerPixelShader ppShader;
|
||||
|
||||
@Override
|
||||
public void createAllEntities() {
|
||||
protected void createAllEntities() {
|
||||
ModelBuilder builder;
|
||||
Entity bomb, box, anim;
|
||||
G3dModelLoader loader;
|
||||
@@ -108,6 +108,8 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
bomb.addToWorld();
|
||||
anim.addToWorld();
|
||||
box.addToWorld();
|
||||
|
||||
entitiesCreated = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,4 +126,12 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||
if(ppShader != null)
|
||||
ppShader.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateAssetManager(){
|
||||
createAllEntities();
|
||||
if(core != null) core.onAssetsLoaded();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,5 +16,23 @@
|
||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
||||
|
||||
public interface ApplicationEventsListener {
|
||||
public void networkStreamConnected(String streamName);
|
||||
/**
|
||||
* <p>Callback used by the networking threads to notify sucessfull connections
|
||||
* to the application</p>
|
||||
*
|
||||
* @param streamName The name of the thread notifying a connection.
|
||||
*/
|
||||
public void onNetworkStreamConnected(String streamName);
|
||||
|
||||
/**
|
||||
* <p>Callback used by the assets loader to notify that all
|
||||
* required game assets are ready to be used.</p>
|
||||
*/
|
||||
public void onAssetsLoaded();
|
||||
|
||||
/**
|
||||
* <p>Callback used by the camera calibration state to notify that the
|
||||
* camera has been succesfully calibrated.</p>
|
||||
*/
|
||||
public void onCameraCalibrated();
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class RobotControlThread extends Thread {
|
||||
try{
|
||||
client = server.accept();
|
||||
client.setTcpNoDelay(true);
|
||||
if(netListener != null) netListener.networkStreamConnected(THREAD_NAME);
|
||||
if(netListener != null) netListener.onNetworkStreamConnected(THREAD_NAME);
|
||||
os = new ObjectOutputStream(client.getOutputStream());
|
||||
is = new ObjectInputStream(client.getInputStream());
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ public class SensorReportThread extends Thread {
|
||||
try{
|
||||
client = server.accept();
|
||||
client.setTcpNoDelay(true);
|
||||
if(netListener != null) netListener.networkStreamConnected(THREAD_NAME);
|
||||
if(netListener != null) netListener.onNetworkStreamConnected(THREAD_NAME);
|
||||
reader = client.getInputStream();
|
||||
|
||||
}catch(IOException io){
|
||||
|
||||
@@ -220,7 +220,7 @@ public class VideoStreamingThread extends Thread{
|
||||
//Gdx.app.debug(TAG, CLASS_NAME + ".run() :: Receiving.");
|
||||
if(netListener != null && !coreNotified && frameMonitor.getCurrentFrame() != null){
|
||||
coreNotified = true;
|
||||
netListener.networkStreamConnected(THREAD_NAME);
|
||||
netListener.onNetworkStreamConnected(THREAD_NAME);
|
||||
}
|
||||
receiveUdp();
|
||||
frames++;
|
||||
|
||||
@@ -88,6 +88,7 @@ public class CameraCalibrationState extends BaseState{
|
||||
private VideoFrameMonitor frameMonitor;
|
||||
|
||||
private float[][] calibrationSamples;
|
||||
@SuppressWarnings("unused")
|
||||
private boolean takeSample;
|
||||
private int lastSampleTaken;
|
||||
|
||||
@@ -215,11 +216,6 @@ public class CameraCalibrationState extends BaseState{
|
||||
// Fetch the current video frame.
|
||||
frame = frameMonitor.getCurrentFrame();
|
||||
|
||||
// Apply the undistortion method if the camera has been calibrated already.
|
||||
/*if(core.cvProc.isCameraCalibrated()){
|
||||
frame = core.cvProc.undistortFrame(frame);
|
||||
}*/
|
||||
|
||||
// Find the calibration points in the video frame.
|
||||
CalibrationData data = core.cvProc.findCalibrationPattern(frame);
|
||||
|
||||
@@ -231,7 +227,7 @@ public class CameraCalibrationState extends BaseState{
|
||||
}
|
||||
|
||||
// If the user requested a sample be taken.
|
||||
if(takeSample && !core.cvProc.isCameraCalibrated() && data.calibrationPoints != null){
|
||||
if(/*takeSample && */!core.cvProc.isCameraCalibrated() && data.calibrationPoints != null){
|
||||
// Disable sample taking.
|
||||
takeSample = false;
|
||||
Gdx.app.log(TAG, CLASS_NAME + ".render(): Sample taken.");
|
||||
@@ -255,8 +251,8 @@ public class CameraCalibrationState extends BaseState{
|
||||
Gdx.app.log(TAG, CLASS_NAME + "render(): Last sample taken.");
|
||||
|
||||
core.cvProc.calibrateCamera(calibrationSamples, frame);
|
||||
msg = "Camera successfully calibrated";
|
||||
core.toast(msg, true);
|
||||
core.onCameraCalibrated();
|
||||
core.nextState = game_states_t.MAIN_MENU;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,14 +295,14 @@ public class CameraCalibrationState extends BaseState{
|
||||
}
|
||||
|
||||
// Render the user interface.
|
||||
if(!Ouya.runningOnOuya){
|
||||
/*if(!Ouya.runningOnOuya){
|
||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||
core.batch.begin();{
|
||||
takeSampleButton.draw(core.batch, 1.0f);
|
||||
}core.batch.end();
|
||||
}else{
|
||||
// TODO: Render OUYA gui.
|
||||
}
|
||||
}*/
|
||||
|
||||
// Save this frame as previous to avoid processing the same frame twice when network latency is high.
|
||||
prevFrame = frame;
|
||||
|
||||
@@ -177,11 +177,7 @@ public class InGameState extends BaseState{
|
||||
frameBufferSprite = null;
|
||||
|
||||
// Set up the game world.
|
||||
gameWorld = new World();
|
||||
|
||||
GameSettings.initGameSettings();
|
||||
GameSettings.entityCreator.setWorld(gameWorld);
|
||||
GameSettings.entityCreator.createAllEntities();
|
||||
gameWorld = GameSettings.getGameWorld();
|
||||
|
||||
gameWorld.setSystem(new MarkerPositioningSystem());
|
||||
gameWorld.setSystem(new ObjectPositioningSystem(), true);
|
||||
@@ -362,9 +358,6 @@ public class InGameState extends BaseState{
|
||||
if(modelBatch != null)
|
||||
modelBatch.dispose();
|
||||
|
||||
if(GameSettings.entityCreator != null)
|
||||
GameSettings.entityCreator.dispose();
|
||||
|
||||
if(videoFrameTexture != null)
|
||||
videoFrameTexture.dispose();
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ public abstract class MainMenuStateBase extends BaseState{
|
||||
|
||||
// Helper fields.
|
||||
protected boolean clientConnected;
|
||||
protected boolean cameraCalibrated;
|
||||
protected boolean assetsLoaded;
|
||||
private float u_scaling[];
|
||||
|
||||
// Buttons and other gui components.
|
||||
@@ -170,7 +172,6 @@ public abstract class MainMenuStateBase extends BaseState{
|
||||
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
|
||||
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||
|
||||
|
||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
touchPointWorldCoords = new Vector2();
|
||||
startButtonTouched = false;
|
||||
@@ -179,6 +180,8 @@ public abstract class MainMenuStateBase extends BaseState{
|
||||
calibrationButtonTouchPointer = -1;
|
||||
|
||||
clientConnected = false;
|
||||
cameraCalibrated = false;
|
||||
assetsLoaded = false;
|
||||
stateActive = false;
|
||||
}
|
||||
|
||||
@@ -240,10 +243,24 @@ public abstract class MainMenuStateBase extends BaseState{
|
||||
|
||||
public void onClientConnected(){
|
||||
clientConnected = true;
|
||||
startButton.setDisabled(false);
|
||||
calibrationButton.setDisabled(false);
|
||||
}
|
||||
|
||||
public void onCameraCalibrated(){
|
||||
cameraCalibrated = true;
|
||||
calibrationButton.setDisabled(true);
|
||||
startGame();
|
||||
}
|
||||
|
||||
public void onAssetsLoaded(){
|
||||
assetsLoaded = true;
|
||||
startGame();
|
||||
}
|
||||
|
||||
private void startGame(){
|
||||
startButton.setDisabled(!(cameraCalibrated && assetsLoaded));
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; INPUT LISTENER METHODS ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
@@ -15,17 +15,54 @@
|
||||
*/
|
||||
package ve.ucv.ciens.ccg.nxtar.utils;
|
||||
|
||||
import com.artemis.World;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||
import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator;
|
||||
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
|
||||
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
|
||||
|
||||
public abstract class GameSettings{
|
||||
public static EntityCreatorBase entityCreator = null;
|
||||
public static GameLogicSystemBase gameLogicSystem = null;
|
||||
private static EntityCreatorBase entityCreator = null;
|
||||
private static GameLogicSystemBase gameLogicSystem = null;
|
||||
private static World gameWorld = null;
|
||||
|
||||
public static void initGameSettings(){
|
||||
entityCreator = new BombGameEntityCreator();
|
||||
gameLogicSystem = null;
|
||||
public static void initGameSettings(NxtARCore core) throws IllegalArgumentException{
|
||||
if(core == null)
|
||||
throw new IllegalArgumentException("Core is null.");
|
||||
|
||||
if(getGameWorld() == null)
|
||||
gameWorld = new World();
|
||||
|
||||
if(getEntityCreator() == null){
|
||||
entityCreator = new BombGameEntityCreator();
|
||||
entityCreator.setWorld(GameSettings.getGameWorld());
|
||||
entityCreator.setCore(core);
|
||||
}
|
||||
|
||||
if(getGameLogicSystem() == null)
|
||||
gameLogicSystem = null;
|
||||
//gameLogicSystem = new BombGameLogicSystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entityCreator
|
||||
*/
|
||||
public static EntityCreatorBase getEntityCreator() {
|
||||
return entityCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gameLogicSystem
|
||||
*/
|
||||
public static GameLogicSystemBase getGameLogicSystem() {
|
||||
return gameLogicSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gameWorld
|
||||
*/
|
||||
public static World getGameWorld() {
|
||||
return gameWorld;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user