public PerformanceTest() { m_Vm = new GossipVM(); m_Vm.RegisterGlobalFunction("GetCustomer", new Func<Int32, Customer>(GetCustomer)); m_Vm.RegisterType(typeof(Customer)); m_Vm.RegisterType(typeof(Account)); }
public static void RunScriptToCompletion(GossipVM engine, CompiledScript compiledScript) { engine.RunScript(compiledScript); while (engine.HasRunningScripts()) { Thread.Sleep(16); engine.Update(16); } }
public ExpressionNormalizerTests() { m_Customer1.Id = 0; m_Customer2.Id = 1; m_Vm = new GossipVM(); m_Vm.RegisterGlobalFunction("GetAccount", new Func<Account>(GetAccount)); m_Vm.RegisterGlobalFunction("GetCustomer", new Func<Int32, Customer>(GetCustomer)); m_Vm.RegisterType(typeof(Customer)); m_Vm.RegisterType(typeof(Account)); }
public void TestFixtureSetup() { m_Customer1.Id = 1; m_Customer2.Id = 2; m_Customer1.Name = "Joe"; m_Customer2.Name = "Jane"; m_Customer1.Account.Name = "Cheque"; m_Customer2.Account.Name = "Savings"; m_Vm = new GossipVM(); m_Vm.RegisterGlobalAction("dialog", new ActionInfo("Say", Say, null, null)); m_Vm.RegisterGlobalAction("dialog", new ActionInfo("AddResponse", AddResponse, null, null)); m_Vm.RegisterGlobalAction("dialog", new ActionInfo("GotoLabel", GotoLabel, null, null)); m_Vm.RegisterGlobalAction("dialog", new ActionInfo("Interject", Interject, null, null)); m_Vm.RegisterGlobalAction("test", new ActionInfo("NoParams", NoParams)); m_Vm.RegisterGlobalFunction("GetAccount", new Func<Account>(GetAccount)); m_Vm.RegisterGlobalFunction("GetCustomer", new Func<Int32, Customer>(GetCustomer)); m_Vm.RegisterType(typeof (Customer)); m_Vm.RegisterType(typeof (Account)); m_Vm.RegisterEnum("TEST_ENUM", 1); }
public ScriptResult Update(GossipVM engine, Int32 deltaMs) { m_Context.Vm = engine; m_Context.DeltaMs = deltaMs; // Always run OnInterrupt if (ActiveNodes.Count > 0) { ScriptNode top = ActiveNodes.Peek(); if (top.OnInterruptEvent == null) { // Go down the stack foreach (ScriptNode node in ActiveNodes) { if (node.OnInterruptEvent != null) { m_Context.CurrentScriptEvent = node.OnInterruptEvent; ScriptResult interruptResult = node.OnInterrupt(m_Context); if (interruptResult != ScriptResult.Ok) return interruptResult; break; } } } else { m_Context.CurrentScriptEvent = top.OnInterruptEvent; ScriptResult interruptResult = top.OnInterrupt(m_Context); if (interruptResult != ScriptResult.Ok) return interruptResult; } } // Run queued Events for (int i = 0; i < QueuedEvents.Count; i++) { QueuedScriptletEvent queuedEvent = QueuedEvents[i]; m_Context.CurrentScriptEvent = queuedEvent.ScriptEvent; m_Context.CurrentScriptEvent.Owner = ScriptOwner; ScriptResult queuedEventResult = queuedEvent.Func(m_Context); if (queuedEventResult != ScriptResult.Ok) return queuedEventResult; // Remove from queue QueuedEvents.RemoveAt(i); i--; } // On Update { if (ActiveNodes.Count == 0) return ScriptResult.Ok; ScriptNode top = ActiveNodes.Peek(); var result = ScriptResult.Ok; if (top.OnUpdateEvent == null) { // Go down the stack foreach (ScriptNode scriptlet in ActiveNodes) { if (scriptlet.OnUpdateEvent != null) { m_Context.CurrentScriptEvent = scriptlet.OnUpdateEvent; result = scriptlet.OnRun(m_Context); break; } } } else { m_Context.CurrentScriptEvent = top.OnUpdateEvent; m_Context.CurrentScriptEvent.Owner = ScriptOwner; result = top.OnUpdateEvent.Run(m_Context); } if (result == ScriptResult.EndProcess) PopActiveNode(); if (result == ScriptResult.Ok) { if (top.OnEndEvent != null) QueuedEvents.Add(new QueuedScriptletEvent(top.OnEnd, top.OnEndEvent)); } // Run any queued events for (int i = 0; i < QueuedEvents.Count; i++) { QueuedScriptletEvent queuedEvent = QueuedEvents[i]; m_Context.CurrentScriptEvent = queuedEvent.ScriptEvent; m_Context.CurrentScriptEvent.Owner = ScriptOwner; ScriptResult queuedEventResult = queuedEvent.Func(m_Context); if (queuedEventResult != ScriptResult.Ok) return queuedEventResult; // Remove from queue QueuedEvents.RemoveAt(i); i--; } return result; } }
public ScriptResult Update(GossipVM engine) { return Update(engine, 0); }