private void DoProcessing() { var entityLookup = m_entityManager.ProcessingEntityLookup; var notificationLog = new NotificationLog(); m_currentDate = m_gameData.CurrentDate; bool shouldUpdateEntitiesFromDisplay = true; try { while (true) { if (WaitHandle.WaitAny(m_threadWaitHandles) == c_stopEventIndex) { break; } if (shouldUpdateEntitiesFromDisplay) { m_gameData.EntityManager.UpdateProcessingEntitiesFromDisplay(); shouldUpdateEntitiesFromDisplay = false; } m_currentDate = m_currentDate + TimeOffset.OneTick; foreach (var system in m_systems) { system.ProcessTick(entityLookup, notificationLog, m_currentDate); } //var shouldStop = m_currentDate >= m_gameData.Calendar.CreateTimePoint(2100, 1, 1); var shouldStop = m_currentDate.Tick % 10 == 0; if (shouldStop || notificationLog.ShouldStopProcessing) { m_threadContinueEvent.Reset(); Log.Info("Pausing processing"); shouldUpdateEntitiesFromDisplay = true; var notifications = notificationLog.Events.ToList(); notificationLog.Reset(); m_dispatcher.Invoke(() => { m_gameData.CurrentDate = m_currentDate; m_gameData.EntityManager.SwapDisplayWithProcessing(); ProcessingStopped.Raise(this, new ProcessingStoppedEventArgs(notifications)); }); } else { m_threadContinueEvent.Set(); } } } finally { m_threadStoppedEvent.Set(); } }
/// <summary> Raises the processing stopped event. </summary> protected void OnProcessingStopped() { ProcessingStopped?.Invoke(this, null); }