protected virtual void OnItemExecute(IGameSequencerItem item) { if (CurrentItem != item) { // it's possible that another thread Pushed or Popped the CurrentItem while the timer went off on the last current item return; } GameSequencerItem ex = item as GameSequencerItem; if (ex != null) { if (ex.HasBegunExecution) // dont execute twice, just in case { return; } ex.HasBegunExecution = true; } string msg = ""; bool rslt = true; rslt = item.TryExecuteEffect(ref msg); FireItemExecuted(ex, rslt, msg); }
protected virtual void OnCurrentItemChanged(IGameSequencerItem oldItem, IGameSequencerItem newItem) { if (oldItem != null) { oldItem.OnBecameNotCurrent(); } if (newItem != null) { newItem.OnBecameCurrent(); } FireCurrentItemChanged(oldItem, newItem); if (newItem == null) { return; } GameSequencerItem ex = newItem as GameSequencerItem; // Get the timeout int timeout = 0; if (ex.ResponseTimerMod == int.MaxValue) { timeout = Timeout.Infinite; } else if (ex.ResponseTimerMod > int.MinValue) { timeout = ex.ResponseTimeout + ex.ResponseTimerMod; } ex.ResponseTimeout = timeout; // Set the timer or execute in case of no timeout if (timeout > 0) { Log.LogMsg(" -> Waiting [" + TimeSpan.FromMilliseconds(timeout).TotalSeconds + "] seconds before executing."); ex.ResponseTime = DateTime.UtcNow.Ticks + TimeSpan.FromMilliseconds(timeout).Ticks; SetTimerForCurrentItem(timeout); OnItemResponseTimerStarted(ex); DateTime exeTime = new DateTime(ex.ResponseTime, DateTimeKind.Utc); TimeSpan len = exeTime - DateTime.UtcNow; Log.LogMsg("It is now [" + DateTime.UtcNow.ToLongTimeString() + "]. Execute time for [" + ((Phase)ex).PhaseName + "] is at [" + exeTime.ToLongTimeString() + "], i.e. in [" + len.TotalSeconds + " seconds]. Response timeout is [" + timeout + " ms]."); } else { OnItemExecute(ex); } }
/// <summary> /// Pushes a new item to the stack. /// </summary> /// <param name="itm">the item to push</param> /// <param name="responseTimerMod">You can add/remove time from the response timer by passing a possitive or negative value as responseTimerMod. Pass /// int.MinValue to disable the response timer and to cause the item to execute as soon as its on the stack. Pass int.MaxValue to never time the /// stack item out.</param> public void AddItem(IGameSequencerItem itm, int responseTimerMod) { lock (CurrentItemSyncRoot) { itm.Sequencer = this; GameSequencerItem ex = itm as GameSequencerItem; ex.ResponseTimerMod = responseTimerMod; if (m_Queue != null) { m_Queue.Enqueue(ex); } else { m_Stack.Push(ex); } } }
protected virtual void OnItemResponseTimerStarted(GameSequencerItem newItem) { FireItemResponseTimerStarted(newItem); }