Example #1
0
        void SaveChunk(byte[] data, int xc, int yc)
        {
            // reuse chunk if it already exists
            Vector3i      coordinate = _loadedChunk + new Vector3i(xc, yc, 0);
            FogOfWarChunk chunk      = _chunks.Find(c => c.coordinate == coordinate);

            if (chunk == null)
            {
                chunk            = new FogOfWarChunk();
                chunk.coordinate = coordinate;
                chunk.fogData    = new byte[_valuesPerChunk];
                _chunks.Add(chunk);
            }
            else if (chunk.fogData == null || chunk.fogData.Length != _valuesPerChunk)
            {
                chunk.fogData = new byte[_valuesPerChunk];
            }

            int halfmapsize = _mapResolution / 2;
            int xstart      = halfmapsize * xc;
            int ystart      = halfmapsize * yc;

            // copy values
            for (int y = 0; y < halfmapsize; ++y)
            {
                System.Array.Copy(data, (ystart + y) * _mapResolution + xstart, chunk.fogData, y * halfmapsize, halfmapsize);
            }
        }
Example #2
0
        void LoadChunk(byte[] data, int xc, int yc)
        {
            // only load if the chunk exists
            Vector3i      coordinate = _loadedChunk + new Vector3i(xc, yc, 0);
            FogOfWarChunk chunk      = _chunks.Find(c => c.coordinate == coordinate);

            if (chunk == null || chunk.fogData == null || chunk.fogData.Length != _valuesPerChunk)
            {
                return;
            }

            int halfmapsize = _mapResolution / 2;
            int xstart      = halfmapsize * xc;
            int ystart      = halfmapsize * yc;

            // copy values
            for (int y = 0; y < halfmapsize; ++y)
            {
                System.Array.Copy(chunk.fogData, y * halfmapsize, data, (ystart + y) * _mapResolution + xstart, halfmapsize);
            }
        }