/// <summary> /// Executes enqueued commands. Updates delayed commands. /// </summary> /// <param name="gameTime"></param> public void ExecuteQueue(GameTime gameTime, CommandAffinity affinity, bool forceDelayed = false) { var delta = (int)gameTime.Elapsed.TotalMilliseconds; lock (lockObject) { delayed.Clear(); while (queue.Any()) { var cmd = queue.Dequeue(); if (cmd.Affinity == affinity) { if (cmd.Delay <= 0 || forceDelayed) { // execute : cmd.Execute(); if (cmd.Result != null) { Log.Message("// Result: {0} //", cmd.Result); } // push to history : if (!cmd.NoRollback && cmd.Affinity == CommandAffinity.Default) { history.Push(cmd); } } else { cmd.Delay -= delta; delayed.Enqueue(cmd); } } else { delayed.Enqueue(cmd); } } Misc.Swap(ref delayed, ref queue); } }
/// <summary> /// /// </summary> public Command ( Invoker invoker ) { Invoker = invoker; Game = invoker.Game; Delay = 0; NoRollback = false; Terminal = false; Result = null; Name = GetType().GetCustomAttribute<CommandAttribute>().Name; Affinity = GetType().GetCustomAttribute<CommandAttribute>().Affinity; }
/// <summary> /// Creates instance of Invoker. /// </summary> /// <param name="game">Game instance</param> public Invoker ( Game game, CommandAffinity affinity ) { Initialize( game, Command.GatherCommands() ); }
/// <summary> /// Executes enqueued commands. Updates delayed commands. /// </summary> /// <param name="gameTime"></param> public void ExecuteQueue ( GameTime gameTime, CommandAffinity affinity, bool forceDelayed = false ) { var delta = (int)gameTime.Elapsed.TotalMilliseconds; lock (lockObject) { delayed.Clear(); while (queue.Any()) { var cmd = queue.Dequeue(); if ( cmd.Affinity == affinity ) { if ( cmd.Delay<=0 || forceDelayed ) { // execute : cmd.Execute(); if (cmd.Result!=null) { Log.Message( "// Result: {0} //", cmd.GetStringResult() ); } // push to history : if (!cmd.NoRollback && cmd.Affinity==CommandAffinity.Default) { history.Push( cmd ); } } else { cmd.Delay -= delta; delayed.Enqueue( cmd ); } } else { delayed.Enqueue( cmd ); } } Misc.Swap( ref delayed, ref queue ); } }
/// <summary> /// /// </summary> /// <param name="name"></param> public CommandAttribute ( string name, CommandAffinity affinity ) { this.Name = name; this.Affinity = affinity; }
/// <summary> /// /// </summary> /// <param name="name"></param> public CommandAttribute(string name, CommandAffinity affinity) { this.Name = name; this.Affinity = affinity; }