예제 #1
0
        void AddNextNode()
        {
            BlockDBCacheNode newHead = new BlockDBCacheNode(nextSize);

            newHead.Prev = Head;
            if (Head != null)
            {
                Head.Next = newHead;
            }
            Head = newHead;
            if (Tail == null)
            {
                Tail = Head;
            }

            // use smaller increases at first to minimise memory usage
            if (nextSize == 50 * 1000)
            {
                nextSize = 100 * 1000;
            }
            if (nextSize == 20 * 1000)
            {
                nextSize = 50 * 1000;
            }
            if (nextSize == 10 * 1000)
            {
                nextSize = 20 * 1000;
            }
        }
예제 #2
0
        bool FindInMemoryBy(int[] ids, int startDelta, int endDelta, Action <BlockDBEntry> output)
        {
            BlockDBCacheNode node = Cache.Head;

            while (node != null)
            {
                int count = node.Count;
                BlockDBCacheEntry[] entries = node.Entries;

                for (int i = count - 1; i >= 0; i--)
                {
                    BlockDBEntry entry = node.Unpack(entries[i]);
                    if (entry.TimeDelta < startDelta)
                    {
                        return(true);
                    }
                    if (entry.TimeDelta > endDelta)
                    {
                        continue;
                    }

                    for (int j = 0; j < ids.Length; j++)
                    {
                        if (entry.PlayerID != ids[j])
                        {
                            continue;
                        }
                        output(entry); break;
                    }
                }
                lock (Cache.Locker) node = node.Prev;
            }
            return(false);
        }
예제 #3
0
        public void Clear()
        {
            lock (Locker) {
                if (Tail == null)
                {
                    return;
                }
                Count = 0;

                BlockDBCacheNode cur = Tail;
                while (cur != null)
                {
                    // Unlink the nodes
                    cur.Prev = null;
                    BlockDBCacheNode next = cur.Next;
                    cur.Next = null;
                    cur      = next;
                }
                Head = null; Tail = null;
            }
        }
예제 #4
0
        void FindInMemoryAt(ushort x, ushort y, ushort z, Action <BlockDBEntry> output)
        {
            int index             = (y * Dims.Z + z) * Dims.X + x;
            BlockDBCacheNode node = Cache.Tail;

            while (node != null)
            {
                BlockDBCacheEntry[] entries = node.Entries;
                int count = node.Count;

                for (int i = 0; i < count; i++)
                {
                    if (entries[i].Index != index)
                    {
                        continue;
                    }
                    BlockDBEntry entry = node.Unpack(entries[i]);
                    output(entry);
                }
                lock (Cache.Locker) node = node.Next;
            }
        }
예제 #5
0
        public override void WriteEntries(Stream s, BlockDBCache cache)
        {
            byte[]           bulk = new byte[BulkEntries * EntrySize];
            BlockDBCacheNode node = cache.Tail;

            while (node != null)
            {
                int count = node.Count;
                for (int i = 0; i < count; i += BulkEntries)
                {
                    int bulkCount = Math.Min(BulkEntries, count - i);
                    for (int j = 0; j < bulkCount; j++)
                    {
                        BlockDBEntry entry = node.Unpack(node.Entries[i + j]);
                        WriteEntry(entry, bulk, j * EntrySize);
                    }
                    s.Write(bulk, 0, bulkCount * EntrySize);
                }

                lock (cache.Locker)
                    node = node.Next;
            }
        }