Class KernelEngine

java.lang.Object
fr.r1r0r0.deltaengine.model.engines.KernelEngine

public final class KernelEngine
extends java.lang.Object
Core of the engine, oversees all engines and use them to render final game.
Game developer uses all given methods to build its game, engines.kernel just try to render his creation using all others engines.
  • Field Details

    • DEFAULT_FRAME_RATE

      public static final int DEFAULT_FRAME_RATE
      See Also:
      Constant Field Values
    • inputEngine

      private final InputEngine inputEngine
    • iaEngine

      private final AIEngine iaEngine
    • physicsEngine

      private final PhysicsEngine physicsEngine
    • eventEngine

      private final EventEngine eventEngine
    • graphicsEngine

      private final GraphicsEngine graphicsEngine
    • soundEngine

      private final SoundEngine soundEngine
    • networkEngine

      private final NetworkEngine networkEngine
    • maps

      private final java.util.Map<java.lang.String,​MapLevel> maps
    • hudElements

      private final java.util.List<HUDElement> hudElements
    • frameRatePrinter

      private final java.lang.Thread frameRatePrinter
    • currentMapLevel

      private MapLevel currentMapLevel
    • currentMapHalted

      private volatile boolean currentMapHalted
    • initialized

      private volatile boolean initialized
    • started

      private volatile boolean started
    • frameRate

      private int frameRate
    • optimalTime

      private int optimalTime
    • currentFrameRate

      private volatile int currentFrameRate
  • Constructor Details

    • KernelEngine

      KernelEngine()
      Default constructor. Creates all sub-engines but not initializing them.
  • Method Details

    • init

      void init​(javafx.stage.Stage stage)
      Initializes Kernel Engine and its components. If kernel was initialized before, then init will be skipped.
      Parameters:
      stage - Given stage by JavaFX
    • start

      void start()
      Kernel Engine loop.
    • tick

      public void tick()
      Do a manual tick on the DeltaEngine (useful to render only 1 frame, when modifications are made, and you need to render them). Only works if current map is halted, if isn't, this method has no effect
    • tick

      public void tick​(Engines engine)
      Do a manual tick on a specific Engine of the DeltaEngine (useful to compute only 1 frame, when modifications are made, and you need to render them). Only works if current map is halted, if isn't, this method has no effect
    • getFrameRate

      public int getFrameRate()
      Allows knowing Engine frame rate goal currently.
      Default : 60. Kernel will try to process itself and all others engines 60 times in one second.
      Returns:
      current frame rate
    • setFrameRate

      public void setFrameRate​(int frameRate)
      To define a frame rate that Engine will try to be sync on
      Default : 60. Kernel will try to process itself and all others engines 60 times in one second.
      Parameters:
      frameRate - new engine frame rate
    • setPhysicalRate

      public void setPhysicalRate​(int physicalRate)
      Allowing to set a new rate for the physics. More the value higher, more the precision is
      Parameters:
      physicalRate - new rate to define
    • printFrameRate

      public void printFrameRate​(boolean enabled)
      Enable or disable printing current FrameRate in standard output.
      Parameters:
      enabled - boolean true to enable it, false to disable it
    • getEngine

      private Engine getEngine​(Engines engine)
      Private method to get others engines. Used while looping on all others engines.
      Parameters:
      engine - engine ID to get
      Returns:
      Engine object
    • getNetworkEngine

      public NetworkEngine getNetworkEngine()
      Getting network engine to send or receive data
      Returns:
      network engine instance
    • getSoundEngine

      public SoundEngine getSoundEngine()
      Getting sound engine to add, remove or control sounds
      Returns:
      sound engine instance
    • addMap

      public void addMap​(MapLevel mapLevel) throws MapLevelAlreadyExistException
      Add new mapLevel to the engine. MapLevel name must be unique.
      Parameters:
      mapLevel - the mapLevel to add
      Throws:
      MapLevelAlreadyExistException - if mapLevel's name already been added
    • removeMap

      public boolean removeMap​(java.lang.String name)
      Remove given name map to the engines.kernel. If current map is the map to remove, map will be unloaded
      Parameters:
      name - the name of the map to remove
      Returns:
      true if removed, false if no map was already been added to this name
    • clearMaps

      public void clearMaps()
      Clear all maps from the engines.kernel. If current map is running, it will be unloaded
    • getCurrentMap

      public MapLevel getCurrentMap()
      Get current loaded and running map
      Returns:
      MapLevel loaded and running
    • setCurrentMap

      public void setCurrentMap​(java.lang.String name) throws MapLevelDoesNotExistException
      Load a previous added map on the Engine by its name
      Parameters:
      name - the name of map to load
      Throws:
      MapLevelDoesNotExistException - if map was not added before
      See Also:
      to add a new map
    • haltCurrentMap

      public void haltCurrentMap()
      Halt all elements to the map, avoiding them to be processed by engines (like a freeze).
      Graphical, Input, Sound and Network engines will not be halted
    • resumeCurrentMap

      public void resumeCurrentMap()
      Resume halted map
    • setInput

      public void setInput​(Key key, InputEvent event) throws InputKeyStackingError
      Bind a keyboard input to an event. Event will be triggered when user press given key.
      If previous input was bound, it will be overridden
      Parameters:
      key - to bind
      event - event to bind on actions
      Throws:
      InputKeyStackingError - if key is already bound
    • clearInput

      public void clearInput​(Key key)
      Clear an input event associated to a key
      Parameters:
      key - to clear
    • addGlobalEvent

      public void addGlobalEvent​(Event event)
      Add a global event, independent of the map
      Parameters:
      event - the event to add
    • removeGlobalEvent

      public void removeGlobalEvent​(Event event)
      Remove specified global event
      Parameters:
      event - the event to remove
    • clearGlobalEvents

      public void clearGlobalEvents()
      Clear all global events
    • addHUDElement

      public void addHUDElement​(HUDElement hudElement)
      Add a static element corresponding to HUD on the interface
      Parameters:
      hudElement - the element to add
    • removeHUDElement

      public void removeHUDElement​(HUDElement hudElement)
      Remove a static element corresponding to HUD previously added on the interface
      Parameters:
      hudElement - the element to remove
    • clearHUDElements

      public void clearHUDElements()
      Clear all static HUD elements from the interface
    • loadMap

      private void loadMap​(MapLevel mapLevel)
      Loads given mapLevel, loading associated elements, AI, and events
      Parameters:
      mapLevel - the mapLevel to load
    • unloadMap

      private void unloadMap()
      Unload current map, loading associated elements, AI, and events
    • setGameIcon

      public void setGameIcon​(java.lang.String img)
      Set up icon of the Engine in the OS Environment.
      Parameters:
      img - logo image path to set
    • canGoToNextCell

      public boolean canGoToNextCell​(Entity entity, Direction direction)
      Check if an entity can go to the next cell according to given direction
      Parameters:
      entity - Entity to check
      direction - Next direction
      Returns:
      boolean true if entity can go to next cell, false otherwise
    • isAvailableDirection

      public boolean isAvailableDirection​(Entity entity, Direction direction)
      Check if the entity can move with the direction given in argument
      Parameters:
      entity - Entity to check
      direction - Next direction
      Returns:
      boolean true if entity can go to the direction, false otherwise
    • addHUDElementToGraphicsEngine

      private void addHUDElementToGraphicsEngine​(HUDElement element)
      Adding an HUD element to the graphics engine, using Platform.runLater of JavaFX
      Parameters:
      element - Element to add
    • removeHUDElementFromGraphicsEngine

      private void removeHUDElementFromGraphicsEngine​(HUDElement element)
      Removing an element from the graphics engine, using Platform.runLater of JavaFX
      Parameters:
      element - Element to remove
    • setMapInTheGraphicsEngine

      private void setMapInTheGraphicsEngine​(MapLevel map)
      Allowing set up wanted map in the Graphics Engine, using Platform.runLater of JavaFX
      Parameters:
      map - map to load
    • clearMapFromTheGraphicsEngine

      private void clearMapFromTheGraphicsEngine()
      Clear current Map rendered from the Graphic engine