Esempio n. 1
0
        public static RawBmp CreateShipBmp(EntityDamageProfileDB shipProfile)
        {
            byte armorID = 255;//shipProfile.Armor.IDCode;
            var  po      = shipProfile.PlacementOrder;

            List <(Guid typeID, RawBmp bmp)> typeBitmaps = shipProfile.TypeBitmaps;
            int componentWidthNum = 0;

            int totalLen    = 0;
            var totalWidth  = 0;
            int widestPoint = 0;
            int widestLen   = 0;

            byte componentInstance = 0;

            for (int i = 0; i < po.Count; i++)
            {
                var typeid  = po[i].id;
                var count   = po[i].count;
                var typeBmp = typeBitmaps[i].bmp;


                if (count > componentWidthNum)
                {
                    componentWidthNum = count;
                }

                totalLen += typeBmp.Width;

                int width = typeBmp.Height * count;
                if (width > totalWidth)
                {
                    totalWidth  = width;
                    widestPoint = totalLen;
                    widestLen   = typeBmp.Width;
                }
            }

            int canvasWidth = totalWidth + 6; //create a bit larger canvas size for the armor.
            int canvasLen   = totalLen + 6;


            int    size    = 4 * canvasLen * canvasWidth;
            int    stride  = canvasLen * 4;
            RawBmp shipBmp = new RawBmp()
            {
                ByteArray = new byte[size],
                Stride    = stride,
                Depth     = 4,
                Width     = canvasLen,
                Height    = canvasWidth,
            };

            if (po.Count <= 0)
            {
                return(shipBmp);
            }

            byte[] shipByteArray = new byte[size];

            int offsetx = 4;

            for (int i = 0; i < po.Count; i++)
            {
                if (po[i].count == 0)
                {
                    continue;
                }
                var typeBmp = typeBitmaps[i].bmp;
                componentInstance++;
                var typeid       = po[i].id;
                var count        = po[i].count;
                int maxPixHeight = typeBmp.Height * count;

                for (int o = 0; o < count; o++)
                {
                    //pixHeight -= - (o * typeBmp.Height);
                    int offsety = (canvasWidth - maxPixHeight) / 2;
                    offsety += typeBmp.Height * o;

                    //not doing anything?
                    int bytesPerLine = 4 * typeBmp.Width;

                    for (int x = 0; x < typeBmp.Width; x++)
                    {
                        for (int y = 0; y < typeBmp.Height; y++)
                        {
                            var srsClr = typeBmp.GetPixel(x, y);
                            int destx  = offsetx + x;
                            int desty  = offsety + y;
                            shipBmp.SetPixel(destx, desty, srsClr.r, componentInstance, srsClr.b, srsClr.a);
                        }
                    }
                }

                /*
                 * for (int j = 0; j < count; j++)
                 * {
                 *  for (int pxstrip = 0; pxstrip < typeBmp.Height; pxstrip++)
                 *  {
                 *      int srcpos = typeBmp.Stride * pxstrip;
                 *      int destPos = shipBmp.GetOffset(offsetx, offsety + pxstrip + (typeBmp.Height * j));
                 *
                 *      Buffer.BlockCopy(typeBmp.ByteArray, srcpos, shipByteArray, destPos, bytesPerLine);
                 *  }
                 * }
                 */
                offsetx += typeBmp.Width;
            }

            //shipBmp.ByteArray = shipByteArray;

            //TODO: somehow make lines thicker without crashing


            //below is a failed attempt at trying to make lines thicker
            //int bezzierMargin = 50;
            //widestPoint -= bezzierMargin;
            //widestLen -= bezzierMargin
            //bool canvasWidthIsBigEnough = canvasWidth > bezzierMargin;
            //bool canvasLenIsBigEnough = canvasLen > bezzierMargin;
            //canvasWidth = (canvasWidthIsBigEnough ? canvasWidth - bezzierMargin : canvasWidth);
            //canvasLen = (canvasLenIsBigEnough?canvasLen-bezzierMargin:canvasLen);
            //((canvasWidthIsBigEnough&&canvasLenIsBigEnough)?4:0);


            float addedLineThickness = 5;

            //adding margins to the bitmap(white space around its edges to make it look cleaner once displayed)
            Vector2 shipbmpMargins = new Vector2(shipBmp.Width * 0.1 + addedLineThickness, shipBmp.Height * 0.1 + addedLineThickness);
            RawBmp  finalShipBmp   = new RawBmp(shipBmp.Width + (int)shipbmpMargins.X * 2, shipBmp.Height + (int)shipbmpMargins.Y * 2, shipBmp.Depth);

            //shifting
            for (int x = 0; x < shipBmp.Width; x++)
            {
                for (int y = 0; y < shipBmp.Height; y++)
                {
                    var srsClr = shipBmp.GetPixel(x, y);
                    finalShipBmp.SetPixel(x + (int)shipbmpMargins.X, y + (int)shipbmpMargins.Y, srsClr.r, srsClr.g, srsClr.b, srsClr.a);
                }
            }

            shipBmp = finalShipBmp;



            //create bezzier control points for front and rear armor/skin

            (int x, int y)[] controlPointsFore = new (int x, int y)[4];
Esempio n. 2
0
        public static RawBmp CreateShipBmp(EntityDamageProfileDB shipProfile)
        {
            byte armorID = 255;//shipProfile.Armor.IDCode;
            var  po      = shipProfile.PlacementOrder;

            List <(Guid typeID, RawBmp bmp)> typeBitmaps = shipProfile.TypeBitmaps;
            List <(int width, int height)>   partsize    = new List <(int width, int height)>();

            partsize.Add((1, 1));
            int componentWidthNum = 0;

            int totalLen   = 0;
            var totalWidth = 0;

            byte componentInstance = 0;

            for (int i = 0; i < po.Count; i++)
            {
                var typeid  = po[i].id;
                var count   = po[i].count;
                var typeBmp = typeBitmaps[i].bmp;


                if (count > componentWidthNum)
                {
                    componentWidthNum = count;
                }

                totalLen += typeBmp.Width;

                int width = typeBmp.Height * count;
                if (width > totalWidth)
                {
                    totalWidth = width;
                }
            }

            int canvasWidth = totalWidth + 6; //create a bit larger canvas size for the armor.
            int canvasLen   = totalLen + 6;


            int    size    = 4 * canvasLen * canvasWidth;
            int    stride  = canvasLen * 4;
            RawBmp shipBmp = new RawBmp()
            {
                ByteArray = new byte[size],
                Stride    = stride,
                Depth     = 4,
                Width     = canvasLen,
                Height    = canvasWidth,
            };

            if (po.Count <= 0)
            {
                return(shipBmp);
            }

            byte[] shipByteArray = new byte[size];

            int offsetx = 0;

            for (int i = 0; i < po.Count; i++)
            {
                if (po[i].count == 0)
                {
                    continue;
                }
                var typeBmp = typeBitmaps[i].bmp;
                componentInstance++;
                var typeid       = po[i].id;
                var count        = po[i].count;
                int maxPixHeight = typeBmp.Height * count;

                partsize.Add(((int)typeBmp.Width, (int)typeBmp.Height * count));

                for (int o = 0; o < count; o++)
                {
                    //pixHeight -= - (o * typeBmp.Height);
                    int offsety = (canvasWidth - maxPixHeight) / 2;
                    offsety += typeBmp.Height * o;

                    //not doing anything?

                    for (int x = 0; x < typeBmp.Width; x++)
                    {
                        for (int y = 0; y < typeBmp.Height; y++)
                        {
                            var srsClr = typeBmp.GetPixel(x, y);
                            int destx  = offsetx + x;
                            int desty  = offsety + y;
                            shipBmp.SetPixel(destx, desty, srsClr.r, componentInstance, srsClr.b, srsClr.a);
                        }
                    }
                }

                offsetx += typeBmp.Width;
            }

            //shipBmp.ByteArray = shipByteArray;

            //TODO: somehow make lines thicker without crashing



            float addedLineThickness = 5;

            //adding margins to the bitmap(white space around its edges to make it look cleaner once displayed)
            Vector2 shipbmpMargins = new Vector2(shipBmp.Width * 0.1, shipBmp.Height * 0.1);
            RawBmp  finalShipBmp   = new RawBmp(shipBmp.Width + (int)shipbmpMargins.X * 2, shipBmp.Height + (int)shipbmpMargins.Y * 2, shipBmp.Depth);

            //shifting
            for (int x = 0; x < shipBmp.Width; x++)
            {
                for (int y = 0; y < shipBmp.Height; y++)
                {
                    var srsClr = shipBmp.GetPixel(x, y);
                    finalShipBmp.SetPixel(x + (int)shipbmpMargins.X, y + (int)shipbmpMargins.Y, srsClr.r, srsClr.g, srsClr.b, srsClr.a);
                }
            }

            shipBmp = finalShipBmp;

            List <(int x, int y)> linePoints = new List <(int x, int y)>();
            List <int>            lineHeight = new List <int>();


            int spacer = 1;

            int numparts = partsize.Count();


            //Grabs the height of each transtion between parts
            for (int partnum = 0; partnum < numparts - 1; partnum++)
            {
                if (partsize[partnum].height > partsize[partnum + 1].height)
                {
                    lineHeight.Add(partsize[partnum].height / 2);
                }
                else
                {
                    lineHeight.Add(partsize[partnum + 1].height / 2);
                }
            }
            lineHeight.Add(partsize[numparts - 1].height / 2);

            linePoints.Add((0, 0));

            //Adds a point at each transtions
            int currentx = 0;

            for (int partnum = 0; partnum < numparts; partnum++)
            {
                currentx += partsize[partnum].width;
                linePoints.Add((currentx, lineHeight[partnum] + spacer));