Esempio n. 1
0
		public IfCommand(AsmInterpreter interpreter, string[] lineParts)
			: base(interpreter, lineParts)
		{
			string comparisonName = lineParts[2];
			string operandLeftName = lineParts[1];
			string operandRightName = lineParts[3];
			
			ComparisonDelegation delegation = GetComparisonDelegation(comparisonName);
			if (delegation == null)
				throw new InvalidOperationException("Invalid comparison operator.");
			comp = delegation;

			ValueStorage vs = null;
			vs = parent.GetVariableByName(operandLeftName);
			if (vs == null)
			{
				vs = parent.GetRegisterByName(operandLeftName);
				if (vs == null)
				{
					vs = parent.GetStackValueFromTop(operandLeftName);
					if (vs == null)
					{
						float number = 0.0f;
						if (float.TryParse(operandLeftName, out number))
						{
							vs = new ValueStorage();
							vs.SetValue(number);
							parent.m_constants.Add(vs);
						}
					}
				}
			}
			if (vs == null)
				throw new InvalidOperationException("Invalid comparison left operand.");
			operandLeft = vs;

			vs = null;
			vs = parent.GetVariableByName(operandRightName);
			if (vs == null)
			{
				vs = parent.GetRegisterByName(operandRightName);
				if (vs == null)
				{
					vs = parent.GetStackValueFromTop(operandRightName);
					if (vs == null)
					{
						float number = 0.0f;
						if (float.TryParse(operandRightName, out number))
						{
							vs = new ValueStorage();
							vs.SetValue(number);
							parent.m_constants.Add(vs);
						}
					}
				}
			}
			if (vs == null)
				throw new InvalidOperationException("Invalid comparison right operand.");
			operandRight = vs;
		}
Esempio n. 2
0
        public PushCommand(AsmInterpreter interpreter, string[] lineParts)
            : base(interpreter, lineParts)
        {
            string sourceName = lineParts[1];
            ValueStorage vs = null;

            vs = parent.GetVariableByName(sourceName);
            if (vs == null)
            {
                vs = parent.GetRegisterByName(sourceName);
                {
                    if (vs == null)
                    {
                        vs = parent.GetStackValueFromTop(sourceName);
                        if (vs == null)
                        {
                            float number = 0.0f;
                            if (float.TryParse(sourceName, out number))
                            {
                                vs = new ValueStorage();
                                vs.SetValue(number);
                                parent.m_constants.Add(vs);
                            }
                        }
                    }
                }
            }
            if (vs == null)
                throw new InvalidOperationException("Invalid push source.");
            source = vs;
        }
        public static bool HandleUserCommand(AsmInterpreter interpreter, List<string> codeLines, int lineIndex, string[] lineParts)
        {
            foreach (var callback in RegisterCallbacks)
            {
                if (callback(interpreter, codeLines, lineIndex, lineParts) == true)
                    return true;
            }

            return false;
        }
Esempio n. 4
0
 public AsmCommand(AsmInterpreter parentInterpreter, string[] lineParts)
 {
     line = "";
     foreach (string part in lineParts)
     {
         line += part + " ";
     }
     line = line.Substring(0, line.Length - 1);
     parent = parentInterpreter;
 }
Esempio n. 5
0
 private static bool HandleTriggerCommand(AsmInterpreter interpreter, List<string> codeLines, int lineIndex, string[] lineParts)
 {
     if (lineParts[0].Equals("trig", StringComparison.CurrentCultureIgnoreCase))
     {
         // Need to implement this later.
         TriggerActionGroupCommand newCmd = new TriggerActionGroupCommand(interpreter, lineParts);
         interpreter.m_commands.Add(newCmd);
         return true;
     }
     return false;
 }
		public CalculationCommand(AsmInterpreter interpreter, string[] lineParts)
			: base(interpreter, lineParts)
		{
			string operatorName = lineParts[0];
			string targetName = lineParts[1];
			string sourceName = lineParts[2];

			CalculationDelegate delegation = GetCalculationDelegation(operatorName);
			if (delegation == null)
				throw new InvalidOperationException("Invalid calculation operator.");
			calc = delegation;

			ValueStorage vs = null;
			vs = parent.GetVariableByName(sourceName);
			if (vs == null)
			{
				vs = parent.GetRegisterByName(sourceName);
				if (vs == null)
				{
					vs = parent.GetStackValueFromTop(sourceName);
					if (vs == null)
					{
						float number = 0.0f;
						if (float.TryParse(sourceName, out number))
						{
							vs = new ValueStorage();
							vs.SetValue(number);
							parent.m_constants.Add(vs);
						}
					}
				}
			}
			if (vs == null)
				throw new InvalidOperationException("Invalid calculation operand.");
			operand = vs;

			vs = parent.GetVariableByName(targetName);
			if (vs == null)
			{
				vs = parent.GetRegisterByName(targetName);
				if (vs == null)
				{
					vs = parent.GetStackValueFromTop(targetName);
				}
			}
			if (vs == null)
				throw new InvalidOperationException("Invalid calculation target.");
			target = vs;
		}
