-
Notifications
You must be signed in to change notification settings - Fork 6
Getting Started
In Salty Engine, everything is about Scenes. Scene
is a class (de.edgelord.saltyengine.scene.Scene
) and it has the following:
- A thread-safe list of
GameObject
s (de.edgelord.saltyengine.gameobject.GameObject
) - A thread-safe list of
DrawingRoutine
s (de.edgelord.saltyengine.gameobject.DrawingRoutine
) - A thread-safe list of
FixedTask
s (de.edgelord.saltyengine.gameobject.FixedTas
) - A
LightSystem
(de.edgelord.saltyengine.cosmetic.light.LightSystem
) - An
UISystem
(de.edgelord.saltyengine.ui.UISystem
) - A
float
value for the speed of the gravity - A float value for the friction
Now, in details, what each of these things are:
- To find out, what a
GameObject
ist and how to work with it, take a look at this wiki page. -
DrawingRoutine
implementsDrawable
, which means that it has the methodvoid draw(SaltyGraphics)
. Also,DrawingRoutine
s have a position, whetherDrawingRoutine.DrawingPosition.BEFORE_GAMEOBJECTS
, where ist gets drawn before theGameObject
s, which means that they will be drawn over it, orDrawingRoutine.DrawingPosition.AFTER_GAMEOBJECTS
, where is gets drawn after all theGameObject
s and so, it is rendered over them. -
FixedTask
implementsFixedTickRoutine
, which means that it has the methodvoid onFixedTick()
. This method is called every fixed tick, find out more about that below. - A
LighSystem
is basically an image, with is completely in one color (which can be set for everyLighSystem
individually) and all of theLight
s are drawn like that, that they're cut out. Read more about in that wiki page, which I'll write in the near future. This image is rendered above everything except the ui and that creates the illusion of light, currently without shadow casting. - An
UISystem
is a collection ofUIElement
s, such as buttons, labels etc. You can read about that in this future page. - Defining the speed for the gravity for each
GameObject
in the Scene - Defining the friction between the scene and each
GameObject
. This effects how the velocity of them will fade in/out when you are working with acceleration
In Salty Engine, you can have multiple scenes, but only one can and should be rendered and calculated.
That is obtained by the SceneManager
(de.edgelord.saltyengine.scene.SceneManager
).
~ the class documentation:
This class manages all
Scene
s needed by a game. The collection of Scenes is stored in a HashMap. Every String name in this map stands for theClass
object of a class extendingScene
. To add aScene
to the collection, callvoid addScene(String, Scene)
orvoid addScene(String, Class)
. Example usage:
`SceneManager.addScene("startMenu", new StartMenu());`
`SceneManager.addScene("starMenu", StartMenu.class);`
When ever you call `SceneManager.setCurrentScene("starMenu");` now, a new instance of `StartMenu` will be created
and set to `currentScene`.
You can pass constructor args into that method, one after another each separated by a comma. Please note that inside a constructor of a class extending Scene, for this to work, you should write fully classified names, e.g.
`public StartMenu(Float value, Integer number, Char character)`
instead of
`public StartMenu(float value, int number, char character)`
To reload the current `Scene`, use `void reloadCurrentScene(Object...)`. You can pass constructor args into that method, one after another each separated by a comma.
To remove a `Scene` from the collection, use `void removeScene(String)`. You can also directly set an instance of a `Scene` as the current by calling `void setCurrentScene(Scene)`
In Salty Engine, there is one class that does all the work basically. It is called Engine
(de.edgelord.saltyengine.core.Engine
).
The engine has two threads, one for the rendering process and one for the fixed ticks.
Every fixed tick happens this:
- If the game is not paused,
SceneManager.getCurrentScene().onFixedTick()
is called. that does: - The
FixedTask
s from the list - Going through each
GameObject
and callinginitialize()
if it wasn't initialized before, the collision detection of theGameObject
s, theonFixedTick()
for everyComponent
of theGameObject
and finally theonFixedTick()
of theGameObject
itself. -
Game.getDefaultGFXController().doGFXFixedTick()
is called, so that the scene-wide GFX are getting recalculated -
onFixedTick()
of theUISystem
is called.
The rendering is whether with as many fps as possible when starting the game with Game#start()
or Game#start(Splash)
, or with a fixed amount of fps when starting with Game#start(long)
or Game#start(long, Splash)
.
When the Game is being rendered, the following things happen, step by step in that order:
- The fps are being calculated and set to
Time
inde.edgelord.saltyengine.utils.Time
-
Game.getHost().repaint()
is called, that does the following (when the host is aDisplayManager
, which is the case if you don't change it): - The stage is being repaint, see below for details
- the scaling of the display is recalculated.
What the stage does when rendering:
- Setting the
RenderingHints
to the graphics context, which defines the render-quality. You can control this usingGraphicsConfiguration#renderingHints
- Setting the view of
Game#camera
to the graphics - Creating a new
SaltyGraphics
with the graphics context - Calling
Engine#render(SaltyGraphics)
, which draw the currentScene
, and so all of the content explained above - If
Game#isDrawFPS()
, then the fps are drawn to the top right corner in a small, red font
In a nutshell, that's how Salty Engine works. Hopefully, that helped, if not, see the Help-Section within the README of this project on GitHub.