Esempio n. 1
0
        void SyncVideoWithPosition()
        {
            // Checks if the position change comes from a new
            if (Position != InternalPosition)
            {
                _internalPosition = Position;

                // Checks if the current action has changed
                SetCurrentAction(false, false);

                if (CurrentAction == null)
                {
                    // If no action (outside boundaries or else)
                    Stop();
                    Source = null;
                    return;
                }
                CurrentAction.LoadAndSync();
                RaiseCurrentActionChanged();

                if (IsPlaying && MediaElement != null)
                {
                    CurrentAction.Run();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Plays the path
        /// </summary>
        public void Play()
        {
            // Try to set the current action if none
            if (CurrentAction == null)
            {
                SetCurrentAction(true, true);
            }

            // If none exists, get out
            if (CurrentAction == null)
            {
                return;
            }

            if (CurrentAction.IsLast && Position >= CurrentAction.End)
            {
                // Sets the first action to play if we were at the end
                var a = _actions.First();
                SeekAndResync(a.Start);
                CurrentAction = a;
            }

            IsPlaying = true;

            // Runs the action
            CurrentAction.LoadAndSync();
            RaiseCurrentActionChanged();
            CurrentAction.Run();

            // Goes to playing mode
            VisualStateManager.GoToState(this, VSM_State_IsPlaying, false);
        }
Esempio n. 3
0
        public IEnumerable <RantOutput> RunSerial(double timeout, RantPattern pattern = null)
        {
            lock (_patternArgs ?? fallbackArgsLockObj)
            {
                if (pattern == null)
                {
                    pattern = _pattern;
                }
                LastTimeout = timeout;
                long timeoutMS = (long)(timeout * 1000);
                bool timed     = timeoutMS > 0;
                bool stopwatchAlreadyRunning = _stopwatch.IsRunning;
                if (!_stopwatch.IsRunning)
                {
                    _stopwatch.Reset();
                    _stopwatch.Start();
                }

                _scriptObjectStack.Clear();
                var callStack   = new Stack <IEnumerator <RantAction> >();
                var actionStack = new Stack <RantAction>();
                IEnumerator <RantAction> action;

                // Push the AST root
                CurrentAction = pattern.Action;
                actionStack.Push(CurrentAction);
                callStack.Push(pattern.Action.Run(this));

top:
                while (callStack.Any())
                {
                    // Get the topmost call stack item
                    action = callStack.Peek();

                    // Execute the node until it runs out of children
                    while (action.MoveNext())
                    {
                        if (timed && _stopwatch.ElapsedMilliseconds >= timeoutMS)
                        {
                            throw new RantRuntimeException(pattern, action.Current.Range,
                                                           $"The pattern has timed out ({timeout}s).");
                        }

                        if (callStack.Count >= RantEngine.MaxStackSize)
                        {
                            throw new RantRuntimeException(pattern, action.Current.Range,
                                                           $"Exceeded the maximum stack size ({RantEngine.MaxStackSize}).");
                        }

                        if (action.Current == null)
                        {
                            break;
                        }

                        if (HandleRichardBreak(callStack, actionStack, action))
                        {
                            goto top;
                        }

                        // Push child node onto stack and start over
                        CurrentAction = action.Current;
                        actionStack.Push(CurrentAction);
                        callStack.Push(CurrentAction.Run(this));
                        goto top;
                    }

                    if (shouldYield)
                    {
                        shouldYield = false;
                        yield return(Return());

                        AddOutputWriter();
                    }

                    if (HandleRichardReturn(callStack, actionStack))
                    {
                        continue;
                    }

                    // Remove node once finished
                    callStack.Pop();
                    actionStack.Pop();
                }

                if (!stopwatchAlreadyRunning)
                {
                    _stopwatch.Stop();
                }
            }
        }
Esempio n. 4
0
        public IEnumerable <RantOutput> RunSerial(double timeout, RantProgram pattern = null)
        {
            Stack <IEnumerator <RST> > callStack;
            IEnumerator <RST>          action;

            LastTimeout = timeout;
            long timeoutMS = (long)(timeout * 1000);
            bool timed     = timeoutMS > 0;
            bool stopwatchAlreadyRunning = _stopwatch.IsRunning;

            lock (PatternArgs ?? fallbackArgsLockObj)
            {
#if !DEBUG
                try
                {
#endif
                if (pattern == null)
                {
                    pattern = Pattern;
                }

                if (!_stopwatch.IsRunning)
                {
                    _stopwatch.Reset();
                    _stopwatch.Start();
                }

                callStack = new Stack <IEnumerator <RST> >();


                // Push the AST root
                CurrentAction = pattern.SyntaxTree;
                callStack.Push(pattern.SyntaxTree.Run(this));
#if !DEBUG
            }
            catch (RantRuntimeException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new RantInternalException(ex);
            }
#endif
top:
                while (callStack.Any())
                {
#if !DEBUG
                    try
                    {
#endif
                    // Get the topmost call stack item
                    action = callStack.Peek();

                    // Execute the node until it runs out of children
                    while (action.MoveNext())
                    {
                        if (timed && _stopwatch.ElapsedMilliseconds >= timeoutMS)
                        {
                            throw new RantRuntimeException(this, action.Current.Location,
                                                           GetString("err-pattern-timeout", timeout));
                        }

                        if (callStack.Count >= RantEngine.MaxStackSize)
                        {
                            throw new RantRuntimeException(this, action.Current.Location,
                                                           GetString("err-stack-overflow", RantEngine.MaxStackSize));
                        }

                        if (action.Current == null)
                        {
                            break;
                        }

                        // Push child node onto stack and start over
                        CurrentAction = action.Current;
                        callStack.Push(CurrentAction.Run(this));
                        goto top;
                    }

#if !DEBUG
                }
                catch (RantRuntimeException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new RantInternalException(ex);
                }
#endif

                    if (shouldYield)
                    {
                        shouldYield = false;
                        yield return(Return());

                        AddOutputWriter();
                    }

#if !DEBUG
                    try
                    {
#endif
                    // Remove node once finished
                    callStack.Pop();
#if !DEBUG
                }
                catch (RantRuntimeException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new RantInternalException(ex);
                }
#endif
                }

                if (!stopwatchAlreadyRunning)
                {
                    _stopwatch.Stop();
                }
            }
        }