/// <summary> /// Add the new floating object to the world. MUST BE THREAD SAFE. /// If the object coordinates are outside the world, object is not added and false is returned. /// </summary> /// <returns>True if the object was added.</returns> private bool Add(FloatingObjectInWorld newObject, bool toNewSet) { ulong key = v_GridKeys.PositionToKey(newObject.Position); bool result = false; if (v_WorldBox.Contains(newObject.Position)) { result = (toNewSet ? v_Grid[key].NewSet : v_Grid[key].OldSet).Add(newObject); } return(result); }
/// <summary> /// Refills the box (OldSet only!) with floating objects up to their pre-defined concentrations in the environment. /// If the concentration of some objects is higher, no objects are removed. /// </summary> private void RefillBox(Box3D box) { var population = v_MSystem.FloatingObjects.Values.ToDictionary(obj => obj, obj => 0); foreach (var key in KeysInBox(box)) { foreach (var obj in v_Grid[key].OldSet.GetHashSet().Where(fltObject => box.Contains(fltObject.Position))) { population[obj.Type]++; } } foreach (var member in population) { for (int i = 0; i < box.Volume * member.Key.Concentration - member.Value - Randomizer.Rng.NextDouble(); i++) { Add(new FloatingObjectInWorld(member.Key, box.RandomPoint()), false); } } }