Added loading bar
This commit is contained in:
parent
fa72657e8f
commit
23c221468e
1 changed files with 129 additions and 57 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package sg.states;
|
package sg.states;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import sg.env.Environment;
|
import sg.env.Environment;
|
||||||
|
|
@ -14,8 +15,10 @@ import com.jme.renderer.Renderer;
|
||||||
import com.jme.scene.Node;
|
import com.jme.scene.Node;
|
||||||
import com.jme.scene.state.LightState;
|
import com.jme.scene.state.LightState;
|
||||||
import com.jme.system.DisplaySystem;
|
import com.jme.system.DisplaySystem;
|
||||||
|
import com.jme.util.GameTaskQueueManager;
|
||||||
import com.jmex.game.state.CameraGameState;
|
import com.jmex.game.state.CameraGameState;
|
||||||
import com.jmex.game.state.GameStateManager;
|
import com.jmex.game.state.GameStateManager;
|
||||||
|
import com.jmex.game.state.load.LoadingGameState;
|
||||||
import com.jmex.physics.DynamicPhysicsNode;
|
import com.jmex.physics.DynamicPhysicsNode;
|
||||||
import com.jmex.physics.PhysicsDebugger;
|
import com.jmex.physics.PhysicsDebugger;
|
||||||
import com.jmex.physics.PhysicsSpace;
|
import com.jmex.physics.PhysicsSpace;
|
||||||
|
|
@ -35,64 +38,25 @@ public class InGameState extends CameraGameState {
|
||||||
|
|
||||||
public InGameState(String name) {
|
public InGameState(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
// ***************** Load the Game **********************************
|
|
||||||
|
|
||||||
// Pass (render thingies)
|
|
||||||
//passManager = new BasicPassManager();
|
|
||||||
|
|
||||||
//physics
|
|
||||||
physicsSpace = PhysicsSpace.create();
|
|
||||||
|
|
||||||
physicsSpace.setDirectionalGravity(new Vector3f(0f, 0f, 0f));
|
|
||||||
StaticPhysicsNode staticNode = physicsSpace.createStaticNode();
|
|
||||||
DynamicPhysicsNode dynamicNode = physicsSpace.createDynamicNode();
|
|
||||||
rootNode.attachChild(dynamicNode);
|
|
||||||
rootNode.attachChild(staticNode);
|
|
||||||
|
|
||||||
// environment
|
|
||||||
environment = new Environment(rootNode);
|
|
||||||
rootNode.attachChild(environment);
|
|
||||||
|
|
||||||
// ship
|
|
||||||
Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds");
|
|
||||||
ship.setLocalTranslation(new Vector3f( 0, 0, 40));
|
|
||||||
rootNode.attachChild(ship);
|
|
||||||
|
|
||||||
// inputs
|
|
||||||
FirstPersonHandler first = new FirstPersonHandler( cam, 50, 1 );
|
|
||||||
input = new InputHandler();
|
|
||||||
input.addToAttachedHandlers( first );
|
|
||||||
|
|
||||||
// lights
|
|
||||||
/** Set up a basic, default light. */
|
|
||||||
PointLight light = new PointLight();
|
|
||||||
light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) );
|
|
||||||
light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
|
||||||
light.setLocation( new Vector3f( 100, 100, 100 ) );
|
|
||||||
light.setEnabled( true );
|
|
||||||
|
|
||||||
/** Attach the light to a lightState and the lightState to rootNode. */
|
|
||||||
LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
|
|
||||||
lightState.setEnabled( true );
|
|
||||||
lightState.attach( light );
|
|
||||||
rootNode.setRenderState( lightState );
|
|
||||||
rootNode.updateRenderState();
|
|
||||||
|
|
||||||
HudState hud = new HudState("hud");
|
|
||||||
GameStateManager.getInstance().attachChild(hud);
|
|
||||||
|
|
||||||
cam.setFrustumFar(5000);
|
|
||||||
// ***************** Done loading **********************************
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onActivate(){
|
public void setActive(boolean b){
|
||||||
super.onActivate();
|
if(b){ // initiate the game
|
||||||
GameStateManager.getInstance().activateChildNamed("hud");
|
if(environment == null){
|
||||||
}
|
GameTaskQueueManager.getManager().update(new LoadingTask(this));
|
||||||
|
this.active = false;
|
||||||
public void onDeactivate(){
|
}
|
||||||
super.onDeactivate();
|
else { // the game is already initaiated
|
||||||
GameStateManager.getInstance().deactivateChildNamed("hud");
|
this.active = true;
|
||||||
|
onActivate();
|
||||||
|
GameStateManager.getInstance().activateChildNamed("hud");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.active = false;
|
||||||
|
onDeactivate();
|
||||||
|
GameStateManager.getInstance().deactivateChildNamed("hud");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stateUpdate(float tpf) {
|
public void stateUpdate(float tpf) {
|
||||||
|
|
@ -118,4 +82,112 @@ public class InGameState extends CameraGameState {
|
||||||
/** Have the PassManager render. */
|
/** Have the PassManager render. */
|
||||||
//passManager.renderPasses(r);
|
//passManager.renderPasses(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//****************************************************************************
|
||||||
|
//************************** Loader *************************************
|
||||||
|
|
||||||
|
private class LoadingTask implements Callable<Void>{
|
||||||
|
private static final int STEP_COUNT = 7;
|
||||||
|
private LoadingGameState loader;
|
||||||
|
private InGameState parentState;
|
||||||
|
private int progress;
|
||||||
|
|
||||||
|
public LoadingTask(InGameState parentState){
|
||||||
|
this.parentState = parentState;
|
||||||
|
|
||||||
|
loader = new LoadingGameState(STEP_COUNT+1);
|
||||||
|
GameStateManager.getInstance().attachChild(loader);
|
||||||
|
loader.setActive(true);
|
||||||
|
|
||||||
|
progress = 0;
|
||||||
|
loader.increment("Loading Passes...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Void call() throws Exception {
|
||||||
|
// ***************** Load the Game **********************************
|
||||||
|
switch(progress){
|
||||||
|
case 0:
|
||||||
|
// Pass (render thingies)
|
||||||
|
//passManager = new BasicPassManager();
|
||||||
|
|
||||||
|
loader.increment("Loading Physics...");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
//physics
|
||||||
|
physicsSpace = PhysicsSpace.create();
|
||||||
|
|
||||||
|
physicsSpace.setDirectionalGravity(new Vector3f(0f, 0f, 0f));
|
||||||
|
StaticPhysicsNode staticNode = physicsSpace.createStaticNode();
|
||||||
|
DynamicPhysicsNode dynamicNode = physicsSpace.createDynamicNode();
|
||||||
|
rootNode.attachChild(dynamicNode);
|
||||||
|
rootNode.attachChild(staticNode);
|
||||||
|
|
||||||
|
loader.increment("Loading Environment...");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// environment
|
||||||
|
environment = new Environment(rootNode);
|
||||||
|
rootNode.attachChild(environment);
|
||||||
|
|
||||||
|
loader.increment("Loading Ships...");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// ship
|
||||||
|
Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds");
|
||||||
|
ship.setLocalTranslation(new Vector3f( 0, 0, 40));
|
||||||
|
rootNode.attachChild(ship);
|
||||||
|
|
||||||
|
loader.increment("Loading Inputs...");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
// inputs
|
||||||
|
FirstPersonHandler first = new FirstPersonHandler( cam, 50, 1 );
|
||||||
|
input = new InputHandler();
|
||||||
|
input.addToAttachedHandlers( first );
|
||||||
|
|
||||||
|
loader.increment("Loading Lights...");
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
// lights
|
||||||
|
/** Set up a basic, default light. */
|
||||||
|
PointLight light = new PointLight();
|
||||||
|
light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) );
|
||||||
|
light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
||||||
|
light.setLocation( new Vector3f( 100, 100, 100 ) );
|
||||||
|
light.setEnabled( true );
|
||||||
|
|
||||||
|
/** Attach the light to a lightState and the lightState to rootNode. */
|
||||||
|
LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
|
||||||
|
lightState.setEnabled( true );
|
||||||
|
lightState.attach( light );
|
||||||
|
rootNode.setRenderState( lightState );
|
||||||
|
rootNode.updateRenderState();
|
||||||
|
|
||||||
|
loader.increment("Loading Hud...");
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
HudState hud = new HudState("hud");
|
||||||
|
GameStateManager.getInstance().attachChild(hud);
|
||||||
|
|
||||||
|
loader.increment("Loading Starting...");
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
cam.setFrustumFar(5000);
|
||||||
|
|
||||||
|
// ***************** Done loading **********************************
|
||||||
|
loader.setActive(false);
|
||||||
|
GameStateManager.getInstance().detachChild(loader);
|
||||||
|
|
||||||
|
parentState.setActive(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progress < STEP_COUNT) {
|
||||||
|
GameTaskQueueManager.getManager().update(this);
|
||||||
|
}
|
||||||
|
progress++;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue