protected void CompleteShot(ref ShotInformation shot)
    {
        if (!shot.valid)
        {
            return;
        }

        bool failedToFindInterestingStrategies = frames > 10 && shot.interestPoint != null && shot.sampledStrategies.Count == 0;

        if (failedToFindInterestingStrategies)
        {
            shot.interestPoint = null;
            frames             = 0;
        }

        if (shot.interestPoint == null)
        {
            EmotionSpectrum emotionAtShotStart = emotionEngine.GetSmoothSpectrum(shot.startEvent.timestamp);
            shot.interestPoint = FindInterestPoint(emotionAtShotStart, shot.startEvent.timestamp);
        }
        else
        {
            SampleStrategies(shot.sampledStrategies, shot.interestPoint, shot.startEvent, shot.duration * ProceduralEngine.Instance.Duration);
        }
    }
    protected void StartTransition(ShotInformation shot)
    {
        if (currentShot.valid && currentShot.strategy != null)
        {
            currentShot.strategy.StopStrategy();
        }

        if (shot.valid)
        {
            // Select the strategy when starting the transition
            shot.strategy       = ProceduralEngine.SelectRandomWeighted(shot.sampledStrategies, x => x.Value).Key;
            shot.selectedCamera = InstanceCamera();

            this.history.Add(shot);
            this.nextShot = new ShotInformation();
            this.nextShot.sampledStrategies = new List <KeyValuePair <ProceduralCameraStrategy, float> >();
            this.nextShotTries  = 0;
            this.currentCutTime = 0f;

            this.currentShot   = shot;
            this.currentCamera = shot.selectedCamera;
            this.currentCamera.InitializeCamera(currentShot.strategy, GetComponent <PostProcessingBehaviour>().profile);
            this.currentShot.strategy.StartStrategy(currentCamera);
        }
    }
Esempio n. 3
0
 public static ShotInformationResponse ToRest(this ShotInformation shotInformation)
 {
     return(new ShotInformationResponse()
     {
         Destroy = shotInformation.Destroy,
         Knock = shotInformation.Knock,
         End = shotInformation.End
     });
 }
    public void InitializeDirector(EmotionEngine engine)
    {
        this.emotionEngine = engine;
        this.nextShot      = new ShotInformation();
        this.grid          = GetComponent <InterestPointGrid>();

        ProceduralEngine.Instance.EventDispatcher.AddListener(this);

        this.currentShot       = new ShotInformation();
        this.currentShot.valid = false;
    }
    public void UpdateCamera(float t)
    {
        if (!currentShot.valid)
        {
            return;
        }

        CompleteShot(ref nextShot);

        if (currentCutTime < currentShot.duration)
        {
            // Normalized delta
            currentCutTime += Time.deltaTime / ProceduralEngine.Instance.Duration;

            if (!nextShot.valid)
            {
                nextShot = TryFindCut(currentShot.selectedNextEventTrigger);
                nextShotTries++;

                //if (nextShot.valid)
                //    Debug.Log("Found shot at frame " + frames);
            }
            else
            {
                CompleteShot(ref nextShot);
            }
        }
        else
        {
            //Debug.Log(frames);
            //Debug.Log(nextShot.interestPoint);
            //Debug.Log(nextShot.sampledStrategies.Count);

            //if (nextShot.sampledStrategies.Count == 0)
            //    Debug.Log(nextShot.interestPoint, nextShot.interestPoint);

            frames = 0;

            if (nextShot.valid)
            {
                StartTransition(nextShot);
            }
            else
            {
                // Couldnt sample an interesting shot, just repeat the last one
                StartTransition(currentShot);
                Debug.Log("Failed finding a shot; repeating...");
            }
        }

        frames++;
    }
Esempio n. 6
0
    public ShotConfiguration GetNextShotConfig()
    {
        bool newFase = setupFase();

        Vector3 position;

        if (hardPositioning)
        {
            position = hardPosition;
        }
        else
        {
            position = AreaManager.GetRandomPoint(CurrentDifficulty,
                                                  ServiceLocator.Request <IGameplayService>().GetGameMode(), centerPercent);
        }

        ShotConfiguration config = new ShotConfiguration()
        {
            Mode = GameMode.Shooter,
            //Position = AreaManager.GetRandomPoint( CurrentDifficulty, ServiceLocator.Request<IGameplayService>().GetGameMode() ),
            Position   = position,
            Bullseyes  = null,
            Difficulty = CurrentDifficulty,
            Fase       = fase,
            IsNewFase  = newFase
        };

        // mostrar la barrera (si procede)
        SetupWall(position);

        // mostrar sábana (si procede)
        SetupSheet();

        lastConfig = config;

        ShotInformation info = new ShotInformation()
        {
            Shot   = config,
            Result = false
        };

        CurrentShot = info;
        sendEvent(config);
        return(config);
    }
    public void StartFirstShot()
    {
        EmotionEvent    firstEvent = emotionEngine.GetFirstEvent();
        ShotInformation firstShot  = new ShotInformation();

        int tries = 64;

        for (int i = 0; i < tries; ++i)
        {
            if (!firstShot.valid)
            {
                firstShot = TryFindCut(firstEvent);
            }
            else
            {
                CompleteShot(ref firstShot);
            }

            // Emulate frames so the interest point reset works
            frames++;
        }

        StartTransition(firstShot);
    }
    /// <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);
    }