Class zodiac

java.lang.Object
com.jme3.app.LegacyApplication
com.jme3.app.SimpleApplication
name.moore.kevin.ze.zodiac
All Implemented Interfaces:
com.jme3.app.Application, com.jme3.system.SystemListener, iZodiacApp

@Singleton public class zodiac extends com.jme3.app.SimpleApplication implements iZodiacApp
Creates, initialises and manages all the globals, subsystems, application states for the game.

Consider this a conductor - it contains a lot of references to other objects but should not be doing much actual work itself. It should only initialise and handle things that are meaningful across all application states. It is a singleton, we only expect one of these to exist at a time. Therefore all of its member fields will also only have one instance ever existing. Anything that is application-wide is created and managed here.

It listens and responds to windowevents through the eventbus. Changing between different states of the application is done through a finite state machine - window events can trigger state changes.

It is responsible for coordinating the setup of the GUI.

Author:
Kevin Moore <dev@kevin.moore.name>
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    Implements a singleton pattern.
    static class 
    Connects the JME app states, a unique identifier and the finite state machine.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private com.google.common.collect.SetMultimap<appFSM.State,​zodiac.ZSTATE>
    All the appstate identifiers to be enabled for each FSM state.
    State machine that controls and transitions between the application states, enabling and disabling as required.
    private com.simsilica.es.EntityData
    Global container holding all of the entities, components, sets
    private com.google.common.eventbus.AsyncEventBus
    The JME application states communicate by posting and receiving gameEvents on this eventbus.
    private static org.slf4j.Logger
     
    private sceneToImage
    Scene processor attached to the application viewport.
    private com.google.common.eventbus.AsyncEventBus
    The user interface communicates to JME through this eventBus.
    private com.thoughtworks.xstream.XStream
    Global XStream object to interface with XML files.
    private zFrame
    The GUI top level object.

    Fields inherited from class com.jme3.app.SimpleApplication

    flyCam, fpsText, guiFont, guiNode, INPUT_MAPPING_CAMERA_POS, INPUT_MAPPING_EXIT, INPUT_MAPPING_HIDE_STATS, INPUT_MAPPING_MEMORY, rootNode, showSettings

    Fields inherited from class com.jme3.app.LegacyApplication

    assetManager, audioRenderer, cam, context, guiViewPort, inputEnabled, inputManager, joyInput, keyInput, listener, lostFocusBehavior, mouseInput, paused, prof, renderer, renderManager, settings, speed, stateManager, timer, touchInput, viewPort
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Initialise global variables and datastructures, required before simpleInitApp() is called.
  • Method Summary

    Modifier and Type
    Method
    Description
    private boolean
    Dialog to confirm user want to exit.
    com.jme3.asset.AssetManager
    com.google.common.eventbus.AsyncEventBus
    static zodiac
    Implement a singleton pattern so we only ever have one zodiac object.
    TODO converted forms eg getIntSetting()
    com.jme3.system.AppSettings
     
    com.google.common.eventbus.AsyncEventBus
    com.thoughtworks.xstream.XStream
    Obtain the correctly configured XStream object from anywhere via zodiac.getInstance().getXstream()
    private void
    initGUI​(int width, int height)
    Create the main application container - a frame with 'dockable' panels.
    private com.thoughtworks.xstream.XStream
    Initialise the XStream system by identifying classes, converters etc.
    private void
    Callback from the FSM on entering a FSM state.
    void
    requestClose​(boolean esc)
     
    void
    setSettings​(com.jme3.system.AppSettings s)
    Annoyingly the JME application settings need to be set ~before~ we start the app so that the rendering dimensions are set correctly.
    void
    Called once by SimpleApplication when the application is started (zodiac.start()), prepares member fields such as XStream.
    void
    simpleUpdate​(float tpf)
    This loop is empty! We moved everything cleanly into AppStates and Controls.
    void
    Shutdown all JME processing and exit the application.
    void
    Listen on the eventbus for zodiac windowEvents.

    Methods inherited from class com.jme3.app.SimpleApplication

    getFlyByCamera, getGuiNode, getRootNode, getSpeed, initialize, isShowSettings, loadGuiFont, setDisplayFps, setDisplayStatView, setShowSettings, setSpeed, simpleRender, start, update

    Methods inherited from class com.jme3.app.LegacyApplication

    createCanvas, destroy, destroyInput, enqueue, enqueue, gainFocus, getAppProfiler, getAudioRenderer, getCamera, getContext, getGuiViewPort, getInputManager, getListener, getLostFocusBehavior, getRenderer, getRenderManager, getStateManager, getTimer, getViewPort, handleError, isPauseOnLostFocus, loseFocus, reshape, restart, runQueuedTasks, setAppProfiler, setAssetManager, setLostFocusBehavior, setPauseOnLostFocus, setTimer, start, start, start, startCanvas, startCanvas, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface name.moore.kevin.ze.game.iZodiacApp

    getRenderManager
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • allStates

      private com.google.common.collect.SetMultimap<appFSM.State,​zodiac.ZSTATE> allStates
      All the appstate identifiers to be enabled for each FSM state. Built from ZSTATE eg State.READY ->{ ZR, ZLS, ... }
    • zf

      private zFrame zf
      The GUI top level object.
    • s2iProcessor

      private sceneToImage s2iProcessor
      Scene processor attached to the application viewport.
    • entityrepository

      private com.simsilica.es.EntityData entityrepository
      Global container holding all of the entities, components, sets
    • xstream

      private com.thoughtworks.xstream.XStream xstream
      Global XStream object to interface with XML files.

      initialised by initXStream() when the app is initialised.

    • gameBus

      private com.google.common.eventbus.AsyncEventBus gameBus
      The JME application states communicate by posting and receiving gameEvents on this eventbus.
      See Also:
      gameEvent
    • windowBus

      private com.google.common.eventbus.AsyncEventBus windowBus
      The user interface communicates to JME through this eventBus.
    • appStateMachine

      private appFSM<appFSM.State,​appFSM.Trigger> appStateMachine
      State machine that controls and transitions between the application states, enabling and disabling as required.
  • Constructor Details

    • zodiac

      private zodiac()
      Initialise global variables and datastructures, required before simpleInitApp() is called.
  • Method Details

    • getInstance

      public static zodiac getInstance()
      Implement a singleton pattern so we only ever have one zodiac object.

      Obtain a 'new' zodiac object with zodiac.getInstance().

      Returns:
      the singleton instance
    • simpleInitApp

      public void simpleInitApp()
      Called once by SimpleApplication when the application is started (zodiac.start()), prepares member fields such as XStream.

      Initialises the finite state machine, GUI, globals etal.

      Specified by:
      simpleInitApp in class com.jme3.app.SimpleApplication
    • simpleUpdate

      public void simpleUpdate(float tpf)
      This loop is empty! We moved everything cleanly into AppStates and Controls.
      Overrides:
      simpleUpdate in class com.jme3.app.SimpleApplication
      Parameters:
      tpf -
    • initGUI

      private void initGUI(int width, int height)
      Create the main application container - a frame with 'dockable' panels. Setup the application viewport and scene processors.
      Parameters:
      width - pixels width
      height - pixels height
    • setSettings

      public void setSettings(com.jme3.system.AppSettings s)
      Annoyingly the JME application settings need to be set ~before~ we start the app so that the rendering dimensions are set correctly.
      Specified by:
      setSettings in interface com.jme3.app.Application
      Overrides:
      setSettings in class com.jme3.app.LegacyApplication
      Parameters:
      s - settings created from the gameconfig.
    • initXStream

      private com.thoughtworks.xstream.XStream initXStream()
      Initialise the XStream system by identifying classes, converters etc.

      Called once when the application is initialised.

      TODO can we figure a way of getting classes that need XStream to register themselves automatically? via a static? Having to hardcode in the required class names is pants.
    • requestClose

      public void requestClose(boolean esc)
      Specified by:
      requestClose in interface com.jme3.system.SystemListener
      Overrides:
      requestClose in class com.jme3.app.LegacyApplication
    • stop

      public void stop()
      Shutdown all JME processing and exit the application. Undo anything created in simpleInitApp(), Invoked when the GUI shuts down to also clear up JME.
      Specified by:
      stop in interface com.jme3.app.Application
      Overrides:
      stop in class com.jme3.app.LegacyApplication
    • getXstream

      public com.thoughtworks.xstream.XStream getXstream()
      Obtain the correctly configured XStream object from anywhere via zodiac.getInstance().getXstream()
      Specified by:
      getXstream in interface iZodiacApp
      Returns:
      prepared XStream object
    • getSettings

      public com.jme3.system.AppSettings getSettings()
      Specified by:
      getSettings in interface iZodiacApp
      Returns:
      JMonkeyEngine application settings
    • getSetting

      public String getSetting(gameConfig.keys key)
      TODO converted forms eg getIntSetting()
      Specified by:
      getSetting in interface iZodiacApp
      Parameters:
      key - one of the gameConfig enums
      Returns:
      a specific value from the application settings
    • getAssetManager

      public com.jme3.asset.AssetManager getAssetManager()
      Specified by:
      getAssetManager in interface com.jme3.app.Application
      Specified by:
      getAssetManager in interface iZodiacApp
      Overrides:
      getAssetManager in class com.jme3.app.LegacyApplication
      Returns:
      JMonkeyEngine assetManager
    • getGameBus

      public com.google.common.eventbus.AsyncEventBus getGameBus()
      Specified by:
      getGameBus in interface iZodiacApp
      Returns:
      the bus distributing gameEvents
    • getWindowBus

      public com.google.common.eventbus.AsyncEventBus getWindowBus()
      Specified by:
      getWindowBus in interface iZodiacApp
      Returns:
      the bus distributing windowEvents
    • windowEvent

      @AsyncThread public void windowEvent(windowEvent event)
      Listen on the eventbus for zodiac windowEvents. Some events cause triggering state machine changes.
      Parameters:
      event -
    • doExitDialog

      private boolean doExitDialog()
      Dialog to confirm user want to exit.
      Returns:
    • onEntry

      private void onEntry(appFSM.State s)
      Callback from the FSM on entering a FSM state. Enable/disable appropriate application states. Its an assumption we can enter the state without restriction (the transition rules were in the FSM)
      Parameters:
      s - The FSM state we are entering.