diff --git a/ShootingStars/lib/vlc/plugins/plugins.dat b/ShootingStars/lib/vlc/plugins/plugins.dat index b26a5a9..b7bb304 100644 Binary files a/ShootingStars/lib/vlc/plugins/plugins.dat and b/ShootingStars/lib/vlc/plugins/plugins.dat differ diff --git a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java index bef7525..eaa8dab 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java +++ b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java @@ -24,6 +24,7 @@ import com.jme3.app.state.AppStateManager; import com.jme3.renderer.Camera; import com.jme3.scene.Node; import org.wyrez.persij.PersiJContainer; +import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.states.State; import org.wyrez.shootingstars.states.StateManager; import tonegod.gui.core.Screen; @@ -44,17 +45,17 @@ public class ShootingStars extends SimpleApplication { @Override public void simpleInitApp() { + System.setProperty("jna.library.path", "lib/vlc"); registerTypes(); initGUI(); + Materials.initialize(assetManager); + cam.setFrustumFar(2500f); + sManager = container.resolve(StateManager.class); sManager.setState(State.START); } - @Override - public void simpleUpdate(float tpf) { - } - private void initGUI() { guiNode.addControl(container.resolve(Screen.class)); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java b/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java new file mode 100644 index 0000000..37091e7 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2013 Darth Affe 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 . + */ +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; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/Cinema.java b/ShootingStars/src/org/wyrez/shootingstars/game/Cinema.java new file mode 100644 index 0000000..99c5eec --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/game/Cinema.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2013 Darth Affe 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 . + */ +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); + } + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java index 3bde6d7..2182847 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java @@ -16,9 +16,13 @@ */ package org.wyrez.shootingstars.gui; +import com.jme3.font.BitmapFont; +import com.jme3.input.event.MouseButtonEvent; import com.jme3.math.Vector2f; +import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.controls.PanelBase; import org.wyrez.shootingstars.gui.listener.GameListener; +import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.windows.Panel; import tonegod.gui.core.Screen; @@ -27,9 +31,10 @@ import tonegod.gui.core.Screen; * @author Darth Affe */ public class GameGUI extends Panel { - + private GameListener listener; - + private Panel pnlStart; + public GameGUI(Screen screen, GameListener listener) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd this.listener = listener; @@ -38,18 +43,38 @@ public class GameGUI extends Panel { create(); this.resize(screen.getWidth(), screen.getHeight(), Borders.SE); } - + private void create() { - //Panel panel = new PanelBase(screen, new Vector2f(15, 15), new Vector2f(800, 500)); - //panel.setIgnoreMouse(true); - - //this.addChild(panel); + pnlStart = new PanelBase(screen, new Vector2f(15, 15), new Vector2f(800, 500)); + pnlStart.setIgnoreMouse(true); + + 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() { screen.addElement(this); } - + public void detach() { screen.removeElement(this); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java b/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java index d8415bd..d63590c 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java @@ -17,15 +17,11 @@ package org.wyrez.shootingstars.gui; import com.jme3.font.BitmapFont; -import com.jme3.input.event.MouseButtonEvent; import com.jme3.math.ColorRGBA; 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.PanelBase; -import org.wyrez.shootingstars.gui.listener.LoadingListener; import org.wyrez.shootingstars.states.util.LoadingProgress; -import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.extras.Indicator; import tonegod.gui.controls.text.Label; import tonegod.gui.controls.windows.Panel; @@ -37,14 +33,11 @@ import tonegod.gui.core.Screen; */ public class LoadingGui extends Panel { - private LoadingListener listener; private Label lblStatus; 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 - this.listener = listener; this.setIgnoreMouse(true); this.setIsVisible(false); create(); @@ -64,19 +57,8 @@ public class LoadingGui extends Panel { lblStatus = new Label(screen, new Vector2f(360f, 400f), new Vector2f(200f, 30f)); 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(lblStatus); - panel.addChild(btnStart); this.addChild(panel); } @@ -93,16 +75,4 @@ public class LoadingGui extends Panel { lblStatus.setText(progress.getText()); indProgress.setCurrentValue(progress.getValue()); } - - public void setLoadingStart() { - btnStart.hide(); - indProgress.show(); - lblStatus.show(); - } - - public void setLoadingDone() { - btnStart.show(); - indProgress.hide(); - lblStatus.hide(); - } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/listener/GameListener.java b/ShootingStars/src/org/wyrez/shootingstars/gui/listener/GameListener.java index 0440857..973c9d8 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/listener/GameListener.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/listener/GameListener.java @@ -22,4 +22,5 @@ package org.wyrez.shootingstars.gui.listener; */ public interface GameListener { + public void start(); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/listener/LoadingListener.java b/ShootingStars/src/org/wyrez/shootingstars/gui/listener/LoadingListener.java deleted file mode 100644 index 1591627..0000000 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/listener/LoadingListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2013 Darth Affe 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 . - */ -package org.wyrez.shootingstars.gui.listener; - -/** - * - * @author Darth Affe - */ -public interface LoadingListener { - - public void startGame(); -} diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index 5c8a050..cbb2884 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -16,9 +16,12 @@ */ package org.wyrez.shootingstars.states; +import com.jme3.app.FlyCamAppState; import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; +import com.jme3.renderer.RenderManager; import com.jme3.scene.Node; +import org.wyrez.shootingstars.game.Cinema; import org.wyrez.shootingstars.gui.GameGUI; import org.wyrez.shootingstars.gui.listener.GameListener; import tonegod.gui.core.Screen; @@ -32,6 +35,7 @@ public class GameState extends AbstractAppState implements GameListener { private StateManager stateManager; private Node rootNode; private GameGUI gui; + private Cinema cinema; public GameState(Node rootNode, Screen screen, StateManager stateManager) { this.rootNode = rootNode; @@ -39,17 +43,43 @@ public class GameState extends AbstractAppState implements GameListener { this.stateManager = stateManager; } + public void loadCinema() { + this.cinema = new Cinema("Broken.mp4"); //TODO settings? + } + + public void start() { + gui.setStart(); + cinema.play(); + } + @Override public void stateAttached(AppStateManager stateManager) { + stateManager.attach(new FlyCamAppState()); //TODO debug + rootNode.attachChild(cinema); + gui.setWait(); gui.attach(); } @Override public void stateDetached(AppStateManager stateManager) { + stateManager.detach(new FlyCamAppState()); //TODO debug gui.detach(); + rootNode.detachChild(cinema); + cinema.cleanup(); + } + + @Override + public void render(RenderManager rm) { + cinema.render(); } @Override public void update(float tpf) { } + + @Override + public void cleanup() { + super.cleanup(); + cinema.cleanup(); + } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java index 517b7af..1654bf3 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java @@ -19,7 +19,6 @@ package org.wyrez.shootingstars.states; import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; import org.wyrez.shootingstars.gui.LoadingGui; -import org.wyrez.shootingstars.gui.listener.LoadingListener; import org.wyrez.shootingstars.states.util.LoadingProgress; import tonegod.gui.core.Screen; @@ -27,7 +26,7 @@ import tonegod.gui.core.Screen; * * @author Darth Affe */ -public class LoadingState extends AbstractAppState implements LoadingListener { +public class LoadingState extends AbstractAppState { private StateManager stateManager; private LoadingGui gui; @@ -35,7 +34,7 @@ public class LoadingState extends AbstractAppState implements LoadingListener { public LoadingState(Screen screen, StateManager stateManager) { this.stateManager = stateManager; - this.gui = new LoadingGui(screen, this); + this.gui = new LoadingGui(screen); } @Override @@ -53,7 +52,6 @@ public class LoadingState extends AbstractAppState implements LoadingListener { public void update(float tpf) { switch (currentProgress) { case START: - gui.setLoadingStart(); currentProgress = LoadingProgress.ANALYSE_LOW_BAND; break; case ANALYSE_LOW_BAND: @@ -62,6 +60,10 @@ public class LoadingState extends AbstractAppState implements LoadingListener { break; case ANALYSE_HIGH_BAND: analyseHighBand(); + currentProgress = LoadingProgress.LOADING_CINEMA; + break; + case LOADING_CINEMA: + loadingCinema(); currentProgress = LoadingProgress.GENERATING_SCENE; break; case GENERATING_SCENE: @@ -69,7 +71,7 @@ public class LoadingState extends AbstractAppState implements LoadingListener { currentProgress = LoadingProgress.DONE; break; case DONE: - gui.setLoadingDone(); + done(); break; } gui.updateProgress(currentProgress); @@ -77,29 +79,22 @@ public class LoadingState extends AbstractAppState implements LoadingListener { private void analyseLowBand() { //TODO fill - try { - Thread.sleep(1000); - } catch (Exception ex) { - } } private void analyseHighBand() { //TODO fill - try { - Thread.sleep(1000); - } catch (Exception ex) { - } + } + + private void loadingCinema() { + GameState gs = stateManager.getState(State.GAME); + gs.loadCinema(); } private void generateScene() { //TODO fill - try { - Thread.sleep(1000); - } catch (Exception ex) { - } } - public void startGame() { + public void done() { stateManager.setState(State.GAME); } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/StateManager.java b/ShootingStars/src/org/wyrez/shootingstars/states/StateManager.java index f63299d..9a9f34b 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/StateManager.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/StateManager.java @@ -40,11 +40,7 @@ public class StateManager { appStateManager.attach(getState(State.getState())); } - public T getTypedState(State state) { - return (T) getState(state); - } - - public AppState getState(State state) { + public T getState(State state) { Class clazz = state.getClazz(); if (clazz == null) { return null; @@ -52,6 +48,6 @@ public class StateManager { if (!container.isTypeRegistered(clazz)) { container.registerType(clazz, true); } - return (AppState) container.resolve(clazz); + return (T) container.resolve(clazz); } } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java b/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java index b44b6b5..951cd7c 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/util/LoadingProgress.java @@ -23,8 +23,8 @@ package org.wyrez.shootingstars.states.util; public enum LoadingProgress { START("Loading...", 0), ANALYSE_LOW_BAND("Analyse Low-Band...", 0), - ANALYSE_HIGH_BAND("Analyse High-Band...", 1), GENERATING_SCENE("Generating Scene...", 2), - DONE("Done!", 3); + ANALYSE_HIGH_BAND("Analyse High-Band...", 1), LOADING_CINEMA("Loading Cinema", 2), + GENERATING_SCENE("Generating Scene...", 3), DONE("Done!", 3); private String text; private float value;