EngineSource for GameDevs

From Spring
Revision as of 19:31, 1 December 2011 by Knorke (talk | contribs) (created page, not if worth to continue?)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Intro

During creation of a Spring game you will soon notice that not everything is documentated. Fortunately, the engine is open source and thus some things can be figured out by looking at it.

Wait, isn't that like, super cryptic? Yes, scroll past those parts. A few things are comprehendible.

Text

For example the code to load UnitDefs can be found here: https://github.com/spring/spring/blob/develop/rts/Sim/Units/UnitDef.cpp

Scroll down to about line 270:
Notice how there are lines like for example this:

metalStorage = udTable.GetFloat("metalStorage", 0.0f);

The word in double quotes ("metalStorage") is the UnitDef tag as it is read from the unit file.

If a tag can not be found in this file in this form, it is very likely that it does nothing and you can remove it from the unit file.

GetFloat means that this tag is a float number. The number, in this case 0.0f, is the default value that is used, when the tag can not be found in the unit file.

Since the engine expects a number (eg 100.0) it is understandable that metalStorage = "a lot", or metalStorage=false will not work.

Beside GetFloat there are:

GetBool - true or false

GetInt - an integer number

GetString - a string, that means a word eg a unit name or a file name

GetFloat3 - 3 floats, for example coordinates in case of "modelCenterOffset" or a vector in case of "flareDropVector"

Interessting files

Most things outside "Sim" folder are uninteressting.

The files where XYdefs get loaded:

https://github.com/spring/spring/blob/develop/rts/Sim/Units/UnitDef.cpp

https://github.com/spring/spring/blob/develop/rts/Sim/Weapons/WeaponDefHandler.cpp

https://github.com/spring/spring/blob/develop/rts/Sim/Features/FeatureHandler.cpp

https://github.com/spring/spring/blob/develop/rts/Sim/MoveTypes/MoveInfo.cpp

Unit actions (damage, kill, experience,...):
https://github.com/spring/spring/blob/develop/rts/Sim/Units/Unit.cpp