public static void AddTurnTimelineEllibilityToTimeline(TurnTimeline p_turnTimeline, TurnTimelineElligibility p_turnTimelineElligibility) { if (p_turnTimelineElligibility.TurnTimelineElligibilityData.IsElligibleForTimeline) { TurnTimeline.addEntityToTimeline(p_turnTimeline, p_turnTimelineElligibility.AssociatedEntity); } }
public static OnTurnTimelineEllibilityComponentAdded build(TurnTimeline p_turnTimeline) { OnTurnTimelineEllibilityComponentAdded l_instance = new OnTurnTimelineEllibilityComponentAdded(); l_instance.TurnTimeline = p_turnTimeline; return(l_instance); }
public static TurnTimeline alloc() { TurnTimeline l_instance = new TurnTimeline(); l_instance.TimelineOrderingDatas = new RefDictionary <Entity, EntityTurnTimelineCalculationData>(); MyEvent <AEntityComponent> .IEventCallback l_turnTimelineComponentAddedEvent = OnTurnTimelineEllibilityComponentAdded.build(l_instance); l_instance.TurnTimelineElligibilityComponentAddedEventHandler = EntityComponentContainer.registerComponentAddedEvent <TurnTimelineElligibility>(ref l_turnTimelineComponentAddedEvent); MyEvent <AEntityComponent> .IEventCallback l_turnTimelineComponentRemovedEvent = OnTurnTimelineEllibilityComponentRemoved.build(l_instance); l_instance.TurnTimelineElligibilityComponentRemovedEventHandler = EntityComponentContainer.registerComponentRemovedEvent <TurnTimelineElligibility>(ref l_turnTimelineComponentRemovedEvent); if (EntityComponentContainer.Components.ContainsKey(typeof(TurnTimelineElligibility))) { List <AEntityComponent> l_turnTimelineElligiblityComponents = EntityComponentContainer.Components[typeof(TurnTimelineElligibility)]; if (l_turnTimelineElligiblityComponents != null) { for (int i = 0; i < l_turnTimelineElligiblityComponents.Count; i++) { OnTurnTimelineEllibilityComponentAdded.AddTurnTimelineEllibilityToTimeline(l_instance, (TurnTimelineElligibility)l_turnTimelineElligiblityComponents[i]); } } } TurnTimelineContainer.UniqueTurnTimeline = l_instance; return(l_instance); }
public static void addEntityToTimeline(TurnTimeline p_turnTimeline, Entity p_entity) { if (!p_turnTimeline.TimelineOrderingDatas.ContainsKey(p_entity)) { EntityTurnTimelineCalculationData l_initialEntityTurnTimelineCalculationdata = EntityTurnTimelineCalculationData.build(); l_initialEntityTurnTimelineCalculationdata.CurrentTimelinePosition = EntityTurnTimelineCalculationData.calculateReferenceTurnTimelineScore(p_entity); p_turnTimeline.TimelineOrderingDatas.Add(p_entity, l_initialEntityTurnTimelineCalculationdata); } }
/// <summary> /// Calculates the next <see cref="Entity"/> to play from the <see cref="TurnTimeline"/>. /// The next <see cref="Entity"/> to play is the one that have the lowest <see cref="EntityTurnTimelineCalculationData.CurrentTimelinePosition"/>. /// When this <see cref="Entity"/> has been found, all <see cref="EntityTurnTimelineCalculationData"/> advances in the timeline by the distance from 0 of the founded <see cref="Entity"/>.<see cref="EntityTurnTimelineCalculationData.CurrentTimelinePosition"/>. /// Then the founded <see cref="Entity"/> is pushed back to the timeline. /// </summary> /// <param name="p_turnTimeline"></param> /// <returns></returns> public static Entity IncrementTimeline(TurnTimeline p_turnTimeline) { Entity l_lowerTimelineScore = null; float l_currentComparedScore = 0.0f; RefDictionary <Entity, EntityTurnTimelineCalculationData> l_entityTurnTimelineDataLookup = p_turnTimeline.TimelineOrderingDatas; var l_entityTurnTimelineDataLookupEnumerator = l_entityTurnTimelineDataLookup.GetRefEnumerator(); while (l_entityTurnTimelineDataLookupEnumerator.MoveNext()) { var l_timelineOrderingDataEntry_ref = l_entityTurnTimelineDataLookupEnumerator.GetCurrentRef(); if (l_lowerTimelineScore == null) { l_lowerTimelineScore = l_timelineOrderingDataEntry_ref.key; l_currentComparedScore = l_timelineOrderingDataEntry_ref.value.CurrentTimelinePosition; } else if (l_timelineOrderingDataEntry_ref.value.CurrentTimelinePosition < l_currentComparedScore) { l_lowerTimelineScore = l_timelineOrderingDataEntry_ref.key; l_currentComparedScore = l_timelineOrderingDataEntry_ref.value.CurrentTimelinePosition; } } if (l_lowerTimelineScore != null) { float l_removedTimelineScore = l_currentComparedScore; // All entities advances in the timeline l_entityTurnTimelineDataLookupEnumerator = l_entityTurnTimelineDataLookup.GetRefEnumerator(); while (l_entityTurnTimelineDataLookupEnumerator.MoveNext()) { l_entityTurnTimelineDataLookupEnumerator.GetCurrentRef().value.CurrentTimelinePosition += (-1 * l_removedTimelineScore); } // The next Entity is pushed back on the Timeline l_entityTurnTimelineDataLookup.ValueRef(l_lowerTimelineScore).CurrentTimelinePosition = EntityTurnTimelineCalculationData.calculateReferenceTurnTimelineScore(l_lowerTimelineScore); } return(l_lowerTimelineScore); }
private void Awake() { TurnTimeline = TurnTimeline.alloc(); }
public static void free(TurnTimeline p_turnTimeline) { EntityComponentContainer.unRegisterComponentAddedEvent <TurnTimelineElligibility>(p_turnTimeline.TurnTimelineElligibilityComponentAddedEventHandler); EntityComponentContainer.unRegisterComponentRemovedEvent <TurnTimelineElligibility>(p_turnTimeline.TurnTimelineElligibilityComponentRemovedEventHandler); }