Example #1
0
        public TileMap(List <Layer> layers, List <BGOVERLAY_DEF> overlayList, List <BGANIM_DEF> animList, uint factor)
        {
            Int32 minX, minY, maxX, maxY;

            TileMap.GetBounds(overlayList, 0, out minX, out minY, out maxX, out maxY);
            this.SizeX   = (maxX - minX) / 16;
            this.SizeY   = (maxY - minY) / 16;
            _cameraIndex = overlayList[0].camNdx;
            _overlays    = new Dictionary <int, Overlay>();
            _animList    = animList;

            bool[] animationArray = new bool[overlayList.Count];
            for (var m = 0; m < animList.Count; m++)
            {
                BGANIM_DEF animation = animList[m];
                for (var n = 0; n < animation.frameList.Count; n++)
                {
                    int index = animation.frameList[n].target;
                    animationArray[index] = true;
                }
            }
            for (int i = 0; i < overlayList.Count; i++)
            {
                BGOVERLAY_DEF info          = overlayList[i];
                Layer         layer         = layers[i];
                bool          animationFlag = animationArray[i];
                Overlay       overlay       = new Overlay(CopyBytesHelper.GetImageData(layer, info, factor), info, i, this.SizeX, this.SizeY, minX, minY, maxX, maxY, animationFlag);
                _overlays[i] = overlay;
            }

            TDMap = new TileDepthMap(_overlays, this.SizeX, this.SizeY);
        }
Example #2
0
        public void CopyRectExp(byte[] atlasArray, int atlasWidth, int toX, int toY, Tile tile, Overlay overlay, Size rectSize, uint fromX, uint fromY, bool ignoreTransparent)
        {
            if (tile.info == null)
            {
                Log.Warning($"MISSING TILE {overlay.GetOrderNumber()}, ({tile.x}, {tile.y}) COPY RECT EXP");
                return;
            }
            uint fromIndexX  = tile.info.offX * _factor + fromX;
            uint trueHeight  = overlay.info.h * _factor;
            uint trueWidth   = overlay.info.w * _factor;
            uint trueOffsetY = tile.info.offY * _factor;
            uint fromIndexY  = trueHeight - (trueOffsetY - fromY + Convert.ToUInt32(this.size.height)); // sigh

            for (uint i = 0; i < rectSize.height; i++)
            {
                for (uint j = 0; j < rectSize.width; j++)
                {
                    uint fromIndex = (fromIndexY + i) * trueWidth + fromIndexX + j;
                    uint toIndex   = (uint)((toY + i) * atlasWidth + toX + j);
                    if (ignoreTransparent && overlay.imageData[fromIndex * 4 + 3] < 127)
                    {
                        continue;
                    }
                    CopyBytesHelper.CopyPixel(overlay.imageData, atlasArray, fromIndex, toIndex);
                }
            }
        }
Example #3
0
        public void CopyStripToAtlas(byte[] atlasArray, int atlasWidth, int atlasX, int atlasY, byte[] stripData, Size stripSize)
        {
            uint k = 0;

            for (uint i = 0; i < stripSize.height; i++)
            {
                for (uint j = 0; j < stripSize.width; j++)
                {
                    uint toIndex = (uint)((atlasY + i) * atlasWidth + atlasX + j);
                    CopyBytesHelper.CopyPixel(stripData, atlasArray, k++, toIndex);
                }
            }
        }
Example #4
0
        public TileMap(int fieldMapNumber, List <Layer> layers, List <BGOVERLAY_DEF> overlayList, List <BGANIM_DEF> animList, List <BGLIGHT_DEF> lightList, int cameraIndex, uint factor)
        {
            Int32 minX, minY, maxX, maxY;

            TileMap.GetBounds(overlayList, cameraIndex, out minX, out minY, out maxX, out maxY);
            this.MinX       = minX;
            this.MinY       = minY;
            this.SizeX      = (maxX - minX) / 16 + 1;
            this.SizeY      = (maxY - minY) / 16 + 1;
            _fieldMapNumber = fieldMapNumber;
            _cameraIndex    = cameraIndex;
            _overlays       = new Dictionary <int, Overlay>();
            _animList       = animList;
            _lightList      = lightList;

            bool[] animationArray = new bool[overlayList.Count];
            for (var m = 0; m < animList.Count; m++)
            {
                BGANIM_DEF animation = animList[m];
                for (var n = 0; n < animation.frameList.Count; n++)
                {
                    int index = animation.frameList[n].target;
                    animationArray[index] = true;
                }
            }
            for (var m = 0; m < lightList.Count; m++)
            {
                BGLIGHT_DEF lightDef = lightList[m];
            }
            for (int i = 0; i < overlayList.Count; i++)
            {
                BGOVERLAY_DEF info = overlayList[i];
                if (info.camNdx != _cameraIndex)
                {
                    continue;
                }
                Layer   layer         = layers[i];
                bool    animationFlag = animationArray[i];
                bool    isLight       = false;
                Overlay overlay       = new Overlay(CopyBytesHelper.GetImageData(layer, info, factor), info, i, this.SizeX, this.SizeY, minX, minY, maxX, maxY, animationFlag);
                _overlays[i] = overlay;
            }

            TDMap = new TileDepthMap(_overlays, this.SizeX, this.SizeY);
        }
Example #5
0
        public void CopyRect(byte[] atlasArray, int atlasWidth, int toX, int toY, Tile tile, Overlay overlay, Size rectSize, uint fromX, uint fromY, bool ignoreTransparent)
        {
            if (tile.info == null)
            {
                Log.Warning($"MISSING TILE {overlay.GetOrderNumber()}, ({tile.x}, {tile.y})");
                return;
            }
            uint fromIndexX  = tile.info.offX * _factor + fromX;
            uint trueHeight  = overlay.info.h * _factor;
            uint trueWidth   = overlay.info.w * _factor;
            uint trueOffsetY = tile.info.offY * _factor;
            uint fromIndexY  = trueHeight - (trueOffsetY - fromY + Convert.ToUInt32(this.size.height)); // sigh

            for (uint i = 0; i < rectSize.height; i++)
            {
                for (uint j = 0; j < rectSize.width; j++)
                {
                    uint fromIndex = (fromIndexY + i) * trueWidth + fromIndexX + j;
                    uint toIndex   = (uint)((toY + i) * atlasWidth + toX + j);
                    try
                    {
                        if (ignoreTransparent && overlay.imageData[fromIndex * 4 + 3] < 255)
                        {
                            continue;
                        }
                        CopyBytesHelper.CopyPixel(overlay.imageData, atlasArray, fromIndex, toIndex);
                    }
                    catch
                    {
                        Log.Message($"trueHeight {trueHeight}, trueOffsetY {trueOffsetY}, fromY {fromY}, size.height {this.size.height}, difference {trueOffsetY - fromY + Convert.ToUInt32(this.size.height)}");
                        Log.Message($"trueWidth {trueWidth}, fromIndexY {fromIndexY}, fromIndexX {fromIndexX}");
                        Log.Message($"fromIndex {fromIndex}, imageData {overlay.imageData.Length} toIndex{toIndex}, atlas {atlasArray.Length}");
                        return;
                    }
                }
            }
        }