/// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        private void CallerFunction(Object obj)
        {
            ExecState status = (ExecState)obj;

            try
            {
                status.Switcher.Wait();
                status.Action(status.State, status.Switcher);
                status.Switcher.SignalNext();
            }
            catch (NUnit.Framework.AssertionException ex)
            {
                status.Switcher.FailedAssertion = ex;
                //Ops exception, this means that no more signaling from this thread occurs.
                status.Switcher.SignalException();
            } catch (Exception ex)
            {
                status.Switcher.FailedAssertion = new AssertionException("Action throw exception", ex);
                status.Switcher.SignalException();
            }
            finally
            {
                Interlocked.Decrement(ref ExecutingCount);
            }
        }
Ejemplo n.º 2
0
 public void PushState(Action.ActionType ty, ExecState ex, bool pushpos = false)
 {
     execlevel++;
     exectype[execlevel]    = ty;
     execstate[execlevel]   = ex;
     execlooppos[execlevel] = (pushpos) ? (nextstepnumber - 1) : -1;
 }
Ejemplo n.º 3
0
    public void AnswerQuestion(string chosenQuestion)
    {
        for (int i = 0; i < curNode.Questions.Length; i++)
        {
            if (curNode.Questions[i] == chosenQuestion)
            {
                bool foundTag = false;
                for (int j = 0; j < curNode.OutDialogues.Length; j++)
                {
                    if (curNode.OutDialogues[j].DiagTopTag == i.ToString())
                    {
                        curDiag = curNode.OutDialogues[j];
                        if (curNode.factors.Length > i)
                        {
                            StaticParameters.factorMoneyFamily += curNode.factors[i].moneyFamily;
                            StaticParameters.factorConvProg    += curNode.factors[i].convProg;
                            StaticParameters.factorIntimicy    += curNode.factors[i].intimicy;
                            StaticParameters.factorTrustFun    += curNode.factors[i].trustFun;
                        }
                        actionIndex = 0;
                        state       = ExecState.ACTION;
                        foundTag    = true;
                        break;
                    }
                }

                if (!foundTag)
                {
                    Debug.LogError("Didnt find following dialog");
                }

                break;
            }
        }
    }
