Exemplo n.º 1
0
        private void ExecuteCmd(ScriptUnit su)
        {
            if(su.UnitType == (ScriptType.BEHAVIOR | ScriptType.SPEECH))
            {
                evExecuteBehavior(su.Behavior);
                evExecuteSpeech(su.Speech);
                areBehaviorDone.WaitOne();
                areSpeechDone.WaitOne();
            }
            else if (su.UnitType == (ScriptType.BEHAVIOR | ScriptType.PAUSE))
            {
                evExecuteBehavior(su.Behavior);
                Thread.Sleep(su.PauseDur);
                areBehaviorDone.WaitOne();
            }
            else if (su.UnitType == ScriptType.BEHAVIOR)
            {
                evExecuteBehavior(su.Behavior);
                areBehaviorDone.WaitOne();
            }
            else if (su.UnitType == ScriptType.SPEECH)
            {
                evExecuteSpeech(su.Speech);
                areSpeechDone.WaitOne();
            }
            else if (su.UnitType == ScriptType.LISTEN)
            {
                evExecuteListen(su.Listen);
            }
            else if (su.UnitType == ScriptType.SCRIPT)
            {
                evExecuteScript(su.ScriptFile, su.ScriptSpeechAccept);
                if(su.ScriptSpeechAccept.Length > 0)
                    areSpeechDone.WaitOne();
            }
            else if (su.UnitType == ScriptType.PAUSE)
            {
                Thread.Sleep(su.PauseDur);
            }
            else if (su.UnitType == ScriptType.SLIDE)
            {
                evSlideControl("NextSlide");
            }
            else if (su.UnitType == ScriptType.CAMERA)
            {
                evCameraPhoto();
            }
            else if (su.UnitType == ScriptType.QUIZ_ANSWER)
            {
                bool disagreement;
                int useranswer1, useranswer2;
                evFetchQuizAnswers(out disagreement, out useranswer1, out useranswer2);
                string speechtoanswers;

                if (useranswer1 == -1) // this means the answer data is not ready!
                {
                    speechtoanswers = "It seems no one knows the answer!";
                }
                else
                {
                    if (disagreement == true) { speechtoanswers = su.QuizAnswer.Last<string>(); }
                    else { speechtoanswers = su.QuizAnswer[useranswer1]; }
                }

                evExecuteSpeech(speechtoanswers);
                areSpeechDone.WaitOne();
            }
            else if (su.UnitType == ScriptType.CONFIG)
            {
                evChangeConfig(su.Config);
            }
            else if (su.UnitType == ScriptType.MOOD)
            {
                evChangeMood(su.Mood);
            }
            else if (su.UnitType == ScriptType.INTERUPT)
            {
                evInterupt();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProcessScriptInQueue(object sender, DoWorkEventArgs e)
        {
            ScriptQueue.Clear();

            ScriptParseComplete = false;

            string[] script = (string[])e.Argument;

            int i = 0;
            while (i < ScriptLineCount)
            {
                if (EnabledParse)
                {
	                if (ScriptQueue.Count < QueueSize)
	                {
		                ScriptUnit su = new ScriptUnit();
	                    su.LineNumber = i;
		
		                string res;
		                ScriptType st = ParseLine(script[i], out res);
                        
                        // A full unit contains
                        //  1. behavior + speech
                        //  2. behavior + pause
                        //  3. only behavior
		                if (st == ScriptType.BEHAVIOR) 

		                {
		                    su.Behavior = res;
		                    su.UnitType |= ScriptType.BEHAVIOR;
		
                            if( i+1<script.Count() ){
                                string res1;
		                        ScriptType st1 = ParseLine(script[i+1], out res1);
		                        if (st1 == ScriptType.SPEECH)
		                        {
		                            su.Speech = res1;
		                            su.UnitType |= ScriptType.SPEECH;
		                            i++;
		                        }
                                else if (st1 == ScriptType.PAUSE)
                                {
                                    su.PauseDur = int.Parse(res1);
                                    su.UnitType |= ScriptType.PAUSE;
                                    i++;
                                }
                            }
	
	                        // Send out for check if it is a leg movement
	                        evLatestScriptUnit(su.Behavior);
		                }
		                else if (st == ScriptType.SPEECH) // this unit does not have Behavior
		                {
		                    su.Speech = res;
		                    su.UnitType |= ScriptType.SPEECH;
		                }
                        else if (st == ScriptType.LISTEN)
                        {
                            su.Listen = res;
                            su.UnitType |= ScriptType.LISTEN;
                        }
                        else if (st == ScriptType.SCRIPT)
                        {
                            string[] temp = res.Split('|');
                            su.ScriptFile = temp[0];
                            if (temp.Length > 1)
                                su.ScriptSpeechAccept = temp[1];
                            else
                                su.ScriptSpeechAccept = "";

                            //EnabledParse = false;
                            su.UnitType |= ScriptType.SCRIPT;
                        }
                        else if (st == ScriptType.PAUSE)
                        {
                            su.PauseDur = int.Parse(res);
                            su.UnitType |= ScriptType.PAUSE;
                        }
                        else if (st == ScriptType.SLIDE)
                        {
                            su.UnitType |= ScriptType.SLIDE;
                        }
                        else if (st == ScriptType.QUIZ_ANSWER)
                        {
                            su.UnitType = ScriptType.QUIZ_ANSWER;
                            su.QuizAnswer = new List<string>();
                            string[] qa = res.Split('|');
                            su.QuizAnswer.AddRange(qa.ToList<string>());
                        }
                        else if (st == ScriptType.CAMERA)
                        {
                            su.UnitType = ScriptType.CAMERA;
                        }
                        else if (st == ScriptType.EMPTY_LINE
                            || st == ScriptType.COMMENT
                            || st == ScriptType.UNDEFINED)
                        {
                            // Do nothing
                        }
                        else if (st == ScriptType.CONFIG)
                        {
                            su.UnitType = ScriptType.CONFIG;
                            su.Config = res;
                        }
                        else if (st == ScriptType.MOOD)
                        {
                            su.UnitType = ScriptType.MOOD;
                            su.Mood = res;
                        }
                        else if (st == ScriptType.INTERUPT)
                        {
                            su.UnitType = ScriptType.INTERUPT;
                        }
	
	                    MutQueue.WaitOne();
		                // In queue
		                ScriptQueue.Enqueue(su);
	                    MutQueue.ReleaseMutex();
	
	                    i++;
	                }
	                else
	                {
	                    //Debug.WriteLine("{0}: ScriptUnit queue full - Queue Length {1}", "ScriptParser", ScriptQueue.Count);
	                }
                }

                Thread.Sleep(333);
            }

            ScriptParseComplete = true;
            Debug.WriteLine("{0}: All Script Parsed! Total lines: {1}", "ScriptParser", i);
        }