Exemple #1
0
 internal void DispatchObjectRemoved(DisplayObject target)
 {
     if (ObjectRemoved != null)
     {
         ObjectRemoved.Invoke(target);
     }
 }
Exemple #2
0
        public string Insert(IDbObject o, TimeSpan time, bool isRelative, ObjectRemoved removeDelegate)
        {
            string key = o.Id + "_" + o.GetType().Name;

            cache.Insert(key, o, time, isRelative, removeDelegate);
            return(ownIp + "_" + key);
        }
        public virtual bool Remove(GameObject obj)
        {
            attachedObjects.Remove(obj);
            ObjectRemoved?.Invoke(obj);

            return(true);
        }
Exemple #4
0
 private static void Script_Destroyed(object obj)
 {
     if (obj is T script)
     {
         if (cachedObjects.Contains(script))
         {
             Debug.Log("Trying to destroy an object that has already been destroyed.");
         }
         else
         {
             foreach (var manager in managers)
             {
                 manager.Remove(script);
             }
             script.transform.SetParent(deadObjectContainer);
             script.gameObject.SetActive(false);
             cachedObjects.Enqueue(script);
             ObjectRemoved?.Invoke(script);
         }
     }
     else
     {
         Debug.LogError($"Somehow this factory subscribed to the Destroy event on an object of type {obj.GetType()} when it was supposed to be of type {typeof(T)}");
     }
 }
Exemple #5
0
 public void Insert(K key, V value, TimeSpan liveTime, bool isRelative, ObjectRemoved removeDelegate)
 {
     localCacheLock.EnterUpgradeableReadLock();
     try
     {
         if (localCache.ContainsKey(key))
         {
             CacheEntry <V> entry = localCache[key];
             entry.Value          = value;
             entry.LiveTime       = liveTime;
             entry.IsTimeRelative = isRelative;
             if (isRelative)
             {
                 entry.DeadTime = DateTime.Now.Add(entry.LiveTime);
             }
         }
         else
         {
             localCacheLock.EnterWriteLock();
             try
             {
                 localCache.Add(key, new CacheEntry <V>(value, liveTime, isRelative, removeDelegate));
             }
             finally
             {
                 localCacheLock.ExitWriteLock();
             }
         }
     }
     finally
     {
         localCacheLock.ExitUpgradeableReadLock();
     }
 }
Exemple #6
0
 public CacheEntry(V value, TimeSpan liveTime, bool isTimeRelative, ObjectRemoved removeDelegate)
 {
     this.value          = value;
     deadTime            = DateTime.Now.Add(liveTime);
     this.liveTime       = this.liveTime;
     this.isTimeRelative = isTimeRelative;
     this.removeDelegate = removeDelegate;
 }
 private void Remove(string objectId)
 {
     lock (_objects)
     {
         _objects.Remove(objectId);
     }
     ObjectRemoved?.Invoke(this, objectId);
 }
Exemple #8
0
        /// <summary>Invokes <see cref="ObjectRemoved"/> and <see cref="CollectionChanged"/> events.</summary>
        /// <param name="item">Removed item.</param>
        protected virtual void InvokeObjectRemoved(TObject item)
        {
            Verify.Argument.IsNotNull(item, nameof(item));

            item.MarkAsDeleted();
            ObjectRemoved?.Invoke(this, CreateEventArgs(item));
            CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(
                                          NotifyCollectionChangedAction.Remove, item));
        }
Exemple #9
0
        public void RemoveObject(TilePos position)
        {
            var currentAtSamePosition = GetObjectAt(position);

            if (currentAtSamePosition != null)
            {
                _objects.Remove(position);

                ObjectRemoved.CallEvent(currentAtSamePosition);
            }
        }
        public void Insert(object key, IDbObject value, TimeSpan time, bool isRelative, ObjectRemoved removeDelegate)
        {
			string valueKey = key.ToString() + "_" + value.GetType().Name;
			string id = cacheLocal.Get(valueKey);
			if (id != null)
			{
				string[] str = id.Split(new char[] { '_' }, 1);
				string host = str[0];
				ServiceCacheProxy cacheProxy = cacheProxies[host];
				if (cacheProxy != null)
				{
					cacheProxy.BeginInsert(FinishInsert, new object[] { valueKey, time, isRelative, removeDelegate },value, time, isRelative, null);
				}
			}
			//TODO insert
			
        }
