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.
Game developer uses all given methods to build its game, engines.kernel just try to render his creation using all others engines.
-
Field Summary
Fields Modifier and Type Field Description private int
currentFrameRate
private boolean
currentMapHalted
private MapLevel
currentMapLevel
static int
DEFAULT_FRAME_RATE
private EventEngine
eventEngine
private int
frameRate
private java.lang.Thread
frameRatePrinter
private GraphicsEngine
graphicsEngine
private java.util.List<HUDElement>
hudElements
private AIEngine
iaEngine
private boolean
initialized
private InputEngine
inputEngine
private java.util.Map<java.lang.String,MapLevel>
maps
private NetworkEngine
networkEngine
private int
optimalTime
private PhysicsEngine
physicsEngine
private SoundEngine
soundEngine
private boolean
started
-
Constructor Summary
Constructors Constructor Description KernelEngine()
Default constructor. -
Method Summary
Modifier and Type Method Description void
addGlobalEvent(Event event)
Add a global event, independent of the mapvoid
addHUDElement(HUDElement hudElement)
Add a static element corresponding to HUD on the interfaceprivate void
addHUDElementToGraphicsEngine(HUDElement element)
Adding an HUD element to the graphics engine, using Platform.runLater of JavaFXvoid
addMap(MapLevel mapLevel)
Add new mapLevel to the engine.boolean
canGoToNextCell(Entity entity, Direction direction)
Check if an entity can go to the next cell according to given directionvoid
clearGlobalEvents()
Clear all global eventsvoid
clearHUDElements()
Clear all static HUD elements from the interfacevoid
clearInput(Key key)
Clear an input event associated to a keyprivate void
clearMapFromTheGraphicsEngine()
Clear current Map rendered from the Graphic enginevoid
clearMaps()
Clear all maps from the engines.kernel.MapLevel
getCurrentMap()
Get current loaded and running mapprivate Engine
getEngine(Engines engine)
Private method to get others engines.int
getFrameRate()
Allows knowing Engine frame rate goal currently.NetworkEngine
getNetworkEngine()
Getting network engine to send or receive dataSoundEngine
getSoundEngine()
Getting sound engine to add, remove or control soundsvoid
haltCurrentMap()
Halt all elements to the map, avoiding them to be processed by engines (like a freeze).(package private) void
init(javafx.stage.Stage stage)
Initializes Kernel Engine and its components.boolean
isAvailableDirection(Entity entity, Direction direction)
Check if the entity can move with the direction given in argumentprivate void
loadMap(MapLevel mapLevel)
Loads given mapLevel, loading associated elements, AI, and eventsvoid
printFrameRate(boolean enabled)
Enable or disable printing current FrameRate in standard output.void
removeGlobalEvent(Event event)
Remove specified global eventvoid
removeHUDElement(HUDElement hudElement)
Remove a static element corresponding to HUD previously added on the interfaceprivate void
removeHUDElementFromGraphicsEngine(HUDElement element)
Removing an element from the graphics engine, using Platform.runLater of JavaFXboolean
removeMap(java.lang.String name)
Remove given name map to the engines.kernel.void
resumeCurrentMap()
Resume halted mapvoid
setCurrentMap(java.lang.String name)
Load a previous added map on the Engine by its namevoid
setFrameRate(int frameRate)
To define a frame rate that Engine will try to be sync on
Default : 60.void
setGameIcon(java.lang.String img)
Set up icon of the Engine in the OS Environment.void
setInput(Key key, InputEvent event)
Bind a keyboard input to an event.private void
setMapInTheGraphicsEngine(MapLevel map)
Allowing set up wanted map in the Graphics Engine, using Platform.runLater of JavaFXvoid
setPhysicalRate(int physicalRate)
Allowing to set a new rate for the physics.(package private) void
start()
Kernel Engine loop.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).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).private void
unloadMap()
Unload current map, loading associated elements, AI, and eventsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DEFAULT_FRAME_RATE
public static final int DEFAULT_FRAME_RATE- See Also:
- Constant Field Values
-
inputEngine
-
iaEngine
-
physicsEngine
-
eventEngine
-
graphicsEngine
-
soundEngine
-
networkEngine
-
maps
-
hudElements
-
frameRatePrinter
private final java.lang.Thread frameRatePrinter -
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
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 method to get others engines. Used while looping on all others engines.- Parameters:
engine
- engine ID to get- Returns:
- Engine object
-
getNetworkEngine
Getting network engine to send or receive data- Returns:
- network engine instance
-
getSoundEngine
Getting sound engine to add, remove or control sounds- Returns:
- sound engine instance
-
addMap
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
Get current loaded and running map- Returns:
- MapLevel loaded and running
-
setCurrentMap
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
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 bindevent
- event to bind on actions- Throws:
InputKeyStackingError
- if key is already bound
-
clearInput
Clear an input event associated to a key- Parameters:
key
- to clear
-
addGlobalEvent
Add a global event, independent of the map- Parameters:
event
- the event to add
-
removeGlobalEvent
Remove specified global event- Parameters:
event
- the event to remove
-
clearGlobalEvents
public void clearGlobalEvents()Clear all global events -
addHUDElement
Add a static element corresponding to HUD on the interface- Parameters:
hudElement
- the element to add
-
removeHUDElement
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
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
Check if an entity can go to the next cell according to given direction- Parameters:
entity
- Entity to checkdirection
- Next direction- Returns:
- boolean true if entity can go to next cell, false otherwise
-
isAvailableDirection
Check if the entity can move with the direction given in argument- Parameters:
entity
- Entity to checkdirection
- Next direction- Returns:
- boolean true if entity can go to the direction, false otherwise
-
addHUDElementToGraphicsEngine
Adding an HUD element to the graphics engine, using Platform.runLater of JavaFX- Parameters:
element
- Element to add
-
removeHUDElementFromGraphicsEngine
Removing an element from the graphics engine, using Platform.runLater of JavaFX- Parameters:
element
- Element to remove
-
setMapInTheGraphicsEngine
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
-