Main loop
Main loop (in D_SRB2Loop) consists of parts:
- Game logic: TryRunTics
- Graphics: D_Display
- Has special case for frozen netplay, which allows for moving the camera in that situation without running game logic
- Screenshot and movie mode handling happens after drawing, based on flags set somewhere earlier
- Sounds: S_UpdateSounds
- LUA GC: LUA_Step
Calls:
-
TryRunTics
- COM_BufTicker
- D_MapChange
-
G_Ticker
- G_CopyTiccmd
-
P_Ticker
- P_RunThinkers (also called twice in P_LoadLevel by P_PreTicker)
- various other tickers
- D_Display
TryRunTics
- Runs a number of game logic tics depending on current time.
- If other code (like rendering) has taken too long, multiple tics can be run to compensate and keep the speed of the game consistent.
Calls:
- COM_BufTicker
- pending console command execution
- D_MapChange
- NetUpdate
- GetPackets
- G_Ticker
- ExtraDataTicker
- netxcmd stuff
G_Ticker
- Runs one tic of game logic.
Calls:
- G_DoReborn (respawn)
- tickers for various game states (in level, intermission, cutscene etc.)
- in level:
- P_Ticker
- ST_Ticker
- title card logic
- F_TextPromptTicker
- AM_Ticker
- automap logic
- HU_Ticker
- hud logic (not much)
NetUpdate
- Input handling and some network functions.
- when game is running fast enough, it will get run inside TryRunTics?
- when game is running slowly, it will also get run in various other places scattered in the code
- not faster than 35 times in a second though
Calls:
- Local_Maketic
- I_OsPolling
- D_ProcessEvents
- responders
- G_BuildTiccmd
- LUAh_PlayerCmd
- LUAh_ViewpointSwitch (reset back to self when moving)
- GetPackets
- CL_SendClientCmd
- other network stuff
- M_Ticker
- CON_Ticker
P_Ticker
- Handles game world.
- Runs player thinking.
- Runs all thinkers.
- Code for various other fixed game logic parts.
- Lua ThinkFrame.
P_RunThinkers
- Runs functions specified in the thinkers.
- Multiple thinker lists for separate purposes.
- polyobjects
- main
- things that move or do stuff but are not mobjs or polyobjects
- mobjs
- P_MobjThinker
- dynamic slopes
- precipitation
- most precip logic is moved to rendering code with culling, but the current implementation still relies on some code running for every precip thinker
P_MobjThinker
- Thinker function for all mobjs. Run for every mobj by P_RunThinkers, except for those with nothink.
- Various checks and switch statements for the different mobj types in the game.
- Mobj states and actions.
- Movement physics.
- XY movement
- Z movement
- Scenery gets a separate similar but somewhat simpler code path.