Demand Script Loading

Demand Script Loading is an optional add-on for the SkookumScript runtime that adds the ability in the IDE to tag a class (and any subclasses) as “demand loaded” so that the runtime can load and unload pre-compiled class group script binaries based on game progression or other criteria.

This is great (and possibly a requirement) for a huge open-world game or a large sprawling massively multiplayer world that you need to fit into memory. It may also be the case that your platform is a tiny mobile device and you must squeeze out every byte you can. In all these cases – the Demand Script Loading add-on is your solution.

Load in or out an entire class (including any subclasses) quickly and easily so that scripts are only in memory when they are needed. Don’t load the game missions that take place at the end of the game at the start of the game. Have a bunch of mission scripts that only take place if you have a certain vehicle or special inventory item? Don’t load them. Have ambient behaviors that are relative to a geographical region that is far away from the current location of the player? Ensure that they take up no space.

This can also be used for code that you want to compile though you only use it in special cases such as smoke tests and you don’t want it taking up space.

Example demand load statistics: Sleeping Dogs
To give an idea of demand load classes in action on an actual project – Sleeping Dogs: Definitive Edition had a limit of 10MB for all the 64-bit SkookumScript code and runtime data. The runtime data was around 2.5MB in preallocated pools of reusable data structures. This left around 7.5MB for SkookumScript code. However, the entire Sleeping Dogs SkookumScript class hierarchy was around 23.5MB in size!

Extensive use of demand load classes made it so that only 5MB was permanently loaded and the remaining 2.5MB was available for demand loaded classes to be loaded and unloaded as needed based on game progression, game geography, etc.

This meant that the 35-40 member scripting team could pound out scripts and they essentially only had to watch memory on a per mission basis rather than the whole game at once.

Working with demand loaded classes

To specify that a class (and any subclasses) should be saved as a separate demand loadable binary, set the demand_load setting in the !Class.skoo-meta file for a class to true – for more info see Class Meta File.

Classes that are set to demand load are saved out as binary files separate from the main SkookumScript class hierarchy binary. Demand load classes are not loaded at SkookumScript initialization by default.

The logic to determine when to load and unload demand load classes is entirely up to your game. There are simple calls to the C++ API to load and unload classes based on the progression of your game or any other criteria that you like.

You can also stream in script binaries pre-emptively once you know they will soon to be needed so players can travel through your huge world seamlessly.