actions&triggers: local and global IDs

an action needs to be able to reference any action or trigger that has been created in order to manipulate it.

For example:

if the player is standing in front of a door and presses X, the door should open.

If he presses X again, the door shouldn’t open again but close instead.

This means the ‘open’ action, once triggered, needs to deactivate itself and activate its sibling action instead.

In order to allow actions such a behaviour, each action needs a global unique identifier.

The action manager manages those IDs and is able to find the according pointer when queried with an ID.

Problem

This is all fine and well if an action wants to manipulate a very specific action or trigger in the global context. But what if the action wants to manipulate a local action?

The above example works fine with global IDs, but imagine what happens when the object containing the ‘open’ and ‘close’ actions gets copied and moved elsewhere.

If the player approaches the copied door and presses X, the door opens. That’s ok so far. The just triggered ‘open’ action deactivates itself as expected, but instead of activating its sibling action, it activates the ‘close’ action of the original door object.

Why? Because the just triggered ‘open’ action references the ‘close’ action by its global ID, which got copied along with the rest of the object.

Introducing Local IDs

In order to prevent exactly this problem from happening, aside from its global ID, each action also contains a ‘local ID‘.

This ID identifies the action within its parent object.

So if the door object’s ‘open’-action references its sibling action by its local ID,  copying the object would be no problem, the copied action would enable the correct sibling action.

The same system will be implemented for triggers.

technical details

the actionmanager class contains a map: “id <-> action pointer” for global IDs

the parent object contains a map: “id <-> action pointer” for local IDs

Whenever a local or global ID changes, the actionmanager or parent object gets notified.

If an action changes objects from one parent to another, the old parent gets notified and deregisters the action, before the new parent registers it.

both actionmanager and object get new methods that return the action pointer corresponding to a certain ID.

in addition to these changes, actions and triggers get the ability to reference target object not by their global ID but by using a constant or string telling them to use their parent object as their target.

One thought on “actions&triggers: local and global IDs

  1. another (perhaps better) approach at solving this issue:

    discard the idea of global IDs and use ID paths instead.

    a certain object within the world is identified through a sequence of IDs. Each ID is the local identifier of a parent object of the object in question.
    The first ID in the sequence is the globally accessible ID of a toplevel object. The second ID is the local ID of one of its children and so on.

    If the path contains “-1” as an ID, that means the next ID will have to be looked for in the current’s parent object.

    This approach uses more memory during loading/saving/editing, but is more flexible overall and solves the issue even for the upcoming object groups.

Leave a Reply