Exemple #11
0
        /// <summary>
        /// Sets the terrain at the given objects location to the given object, overwriting any terrain already present there.
        /// </summary>
        /// <param name="terrain">Terrain to replace the current terrain with. <paramref name="terrain"/> must have its
        /// <see cref="IGameObject.IsStatic"/> flag set to true and its <see cref="IHasLayer.Layer"/> must be 0, or an exception will be thrown.</param>
        public void SetTerrain(IGameObject terrain)
        {
            if (terrain.Layer != 0)
            {
                throw new ArgumentException($"Terrain for Map must reside on layer 0.", nameof(terrain));
            }

            if (!terrain.IsStatic)
            {
                throw new ArgumentException($"Terrain for Map must be marked static via its {nameof(IGameObject.IsStatic)} flag.", nameof(terrain));
            }

            if (terrain.CurrentMap != null)
            {
                throw new ArgumentException($"Cannot add terrain to more than one {nameof(Map)}.", nameof(terrain));
            }

            if (!this.Contains(terrain.Position))
            {
                throw new ArgumentException($"Terrain added to map must be within the bounds of that map.");
            }

            if (!terrain.IsWalkable)
            {
                foreach (var obj in Entities.GetItems(terrain.Position))
                {
                    if (!obj.IsWalkable)
                    {
                        throw new Exception("Tried to place non-walkable terrain at a location that already has another non-walkable item.");
                    }
                }
            }

            var oldTerrain = _terrain[terrain.Position];

            if (oldTerrain != null)
            {
                oldTerrain.OnMapChanged(null);
                ObjectRemoved?.Invoke(this, new ItemEventArgs <IGameObject>(oldTerrain, oldTerrain.Position));
            }

            _terrain[terrain.Position] = terrain;

            terrain.OnMapChanged(this);
            ObjectAdded?.Invoke(this, new ItemEventArgs <IGameObject>(terrain, terrain.Position));
        }
        /// <summary>
        /// Removes an object from the selected objects.
        /// </summary>
        /// <param name="obj">The object to remove.</param>
        public void Remove(T obj)
        {
            if (obj == null)
            {
                return;
            }

            if (!_selectedObjs.Remove(obj))
            {
                return;
            }

            OnObjectRemoved(obj);
            if (ObjectRemoved != null)
            {
                ObjectRemoved.Raise(this, EventArgsHelper.Create(obj));
            }

            UpdateSelection();
        }
        /// <summary>
        /// Clears all selected objects.
        /// </summary>
        public void Clear()
        {
            if (_selectedObjs.Count == 0)
            {
                return;
            }

            while (_selectedObjs.Count > 0)
            {
                var obj = _selectedObjs[_selectedObjs.Count - 1];
                _selectedObjs.RemoveAt(_selectedObjs.Count - 1);

                OnObjectRemoved(obj);
                if (ObjectRemoved != null)
                {
                    ObjectRemoved.Raise(this, EventArgsHelper.Create(obj));
                }
            }

            Debug.Assert(_selectedObjs.Count == 0);

            UpdateSelection();
        }
