public virtual bool Add(IEntity entity)
        {
            if (entity.LocalId == 0)
            {
                MainConsole.Instance.Warn("Entity with 0 localID!");
                return(false);
            }

            try
            {
                if (entity is ISceneEntity)
                {
                    lock (m_child_2_parent_entitiesLock)
                    {
                        foreach (ISceneChildEntity part in (entity as ISceneEntity).ChildrenEntities())
                        {
                            m_child_2_parent_entities.Remove(part.UUID);
                            m_child_2_parent_entities.Remove(part.LocalId);
                            m_child_2_parent_entities.Add(part.UUID, part.LocalId, entity.UUID);
                        }
                    }
                    lock (m_objectEntitiesLock)
                        m_objectEntities.Add(entity.UUID, entity.LocalId, entity as ISceneEntity);
                }
                else
                {
                    IScenePresence presence = (IScenePresence)entity;

                    lock (m_presenceEntitiesLock)
                    {
                        m_presenceEntitiesList.Add(presence);
                        m_presenceEntities.Add(presence.UUID, presence);
                    }
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat("Add Entity failed: {0}", e.Message);
                return(false);
            }
            return(true);
        }
        public virtual bool Remove(IEntity entity)
        {
            if (entity == null)
            {
                return(false);
            }

            try
            {
                if (entity is ISceneEntity)
                {
                    lock (m_child_2_parent_entitiesLock)
                    {
                        //Remove all child entities
                        foreach (ISceneChildEntity part in (entity as ISceneEntity).ChildrenEntities())
                        {
                            m_child_2_parent_entities.Remove(part.UUID);
                            m_child_2_parent_entities.Remove(part.LocalId);
                        }
                    }
                    lock (m_objectEntitiesLock)
                    {
                        m_objectEntities.Remove(entity.UUID);
                        m_objectEntities.Remove(entity.LocalId);
                    }
                }
                else
                {
                    lock (m_presenceEntitiesLock)
                    {
                        m_presenceEntitiesList.Remove((IScenePresence)entity);
                        m_presenceEntities.Remove(entity.UUID);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat("Remove Entity failed for {0}", entity.UUID, e);
                return(false);
            }
        }
        public void RemoveLevel2ReturnsFalseIfNothingFound()
        {
            var key1  = 5;
            var key21 = "key1";
            var key22 = "key2";
            var key12 = 2;

            var dictionary = new DoubleKeyDictionary <int, string, string>();

            dictionary.Add(key1, key21, "value11");
            dictionary.Add(key1, key22, "value2");
            dictionary.Add(key12, key21, "value3");
            dictionary.Add(key12, key22, "value4");

            var result  = dictionary.Remove(3, key21);
            var result2 = dictionary.Remove(5, "key3");

            result.Should().BeFalse();
            result2.Should().BeFalse();
        }
 /// <summary>
 /// Registers the specified model unique identifier.
 /// </summary>
 /// <typeparam name="T">Geometry Buffer Type</typeparam>
 /// <param name="modelGuid">The model unique identifier.</param>
 /// <param name="geometry">The geometry.</param>
 /// <returns></returns>
 public IGeometryBufferModel Register <T>(Guid modelGuid, Geometry3D geometry) where T : class, IGeometryBufferModel, new()
 {
     if (geometry == null || modelGuid == Guid.Empty)
     {
         return(EmptyGeometryBufferModel.Empty);
     }
     lock (bufferDictionary)
     {
         IGeometryBufferModel container;
         if (bufferDictionary.TryGetValue(typeof(T), geometry.GUID, out var obj))
         {
             if (logger.IsEnabled(LogLevel.Trace))
             {
                 logger.LogTrace("Existing buffer found, GeomoetryGUID = {}", geometry.GUID);
             }
             container = obj as IGeometryBufferModel;
             obj.IncRef();
         }
         else
         {
             if (logger.IsEnabled(LogLevel.Trace))
             {
                 logger.LogTrace("Buffer not found, create new buffer. GeomoetryGUID = {}", geometry.GUID);
             }
             container = new T();
             var id = geometry.GUID;
             obj           = container as DisposeObject;
             obj.Disposed += (s, e) =>
             {
                 if (logger.IsEnabled(LogLevel.Trace))
                 {
                     logger.LogTrace("Disposing Geometry Buffer. GeomoetryGUID = {}", id);
                 }
                 lock (bufferDictionary)
                 {
                     bufferDictionary.Remove(typeof(T), id);
                 }
             };
             container.EffectsManager = manager;
             container.Geometry       = geometry;
             bufferDictionary.Add(typeof(T), geometry.GUID, obj);
         }
         return(container);
     }
 }
        private void Destroy(int i, int j, RenderMode renderMode)
        {
            Tile tile;

            if (renderMode == RenderMode.Scene)
            {
                tile = _allSceneTiles[i, j];
                _allSceneTiles.Remove(i, j);
            }
            else
            {
                tile = _allOverviewTiles[i, j];
                _allOverviewTiles.Remove(i, j);
            }

            _tileActivator.Destroy(tile);
            _messageBus.Send(new TileDestroyMessage(tile));
        }
        public MaterialVariable Register(IMaterial material, IRenderTechnique technique)
        {
            if (material == null || technique.IsNull)
            {
                return(EmptyMaterialVariable.EmptyVariable);
            }
            var guid     = material.Guid;
            var techGuid = technique.GUID;

            lock (dictionary)
            {
                if (dictionary.TryGetValue(guid, techGuid, out MaterialVariable value))
                {
                    value.IncRef();
                    return(value);
                }
                else
                {
                    var v = material.CreateMaterialVariables(effectsManager, technique);
                    v.Initialize();
                    v.Disposed += (s, e) =>
                    {
                        lock (dictionary)
                        {
                            dictionary.Remove(guid, techGuid);
                        }
                    };
                    dictionary.Add(guid, techGuid, v);
                    if (IDMAX - (ushort)Count > 1000)
                    {
                        IDMAX = 0;
                        foreach (var m in dictionary)
                        {
                            m.Value.ID = ++IDMAX;
                        }
                    }
                    else
                    {
                        v.ID = ++IDMAX;
                    }
                    return(v);
                }
            }
        }
Exemple #7
0
        //method to destroy object
        //had to do this as destroy can only be called from the main thread
        void Destroy(int x, int z)
        {
            //Create the voxel data


            if (m_voxelChunk[x, z].HasChanged && m_voxelChunk[x, z].shouldrender)
            {
                m_voxelChunk[x, z].SaveVoxels();
            }

            if (m_voxelChunk.ContainsKey(x, z))
            {
                ToDestroy.Add(m_voxelChunk[x, z]);
            }

            if (m_voxelChunk.ContainsKey(x, z))
            {
                m_voxelChunk.Remove(x, z);
            }
        }
        public void CanRemoveExactEntry()
        {
            var key1  = 5;
            var key21 = "key1";
            var key22 = "key2";
            var key12 = 2;

            var dictionary = new DoubleKeyDictionary <int, string, string>();

            dictionary.Add(key1, key21, "value11");
            dictionary.Add(key1, key22, "value2");
            dictionary.Add(key12, key21, "value3");
            dictionary.Add(key12, key22, "value4");

            var result = dictionary.Remove(key1, key21);

            result.Should().BeTrue();
            dictionary.Count.Should().Be(3);
            dictionary.Contains(key1, key21).Should().BeFalse();
            dictionary.GetAll().FirstOrDefault(x => x == "value11").Should().BeNullOrEmpty();
        }
        internal EnumTypeCache RequestCacheForTypeName(string name, bool checkDeactivated = true)
        {
            LoadCache();

            if (entriesFromRequests.TryGetValue(name, out int value))
            {
                return(new EnumTypeCache(value, name));
            }
            else if (entriesFromFile.TryGetValue(name, out value))
            {
                entriesFromRequests.Add(value, name);
                return(new EnumTypeCache(value, name));
            }
            else if (checkDeactivated && entriesFromDeactivatedFile.TryGetValue(name, out value))
            {
                entriesFromRequests.Add(value, name);
                entriesFromDeactivatedFile.Remove(value, name);
                return(new EnumTypeCache(value, name));
            }

            return(null);
        }
         /// <summary>
         /// Registers the specified model unique identifier.
         /// </summary>
         /// <typeparam name="T">Geometry Buffer Type</typeparam>
         /// <param name="modelGuid">The model unique identifier.</param>
         /// <param name="geometry">The geometry.</param>
         /// <returns></returns>
         public IGeometryBufferModel Register <T>(Guid modelGuid, Geometry3D geometry) where T : class, IGeometryBufferModel, new()
         {
             if (geometry == null || modelGuid == Guid.Empty)
             {
                 return(EmptyGeometryBufferModel.Empty);
             }
             lock (bufferDictionary)
             {
                 IGeometryBufferModel container;
                 if (bufferDictionary.TryGetValue(typeof(T), geometry.GUID, out ReferenceCountDisposeObject obj))
                 {
 #if DEBUGDETAIL
                     Debug.WriteLine("Existing buffer found, GeomoetryGUID = " + geometry.GUID);
 #endif
                     container = obj as IGeometryBufferModel;
                     obj.IncRef();
                 }
                 else
                 {
 #if DEBUGDETAIL
                     Debug.WriteLine("Buffer not found, create new buffer. GeomoetryGUID = " + geometry.GUID);
 #endif
                     container = new T();
                     var id = geometry.GUID;
                     obj           = container as ReferenceCountDisposeObject;
                     obj.Disposed += (s, e) =>
                     {
                         lock (bufferDictionary)
                         {
                             bufferDictionary.Remove(typeof(T), id);
                         }
                     };
                     container.EffectsManager = manager;
                     container.Geometry       = geometry;
                     bufferDictionary.Add(typeof(T), geometry.GUID, obj);
                 }
                 return(container);
             }
         }
Exemple #11
0
        void checkActiveChunks()
        {
            if (ActiveChunks.Count > 0)
            {
                for (int i = 0; i < ActiveChunks.Count; i++)
                {
                    VoxelChunk chunk    = ActiveChunks[i];
                    Vector2    chunkpos = new Vector2(chunk.m_pos.x, chunk.m_pos.z) / TriSize[minLod];

                    Vector2 playerpos = Vector2.zero;
                    if (Vector2.Distance(chunkpos, playerpos) >= distanceToLoad + 25)
                    {
                        if (chunk.HasChanged && chunk.shouldrender)
                        {
                            chunk.SaveVoxels();
                        }
                        Trash.Enqueue(chunk);
                        m_voxelChunk.Remove(chunk.RealPos * minLod, new Vector3(m_voxelWidthLength, m_voxelHeight, m_voxelWidthLength));
                        ActiveChunks.Remove(chunk);
                        return;
                    }
                }
            }
        }