Code structure

Code structure

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Muon
Posts: 24
Joined: 23 Jan 2012, 21:42

Code structure

Post by Muon »

I've been wading around in the code for some time now, and I honestly don't understand much of it. I'd really like to actually do something useful! So, here are my initial questions:
  • Where does the world get updated?
  • How is rendering done, and what is responsible for it?
  • What is exposed to Lua?
  • How stable is the Lua interface?
  • Why are there so many globals?
  • Why do so many files include GlobalRendering.h?
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Code structure

Post by SirMaverick »

Muon wrote:I've been wading around in the code for some time now, and I honestly don't understand much of it.
It's complex (450000 lines of code). It takes time.
[*]Where does the world get updated?
I assume "world == all stuff you see: units, features, map etc.".
Let's follow the code! The main function is in rts/System/Main.*, which starts an instance of SpringApp (rts/System/SpringApp.*) and runs SpringApp::Run(). After Initialization etc. it runs a loop where it calls UpdateSim() (internally calls activeController->Update()) and activeController->Draw().

The activeController (base class CGameController) is an abstraction of the interface. There are several types: e.g. PreGame, LoadScreen and Game. Once the game is loaded and running CGame (rts/Game/Game.*) is the activeController.

So each controller has an Update and Draw function. The Update function updates the game state. The Draw function will update the graphics.
CGame::Update() reads the network input. As the simulation is synced, updates will only be done on input that is send from the server.
Once the server sends a NEWFRAME message CGame::SimFrame() is called, where you can see a long list of stuff that gets updated (map, units, features, wind, los, teams, players etc.).

Follow the code further to see more details!
Muon
Posts: 24
Joined: 23 Jan 2012, 21:42

Re: Code structure

Post by Muon »

Thanks! :-) That was very informative.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Code structure

Post by PicassoCT »

indeed
User avatar
MelKor
Posts: 38
Joined: 15 Oct 2010, 16:05

Re: Code structure

Post by MelKor »

This explanation should be in wiki, srsly.

MelKor
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Code structure

Post by smoth »

MelKor wrote:This explanation should be in wiki, srsly.
then put it in there.

-Smoth

oh and my name is on the left of this post also.
Post Reply

Return to “Engine”