public static EntitiesIndexedByNavigationNodes build(NavigationEngine p_navigationEngine) { EntitiesIndexedByNavigationNodes l_instance = new EntitiesIndexedByNavigationNodes(); l_instance.Entities = new Dictionary <NavigationNode, List <Entity> >(); return(l_instance); }
/// <summary> /// If the <paramref name="p_entity"/> has a <see cref="NavigationModifier"/> component, then the fact that he has moved involves that the /// <see cref="NavigationGraph"/> layout is no more valid. <see cref="NavigationLink"/> must be recomputed to take into account the change. /// </summary> /// /// <param name="p_newNavigationNode"> /// The next <see cref="NavigationNode"/> where the <paramref name="p_entity"/> will be. /// This value can be null, meaning that the <paramref name="p_entity"/>"s <see cref="NavigationModifier"/> component has been detached. /// </param> public static void resolveNavigationObstacleAlterations(NavigationEngine p_navigationEngine, Entity p_entity, NavigationNode p_oldNavigationNode, NavigationNode p_newNavigationNode) { if (p_oldNavigationNode != p_newNavigationNode) { NavigationModifier l_entityNavigationModifier = EntityComponent.get_component <NavigationModifier>(p_entity); if (l_entityNavigationModifier != null && l_entityNavigationModifier.NavigationModifierData.IsObstacle) { if (p_newNavigationNode != null) { if (p_oldNavigationNode != null) { // We restore p_oldNavigationNode NavigationLinks only if there is no more NavigationModifier.Obstacle if (!EntityQuery.isThereAtLeastOfComponentOfType <NavigationModifier>(ref p_navigationEngine.EntitiesIndexedByNavigationNodes, p_oldNavigationNode, NavigationModifier.IsObstacle)) { NavigationLinkAlteration.restoreNavigationLinksFromSnapshot(NavigationGraphContainer.UniqueNavigationGraph, NavigationLinkAlteration.ENavigationLinkAlterationMethod.TO, p_oldNavigationNode); } } NavigationLinkAlteration.removeNavigationLinks(NavigationGraphContainer.UniqueNavigationGraph, NavigationLinkAlteration.ENavigationLinkAlterationMethod.TO, p_newNavigationNode); } else { // We restore p_oldNavigationNode NavigationLinks only if there is no more NavigationModifier.Obstacle if (!EntityQuery.isThereAtLeastOfComponentOfType <NavigationModifier>(ref p_navigationEngine.EntitiesIndexedByNavigationNodes, p_oldNavigationNode, NavigationModifier.IsObstacle)) { NavigationLinkAlteration.restoreNavigationLinksFromSnapshot(NavigationGraphContainer.UniqueNavigationGraph, NavigationLinkAlteration.ENavigationLinkAlterationMethod.TO, p_oldNavigationNode); } } } } }
/// <summary> /// Calls trigger event <see cref="INavigationTriggerComponent.OnTriggerEnter(Entity, List{_EventQueue.AEvent})"/> if the <paramref name="p_movingEntity"/> /// moves to a <see cref="NavigationNode"/> that contains any <see cref="INavigationTriggerComponent"/>. /// <see cref="INavigationTriggerComponent.OnTriggerEnter"/> event call are ordered by order defined by <see cref="TriggerResolutionOrder.TriggerComponentResolutionOrder"/>. /// </summary> public static void resolveTrigger(NavigationEngine p_navigationEngine, Entity p_movingEntity, NavigationNode p_oldNavigationNode, NavigationNode p_newNavigationNode) { if (p_newNavigationNode != null) { if (p_navigationEngine.EntitiesIndexedByNavigationNodes.Entities.ContainsKey(p_newNavigationNode)) { List <Entity> l_entitiesOnTheNewNavigationNode = p_navigationEngine.EntitiesIndexedByNavigationNodes.Entities[p_newNavigationNode]; List <INavigationTriggerComponent> l_currentEntityTriggerComponents = new List <INavigationTriggerComponent>(); for (int i = 0; i < l_entitiesOnTheNewNavigationNode.Count; i++) { Entity l_entity = l_entitiesOnTheNewNavigationNode[i]; if (l_entity != p_movingEntity) { TriggerResolutionOrder.extractTriggerComponentSortedByExecutionOrder(l_currentEntityTriggerComponents, l_entity); for (int j = 0; j < l_currentEntityTriggerComponents.Count; j++) { INavigationTriggerComponent l_resolvedComponent = l_currentEntityTriggerComponents[j]; l_resolvedComponent.OnTriggerEnter(p_movingEntity, p_navigationEngine.CachedProducedEventsStackByTriggers); } } } } } }
/// <summary> /// Tick the <see cref="NavigationEngine"/> : /// - Updates the position of the <paramref name="p_entity"/> on the <see cref="NavigationNode"/> indexed containers. /// (see <see cref="EntitiesIndexedByNavigationNodes.onNavigationNodeChange(ref EntitiesIndexedByNavigationNodes, Entity, NavigationNode, NavigationNode)"/>). /// - If the <paramref name="p_entity"/> is defined as an obstacle <see cref="_Navigation._Modifier.NavigationModifier"/>, then obstacles representation /// of the <see cref="NavigationGraph"/> is updated (see <see cref="ObstacleStep.resolveNavigationObstacleAlterations(NavigationEngine, Entity, NavigationNode, NavigationNode)"/>). /// - Calls the trigger events if elligible (see <see cref="TriggerResolutionStep.resolveTrigger(NavigationEngine, Entity, NavigationNode, NavigationNode)"/>). /// </summary> /// <param name="p_oldNavigationNode"> Thr old <see cref="NavigationNode"/> can be null. Meaning that the <paramref name="p_entity"/> wasn't positioned inside the <see cref="NavigationGraph"/> before. </param> /// <param name="p_newNavigationNode"> The target <see cref="NavigationNode"/> can be null. Meaning that the <paramref name="p_entity"/> have been destroyed. </param> public static List <AEvent> resolveEntityNavigationNodeChange(NavigationEngine p_navigationEngine, Entity p_entity, NavigationNode p_oldNavigationNode, NavigationNode p_newNavigationNode) { p_navigationEngine.CachedProducedEventsStackByTriggers.Clear(); EntitiesIndexedByNavigationNodes.onNavigationNodeChange(ref p_navigationEngine.EntitiesIndexedByNavigationNodes, p_entity, p_oldNavigationNode, p_newNavigationNode); ObstacleStep.resolveNavigationObstacleAlterations(p_navigationEngine, p_entity, p_oldNavigationNode, p_newNavigationNode); TriggerResolutionStep.resolveTrigger(p_navigationEngine, p_entity, p_oldNavigationNode, p_newNavigationNode); return(p_navigationEngine.CachedProducedEventsStackByTriggers); }
public static void free(NavigationEngine p_navigationEngine) { EntitiesIndexedByNavigationNodes.free(ref p_navigationEngine.EntitiesIndexedByNavigationNodes); if (NavigationEngineContainer.UniqueNavigationEngine == p_navigationEngine) { NavigationEngineContainer.UniqueNavigationEngine = null; } ; }
public static NavigationEngine alloc() { NavigationEngine l_instance = new NavigationEngine(); l_instance.EntitiesIndexedByNavigationNodes = EntitiesIndexedByNavigationNodes.build(l_instance); l_instance.CachedProducedEventsStackByTriggers = new List <AEvent>(); NavigationEngineContainer.UniqueNavigationEngine = l_instance; return(l_instance); }