コード例 #1
0
        /// <summary>
        /// Make a new instance, copy from other instance (copy c'tor A, second c'tor variant).
        /// Makes a copy of the other ring buffer (but only copies useful data, to safe time).
        /// </summary>
        /// <param name="other">the other instance</param>
        public BinaryRingBuffer3D(BinaryRingBuffer3D other) : this(other.MemSlots, other.CellsX, other.CellsY)
        {
            //we copy as much as we can from the other
            //use 'newestGenPos', work into the direction of 'oldestGenPos' (fit as much as we can)
            //use top-left corner (0,0), work into x and y direction as far as we can
            //if this new ringbuffer is bigger than the other: fill with 'defaultValue'

            this.newestGenPos = other.newestGenPos;
            this.oldestGenPos = other.oldestGenPos;

            int i = oldestGenPos;

            do
            {
                MakeGeneration(i, false, false);

                ringBuffer[i] = (BitArray)other.ringBuffer[i].Clone(); //TODO: hopefully, this works as intended? (shallow copy should work?)

                i++;
                if (i >= MemSlots)
                {
                    i = 0;
                }
            }while (i != newestGenPos);
        }
コード例 #2
0
        /// <summary>
        /// Make a new instance, copy from other instance (copy c'tor B, third c'tor variant).
        /// Tries to grab as much data from the other instance as possible.
        /// </summary>
        /// <param name="mem">number of memory slots in the ring buffer (1st dimension)</param>
        /// <param name="x">number of cells in x direction (2nd dimension)</param>
        /// <param name="y">number of cells in y direction (3rd dimension)</param>
        /// <param name="other">the other instance</param>
        public BinaryRingBuffer3D(int mem, int x, int y, BinaryRingBuffer3D other) : this(mem, x, y)
        {
            //we copy as much as we can from the other
            //use 'newestGenPos', work into the direction of 'oldestGenPos' (fit as much as we can)
            //use top-left corner (0,0), work into x and y direction as far as we can
            //if this new ringbuffer is bigger than the other: fill with 'defaultValue'

            this.newestGenPos = other.newestGenPos;
            this.oldestGenPos = other.oldestGenPos;

            int i = oldestGenPos;

            do
            {
                MakeGeneration(i, false, false);

                int      ox = other.CellsX;
                int      oy = other.CellsY;
                BitArray arr = ringBuffer[i];
                BitArray oarr = other.ringBuffer[i];
                int      pos, opos;
                bool     value;
                for (int a = 0; a < x; a++)
                {
                    if (a >= ox)
                    {
                        break;
                    }
                    for (int b = 0; b < y; b++)
                    {
                        if (b >= oy)
                        {
                            break;
                        }
                        pos   = b * CellsX + a;
                        opos  = b * other.CellsX + a;
                        value = oarr.Get(opos);
                        arr.Set(pos, value);
                    }
                }

                i++;
                if (i >= MemSlots)
                {
                    i = 0;
                }
            }while (i != newestGenPos);
        }