Esempio n. 7
0
        public PopCommand(AsmInterpreter interpreter, string[] lineParts)
            : base(interpreter, lineParts)
        {
            if (lineParts.Length == 2)
            {
                string targetName = lineParts[1];
                ValueStorage vs = null;

                vs = parent.GetVariableByName(targetName);
                if (vs == null)
                {
                    vs = parent.GetRegisterByName(targetName);
                }
                if (vs == null)
                    throw new InvalidOperationException("Invalid pop target.");
                target = vs;
            }
            else
            {
                target = null;
            }
        }
 public NoOperationCommand(AsmInterpreter interpreter, string[] lineParts)
     : base(interpreter, lineParts)
 {
 }
Esempio n. 9
0
 public EndCommand(AsmInterpreter interpreter, string[] lineParts)
     : base(interpreter, lineParts)
 {
 }
Esempio n. 10
0
        static void Main(string[] args)
        {
            AsmInterpreter asmInterpreter = new AsmInterpreter();
            UserCommandModuleHandler.RegisterCodeHandler(HandleTriggerCommand);

            asmInterpreter.m_namedVariables.Add(new NamedValueStorage("MissionTime", 0.0f));
            asmInterpreter.m_namedVariables.Add(new NamedValueStorage("AirDensity", 0.0f));
            asmInterpreter.m_namedVariables.Add(new NamedValueStorage("TotalAvailableThrust", 0.0f));
            string testCode =
            @"// Initialize variables
            var boosterDecoupled = 0
            var fairingsDecoupled = 0
            var solarPanelsExpanded = 0

            // Wait for update() calls.
            yield

            // Main loop goes here.
            r[0] = boosterDecoupled
            r[0] += fairingsDecoupled
            r[0] += solarPanelsExpanded
            while r[0] < 3
            // Don't start triggering action groups too early.
            if MissionTime >= 15
            // If boosters are exhausted, decouple them.
            if TotalAvailableThrust < 1500
            if boosterDecoupled != 1 // Check if we've already decoupled.
                trig Custom01
                boosterDecoupled = 1
            end
            end

            // If air density is low enough, we can decouple the fairings to reduce weight.
            if AirDensity <= 0.0001
            if fairingsDecoupled != 1 // Check if we've already decoupled.
                trig Custom02
                fairingsDecoupled = 1
            end
            end

            // If we've got to the last stage, we should expand our solar panels to gain electricity.
            if TotalAvailableThrust <= 100
            if solarPanelsExpanded != 1 // Check if we've already expanded.
                trig Custom03
                solarPanelsExpanded = 1
            end
            end
            end

            yield

            // A check-up to see if we've finished all three jobs.
            r[0] = boosterDecoupled
            r[0] += fairingsDecoupled
            r[0] += solarPanelsExpanded
            end
            ";
            asmInterpreter.LoadString(testCode);
            asmInterpreter.Start();
            float MissionTime = 0.0f;
            float AirDensity = 1.0f;
            float TotalAvailableThrust = 1800.0f;
            while (asmInterpreter.m_started)
            {
                MissionTime += 0.0001f;
                AirDensity -= 0.000001f;
                if (AirDensity < 0.0f) AirDensity = 0.0f;

                if (MissionTime >= 25.0f) TotalAvailableThrust = 1200.0f;
                if (MissionTime >= 120.0f) TotalAvailableThrust = 450.0f;
                if (MissionTime >= 300.0f) TotalAvailableThrust = 10.0f;

                asmInterpreter.GetVariableByName("MissionTime").SetValue(MissionTime);
                asmInterpreter.GetVariableByName("AirDensity").SetValue(AirDensity);
                asmInterpreter.GetVariableByName("TotalAvailableThrust").SetValue(TotalAvailableThrust);
                asmInterpreter.Resume();
            }
        }
 public TriggerActionGroupCommand(AsmInterpreter interpreter, string[] lineParts)
     : base(interpreter, lineParts)
 {
     actionGroupName = lineParts[1];
 }