/// <summary> /// Performs every-frame updates which include moving queued instructions to the main instruction list and /// executing instructions according to their TimeToExecute. /// </summary> internal static void Update() { //Flush(); var currentTime = TimeManager.CurrentTime; Instructions.Instruction instruction; lock (syncLock) { while (instructionQueue.Count > 0) { Add(instructionQueue.Dequeue()); } } while (mIsExecutingInstructions && mInstructions.Count > 0 && mInstructions[0].TimeToExecute <= currentTime) { instruction = mInstructions[0]; instruction.Execute(); // The instruction may have cleared the InstructionList, so we need to test if it did. if (mInstructions.Count < 1) { continue; } if (instruction.CycleTime == 0) { mInstructions.Remove(instruction); } else { instruction.TimeToExecute += instruction.CycleTime; mInstructions.InsertionSortAscendingTimeToExecute(); } } // The ScreenManager doesn't have any engine-initiated // activity, it's all initiated by custom code. However, // instructions are supposed to execute before any custom code // runs. Therefore, we're going to have these be handled here: if (Screens.ScreenManager.CurrentScreen != null) { ExecuteInstructionsOnConsideringTime(Screens.ScreenManager.CurrentScreen); } }
/// <summary> /// Performs every-frame updates which include moving queued instructions to the main instruction list and /// executing instructions according to their TimeToExecute. /// </summary> internal static void Update() { //Flush(); var currentTime = TimeManager.CurrentTime; Instructions.Instruction instruction; lock (syncLock) { while (instructionQueue.Count > 0) { Add(instructionQueue.Dequeue()); } } while (mIsExecutingInstructions && mInstructions.Count > 0 && mInstructions[0].TimeToExecute <= currentTime) { instruction = mInstructions[0]; // Nov 2, 2019 // An instruction // may pause the game, // which would then take // this instruction and put // it on the to-execute list // of instructions. But since // it's already executing we don't // want that to happen, so going to // remove it before executing. This is // different from how the engine used to // work prior to this date, so hopefully this // doesn't introduce any weird behaviors if (instruction.CycleTime == 0) { mInstructions.Remove(instruction); } instruction.Execute(); // The instruction may have cleared the InstructionList, so we need to test if it did. if (mInstructions.Count < 1) { continue; } if (instruction.CycleTime != 0) { instruction.TimeToExecute += instruction.CycleTime; mInstructions.InsertionSortAscendingTimeToExecute(); } } // The ScreenManager doesn't have any engine-initiated // activity, it's all initiated by custom code. However, // instructions are supposed to execute before any custom code // runs. Therefore, we're going to have these be handled here: if (Screens.ScreenManager.CurrentScreen != null) { ExecuteInstructionsOnConsideringTime(Screens.ScreenManager.CurrentScreen); } }