SCRMaps
/
Sign in

Holding on to many units

UnitGroup and EUDBag: keeping a list of units instead of finding them again every cycle.

5 min read

A unit loop is expensive: every cycle it walks 1,700 slots to pick out the ones that match, even though the set it finds barely changes. A UnitGroup is a structure that keeps that set and iterates only it.

The implementation is the interesting part. Triggers are a linked list that points at itself, and EUDBag uses exactly that: it keeps triggers holding between one and 64 actions, in sorted order. The data structure is not an array in memory, it is the trigger chain.

Units in your list die. That is why UnitGroup carries the uniquenessIdentifier, and if you roll your own list you have to make the same check. Without it you command whichever unit moved into the dead one's slot - the symptom is "sometimes the wrong unit moves", and that is very hard to reproduce.

Getting a handle on one unit
Sign in to track your progress