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 intcurrentFrameRateprivate booleancurrentMapHaltedprivate MapLevelcurrentMapLevelstatic intDEFAULT_FRAME_RATEprivate EventEngineeventEngineprivate intframeRateprivate java.lang.ThreadframeRatePrinterprivate GraphicsEnginegraphicsEngineprivate java.util.List<HUDElement>hudElementsprivate AIEngineiaEngineprivate booleaninitializedprivate InputEngineinputEngineprivate java.util.Map<java.lang.String,MapLevel>mapsprivate NetworkEnginenetworkEngineprivate intoptimalTimeprivate PhysicsEnginephysicsEngineprivate SoundEnginesoundEngineprivate booleanstarted -
Constructor Summary
Constructors Constructor Description KernelEngine()Default constructor. -
Method Summary
Modifier and Type Method Description voidaddGlobalEvent(Event event)Add a global event, independent of the mapvoidaddHUDElement(HUDElement hudElement)Add a static element corresponding to HUD on the interfaceprivate voidaddHUDElementToGraphicsEngine(HUDElement element)Adding an HUD element to the graphics engine, using Platform.runLater of JavaFXvoidaddMap(MapLevel mapLevel)Add new mapLevel to the engine.booleancanGoToNextCell(Entity entity, Direction direction)Check if an entity can go to the next cell according to given directionvoidclearGlobalEvents()Clear all global eventsvoidclearHUDElements()Clear all static HUD elements from the interfacevoidclearInput(Key key)Clear an input event associated to a keyprivate voidclearMapFromTheGraphicsEngine()Clear current Map rendered from the Graphic enginevoidclearMaps()Clear all maps from the engines.kernel.MapLevelgetCurrentMap()Get current loaded and running mapprivate EnginegetEngine(Engines engine)Private method to get others engines.intgetFrameRate()Allows knowing Engine frame rate goal currently.NetworkEnginegetNetworkEngine()Getting network engine to send or receive dataSoundEnginegetSoundEngine()Getting sound engine to add, remove or control soundsvoidhaltCurrentMap()Halt all elements to the map, avoiding them to be processed by engines (like a freeze).(package private) voidinit(javafx.stage.Stage stage)Initializes Kernel Engine and its components.booleanisAvailableDirection(Entity entity, Direction direction)Check if the entity can move with the direction given in argumentprivate voidloadMap(MapLevel mapLevel)Loads given mapLevel, loading associated elements, AI, and eventsvoidprintFrameRate(boolean enabled)Enable or disable printing current FrameRate in standard output.voidremoveGlobalEvent(Event event)Remove specified global eventvoidremoveHUDElement(HUDElement hudElement)Remove a static element corresponding to HUD previously added on the interfaceprivate voidremoveHUDElementFromGraphicsEngine(HUDElement element)Removing an element from the graphics engine, using Platform.runLater of JavaFXbooleanremoveMap(java.lang.String name)Remove given name map to the engines.kernel.voidresumeCurrentMap()Resume halted mapvoidsetCurrentMap(java.lang.String name)Load a previous added map on the Engine by its namevoidsetFrameRate(int frameRate)To define a frame rate that Engine will try to be sync on
Default : 60.voidsetGameIcon(java.lang.String img)Set up icon of the Engine in the OS Environment.voidsetInput(Key key, InputEvent event)Bind a keyboard input to an event.private voidsetMapInTheGraphicsEngine(MapLevel map)Allowing set up wanted map in the Graphics Engine, using Platform.runLater of JavaFXvoidsetPhysicalRate(int physicalRate)Allowing to set a new rate for the physics.(package private) voidstart()Kernel Engine loop.voidtick()Do a manual tick on the DeltaEngine (useful to render only 1 frame, when modifications are made, and you need to render them).voidtick(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 voidunloadMap()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
-