public void CanLimitTasksPerUpdate( ) { int i = 0; um = new UnityManager(2); for ( int j = 0; j < 5; j++ ) { ITask task = new ActionTask(( _ ) => i++, false); um.EnqueueTask(task); } um.UnsafeUpdate(); Assert.AreEqual(2, i, "Didn't just run 2."); um.UnsafeUpdate(); Assert.AreEqual(4, i, "Didn't just run 2."); um.UnsafeUpdate(); Assert.AreEqual(5, i, "Didn't run last one correctly."); i = 0; um = new UnityManager(1); for ( int j = 0; j < 5; j++ ) { ITask task = new ActionTask(( _ ) => i++, false); um.EnqueueTask(task); } for ( int j = 0; j < 5; j++ ) { um.UnsafeUpdate(); Assert.AreEqual(j + 1, i, "Didn't just run 1."); } }
public void NappingTestsDontCountTowardsLimit( ) { int i = 0; um = new UnityManager(1); ActionTask task = new ActionTask(( _ ) => _.IsNapping = true, false); task.Extend(( _ ) => i = 100); um.EnqueueTask(task); for ( int j = 0; j < 5; j++ ) { ITask t = new ActionTask(( _ ) => i++, false); um.EnqueueTask(t); } um.UnsafeUpdate(); Assert.IsTrue(task.IsNapping, "Task didn't start napping."); for ( int j = 0; j < 5; j++ ) { um.UnsafeUpdate(); Assert.AreEqual(j + 1, i, "Didn't just run 1."); } task.IsNapping = false; um.UnsafeUpdate(); Assert.AreEqual(100, i, "Didn't run awakened task."); }
/// <summary> /// Unity's update loop. All we need to do is update the managers. /// </summary> internal void Update( ) { // Maybe the threadManager should be moved to its own thread. threadManager.UnsafeUpdate(); unityManager.UnsafeUpdate(); }