added cinema, tweaked gui

This commit is contained in:
Raybz@Raybz 2013-05-17 14:24:14 +02:00
parent 068be09309
commit 9bfe178ff8
12 changed files with 245 additions and 96 deletions

View File

@ -24,6 +24,7 @@ import com.jme3.app.state.AppStateManager;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import org.wyrez.persij.PersiJContainer; import org.wyrez.persij.PersiJContainer;
import org.wyrez.shootingstars.factories.Materials;
import org.wyrez.shootingstars.states.State; import org.wyrez.shootingstars.states.State;
import org.wyrez.shootingstars.states.StateManager; import org.wyrez.shootingstars.states.StateManager;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
@ -44,17 +45,17 @@ public class ShootingStars extends SimpleApplication {
@Override @Override
public void simpleInitApp() { public void simpleInitApp() {
System.setProperty("jna.library.path", "lib/vlc");
registerTypes(); registerTypes();
initGUI(); initGUI();
Materials.initialize(assetManager);
cam.setFrustumFar(2500f);
sManager = container.resolve(StateManager.class); sManager = container.resolve(StateManager.class);
sManager.setState(State.START); sManager.setState(State.START);
} }
@Override
public void simpleUpdate(float tpf) {
}
private void initGUI() { private void initGUI() {
guiNode.addControl(container.resolve(Screen.class)); guiNode.addControl(container.resolve(Screen.class));
} }

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.factories;
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
/**
*
* @author Darth Affe
*/
public enum Materials {
UNSHADED("Common/MatDefs/Misc/Unshaded.j3md", null);
private static AssetManager assetManager;
private String material;
private String texture;
Materials(String material, String texture) {
this.material = material;
this.texture = texture;
}
public Material create() {
Material mat = new Material(assetManager, material);
//TODO load textures
//if (texture != null) {
//mat.setTexture("ColorMap", texture);
//}
return mat;
}
public static void initialize(AssetManager assetManager) {
Materials.assetManager = assetManager;
}
}

View File

@ -0,0 +1,107 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.game;
import com.jme3.material.Material;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.texture.Image;
import com.jme3.texture.Texture2D;
import com.sun.jna.Memory;
import java.nio.ByteBuffer;
import org.wyrez.shootingstars.factories.Materials;
import org.wyrez.shootingstars.mesh.CinemaHex;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.BufferFormat;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;
/**
*
* @author Darth Affe
*/
public class Cinema extends Geometry implements RenderCallback {
private static final int WIDTH = 1280;
private static final int HEIGHT = 720;
private static final int DEPTH = 4;
private static final String VIDEO_FORMAT = "RGBA";
private static final Image.Format TEXTURE_FORMAT = Image.Format.RGBA8;
private final MediaPlayerFactory mediaPlayerFactory;
private final DirectMediaPlayer mediaPlayer;
private final Image videoImage;
private final Texture2D videoTexture;
private final Object bufferLock = new Object();
private ByteBuffer buffer;
public Cinema(String file) {
this(file, 1000f);
}
public Cinema(String file, float radius) {
this(file, radius, Vector3f.ZERO);
}
public Cinema(String file, float radius, Vector3f pos) {
super("Cinema: " + file, new CinemaHex(pos, radius,
radius * ((float) HEIGHT / (float) WIDTH)));
mediaPlayerFactory = new MediaPlayerFactory("--no-video-title-show", "--quiet");
mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer(VIDEO_FORMAT, WIDTH, HEIGHT, WIDTH * DEPTH, this);
videoImage = new Image(TEXTURE_FORMAT, WIDTH, HEIGHT, null);
videoTexture = new Texture2D(videoImage);
Material mat = Materials.UNSHADED.create();
mat.setTexture("ColorMap", videoTexture);
this.setMaterial(mat);
this.rotate(0f, FastMath.PI / 6f, 0f);
mediaPlayer.prepareMedia(file);
}
public void play() {
mediaPlayer.play();
}
public void pause() {
mediaPlayer.pause();
}
public void stop() {
mediaPlayer.stop();
}
public void cleanup() {
stop();
mediaPlayer.release();
mediaPlayerFactory.release();
}
public void render() {
synchronized (bufferLock) {
videoImage.setData(buffer);
}
}
@Override
public void display(DirectMediaPlayer mediaPlayer, Memory[] nativeBuffers, BufferFormat bufferFormat) {
synchronized (bufferLock) {
buffer = nativeBuffers[0].getByteBuffer(0, WIDTH * HEIGHT * DEPTH);
}
}
}

View File

@ -16,9 +16,13 @@
*/ */
package org.wyrez.shootingstars.gui; package org.wyrez.shootingstars.gui;
import com.jme3.font.BitmapFont;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.controls.PanelBase; import org.wyrez.shootingstars.gui.controls.PanelBase;
import org.wyrez.shootingstars.gui.listener.GameListener; import org.wyrez.shootingstars.gui.listener.GameListener;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.windows.Panel; import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
@ -29,6 +33,7 @@ import tonegod.gui.core.Screen;
public class GameGUI extends Panel { public class GameGUI extends Panel {
private GameListener listener; private GameListener listener;
private Panel pnlStart;
public GameGUI(Screen screen, GameListener listener) { public GameGUI(Screen screen, GameListener listener) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
@ -40,10 +45,30 @@ public class GameGUI extends Panel {
} }
private void create() { private void create() {
//Panel panel = new PanelBase(screen, new Vector2f(15, 15), new Vector2f(800, 500)); pnlStart = new PanelBase(screen, new Vector2f(15, 15), new Vector2f(800, 500));
//panel.setIgnoreMouse(true); pnlStart.setIgnoreMouse(true);
//this.addChild(panel); Button btnStart = new ButtonBase(screen, new Vector2f(360f, 360f),
new Vector2f(200f, 30f)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
listener.start();
}
};
btnStart.setText("Start Game");
btnStart.setTextAlign(BitmapFont.Align.Center);
pnlStart.addChild(btnStart);
this.addChild(pnlStart);
}
public void setStart() {
pnlStart.hide();
}
public void setWait() {
pnlStart.show();
} }
public void attach() { public void attach() {

View File

@ -17,15 +17,11 @@
package org.wyrez.shootingstars.gui; package org.wyrez.shootingstars.gui;
import com.jme3.font.BitmapFont; import com.jme3.font.BitmapFont;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.controls.IndicatorBase; import org.wyrez.shootingstars.gui.controls.IndicatorBase;
import org.wyrez.shootingstars.gui.controls.PanelBase; import org.wyrez.shootingstars.gui.controls.PanelBase;
import org.wyrez.shootingstars.gui.listener.LoadingListener;
import org.wyrez.shootingstars.states.util.LoadingProgress; import org.wyrez.shootingstars.states.util.LoadingProgress;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.extras.Indicator; import tonegod.gui.controls.extras.Indicator;
import tonegod.gui.controls.text.Label; import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.windows.Panel; import tonegod.gui.controls.windows.Panel;
@ -37,14 +33,11 @@ import tonegod.gui.core.Screen;
*/ */
public class LoadingGui extends Panel { public class LoadingGui extends Panel {
private LoadingListener listener;
private Label lblStatus; private Label lblStatus;
private Indicator indProgress; private Indicator indProgress;
private Button btnStart;
public LoadingGui(Screen screen, LoadingListener listener) { public LoadingGui(Screen screen) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
this.listener = listener;
this.setIgnoreMouse(true); this.setIgnoreMouse(true);
this.setIsVisible(false); this.setIsVisible(false);
create(); create();
@ -64,19 +57,8 @@ public class LoadingGui extends Panel {
lblStatus = new Label(screen, new Vector2f(360f, 400f), new Vector2f(200f, 30f)); lblStatus = new Label(screen, new Vector2f(360f, 400f), new Vector2f(200f, 30f));
lblStatus.setTextAlign(BitmapFont.Align.Center); lblStatus.setTextAlign(BitmapFont.Align.Center);
btnStart = new ButtonBase(screen, new Vector2f(360f, 360f),
new Vector2f(200f, 30f)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
listener.startGame();
}
};
btnStart.setText("Start Game");
btnStart.setTextAlign(BitmapFont.Align.Center);
panel.addChild(indProgress); panel.addChild(indProgress);
panel.addChild(lblStatus); panel.addChild(lblStatus);
panel.addChild(btnStart);
this.addChild(panel); this.addChild(panel);
} }
@ -93,16 +75,4 @@ public class LoadingGui extends Panel {
lblStatus.setText(progress.getText()); lblStatus.setText(progress.getText());
indProgress.setCurrentValue(progress.getValue()); indProgress.setCurrentValue(progress.getValue());
} }
public void setLoadingStart() {
btnStart.hide();
indProgress.show();
lblStatus.show();
}
public void setLoadingDone() {
btnStart.show();
indProgress.hide();
lblStatus.hide();
}
} }

View File

@ -22,4 +22,5 @@ package org.wyrez.shootingstars.gui.listener;
*/ */
public interface GameListener { public interface GameListener {
public void start();
} }

View File

@ -1,26 +0,0 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.listener;
/**
*
* @author Darth Affe
*/
public interface LoadingListener {
public void startGame();
}

View File

@ -16,9 +16,12 @@
*/ */
package org.wyrez.shootingstars.states; package org.wyrez.shootingstars.states;
import com.jme3.app.FlyCamAppState;
import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager; import com.jme3.app.state.AppStateManager;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import org.wyrez.shootingstars.game.Cinema;
import org.wyrez.shootingstars.gui.GameGUI; import org.wyrez.shootingstars.gui.GameGUI;
import org.wyrez.shootingstars.gui.listener.GameListener; import org.wyrez.shootingstars.gui.listener.GameListener;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
@ -32,6 +35,7 @@ public class GameState extends AbstractAppState implements GameListener {
private StateManager stateManager; private StateManager stateManager;
private Node rootNode; private Node rootNode;
private GameGUI gui; private GameGUI gui;
private Cinema cinema;
public GameState(Node rootNode, Screen screen, StateManager stateManager) { public GameState(Node rootNode, Screen screen, StateManager stateManager) {
this.rootNode = rootNode; this.rootNode = rootNode;
@ -39,17 +43,43 @@ public class GameState extends AbstractAppState implements GameListener {
this.stateManager = stateManager; this.stateManager = stateManager;
} }
public void loadCinema() {
this.cinema = new Cinema("Broken.mp4"); //TODO settings?
}
public void start() {
gui.setStart();
cinema.play();
}
@Override @Override
public void stateAttached(AppStateManager stateManager) { public void stateAttached(AppStateManager stateManager) {
stateManager.attach(new FlyCamAppState()); //TODO debug
rootNode.attachChild(cinema);
gui.setWait();
gui.attach(); gui.attach();
} }
@Override @Override
public void stateDetached(AppStateManager stateManager) { public void stateDetached(AppStateManager stateManager) {
stateManager.detach(new FlyCamAppState()); //TODO debug
gui.detach(); gui.detach();
rootNode.detachChild(cinema);
cinema.cleanup();
}
@Override
public void render(RenderManager rm) {
cinema.render();
} }
@Override @Override
public void update(float tpf) { public void update(float tpf) {
} }
@Override
public void cleanup() {
super.cleanup();
cinema.cleanup();
}
} }

View File

@ -19,7 +19,6 @@ package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager; import com.jme3.app.state.AppStateManager;
import org.wyrez.shootingstars.gui.LoadingGui; import org.wyrez.shootingstars.gui.LoadingGui;
import org.wyrez.shootingstars.gui.listener.LoadingListener;
import org.wyrez.shootingstars.states.util.LoadingProgress; import org.wyrez.shootingstars.states.util.LoadingProgress;
import tonegod.gui.core.Screen; import tonegod.gui.core.Screen;
@ -27,7 +26,7 @@ import tonegod.gui.core.Screen;
* *
* @author Darth Affe * @author Darth Affe
*/ */
public class LoadingState extends AbstractAppState implements LoadingListener { public class LoadingState extends AbstractAppState {
private StateManager stateManager; private StateManager stateManager;
private LoadingGui gui; private LoadingGui gui;
@ -35,7 +34,7 @@ public class LoadingState extends AbstractAppState implements LoadingListener {
public LoadingState(Screen screen, StateManager stateManager) { public LoadingState(Screen screen, StateManager stateManager) {
this.stateManager = stateManager; this.stateManager = stateManager;
this.gui = new LoadingGui(screen, this); this.gui = new LoadingGui(screen);
} }
@Override @Override
@ -53,7 +52,6 @@ public class LoadingState extends AbstractAppState implements LoadingListener {
public void update(float tpf) { public void update(float tpf) {
switch (currentProgress) { switch (currentProgress) {
case START: case START:
gui.setLoadingStart();
currentProgress = LoadingProgress.ANALYSE_LOW_BAND; currentProgress = LoadingProgress.ANALYSE_LOW_BAND;
break; break;
case ANALYSE_LOW_BAND: case ANALYSE_LOW_BAND:
@ -62,6 +60,10 @@ public class LoadingState extends AbstractAppState implements LoadingListener {
break; break;
case ANALYSE_HIGH_BAND: case ANALYSE_HIGH_BAND:
analyseHighBand(); analyseHighBand();
currentProgress = LoadingProgress.LOADING_CINEMA;
break;
case LOADING_CINEMA:
loadingCinema();
currentProgress = LoadingProgress.GENERATING_SCENE; currentProgress = LoadingProgress.GENERATING_SCENE;
break; break;
case GENERATING_SCENE: case GENERATING_SCENE:
@ -69,7 +71,7 @@ public class LoadingState extends AbstractAppState implements LoadingListener {
currentProgress = LoadingProgress.DONE; currentProgress = LoadingProgress.DONE;
break; break;
case DONE: case DONE:
gui.setLoadingDone(); done();
break; break;
} }
gui.updateProgress(currentProgress); gui.updateProgress(currentProgress);
@ -77,29 +79,22 @@ public class LoadingState extends AbstractAppState implements LoadingListener {
private void analyseLowBand() { private void analyseLowBand() {
//TODO fill //TODO fill
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
} }
private void analyseHighBand() { private void analyseHighBand() {
//TODO fill //TODO fill
try { }
Thread.sleep(1000);
} catch (Exception ex) { private void loadingCinema() {
} GameState gs = stateManager.getState(State.GAME);
gs.loadCinema();
} }
private void generateScene() { private void generateScene() {
//TODO fill //TODO fill
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
} }
public void startGame() { public void done() {
stateManager.setState(State.GAME); stateManager.setState(State.GAME);
} }
} }

View File

@ -40,11 +40,7 @@ public class StateManager {
appStateManager.attach(getState(State.getState())); appStateManager.attach(getState(State.getState()));
} }
public <T extends AppState> T getTypedState(State state) { public <T extends AppState> T getState(State state) {
return (T) getState(state);
}
public AppState getState(State state) {
Class clazz = state.getClazz(); Class clazz = state.getClazz();
if (clazz == null) { if (clazz == null) {
return null; return null;
@ -52,6 +48,6 @@ public class StateManager {
if (!container.isTypeRegistered(clazz)) { if (!container.isTypeRegistered(clazz)) {
container.registerType(clazz, true); container.registerType(clazz, true);
} }
return (AppState) container.resolve(clazz); return (T) container.resolve(clazz);
} }
} }

View File

@ -23,8 +23,8 @@ package org.wyrez.shootingstars.states.util;
public enum LoadingProgress { public enum LoadingProgress {
START("Loading...", 0), ANALYSE_LOW_BAND("Analyse Low-Band...", 0), START("Loading...", 0), ANALYSE_LOW_BAND("Analyse Low-Band...", 0),
ANALYSE_HIGH_BAND("Analyse High-Band...", 1), GENERATING_SCENE("Generating Scene...", 2), ANALYSE_HIGH_BAND("Analyse High-Band...", 1), LOADING_CINEMA("Loading Cinema", 2),
DONE("Done!", 3); GENERATING_SCENE("Generating Scene...", 3), DONE("Done!", 3);
private String text; private String text;
private float value; private float value;