I'd avoid extra offsets. What you're trying to do can be implemented this way (untested):
Syntax: Select all
from entities.dictionary import EntityDictionary
from entities.entity import Entity
from entities.helpers import index_from_pointer
from entities.hooks import EntityCondition, EntityPostHook
from memory import make_object
TRIGGER_CLASSNAME = 'trigger_multiple'
_touching_entities = EntityDictionary(lambda index: list())
@EntityPostHook(EntityCondition.equals_entity_classname(TRIGGER_CLASSNAME), 'start_touch')
def post_start_touch(stack_data, ret_val):
trigger = make_object(Entity, stack_data[0])
if trigger.classname != TRIGGER_CLASSNAME:
return
_touching_entities[trigger.index].append(make_object(Entity, stack_data[1]))
@EntityPostHook(EntityCondition.equals_entity_classname(TRIGGER_CLASSNAME), 'end_touch')
def post_end_touch(stack_data, ret_val):
trigger = make_object(Entity, stack_data[0])
if trigger.classname != TRIGGER_CLASSNAME:
return
entity = make_object(Entity, stack_data[1])
# If hot plugged, the entity might have been touching the trigger without us knowing
if entity in _touching_entities[trigger.index]:
_touching_entities[trigger.index].remove(entity)
def is_touching(trigger, entity):
return entity in _touching_entities[trigger.index]
This is assuming that when the entity is removed, it will call
end_touch of the trigger it is in - I don't know if it's true in fact.
Also I hope that
start_touch and
end_touch don't mess up its stack arguments while executing, otherwise you'll have to replace post-hooks with pre-hooks.
EDIT: It may occur that the engine will call
StartTouch multiple times for a single entity (without calling
EndTouch) - nobody guarantees the opposite. So you might need to check if the entity is in your list before appending to it.