/// <summary> /// Remove all of the items from the <c>addPool</c> list from the environment. /// </summary> private void RemovePoolObjects() { foreach (SceneObject sceneObject in removePool) { if (sceneObject is Jumpman j) { this.jumpmen.Remove(j); } if (sceneObject is Food f) { this.food.Remove(f); } if (sceneObject is Entity e) { this.entities.Remove(e); } this.sceneObjects.Remove(sceneObject); // Send and event to any listeners. var args = new SceneObjectAddedOrRemovedEventArgs(); args.Object = sceneObject; args.Time = Time; OnSceneObjectRemoved(args); } removePool.Clear(); }
/// <summary> /// Collect statistics when a <c>SceneObject</c> is removed. /// </summary> void c_SceneObjectRemoved(object sender, SceneObjectAddedOrRemovedEventArgs e) { lock (sceneObjectRemovedLock) { if (e.Object is Jumpman j) { // Update and log the average attributes. double avgSpeed = 0; double avgSize = 0; int n = jumpmanCount; if (n > 0) { avgSpeed = averageJumpmanAttr.speed; avgSize = averageJumpmanAttr.size; avgSpeed = ((avgSpeed * n) - j.attr.speed) / (n - 1); avgSize = ((avgSize * n) - j.attr.size) / (n - 1); } averageJumpmanAttr.speed = avgSpeed; averageJumpmanAttr.size = avgSize; LogData <JumpmanAttributes>(averageJumpmanAttrSW, e.Time, averageJumpmanAttr); // Update and log the jumpman count. jumpmanCount -= 1; LogData <int>(jumpmanCountSW, e.Time, jumpmanCount); } else if (e.Object is Food f) { nutrition -= f.nutrition; LogData <double>(nutritionSW, e.Time, nutrition); } } }
/// <summary> /// Add all of the items from the <c>addPool</c> list to the environment. /// </summary> private void AddPoolObjects() { foreach (SceneObject sceneObject in addPool) { if (sceneObject is Jumpman j) { this.jumpmen.Add(j); } if (sceneObject is Food f) { this.food.Add(f); } if (sceneObject is Entity e) { this.entities.Add(e); } this.sceneObjects.Add(sceneObject); sceneObject.environment = this; // Send and event to any listeners. var args = new SceneObjectAddedOrRemovedEventArgs(); args.Object = sceneObject; args.Time = Time; OnSceneObjectAdded(args); } addPool.Clear(); }
/// <summary> /// Collect statistics when a <c>SceneObject</c> is added. /// </summary> void c_SceneObjectAdded(object sender, SceneObjectAddedOrRemovedEventArgs e) { lock (sceneObjectAddedLock) { if (e.Object is Jumpman j) { // Update and log the jumpman count. jumpmanCount += 1; LogData <int>(jumpmanCountSW, e.Time, jumpmanCount); // Update and log the average attributes. double avgSpeed = averageJumpmanAttr.speed; double avgSize = averageJumpmanAttr.size; int n = jumpmanCount; avgSpeed += (j.attr.speed - avgSpeed) / n; avgSize += (j.attr.size - avgSize) / n; averageJumpmanAttr.speed = avgSpeed; averageJumpmanAttr.size = avgSize; LogData <JumpmanAttributes>(averageJumpmanAttrSW, e.Time, averageJumpmanAttr); if (j.attr.speed > maxSpeed) { maxSpeed = j.attr.speed; Console.WriteLine("New max speed: {0}", maxSpeed); } if (averageJumpmanAttr.speed > maxAvgSpeed) { maxAvgSpeed = averageJumpmanAttr.speed; Console.WriteLine("New max avg speed: {0}", maxAvgSpeed); } } else if (e.Object is Food f) { nutrition += f.nutrition; LogData <double>(nutritionSW, e.Time, nutrition); } } }
protected virtual void OnSceneObjectRemoved(SceneObjectAddedOrRemovedEventArgs e) { EventHandler <SceneObjectAddedOrRemovedEventArgs> handler = SceneObjectRemoved; if (handler != null) { handler(this, e); } }