From 1e93c322676e5712d4e285a3136a36d5da5737fa Mon Sep 17 00:00:00 2001 From: nightm4re94 Date: Sun, 29 Nov 2020 19:22:09 +0100 Subject: [PATCH] Resolve #1. Document RenderTypes in the environment introduction. --- game-api/game-world.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/game-api/game-world.md b/game-api/game-world.md index 0fc6485..6ad5375 100644 --- a/game-api/game-world.md +++ b/game-api/game-world.md @@ -2,7 +2,7 @@ ## Introduction to Environments -Every game engine needs a container that holds all the visual and non-visual things that will, in the end, make up the game world. This container is called `Environment` in the LITIENGINE. Only one Environment is loaded at a time and the Game holds the currently active Environment. Every time you want to position something within the two-dimensional space of your game, you can do so by adding it to the Environment. When the active Screen calls the `Environment.render(Graphics2D)` method, it’s internal rendering pipeline is executed which will render everything that was previously added/loaded to the environment. There are different render types (`BACKGROUND`, `OVERLAY`, …) that define in which order the objects will be rendered, but more on that topic in a later tutorial. +Every game engine needs a container that holds all the visual and non-visual things that will, in the end, make up the game world. This container is called `Environment` in the LITIENGINE. Only one Environment is loaded at a time and the Game holds the currently active Environment. Every time you want to position something within the two-dimensional space of your game, you can do so by adding it to the Environment. It’s important to point out, that the Environment is related to exactly one Map and that the LITIENGINE provides an interface to load MapObjects to the environment. The implementations that take care of this task are called MapObjectLoaders. They basically translate the information form the *.tmx map* format to objects that can be managed by the engine. @@ -29,4 +29,19 @@ Game.world().environment().addEntityListener(new EnvironmentEntityListener(){ // do sth when entities are added } }); -``` \ No newline at end of file +``` + ### Layering + When the active Screen calls the `Environment.render(Graphics2D)` method, its internal rendering pipeline is executed which will render everything that was previously added/loaded to the environment. There are different `RenderType`s that define in which order the objects and tile layers will be rendered. Think of the `RenderType`s as layers that are painted on our canvas one after another. + + The rendering order is as follows: + + `BACKGROUND` -> `GROUND` -> `SURFACE` -> `NORMAL` -> (static shadows) -> `OVERLAY` -> (ambient light) -> `UI` + + Internally, the Environment.render method does the following for every `RenderType` (besides `RenderType.NONE`, which can, for example, be used to make objects invisible temporarily): + + 1. Render all Map Layers of that type + 2. Render all registered `IRenderable` implementations of that type + 3. Render all added `IEntities` of that type + 4. Call-back on the `EnvironmentRenderListener.rendered` listeners for that type + 5. If `dbg_logDetailedRenderTimes = true`: track the time it took to execute the rendering +