Management class for the whole gameflow, this is where the main-loop is.
More...
#include <main_loop.hpp>
|
| MainLoop (unsigned parent_pid, bool download_assets=false) |
|
void | run () |
| Run the actual main loop.
|
|
void | abort () |
| Set the abort flag, causing the mainloop to be left.
|
|
void | requestAbort () |
|
void | setThrottleFPS (bool throttle) |
|
void | setAllowLargeDt (bool enable) |
|
void | renderGUI (int phase, int loop_index=-1, int loop_size=-1) |
| Renders the GUI.
|
|
bool | isAborted () const |
| Returns true if STK is to be stoppe.
|
|
void | setFrameBeforeLoadingWorld () |
|
void | setTicksAdjustment (int ticks) |
|
void | setPaused (bool val) |
|
bool | isPaused () const |
|
|
using | TimePoint = std::chrono::steady_clock::time_point |
|
|
double | getLimitedDt () |
| Returns the current dt, which guarantees a limited frame rate.
|
|
void | updateRace (int ticks, bool fast_forward) |
| Updates all race related objects.
|
|
double | convertToTime (const TimePoint &cur, const TimePoint &prev) const |
|
|
std::atomic_bool | m_abort |
| True if the main loop should exit.
|
|
std::atomic_bool | m_request_abort |
|
std::atomic_bool | m_paused |
|
bool | m_throttle_fps |
| True if the frame rate should be throttled.
|
|
bool | m_allow_large_dt |
| True if dt is not decreased for low fps.
|
|
bool | m_frame_before_loading_world |
|
bool | m_download_assets |
|
Synchronised< int > | m_ticks_adjustment |
|
TimePoint | m_curr_time |
|
TimePoint | m_prev_time |
|
unsigned | m_parent_pid |
|
Management class for the whole gameflow, this is where the main-loop is.
◆ getLimitedDt()
double MainLoop::getLimitedDt |
( |
| ) |
|
|
private |
Returns the current dt, which guarantees a limited frame rate.
If dt is too low (the frame rate too high), the process will sleep to reach the maximum frame rate.
◆ renderGUI()
void MainLoop::renderGUI |
( |
int |
phase, |
|
|
int |
loop_index = -1 , |
|
|
int |
loop_size = -1 |
|
) |
| |
Renders the GUI.
This function is used during loading a track to get a responsive GUI, and allow GUI animations (like a progress bar) to be shown.
- Parameters
-
phase | An integer indicated a phase. The maximum number of phases is used to show a progress bar. The values are between 0 and 8200. |
loop_index | If the call is from a loop, the current loop index. |
loop_size | The number of loop iterations. Used to smooth update e.g. a progress bar. |
◆ run()
Run the actual main loop.
The sequence in which various parts of STK are updated is:
- Determine next time step size (
getLimitedDt
). This takes maximum fps into account (i.e. sleep if the fps would be too high), and will actually slow down the in-game clock if the fps are too low (if more than 3/60 of a second have passed, more than 3 physics time steps would be needed, and physics do at most 3 time steps).
- if a race is taking place (i.e. not only a menu being shown), call
updateRace()
, which is a thin wrapper around a call to World::updateWorld()
:
- Update history manager (which will either set the kart position and/or controls when replaying, or store the current info for a replay). This is mostly for debugging only (though available even in release mode).
- Updates Replays - either storing data when not replaying, or updating kart positions/control when replaying).
- Calls
WorldStatus::update()
, which updates the race state (e.g. go from 'ready' to 'set' etc), and clock.
- Updates the physics (
Physics::update()
). This will simulate all physical objects for the specified time with bullet.
- Updates all karts (
Kart::update()
). Obviously the update function does a lot more than what is described here, this is only supposed to be a very high level overview:
- Updates its rewinder (to store potentially changed controls as events) in
KartRewinder::update()
.
- Calls
Moveable::update()
, which takes the new position from the physics and saves it (and computes dependent values, like heading, local velocity).
- Updates its controller. This is either:
- an AI using
SkiddingController::update()
(which then will compute the new controls), or
- a player controller using
PlayerController::update()
, which will handle smooth steering (in case of digital input devices steering is adjusted a bit over time to avoid an instant change from all left to all right). Input events will be handled when updating the irrlicht driver later at the end of the main loop.
- Updates kart animation (like rescue, ...) if one is shown atm.
- Update attachments.
- update physics, i.e. taking the current steering and updating the bullet raycast vehicle with that data. The settings are actually only used in the next frame when the physics are updated.
- Updates all cameras via
Camera::update()
. The camera position and rotation is adjusted according to the position etc of the kart (and special circumstances like rescue, falling).
- Updates all projectiles using the projectile manager. Some of the projectiles are mostly handled by the physics (e.g. a cake will mainly check if it's out of bounds), others (like basket ball) do all their aiming and movement here.
- Updates the rewind manager to store rewind states.
- Updates the music manager.
- Updates the input manager (which only updates internal time, actual input handling follows late)
- Updates the wiimote manager. This will read the data of all wiimotes and feed the corresponding events to the irrlicht event system.
- Updates the STK internal gui engine. This updates all widgets, and e.g. takes care of the rotation of the karts in the KartSelection screen using the ModelViewWidget.
- Updates STK's irrlicht driver
IrrDriver::update()
:
- Calls Irrlicht's
beginScene()
.
- Renders the scene (several times with different viewport if split screen is being used)
- Calls
GUIEngine::render()
, which renders all widgets with the help of Irrlicht's GUIEnvironment (drawAll()
). This will also handle all events, i.e. all input is now handled (e.g. steering, firing etc are all set in the corresponding karts depending on user input).
- Calls Irrlicht's
endScene()
◆ updateRace()
void MainLoop::updateRace |
( |
int |
ticks, |
|
|
bool |
fast_forward |
|
) |
| |
|
private |
Updates all race related objects.
- Parameters
-
ticks | Number of ticks (physics steps) to simulate - should be 1. |
fast_forward | If true, then only rewinders in network will be updated, but not the physics. |
The documentation for this class was generated from the following files: