Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes a floating object in space from the world.
        /// </summary>
        private void Remove(FloatingObjectInWorld fltObject, bool mayBeInNewSet = false)
        {
            if (fltObject == null)
            {
                throw new ArgumentNullException($"Removed floating object cannot be null");
            }
            var key = v_GridKeys.PositionToKey(fltObject.Position);

            if (v_Grid.ContainsKey(key) && (v_Grid[key].OldSet.Remove(fltObject) ||
                                            mayBeInNewSet && v_Grid[key].NewSet.Remove(fltObject)))
            {
                return;
            }

            throw new ArgumentException($"{fltObject} could not be removed from the world");
        }