/// <summary> /// Adds an attribute update to the list of attribute that are queued to be persisted /// </summary> /// <param name="changedComponentGuid">Guid of the Attribute that has changed</param> /// <param name="newValue">New value of the changed attribute</param> private void AddAttributeToPersisted(Guid changedComponentGuid, string attributeName, object newValue) { lock (attributeQueueLock) { if (!ComponentAttributesToPersist.ContainsKey(changedComponentGuid)) { ComponentAttributesToPersist.Add(changedComponentGuid, new Dictionary <string, object>()); } else { ComponentAttributesToPersist[changedComponentGuid][attributeName] = newValue; } } }
/// <summary> /// Thread worker function that performs the persisting steps for queued entities and attributes /// </summary> private void PersistChangedEntities() { while (true) { lock (entityQueueLock) { if (EntitiesToPersist.Count > 0) { CommitCurrentEntityUpdates(); EntitiesToPersist.Clear(); } } lock (attributeQueueLock) { if (ComponentAttributesToPersist.Count > 0) { CommitCurrentAttributeUpdates(); ComponentAttributesToPersist.Clear(); } } Thread.Sleep(5); } }