Spring Engine Code: Difference between revisions
Hughperkins (talk | contribs) added Scripts section |
Hughperkins (talk | contribs) Added summary of mods |
||
| Line 28: | Line 28: | ||
The current loaded script is specified by Game/StartScripts/ScriptHandler.cpp : CScriptHandler::Instance->chosenScript | The current loaded script is specified by Game/StartScripts/ScriptHandler.cpp : CScriptHandler::Instance->chosenScript | ||
== Mods == | |||
The mod selection takes place in PreGame.cpp. | |||
The mod is loaded by multiple files, such as Sim/Units/UnitDefHandler.cpp , which are called from Game.cpp, in the constructor: | |||
unitDefHandler=new CUnitDefHandler(); | |||
[[Category:Source development]] | [[Category:Source development]] | ||
Revision as of 19:00, 10 November 2006
To get people somewhat started into the mass of spring engine code, here is a small "walkthrough" of the game process. Another good way of learning the code is building it in debug mode, setting a breakpoint at some place, and running spring. When it breaks on that point you'll be able to see full call stack which is very educational.
- Application entry point (Main.cpp)
- Window is created
- VFS is initialized (VFSHandler.cpp)
- Game setup:
- if there is a start script (like script.txt) this is used to initialize the global gameSetup (in GameSetup.cpp)
- CPreGame is created
- if it's a client: CPreGame either waits for a start script.txt i
- if it's a server: CPreGame uses the given start script (if one) or shows the list of startup CScript classes such as Commanders or Global AI
- CGame is created
- CGame::CGame() will load all game data such as the map, unit models, textures, features
- Main window message loop starts
Game Update
- update the networking, and when a message for a new frame arrives start update the game. This might seem weird, but because all game simulations have to be synced, it shouldn't run the game further until the server is ready.
- unit handler update
- feature update
- projectile handler update
- ...
Scripts
A script may optionally be loaded, and is run once a frame. This is not the same as the script.txt which only provides initialization data, typically to communicate from the lobby to spring.exe.
The current loaded script is specified by Game/StartScripts/ScriptHandler.cpp : CScriptHandler::Instance->chosenScript
Mods
The mod selection takes place in PreGame.cpp.
The mod is loaded by multiple files, such as Sim/Units/UnitDefHandler.cpp , which are called from Game.cpp, in the constructor:
unitDefHandler=new CUnitDefHandler();