Godot RTS Template documentation
Principles
All units will use Static Function Modules, linked together through scripting to formulate the behaviors wanted for each unit, allowing great perfomance and customization, as RefCounted object type doesn't save any information, only works as Data Scripts. The idea is to use them to group similar methods or actions, for modules that needs to track it's values, them extending from Object should work, which can hold variables and track logics.
Tradeoffs
Abstract Coding / Limited to Static Functions
Module code needs to be abstract, modules are limited to static functions only, with no easy access to variables other than given by arguments. Unless you type.new() after preloading the script, which creates a new instance that can hold properties, which we want to avoid in order to achieve more perfomance.
An interface is required to access a module, making a module process by itself some logic is possible, but it cannot store any values on itself (this is a limitation we imposed to be more perfomant), so everything must be fed to these modules as an argument through the functions. A module can 'manage' indirectly something by giving a procedure to follow always, this assure they will work with a pre-defined values and behaviors.
For instance, one can add meta-data to any Object derivated class in Godot, we can use it to store information for this module or even for other modules, this way we can later track and adjust the correct wanted behavior for our module functionality, but keep the variables only in one place, avoiding multiple .new()
instances of a script.
We can keep track of metadata constants in a separate class to not mess things up, whenever we change those constants they should be updated for all modules.
NOTICE: Modules should avoid interacting with other modules, they don't do nothing by themselves, we want a library of books, a book shouldn't read other books, but someone could go pick a book and use it. This is an imposed limitation.
- If we want only functions to be applied we shouldn't do
.new()
after loading a script. (Only use Static Functions) - If we want a script to hold variables then we should do
.new()
to create a instance of it. (Can use and store variables outside Function Scope)
RefCounted vs Objects
Note
By not declaring an extent to a script file, it will automatically extend from RefCounted type
RefCounted delete itself when not used, opposed to the Object that stay until free()
or queue_free()
Game example
A sound created by a monster
Sound -> Resource -> RefCounted
When the sound is no longer in use it's going to automatically be freed.
For performance purpose, we will use a lot of RefCounted script, so that every time it's not used, it will be freed.
Main classes
see Classes to have an exhaustive list of class and implementation