Ejemplo n.º 4
0
        void InitializeExecutionEngine(bool loadConfig, bool showHelp)
        {
            Debug.Assert(execState == null);
            if (execState != null)
            {
                throw new InvalidOperationException();
            }

            execState = new ExecState(this, new CancellationTokenSource());
            var execStateCache = execState;

            Task.Run(() => {
                AppCulture.InitializeCulture();
                execStateCache.CancellationTokenSource.Token.ThrowIfCancellationRequested();

                var userOpts = new UserScriptOptions();
                if (loadConfig)
                {
                    userOpts.LibPaths.AddRange(GetDefaultLibPaths());
                    userOpts.LoadPaths.AddRange(GetDefaultLoadPaths());
                    InitializeUserScriptOptions(userOpts);
                }
                var opts = ScriptOptions.Default;
                opts     = opts.WithMetadataResolver(ScriptMetadataResolver.Default
                                                     .WithBaseDirectory(AppDirectories.BinDirectory)
                                                     .WithSearchPaths(userOpts.LibPaths.Distinct(StringComparer.OrdinalIgnoreCase)));
                opts = opts.WithSourceResolver(ScriptSourceResolver.Default
                                               .WithBaseDirectory(AppDirectories.BinDirectory)
                                               .WithSearchPaths(userOpts.LoadPaths.Distinct(StringComparer.OrdinalIgnoreCase)));
                opts = opts.WithImports(userOpts.Imports);
                opts = opts.WithReferences(userOpts.References);
                execStateCache.ScriptOptions = opts;

                var script = Create <object>(string.Empty, execStateCache.ScriptOptions, typeof(IScriptGlobals), null);
                execStateCache.CancellationTokenSource.Token.ThrowIfCancellationRequested();
                execStateCache.ScriptState = script.RunAsync(execStateCache.Globals, execStateCache.CancellationTokenSource.Token).Result;
                if (showHelp)
                {
                    this.replEditor.OutputPrintLine(Help);
                }
            }, execStateCache.CancellationTokenSource.Token)
            .ContinueWith(t => {
                execStateCache.IsInitializing = false;
                var ex = t.Exception;
                if (!t.IsCanceled && !t.IsFaulted)
                {
                    CommandExecuted();
                }
                else
                {
                    replEditor.OutputPrintLine(string.Format("Could not create the script:\n\n{0}", ex));
                }
            }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Resets the executive - this clears the event list and resets now to 1/1/01, 12:00 AM
        /// </summary>
        public void Reset()
        {
            m_eventArray     = new _ExecEvent[InitialSize + 1];
            m_execEventCache = new ExecEventCache(InitialSize + 1);

            m_eventArraySize            = InitialSize;
            m_numEventsPending          = 0;
            m_numNonDaemonEventsPending = 0;
            m_now           = DateTime.MinValue;
            m_execState     = ExecState.Stopped;
            m_eventCount    = 0;
            m_stopRequested = false;
            m_key           = 0;
        }
Ejemplo n.º 6
0
        public void OutputGen_Returns_Correctly_Formatted_Disassembly_For_Last_Executed_Instruction()
        {
            // Arrange
            var cpu = new CPU(ExecState.ExecStateAfterInstruction(0, false, OpCodeId.LDX_I.ToByte(), 0xc0a0));
            var mem = new Memory();

            mem[0xc0a0] = OpCodeId.LDX_I.ToByte();
            mem[0xc0a1] = 0xee;

            // Act
            var outputString = OutputGen.GetLastInstructionDisassembly(cpu, mem);

            // Assert
            Assert.Equal("c0a0  a2 ee     LDX #$EE   ", outputString);
        }
Ejemplo n.º 7
0
    public void ContinueClick()
    {
        if (state == ExecState.ACTION_WAIT)
        {
            if (runningSpeakAnim)
            {
                for (int i = 0; i < animationFinders.Length; i++)
                {
                    if (animationFinders[i].animatorName == (runningSpeakAnimLeftPerson ? "Left" : "Right") + "Person")
                    {
                        animationFinders[i].GetComponent <Animator>().SetBool(runningSpeakAnimName, false);
                        runningSpeakAnim = false;
                    }
                }
            }



            state = ExecState.ACTION;
        }
    }
Ejemplo n.º 8
0
        private void ReadArduinoData()
        {
            /*
             * "ClearButtonState",
             * "SaveButtonState",
             * "LineTypeButtonState",
             * "ExecButtonState",
             * "LineWidthValue",
             * "AngleValue",
             * "DrawRateValue"
             */
            try
            {
                int temp = 0;
                int.TryParse(ArduinoSettings.Connection.ReadVariable("LineTypeButtonState").ToString(), out temp);
                drawType = temp == 0 ? DrawType.Line : DrawType.Arc;

                prevExecState = currentExecState;
                int.TryParse(ArduinoSettings.Connection.ReadVariable("ExecButtonState").ToString(), out temp);
                currentExecState = temp == 1 ? ExecState.Stop : ExecState.Go;

                prevClearState = clearState;
                int.TryParse(ArduinoSettings.Connection.ReadVariable("ClearButtonState").ToString(), out temp);
                clearState = temp == 0;

                prevSaveState = saveState;
                int.TryParse(ArduinoSettings.Connection.ReadVariable("SaveButtonState").ToString(), out temp);
                saveState = temp == 0;

                int.TryParse(ArduinoSettings.Connection.ReadVariable("LineWidthValue").ToString(), out lineWidth);

                int.TryParse(ArduinoSettings.Connection.ReadVariable("AngleValue").ToString(), out temp);
                //angleInRadians = temp * Math.PI / 180;
                initialAngleInRadians = temp * Math.PI / 180;

                int.TryParse(ArduinoSettings.Connection.ReadVariable("DrawRateValue").ToString(), out drawRate);
            }
            catch (Exception ex) { }
        }
Ejemplo n.º 9
0
        bool Exec()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                this.action();
            }
            catch (Exception e)
            {
                this.exception = e;
            }
            stopwatch.Stop();

            ExecState resultState;

            if (this.exception != null && !this.swallowExceptions)
            {
                if (this.exception is AssertFailedException || this.exception is AssertInconclusiveException)
                {
                    resultState = ExecState.Failed;
                }
                else
                {
                    resultState = ExecState.Exception;
                }
            }
            else
            {
                resultState = ExecState.Passed;
            }

            this.results.Add(Tuple.Create(stopwatch.ElapsedMilliseconds, this.exception));
            if (this.state <= resultState)
            {
                this.state = resultState;
            }
            return(resultState == ExecState.Passed || this.swallowExceptions);
        }
Ejemplo n.º 10
0
 public void ChangeState(ExecState ex)
 {
     this.execstate[execlevel] = ex;
 }
