Пример #1
0
        public void SetFrom(TextureGrid <T> instanceToSetFrom)
        {
            mBaseTexture = instanceToSetFrom.mBaseTexture;

            mTextures = new List <List <T> >();

            for (int i = 0; i < instanceToSetFrom.mTextures.Count; i++)
            {
                mTextures.Add(new List <T>(instanceToSetFrom.mTextures[i]));
            }

            mFirstPaintedX = new List <float>(instanceToSetFrom.mFirstPaintedX);
            mLastPaintedX  = new List <float>(instanceToSetFrom.mLastPaintedX);

            mFirstPaintedY = instanceToSetFrom.mFirstPaintedY;
            mLastPaintedY  = instanceToSetFrom.mLastPaintedY;

            mXOffset = instanceToSetFrom.mXOffset;
            mYOffset = instanceToSetFrom.mYOffset;

            mGridSpacingX = instanceToSetFrom.mGridSpacingX;
            mGridSpacingY = instanceToSetFrom.mGridSpacingY;

            mSpaceHalfX = instanceToSetFrom.mSpaceHalfX;
            mSpaceHalfY = instanceToSetFrom.mSpaceHalfY;

            mSpaceFourthX = instanceToSetFrom.mSpaceFourthX;
            mSpaceFourthY = instanceToSetFrom.mSpaceFourthY;
        }
Пример #2
0
        public TextureGrid <T> Clone()
        {
            TextureGrid <T> gridToReturn = (TextureGrid <T>)(MemberwiseClone());

            gridToReturn.mTextures = new List <List <T> >();

            foreach (List <T> array in mTextures)
            {
                List <T> ta = new List <T>();
                gridToReturn.mTextures.Add(ta);

                foreach (T texture in array)
                {
                    ta.Add(texture);
                }
            }

            gridToReturn.mFirstPaintedX = new List <float>();
            foreach (float f in mFirstPaintedX)
            {
                gridToReturn.mFirstPaintedX.Add(f);
            }

            gridToReturn.mLastPaintedX = new List <float>();
            foreach (float f in mLastPaintedX)
            {
                gridToReturn.mLastPaintedX.Add(f);
            }


            return(gridToReturn);
        }
Пример #3
0
        public List <TextureLocation <T> > GetTextureLocationDifferences(TextureGrid <T> originalGrid)
        {
            List <TextureLocation <T> > textureLocationArray = new List <TextureLocation <T> >();

            // These are empty grids, so there's no changes.
            if (this.FirstPaintedX.Count == 0 && originalGrid.FirstPaintedX.Count == 0)
            {
                return(textureLocationArray);
            }


            int thisYOn     = 0;
            int originalYOn = 0;

            #region Get minY which is the smallest painted Y

            float minY = (float)System.Math.Min(mFirstPaintedY, originalGrid.mFirstPaintedY);
            if (originalGrid.mTextures.Count == 0)
            {
                minY = mFirstPaintedY;
            }
            else if (this.mTextures.Count == 0)
            {
                minY = originalGrid.mFirstPaintedY;
            }

            if (float.IsNaN(originalGrid.mFirstPaintedY))
            {
                minY = mFirstPaintedY;
            }
            #endregion

            #region Get maxY which is the largest painted Y

            float maxY = (float)System.Math.Max(mLastPaintedY, originalGrid.mLastPaintedY);

            if (originalGrid.mTextures.Count == 0)
            {
                maxY = mLastPaintedY;
            }
            else if (this.mTextures.Count == 0)
            {
                maxY = originalGrid.mLastPaintedY;
            }

            if (float.IsNaN(originalGrid.mLastPaintedY))
            {
                maxY = mLastPaintedY;
            }
            #endregion

            if (originalGrid.mTextures.Count == 0)
            {
                originalYOn = 0;
                thisYOn     = 0;
            }
            else if (originalGrid.mFirstPaintedY - mFirstPaintedY > mSpaceHalfY)
            {
                thisYOn     = 0;
                originalYOn = (int)System.Math.Round((mFirstPaintedY - originalGrid.mFirstPaintedY) / mGridSpacingY);
            }
            else if (mFirstPaintedY - originalGrid.mFirstPaintedY > mSpaceHalfY)
            {// if the this instance begins below originalGrid
                originalYOn = 0;
                thisYOn     = (int)System.Math.Round((mFirstPaintedY - originalGrid.mFirstPaintedY) / mGridSpacingY);
            }


            //			float minX = 0;
            float maxX = 0;



            T originalTexture = default(T);

            for (float y = minY; y - mSpaceFourthY < maxY; y += mGridSpacingY)
            {
                if (originalGrid.mTextures.Count == 0 || originalYOn < 0)
                {// if the this instance begins below originalGrid
                    for (float x = this.mFirstPaintedX[thisYOn]; x - mSpaceFourthX < this.mLastPaintedX[thisYOn]; x += mGridSpacingX)
                    {
                        textureLocationArray.Add(new TextureLocation <T>(originalGrid.mBaseTexture, x, y));
                    }
                }
                else if (thisYOn < 0)
                {// the original grid is below this grid
                    for (float x = originalGrid.mFirstPaintedX[originalYOn]; x - mSpaceFourthX < originalGrid.mLastPaintedX[originalYOn]; x += mGridSpacingX)
                    {
                        textureLocationArray.Add(new TextureLocation <T>(this.mBaseTexture, x, y));
                    }
                }
                else
                {     // y is above the bottom border of both grids
                    if (thisYOn > this.mTextures.Count - 1)
                    { // y is above the this instance top
                        for (float x = originalGrid.mFirstPaintedX[originalYOn]; x - mSpaceFourthX < originalGrid.mLastPaintedX[originalYOn]; x += mGridSpacingX)
                        {
                            textureLocationArray.Add(new TextureLocation <T>(this.mBaseTexture, x, y));
                        }
                    }
                    else if (originalYOn > originalGrid.mTextures.Count - 1)
                    { // Y is above the originalGrid's top
                        for (float x = this.mFirstPaintedX[thisYOn]; x - mSpaceFourthX < this.mLastPaintedX[thisYOn]; x += mGridSpacingX)
                        {
                            textureLocationArray.Add(new TextureLocation <T>(originalGrid.mBaseTexture, x, y));
                        }
                    }
                    else
                    { // y is between the top and bottom of both grids
                        maxX = System.Math.Max(this.mLastPaintedX[thisYOn], originalGrid.mLastPaintedX[originalYOn]);


                        for (float x = System.Math.Min(this.mFirstPaintedX[thisYOn], originalGrid.mFirstPaintedX[originalYOn]); x - mSpaceFourthX < maxX; x += mGridSpacingX)
                        {
                            originalTexture = originalGrid.GetTextureAt(x, y);

                            T newTexture = this.GetTextureAt(x, y);

                            bool areBothNull = newTexture == null && originalTexture == null;

                            if (!areBothNull)
                            {
                                if ((originalTexture == null && newTexture != null) ||
                                    originalTexture.Equals(this.GetTextureAt(x, y)) == false)
                                {
                                    textureLocationArray.Add(new TextureLocation <T>(originalTexture, x, y));
                                }
                            }
                        }
                    }
                }

                // moving up one row, so increment the y value
                originalYOn++;
                thisYOn++;
            }

            return(textureLocationArray);
        }