Exemple #14
0
        public void Remove(ISimpleGameObject obj)
        {
            if (!obj.InWorld)
            {
                return;
            }

            var lockedRegions = LockMultitileRegions(obj.PrimaryPosition.X, obj.PrimaryPosition.Y, obj.Size);

            if (RemoveFromPrimaryRegionAndAllTiles(obj, obj.PrimaryPosition.X, obj.PrimaryPosition.Y))
            {
                obj.InWorld = false;

                DeregisterObjectEventListeners(obj);

                IMiniMapRegionObject miniMapRegionObject = obj as IMiniMapRegionObject;
                if (miniMapRegionObject != null)
                {
                    MiniMapRegions.Remove(miniMapRegionObject);
                }

                ushort regionId = regionLocator.GetRegionIndex(obj);
                channel.Post("/WORLD/" + regionId, () =>
                {
                    var packet = new Packet(Command.ObjectRemove);
                    packet.AddUInt16(regionId);
                    packet.AddUInt32(obj.GroupId);
                    packet.AddUInt32(obj.ObjectId);
                    return(packet);
                });
            }

            UnlockRegions(lockedRegions);

            // Raise event
            ObjectRemoved.Raise(this, new ObjectEvent(obj));
        }
        public void Remove <T>(T obj) where T : Sprite
        {
            if (obj == null)
            {
                return;
            }

            lock (syncLock)
            {
                if (obj is Aisling)
                {
                    _aislings.Remove(obj);
                }

                if (obj is Monster)
                {
                    _monsters.Remove(obj);
                }

                if (obj is Mundane)
                {
                    _mundanes.Remove(obj);
                }

                if (obj is Money)
                {
                    _money.Remove(obj);
                }

                if (obj is Item)
                {
                    _items.Remove(obj);
                }

                ObjectRemoved?.Invoke(obj);
            }
        }
Exemple #16
0
        /// <summary>
        /// Constructor.  Constructs map with the given terrain layer, determining width/height based on the width/height of that terrain layer.
        /// </summary>
        /// <remarks>
        /// Because of the way polymorphism works for custom classes in C#, the <paramref name="terrainLayer"/> parameter MUST be of type
        /// <see cref="ISettableMapView{IGameObject}"/>, rather than <see cref="ISettableMapView{T}"/> where T is a type that derives from or implements
        /// <see cref="IGameObject"/>.  If you need to use a map view storing type T rather than IGameObject, use the
        /// <see cref="CreateMap{T}(ISettableMapView{T}, int, Distance, uint, uint, uint)"/> function to create the map.
        /// </remarks>
        /// <param name="terrainLayer">The <see cref="ISettableMapView{IGameObject}"/> that represents the terrain layer for this map.  After the
        /// map has been created, you should use the <see cref="SetTerrain(IGameObject)"/> function to modify the values in this map view, rather
        /// than setting the values via the map view itself -- if you re-assign the value at a location via the map view, the
        /// <see cref="ObjectAdded"/>/<see cref="ObjectRemoved"/> events are NOT guaranteed to be called, and many invariants of map may not be properly
        /// enforced.</param>
        /// <param name="numberOfEntityLayers">Number of non-terrain layers for the map.</param>
        /// <param name="distanceMeasurement"><see cref="Distance"/> measurement to use for pathing/measuring distance on the map.</param>
        /// <param name="layersBlockingWalkability">Layer mask containing those layers that should be allowed to have items that block walkability.
        /// Defaults to all layers.</param>
        /// <param name="layersBlockingTransparency">Layer mask containing those layers that should be allowed to have items that block FOV.
        /// Defaults to all layers.</param>
        /// <param name="entityLayersSupportingMultipleItems">Layer mask containing those layers that should be allowed to have multiple objects at the same
        /// location on the same layer.  Defaults to no layers.</param>
        public Map(ISettableMapView <IGameObject> terrainLayer, int numberOfEntityLayers, Distance distanceMeasurement, uint layersBlockingWalkability = uint.MaxValue,
                   uint layersBlockingTransparency = uint.MaxValue, uint entityLayersSupportingMultipleItems = 0)
        {
            _terrain = terrainLayer;
            Explored = new ArrayMap <bool>(_terrain.Width, _terrain.Height);

            _entities = new LayeredSpatialMap <IGameObject>(numberOfEntityLayers, 1, entityLayersSupportingMultipleItems);

            LayersBlockingWalkability  = layersBlockingWalkability;
            LayersBlockingTransparency = layersBlockingTransparency;

            _entities.ItemAdded   += (s, e) => ObjectAdded?.Invoke(this, e);
            _entities.ItemRemoved += (s, e) => ObjectRemoved?.Invoke(this, e);
            _entities.ItemMoved   += (s, e) => ObjectMoved?.Invoke(this, e);

            if (layersBlockingTransparency == 1)             // Only terrain so we optimize
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsTransparent);
            }
            else
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsTransparent);
            }

            if (layersBlockingWalkability == 1)             // Similar, only terrain blocks, so optimize
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsWalkable);
            }
            else
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsWalkable);
            }

            _fov  = new FOV(TransparencyView);
            AStar = new AStar(WalkabilityView, distanceMeasurement);
        }