Ejemplo n.º 11
0
    private void Update()
    {
        for (int i = 0; i < toStopAnims.Count; i++)
        {
            toStopAnims[i].stopIn -= Time.deltaTime;
            if (toStopAnims[i].stopIn <= 0f)
            {
                toStopAnims[i].animator.SetBool(toStopAnims[i].animationClip, false);
                toStopAnims.RemoveAt(i);
                i--;
            }
        }
        if (RUN == false && isRunning)
        {
            isRunning = false;
        }
        if (RUN && wasRunning == false)
        {
            resetAllGlows();

            curNode           = startQuestion;
            curNode.IsGlowing = true;

            state      = ExecState.QUESTION;
            wasRunning = true;

            //isRunning = true;
        }
        else if (RUN && wasRunning)
        {
            switch (state)
            {
            case ExecState.QUESTION:

                curNode.IsGlowing = true;
                if (curNode.endingIndex != -1)
                {
                    newsPaperFlyer.Fly(curNode.endingIndex);
                }
                else
                {
                    if (curNode.isFactorNode)
                    {
                        Debug.Log("Factor question node");
                        Debug.Log("Factors: " + StaticParameters.factorMoneyFamily.ToString() + ", " + StaticParameters.factorIntimicy + ", " + StaticParameters.factorConvProg + ", " + StaticParameters.factorTrustFun);

                        string[] toAsk  = curNode.Questions;
                        float    maxVal = Mathf.Max(StaticParameters.factorConvProg, StaticParameters.factorIntimicy, StaticParameters.factorMoneyFamily, StaticParameters.factorTrustFun);
                        if (maxVal == StaticParameters.factorConvProg)
                        {
                            AnswerQuestion("ConvProg");
                        }
                        else if (maxVal == StaticParameters.factorMoneyFamily)
                        {
                            AnswerQuestion("MoneyFamily");
                        }
                        else if (maxVal == StaticParameters.factorIntimicy)
                        {
                            AnswerQuestion("Intimicy");
                        }
                        else
                        {
                            AnswerQuestion("TrustFun");
                        }
                    }
                    else
                    {
                        string[] toAsk = Utils <string> .Mix(curNode.Questions);

                        AskQuestion(toAsk);

                        Debug.Log("Asking questions: " + toAsk.ToString());

                        state = ExecState.QUESTION_WAIT;



                        // H_ATS
                        if (curNode.hat.Length > 0)
                        {
                            bool foundTarget = false;
                            for (int i = 0; i < animationFinders.Length; i++)
                            {
                                if (animationFinders[i].animatorName == "LeftPerson")
                                {
                                    for (int j = 0; j < allHats.Length; j++)
                                    {
                                        animationFinders[i].GetComponent <Animator>().SetBool("hat_" + allHats[j], false);
                                    }

                                    animationFinders[i].GetComponent <Animator>().SetBool("hat_" + curNode.hat, true);
                                }
                            }
                        }



                        if (curNode.hatRight.Length > 0)
                        {
                            bool foundTarget = false;
                            for (int i = 0; i < animationFinders.Length; i++)
                            {
                                if (animationFinders[i].animatorName == "RightPerson")
                                {
                                    for (int j = 0; j < allHats.Length; j++)
                                    {
                                        animationFinders[i].GetComponent <Animator>().SetBool("hat_" + allHats[j], false);
                                    }

                                    animationFinders[i].GetComponent <Animator>().SetBool("hat_" + curNode.hatRight, true);
                                }
                            }
                        }
                    }
                }

                break;

            case ExecState.ACTION:

                if (curAction != null)
                {
                    curAction.IsGlowing = false;
                }
                if (curNode != null)
                {
                    curNode.IsGlowing = false;
                }

                if (actionIndex < curDiag.Actions.Length)
                {
                    curAction           = curDiag.Actions[actionIndex];
                    curAction.IsGlowing = true;
                    actionIndex++;

                    waitTime = curAction.Time;



                    // Actions
                    if (curAction.GetType() == typeof(TB_ActionMusicLayer))
                    {
                        Debug.Log("Action Music Layer");
                        TB_ActionMusicLayer actionMusicLayer = (TB_ActionMusicLayer)curAction;

                        musicController.PlayLayers(actionMusicLayer.MusicLayerProps);
                    }
                    else if (curAction.GetType() == typeof(TB_ActionSpeak))
                    {
                        Debug.Log("Action Speak");
                        TB_ActionSpeak actionSpeak = (TB_ActionSpeak)curAction;

                        if (actionSpeak.SpeakAnimation.Length > 0)
                        {
                            for (int i = 0; i < animationFinders.Length; i++)
                            {
                                if (animationFinders[i].animatorName == (actionSpeak.PersonSpeakIndex == 0 ? "Left" : "Right") + "Person")
                                {
                                    animationFinders[i].GetComponent <Animator>().SetBool(actionSpeak.SpeakAnimation, true);
                                    runningSpeakAnim           = true;
                                    runningSpeakAnimLeftPerson = actionSpeak.PersonSpeakIndex == 0;
                                    runningSpeakAnimName       = actionSpeak.SpeakAnimation;
                                }
                            }
                        }

                        interactor.ShowDialogText(actionSpeak.SpeakText, actionSpeak.PersonSpeakIndex == 0, actionSpeak.SpeakClip);
                    }
                    else if (curAction.GetType() == typeof(TB_ActionSound))
                    {
                        Debug.Log("Action Sound");
                        TB_ActionSound actionSound = (TB_ActionSound)curAction;

                        GameObject gamAudioSource = new GameObject("Sound " + actionSound.Clip.name);
                        gamAudioSource.AddComponent <AudioSource>();
                        AudioSource audioSource = gamAudioSource.GetComponent <AudioSource>();
                        audioSource.clip   = actionSound.Clip;
                        audioSource.volume = actionSound.Volume;
                        audioSource.loop   = false;
                        audioSource.Play();

                        Destroy(gamAudioSource, actionSound.Clip.length + 2f);
                    }
                    else if (curAction.GetType() == typeof(TB_ActionAnimation))
                    {
                        Debug.Log("Action Animation");
                        TB_ActionAnimation actionAnimation = (TB_ActionAnimation)curAction;

                        bool foundTarget = false;
                        for (int i = 0; i < animationFinders.Length; i++)
                        {
                            if (animationFinders[i].animatorName == actionAnimation.AnimatorTarget)
                            {
                                foundTarget = true;

                                if (actionAnimation.Duration == -2f)
                                {
                                    animationFinders[i].GetComponent <Animator>().SetBool(actionAnimation.AnimationClipName, false);
                                }
                                else if (actionAnimation.Duration == -1f)
                                {
                                    animationFinders[i].GetComponent <Animator>().SetBool(actionAnimation.AnimationClipName, true);
                                }
                                else
                                {
                                    animationFinders[i].GetComponent <Animator>().SetBool(actionAnimation.AnimationClipName, true);

                                    AnimationStopper animStop = new AnimationStopper();
                                    animStop.animationClip = actionAnimation.AnimationClipName;
                                    animStop.animator      = animationFinders[i].GetComponent <Animator>();
                                    animStop.stopIn        = actionAnimation.Duration;

                                    toStopAnims.Add(animStop);
                                }
                            }
                        }

                        if (!foundTarget)
                        {
                            Debug.LogError("Didn't find animation target. Is a AnimationFinder attached to the Animator object?");
                        }
                    }
                    else if (curAction.GetType() == typeof(TB_ActionSprite))
                    {
                        TB_ActionSprite actionSprite = (TB_ActionSprite)curAction;

                        bool foundTarget = false;
                        for (int i = 0; i < spriteFinders.Length; i++)
                        {
                            if (spriteFinders[i].spriteName == actionSprite.SpriteName)
                            {
                                foundTarget = true;

                                SpriteRenderer[] children    = spriteFinders[i].GetComponentsInChildren <SpriteRenderer>();
                                GameObject       spriteFader = new GameObject("Sprite Fader");
                                spriteFader.AddComponent <SpriteFader>();
                                spriteFader.GetComponent <SpriteFader>().fadeTime           = 5f;
                                spriteFader.GetComponent <SpriteFader>().fadeToSprite       = actionSprite.Sprite;
                                spriteFader.GetComponent <SpriteFader>().spriteRenderer     = children[0].sprite == null ? children[1] : children[0];
                                spriteFader.GetComponent <SpriteFader>().spriteRendererDest = children[1].sprite == null ? children[1] : children[0];
                                spriteFader.GetComponent <SpriteFader>().StartAnim();

                                //spriteFinders[i].GetComponent<SpriteRenderer>().sprite = actionSprite.Sprite;
                            }
                        }

                        if (!foundTarget)
                        {
                            Debug.LogError("Didn't find sprite target. Is a SpriteFinder attached to the SpriteRenderer object?");
                        }
                    }


                    state = ExecState.ACTION_WAIT;
                }

                // Was last action
                else
                {
                    Debug.Log("Last Action");
                    curNode = curDiag.QuestionTo;
                    state   = ExecState.QUESTION;
                }

                break;

            case ExecState.ACTION_WAIT:
                if (waitTime != -1f)
                {
                    waitTime -= Time.deltaTime;
                    if (waitTime <= 0f)
                    {
                        state = ExecState.ACTION;
                    }
                }
                break;
            }
        }
    }