-
Notifications
You must be signed in to change notification settings - Fork 0
Engine logics
The engine first reads and checks the configuration information from "the_engine_config.json" and then initializes the subsystems:
The Lua Runtime is the first subsystem to be initialized. It is used to control the logic of user projects, as well as to provide various classes that can be used by the lua scripts.
The pre-initialization script at "the_engine/data/lua/preInit.lua" runs upon its initialization.
The Render Manager dictates display elements. Upon initialization, it creates a window, loads the placeholder texture file from "the_engine/assets/textures/misc/placeholder.png", and loads the default font from "the_engine/assets/fonts/default.ttf".
The Sound Manager controls music and sound effects.
Following this, the Lua runtime executes the post-initialization script at "the_engine/data/lua/postInit.lua", loads "data/lua/main.lua" from the user project folder, and calls prepare()
. The engine seamlessly transitions into the main loop after completing initialization.
The main loop encapsulates the following steps:
-
Window Information Update: Update window details, including location and size. The user may go to operate the window directly without going through the program, so do this first to avoid the window information in the program and the real window information being out of sync.
-
Lua Runtime Execution: Run the
tick()
function within the Lua runtime. -
Window Content Update: Update the window content. This is done by RenderManager.
-
Loop Continuation: If no stop signal is encountered, the loop repeats.
This iterative cycle, is called a tick. By default, there will be 60 ticks per second (configurable in "the_engine_config.json"). This implies that the logic of your project has approximately 16 milliseconds to execute. Overloaded operations may result in perceptible graphics and program lag.
This is the engine's normal shutdown process, which is triggered either by clicking the window's close button or by executing Engine.stop()
in the Lua script.
If the program encounters an unexpected problem (either in the Lua script or in the engine itself), it will simply crash without further action.
The general logic of the shut down process is:
- Exit the main loop. If the current tick has code left to execute, exit after the execution is complete.
- Call the
cleanup()
function in the Lua runtime. - Shut down SoundManager.
- Shut down RenderManager.
- Exit the program.