1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-28 01:04:50 +01:00

adding stub links to earlier parts of the page

novabyte
2025-02-19 23:36:10 -05:00
parent b364158133
commit 9097c2c2aa

@@ -4,29 +4,29 @@ The goal of this page is to provide an abstract overview of the components that
## Entry Point
The main entry point for non-Windows systems (Windows instead uses its own DLL proxy) is located in the `Cli.cpp` file. The `main` function here calls `CommandLine::HandleCommandDefault` which handles a few simple commands (`about`, `help`) and sets some defaults for global variables like if the game should run in headless mode and paths where game data can be found. Once it checks that all of that happened properly it sets the game to run headless with no graphics (because no graphics have been loaded yet) and creates the game context by calling `CreateContext`.
The main entry point for non-Windows systems (Windows instead uses its own DLL proxy) is located in the `Cli.cpp` file. The `main` function here calls `CommandLine::HandleCommandDefault` which handles a few simple commands (`about`, `help`) and sets some defaults for global variables like if the game should run in headless mode and paths where game data can be found. Once it checks that all of that happened properly it sets the game to run headless with no graphics (because no graphics have been loaded yet) and creates the [[game context|Game Context]] by calling `CreateContext`.
## Game Context (services)
The game context is comprised of 3 main components: `PlatformEnvironment`, `AudioContext`, and `UiContext`. The `PlatformEnvironment` informs OpenRCT2 in how to go about loading paths depending on the OS environment it's running in. `AudioContext` handles playing music and sound effects. `UiContext` handles the window or screen that OpenRCT2 is presented on. The default context that is created has dummy audio and ui contexts, and is returned.
The [[game context|Game Context]] is comprised of 3 main components: `PlatformEnvironment`, `AudioContext`, and `UiContext`. The `PlatformEnvironment` informs OpenRCT2 in how to go about loading paths depending on the OS environment it's running in. `AudioContext` handles playing music and sound effects. `UiContext` handles the window or screen that OpenRCT2 is presented on. The default [[game context|Game Context]] that is created has dummy audio and ui contexts, and is returned.
## Game Initialization & Launch
### Initialization
After the context is created we can call `RunOpenRCT2` which will try to `Initialise` and then `Launch` the game.
After the [[game context|Game Context]] is created we can call `RunOpenRCT2` which will try to `Initialise` and then `Launch` the game.
`Initialise` handles a lot of stuff but the most prominent things it handles are creating the exception handling, creating the `AssetPackManager`, creating the window, makes sure things are loaded that need to be, initializes `Audio`, copies files, initializes all viewports, initializes the context, sets the active scene, and initializes repositories and the script engine.
<details>
<summary>click for full list</summary>
- creating the exception handling
- creating the [[exception handling|Exception Handling]]
- whether to show a changelog
- handles configuring the language
- handles [[configuring the language|Internationalization]]
- gets or prompts for the installation path of RCT2
- creating the `AssetPackManager`
- creating the `DiscordService` if enabled
- creating the `AssetPackManager` for [[managing assets|Asset Management]]
- creating the `DiscordService` if enabled for [[interacting with discord|Discord Integration]]
- issuing various warnings
- creating the window
- ensuring the user content directories exist
@@ -39,15 +39,15 @@ After the context is created we can call `RunOpenRCT2` which will try to `Initia
- loads the base graphics
- initializes lighting fx
- initializes all viewports
- initializes the context
- initializes the [[game context|Game Context]]
- sets the active scene
- initializes the repositories
- initializes the script engine
- initializes the [[script engine|Script Engine]]
</details>
### Launch
If `Initialise` completes with no error and returns `true` the we can `Launch` the game. First we check to see if there is a new version of the game so we can inform the player if there is. Then, we switch to the startup scene which by default is set in `OpenRCT2.cpp` to `StartupAction::Title`. If the game is running in headless mode, then `StartupAction::None` or `StartupAction::Open` are the only actions. Otherwise, depending on the startup action we will decide what scene to load and set it as the active scene and initialize the game networking. By default the title scene is chosen.
If `Initialise` completes with no error and returns `true` the we can `Launch` the game. First we check to see if there is a new version of the game so we can inform the player if there is. Then, we switch to the startup scene which by default is set in `OpenRCT2.cpp` to `StartupAction::Title`. If the game is running in headless mode, then `StartupAction::None` or `StartupAction::Open` are the only actions. Otherwise, depending on the startup action we will decide what scene to load and set it as the active scene and initialize the game [[networking|Networking]]. By default the title scene is chosen.
## Game Loop
@@ -55,7 +55,7 @@ After the startup scene is set we can finally jump into the game loop by calling
### Run Frame
At this point we know we are dealing with logic for a single-frame of gameplay. Any code put here will potentially run once per frame, so be mindful of performance, but don't optimize until necessary. The first point of order is to get the time that has elapsed since the last frame referred to as `deltaTime` (delta often standing for "the change in", so the "change in time since the last frame") which is an important variable in most, if not all, games to ensure smooth interpolation between frames since the time between frames can differ each time.
At this point we know we are dealing with logic for a single-frame of gameplay. Any code put here will most likely run once per frame, so be mindful of performance, but don't optimize until necessary. The first point of order is to get the time that has elapsed since the last frame referred to as `deltaTime` (delta often standing for "the change in", so the "change in time since the last frame") which is an important variable in most, if not all games to ensure smooth interpolation between frames since the time between frames can differ each time.
We then check again to see if a variable frame should be run to capture any change in state. If it changes from running a variable frame to a fixed frame we need to reset the entity positions back to their end of tick positions of the previous tick. Then, we update the time accumulators (which keep track of game ticks and real time) and then we either `RunVariableFrame` or `RunFixedFrame`.