private bool OverlapNode() { // Calculate bulk hull for _object _objectHullX = (_object.X < _object.Last.X) ? _object.X : _object.Last.X; _objectHullY = (_object.Y < _object.Last.Y) ? _object.Y : _object.Last.Y; _objectHullWidth = _object.X - _object.Last.X; _objectHullWidth = _object.Width + ((_objectHullWidth > 0) ? _objectHullWidth : -_objectHullWidth); _objectHullHeight = _object.Y - _object.Last.Y; _objectHullHeight = _object.Height + ((_objectHullHeight > 0) ? _objectHullHeight : -_objectHullHeight); // Walk the list and check for overlaps bool overlapProcessed = false; FlxObject checkObject; while (_iterator != null) { checkObject = _iterator.FlxObject; if (_object == checkObject || !checkObject.Exists || checkObject.AllowCollisions <= 0) { _iterator = _iterator.Next; continue; } // Calculate bulk hull for checkObject _checkObjectHullX = (checkObject.X < checkObject.Last.X) ? checkObject.X : checkObject.Last.X; _checkObjectHullY = (checkObject.Y < checkObject.Last.Y) ? checkObject.Y : checkObject.Last.Y; _checkObjectHullWidth = checkObject.X - checkObject.Last.X; _checkObjectHullWidth = checkObject.Width + ((_checkObjectHullWidth > 0) ? _checkObjectHullWidth : -_checkObjectHullWidth); _checkObjectHullHeight = checkObject.Y - checkObject.Last.Y; _checkObjectHullHeight = checkObject.Height + ((_checkObjectHullHeight > 0) ? _checkObjectHullHeight : -_checkObjectHullHeight); // Check for intersection of the two hulls if ((_objectHullX + _objectHullWidth > _checkObjectHullX) && (_objectHullX < _checkObjectHullX + _checkObjectHullWidth) && (_objectHullY + _objectHullHeight > _checkObjectHullY) && (_objectHullY < _checkObjectHullY + _checkObjectHullHeight)) { // Execute callback functions if they exist if (_processingCallback == null || _processingCallback(_object, checkObject)) { overlapProcessed = true; _notifyCallback?.Invoke(_object, checkObject); } } if (_iterator != null) { _iterator = _iterator.Next; } } return(overlapProcessed); }
public int RegisterInitializedCallback(NotifyCallback callback, bool initialNotify = false) { HAL_NotifyCallback modCallback = (IntPtr namePtr, IntPtr param, ref HAL_Value value) => { string varName = ReadUTF8String(namePtr); callback?.Invoke(varName, value); }; int uid = HALSIM_RegisterDigitalPWMInitializedCallback(Index, modCallback, IntPtr.Zero, initialNotify); if (!m_initializedCallbacks.TryAdd(uid, modCallback)) { HALSIM_CancelDigitalPWMInitializedCallback(Index, uid); throw new ArgumentException("Key cannot be added multiple times to the dictionary"); } return(uid); }
public int RegisterSolenoidOutputCallback(int channel, NotifyCallback callback, bool initialNotify = false) { HAL_NotifyCallback modCallback = (IntPtr namePtr, IntPtr param, ref HAL_Value value) => { string varName = ReadUTF8String(namePtr); callback?.Invoke(varName, value); }; int uid = HALSIM_RegisterPCMSolenoidOutputCallback(Index, channel, modCallback, IntPtr.Zero, initialNotify); if (!m_solenoidOutputCallbacks[channel].TryAdd(uid, modCallback)) { HALSIM_CancelPCMSolenoidOutputCallback(Index, channel, uid); throw new ArgumentException("Key cannot be added multiple times to the dictionary"); } return(uid); }