Esempio n. 1
0
        public void Update(float timeSinceLastFrame)
        {
            for (int i = Triggers.Count - 1; i >= 0; i--)
            {
                if (Triggers.ElementAt(i).Value.delayTime > 0)
                {
                    Triggers.ElementAt(i).Value.CurrentDelay = Triggers.ElementAt(i).Value.delayTime;
                    triggerDelayQueue.Add(Triggers.ElementAt(i).Value);
                }
                else
                {
                    triggerExecuteQueue.Add(Triggers.ElementAt(i).Value);
                }
                Triggers.Remove(Triggers.ElementAt(i).Key);
            }

            for (int i = triggerDelayQueue.Count - 1; i >= 0; i--)
            {
                if (triggerDelayQueue[i].CurrentDelay > 0)
                {
                    triggerDelayQueue[i].CurrentDelay--;
                }
                else
                {
                    triggerExecuteQueue.Add(triggerDelayQueue[i]);
                    triggerDelayQueue.Remove(triggerDelayQueue[i]);
                }
            }

            for (int i = triggerExecuteQueue.Count - 1; i >= 0; i--)
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (o, e) =>
                {
                    int index = int.Parse(e.Argument.ToString());
                    triggerExecuteQueue[index].Execute(world);
                };
                worker.RunWorkerAsync(i);
            }

            for (int i = triggerForzenQueue.Count - 1; i >= 0; i--)
            {
                if (triggerForzenQueue[i].frozenTime == ScriptTrigger.TRIGGER_ONCE)
                {
                    continue;
                }

                if (triggerForzenQueue[i].frozenTime > 0)
                {
                    triggerForzenQueue[i].CurrentFrozen--;
                }
                else
                {
                    if (!Triggers.ContainsKey(triggerForzenQueue[i].Name))
                    {
                        Triggers.Add(triggerForzenQueue[i].Name, triggerForzenQueue[i]);
                    }
                    triggerForzenQueue.Remove(triggerForzenQueue[i]);
                }
            }
        }
Esempio n. 2
0
        protected override void OnProfileChanged(HeliosProfile oldProfile)
        {
            base.OnProfileChanged(oldProfile);
            if (!DesignMode)
            {
                return;
            }

            // grab the default interface, if it exists
            foreach (Type supportedInterface in SupportedInterfaces)
            {
                _defaultInterface = Profile.Interfaces.FirstOrDefault(i => supportedInterface.IsInstanceOfType(i));
                if (_defaultInterface != null)
                {
                    Logger.Info($"{Name} auto binding to interface '{_defaultInterface.Name}'");
                    break;
                }
            }

            if (_defaultInterface == null)
            {
                Logger.Info($"{Name} could not locate any supported interface for auto binding");
                return;
            }

            // looping for all default input bindings to assign the value
            foreach (DefaultInputBinding defaultBinding in _defaultInputBindings)
            {
                if (!Children.ContainsKey(defaultBinding.ChildName))
                {
                    Logger.Error("Cannot find child " + defaultBinding.ChildName);
                    continue;
                }
                Logger.Debug("Auto binding child " + defaultBinding.ChildName);
                HeliosVisual child = Children[defaultBinding.ChildName];
                if (!child.Actions.ContainsKey(defaultBinding.DeviceActionName))
                {
                    Logger.Error("Cannot find action " + defaultBinding.DeviceActionName);
                    continue;
                }
                if (defaultBinding.InterfaceTriggerName != "")
                {
                    if (!_defaultInterface.Triggers.ContainsKey(defaultBinding.InterfaceTriggerName))
                    {
                        Logger.Error("Cannot find interface trigger " + defaultBinding.InterfaceTriggerName);
                        continue;
                    }

                    Logger.Debug("Auto binding trigger " + defaultBinding.InterfaceTriggerName + " to " + defaultBinding.ChildName + defaultBinding.DeviceActionName);
                    child.OutputBindings.Add(CreateNewBinding(_defaultInterface.Triggers[defaultBinding.InterfaceTriggerName],
                                                              child.Actions[defaultBinding.DeviceActionName]));
                }
                else
                {
                    if (!Triggers.ContainsKey(defaultBinding.DeviceTriggerName))
                    {
                        Logger.Error("Cannot find interface trigger " + defaultBinding.DeviceTriggerName);
                        continue;
                    }

                    Logger.Debug("Auto binding trigger " + defaultBinding.DeviceTriggerName + " to " + defaultBinding.ChildName + defaultBinding.DeviceActionName);
                    child.OutputBindings.Add(CreateNewBinding(Triggers[defaultBinding.DeviceTriggerName],
                                                              child.Actions[defaultBinding.DeviceActionName], defaultBinding.DeviceTriggerBindingValue));
                }

                //child.OutputBindings.Add(
                //    new HeliosBinding(_defaultInterface.Triggers[defaultBinding.InterfaceTriggerName],
                //        child.Actions[defaultBinding.DeviceActionName]));
            }

            // now looping for all default output bindings to assign the value
            foreach (DefaultOutputBinding defaultBinding in _defaultOutputBindings)
            {
                if (!Children.ContainsKey(defaultBinding.ChildName))
                {
                    Logger.Error("Cannot find child " + defaultBinding.ChildName);
                    continue;
                }
                HeliosVisual child = Children[defaultBinding.ChildName];
                if (!child.Triggers.ContainsKey(defaultBinding.DeviceTriggerName))
                {
                    Logger.Error("Cannot find trigger " + defaultBinding.DeviceTriggerName);
                    continue;
                }
                if (!_defaultInterface.Actions.ContainsKey(defaultBinding.InterfaceActionName))
                {
                    Logger.Error("Cannot find action " + defaultBinding.InterfaceActionName);
                    continue;
                }
                Logger.Debug("Child Output binding trigger " + defaultBinding.DeviceTriggerName + " to " + defaultBinding.InterfaceActionName);
                child.OutputBindings.Add(CreateNewBinding(child.Triggers[defaultBinding.DeviceTriggerName],
                                                          _defaultInterface.Actions[defaultBinding.InterfaceActionName]));

                //            child.OutputBindings.Add(
                //new HeliosBinding(child.Triggers[defaultBinding.DeviceTriggerName],
                //                  _defaultInterface.Actions[defaultBinding.InterfaceActionName]));
            }
        }