예제 #1
0
        /// <summary>
        /// Gibt einen abonnierten Chunk wieder frei.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="writeable"></param>
        public void Release(PlanetIndex3 position, bool writeable)
        {
            lock (lockObject)
            {
                CacheItem cacheItem = null;
                if (!cache.TryGetValue(position, out cacheItem))
                {
                    throw new NotSupportedException("Kein Chunk für Position in Cache");
                }

                cacheItem.References--;
                if (writeable) cacheItem.WritableReferences--;

                if (cacheItem.WritableReferences <= 0)
                {
                    saveDelegate(position, cacheItem.Chunk);
                }

                if (cacheItem.References <= 0)
                {
                    cacheItem.Chunk = null;
                    cache.Remove(position);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Gibt einen abonnierten Chunk wieder frei.
        /// </summary>
        /// <param name="position">Die Position des Chunks der Freigegeben wird</param>
        /// <param name="writeable">Gibt an, ob der Subscriber schreibend zugegriffen hat</param>
        public void Release(PlanetIndex3 position, bool writeable)
        {
            lock (lockObject)
            {
                CacheItem cacheItem = null;
                if (!cache.TryGetValue(position, out cacheItem))
                {
                    throw new NotSupportedException("Kein Chunk für Position in Cache");
                }

                cacheItem.References--;
                if (writeable)
                {
                    cacheItem.WritableReferences--;
                }

                if (cacheItem.WritableReferences <= 0)
                {
                    saveDelegate(position, cacheItem.Chunk);
                }

                if (cacheItem.References <= 0)
                {
                    cacheItem.Chunk = null;
                    cache.Remove(position);
                }
            }
        }
예제 #3
0
        public override bool Equals(object obj)
        {
            if (!(obj is PlanetIndex3))
            {
                return(false);
            }

            PlanetIndex3 other = (PlanetIndex3)obj;

            return(
                other.Planet == this.Planet &&
                other.ChunkIndex.X == this.ChunkIndex.X &&
                other.ChunkIndex.Y == this.ChunkIndex.Y &&
                other.ChunkIndex.Z == this.ChunkIndex.Z);
        }
예제 #4
0
        /// <summary>
        /// Abonniert einen Chunk.
        /// </summary>
        /// <param name="position">Position des Chunks</param>
        /// <param name="writeable">Gibt an, ob der Subscriber schreibend zugreifen will</param>
        /// <returns></returns>
        public IChunk Subscribe(PlanetIndex3 position, bool writeable)
        {
            lock (lockObject)
            {
                CacheItem cacheItem = null;
                if (!cache.TryGetValue(position, out cacheItem))
                {
                    cacheItem = new CacheItem()
                    {
                        Position = position,
                        References = 0,
                        Chunk = loadDelegate(position),
                    };

                    cache.Add(position, cacheItem);
                }
                cacheItem.References++;
                if (writeable) cacheItem.WritableReferences++;
                return cacheItem.Chunk;
            }
        }
예제 #5
0
        /// <summary>
        /// Abonniert einen Chunk.
        /// </summary>
        /// <param name="position">Position des Chunks</param>
        /// <param name="writeable">Gibt an, ob der Subscriber schreibend zugreifen will</param>
        /// <returns></returns>
        public IChunk Subscribe(PlanetIndex3 position, bool writeable)
        {
            lock (lockObject)
            {
                CacheItem cacheItem = null;
                if (!cache.TryGetValue(position, out cacheItem))
                {
                    cacheItem = new CacheItem()
                    {
                        Position   = position,
                        References = 0,
                        Chunk      = loadDelegate(position),
                    };

                    cache.Add(position, cacheItem);
                }
                cacheItem.References++;
                if (writeable)
                {
                    cacheItem.WritableReferences++;
                }
                return(cacheItem.Chunk);
            }
        }