Example #1
0
    public void OnEventGroupDispatch(EmotionEventGroup g)
    {
        EmotionStateMachineData data = new EmotionStateMachineData();

        data.associatedEventGroup = g;
        data.timestamp            = ProceduralEngine.Instance.CurrentTimeNormalized;
        EvaluateTransitions(data);
    }
    public void UpdateEvents(float currentTimeNormalized)
    {
        // Event group dispatch
        if (timeCounter >= timeResolution)
        {
            timeCounter = 0f;

            int currentGroup    = GetGroupIndexForNormalizedTime(currentTimeNormalized);
            EmotionEventGroup g = eventGroups[currentGroup];

            if (g != null)
            {
                foreach (ProceduralEventListener l in listeners)
                {
                    l.OnEventGroupDispatch(g);
                }

                // Add all new future events to the queue
                foreach (EmotionEvent e in g.events)
                {
                    currentQueue.Enqueue(e);
                }

                //Debug.Log("Dispatched a group with " + g.events.Count + " events. Index: " + currentGroup);
            }
        }
        else
        {
            timeCounter += Time.deltaTime;
        }

        // Dispatch actual events
        while (currentQueue.Count > 0 && currentQueue.Peek().timestamp < currentTimeNormalized)
        {
            // Consume it
            EmotionEvent e = currentQueue.Dequeue();

            foreach (ProceduralEventListener l in listeners)
            {
                l.OnEventDispatch(e);
            }

            //Debug.Log("Dispatched event: " + e.ToString() + " at time " + currentTimeNormalized);
        }
    }
    protected void GatherEvents()
    {
        int groupsCount = Mathf.CeilToInt(ProceduralEngine.Instance.Duration / timeResolution);

        eventGroups = new EmotionEventGroup[groupsCount];

        Queue <EmotionEvent> queue = ProceduralEngine.Instance.EmotionEngine.BuildEventQueue();

        while (queue.Count > 0)
        {
            EmotionEvent e     = queue.Dequeue();
            int          index = GetGroupIndexForNormalizedTime(e.timestamp);

            if (eventGroups[index] == null)
            {
                eventGroups[index] = new EmotionEventGroup();
            }

            eventGroups[index].events.Add(e);
        }
    }
 public void OnEventGroupDispatch(EmotionEventGroup g)
 {
 }
    /// <summary>
    /// This method has two main responsibilities:
    /// - Decide when to cut
    /// - Decide what shot to take
    /// It is tied to a specific event, so that the chaining of shots is possible
    /// </summary>
    protected ShotInformation TryFindCut(EmotionEvent startEvent)
    {
        ShotInformation shot = new ShotInformation();

        shot.valid             = false;
        shot.selectedCamera    = null;
        shot.type              = TransitionType.Cut; // TODO: for now...
        shot.strategy          = null;
        shot.interestPoint     = null;
        shot.sampledStrategies = new List <KeyValuePair <ProceduralCameraStrategy, float> >();
        shot.startEvent        = startEvent;

        // Make sure we don't lag
        float timestamp = Mathf.Max(startEvent.timestamp, ProceduralEngine.Instance.CurrentTimeNormalized);

        CutRange searchRange = EvaluateCutRangeForEvent(startEvent);
        float    minT        = timestamp + searchRange.minCutTime;
        float    maxT        = timestamp + searchRange.maxCutTime * (1f + nextShotTries * .1f); // Increase search range when it fails

        List <EmotionEventGroup> searchEvents = ProceduralEngine.Instance.EventDispatcher.GetFutureEventGroups(minT, maxT);

        if (searchEvents.Count == 0)
        {
            Debug.Log("Could not find event groups... " + minT + ", " + maxT);
            return(shot);
        }

        EmotionEventGroup selectedGroup = null;
        bool structural = false;

        foreach (EmotionEventGroup g in searchEvents)
        {
            if (g.ContainsStructuralEvent())
            {
                selectedGroup = g;
                structural    = true;
            }
        }

        if (selectedGroup == null)
        {
            selectedGroup = ProceduralEngine.SelectRandomWeighted(searchEvents, x => x.GetPriority());
        }

        // We found a subset of interesting events, now we can pick something in here
        if (selectedGroup != null && selectedGroup.events.Count > 0)
        {
            EmotionEvent selectedEvent;

            if (structural)
            {
                selectedEvent = selectedGroup.GetStructuralEvent();
            }
            else
            {
                selectedEvent = ProceduralEngine.SelectRandomWeighted(selectedGroup.events, x => GetEventPriority(x));
            }

            shot.duration = (selectedEvent.timestamp - timestamp);
            shot.selectedNextEventTrigger = selectedEvent;

            // Try cutting before, but not after
            float margin        = emotionEngine.BeatDurationNormalized * .5f;
            float fuzzyDuration = shot.duration - ProceduralEngine.RandomRange(0f, margin);

            if (fuzzyDuration > searchRange.minCutTime && fuzzyDuration < searchRange.maxCutTime)
            {
                shot.duration = fuzzyDuration;
            }

            shot.valid = true;
        }

        return(shot);
    }