In a game, each actor is defined by a set of behaviors that are active over time. These behaviors can take effect for any reason, and remain active for a certain duration of time. For example, “waving to somebody” or “saying a few words” are behaviors.
Generally speaking, such a behavior is modular if it:
Requires minimal number of dependencies to other elements within the game’s engine and data.
Conforms to a pre-established specification when applied to an actor.
Behaviors are a composed of their own computation and memory. So, both must have the fewest possible dependencies and conform to a standard interface.
To reduce the dependencies of your behaviors’ computation, they should be allowed as much as possible to:
Run independently from other behaviors.
Execute in parallel with other non-conflicting behaviors.
Disassociate themselves from the rest of the engine code.
This provides a great deal of flexibility, and it opens the door for parallelism of behaviors. Of course to make this really modular, you also need to think about their data too…
Similar principles apply to the memory used by your behaviors if you want them to be modular:
Should be able to function with only the necessary data components of an actor.
Optionally use private memory, and be responsible for it.
Use a minimal of memory from other behaviors, preferably none.
As you’ll see in the next part, there are two opposite strategies for deciding exactly how to implement this.