Exemple #17
0
 public static void RemoveObject(GameObject gameObject)
 {
     sceneObjects.Remove(gameObject);
     SceneObjectListChanged?.Invoke(gameObject, new EventArgs());
     ObjectRemoved?.Invoke(gameObject, new EventArgs());
 }
Exemple #18
0
        public void Insert(object key, IDbObject value, TimeSpan time, bool isRelative, ObjectRemoved removeDelegate)
        {
            string valueKey = key.ToString() + "_" + value.GetType().Name;
            string id       = cacheLocal.Get(valueKey);

            if (id != null)
            {
                string[]          str        = id.Split(new char[] { '_' }, 1);
                string            host       = str[0];
                ServiceCacheProxy cacheProxy = cacheProxies[host];
                if (cacheProxy != null)
                {
                    cacheProxy.BeginInsert(FinishInsert, new object[] { valueKey, time, isRelative, removeDelegate }, value, time, isRelative, null);
                }
            }
            //TODO insert
        }
Exemple #19
0
		public string Insert(IDbObject o, TimeSpan time, bool isRelative, ObjectRemoved removeDelegate)
        {
			string key = o.Id + "_" + o.GetType().Name;
            cache.Insert(key, o, time, isRelative, removeDelegate);
        	return ownIp + "_" + key;
        }
Exemple #20
0
        public void OnRemoveScript(uint localID, UUID itemID)
        {
            lock (m_Scripts)
            {
                // Do we even have it?
                if (!m_Scripts.ContainsKey(itemID))
                {
                    return;
                }

                IScriptInstance instance = m_Scripts[itemID];
                m_Scripts.Remove(itemID);

                instance.ClearQueue();
                instance.Stop(0);

                SceneObjectPart part =
                    m_Scene.GetSceneObjectPart(localID);

                if (part != null)
                {
                    part.RemoveScriptEvents(itemID);
                }

//                bool objectRemoved = false;

                lock (m_PrimObjects)
                {
                    // Remove the script from it's prim
                    if (m_PrimObjects.ContainsKey(localID))
                    {
                        // Remove inventory item record
                        if (m_PrimObjects[localID].Contains(itemID))
                        {
                            m_PrimObjects[localID].Remove(itemID);
                        }

                        // If there are no more scripts, remove prim
                        if (m_PrimObjects[localID].Count == 0)
                        {
                            m_PrimObjects.Remove(localID);
//                            objectRemoved = true;
                        }
                    }
                }

                m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
                if (m_DomainScripts[instance.AppDomain].Count == 0)
                {
                    m_DomainScripts.Remove(instance.AppDomain);
                    UnloadAppDomain(instance.AppDomain);
                }

                instance.RemoveState();
                instance.DestroyScriptInstance();

                instance = null;

                ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
                if (handlerObjectRemoved != null)
                {
                    handlerObjectRemoved(part.UUID);
                }

                CleanAssemblies();
            }

            ScriptRemoved handlerScriptRemoved = OnScriptRemoved;

            if (handlerScriptRemoved != null)
            {
                handlerScriptRemoved(itemID);
            }
        }
Exemple #21
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnObjectRemoved(HlaObjectEventArgs e)
 {
     ObjectRemoved?.Invoke(this, e);// Raise the event.
 }