Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Getting Started

Malte edited this page Jan 19, 2020 · 3 revisions

Getting Started

The basic concept of Salty Engine

Scenes

In Salty Engine, everything is about Scenes. Scene is a class (de.edgelord.saltyengine.scene.Scene) and it has the following:

  1. A thread-safe list of GameObjects (de.edgelord.saltyengine.gameobject.GameObject)
  2. A thread-safe list of DrawingRoutines (de.edgelord.saltyengine.gameobject.DrawingRoutine)
  3. A thread-safe list of FixedTasks (de.edgelord.saltyengine.gameobject.FixedTas)
  4. A LightSystem (de.edgelord.saltyengine.cosmetic.light.LightSystem)
  5. An UISystem (de.edgelord.saltyengine.ui.UISystem)
  6. A float value for the speed of the gravity
  7. A float value for the friction

Now, in details, what each of these things are:

  1. To find out, what a GameObject ist and how to work with it, take a look at this wiki page.
  2. DrawingRoutine implements Drawable, which means that it has the method void draw(SaltyGraphics). Also, DrawingRoutines have a position, whether DrawingRoutine.DrawingPosition.BEFORE_GAMEOBJECTS, where ist gets drawn before the GameObjects, which means that they will be drawn over it, or DrawingRoutine.DrawingPosition.AFTER_GAMEOBJECTS, where is gets drawn after all the GameObjects and so, it is rendered over them.
  3. FixedTask implements FixedTickRoutine, which means that it has the method void onFixedTick(). This method is called every fixed tick, find out more about that below.
  4. A LighSystem is basically an image, with is completely in one color (which can be set for every LighSystem individually) and all of the Lights 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.
  5. An UISystem is a collection of UIElements, such as buttons, labels etc. You can read about that in this future page.
  6. Defining the speed for the gravity for each GameObject in the Scene
  7. 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

SceneManager

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 Scenes needed by a game. The collection of Scenes is stored in a HashMap. Every String name in this map stands for the Class object of a class extending Scene. To add a Scene to the collection, call void addScene(String, Scene) or void 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)`

The Engine

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:

  1. If the game is not paused, SceneManager.getCurrentScene().onFixedTick() is called. that does:
  2. The FixedTasks from the list
  3. Going through each GameObject and calling initialize() if it wasn't initialized before, the collision detection of the GameObjects, the onFixedTick() for every Component of the GameObject and finally the onFixedTick() of the GameObject itself.
  4. Game.getDefaultGFXController().doGFXFixedTick() is called, so that the scene-wide GFX are getting recalculated
  5. onFixedTick() of the UISystem 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:

  1. The fps are being calculated and set to Time in de.edgelord.saltyengine.utils.Time
  2. Game.getHost().repaint() is called, that does the following (when the host is a DisplayManager, which is the case if you don't change it):
  3. The stage is being repaint, see below for details
  4. the scaling of the display is recalculated.

What the stage does when rendering:

  1. Setting the RenderingHints to the graphics context, which defines the render-quality. You can control this using GraphicsConfiguration#renderingHints
  2. Setting the view of Game#camera to the graphics
  3. Creating a new SaltyGraphics with the graphics context
  4. Calling Engine#render(SaltyGraphics), which draw the current Scene, and so all of the content explained above
  5. 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.