Example #1
0
        void SetBatchRenderedTileGID(int column, int row, CCTileGidAndFlags gidAndFlags)
        {
            int flattenedIndex        = FlattenedTileIndex(column, row);
            CCTileGidAndFlags prevGid = TileGIDAndFlagsArray[flattenedIndex];

            if (gidAndFlags != prevGid)
            {
                TileGIDAndFlagsArray[flattenedIndex] = gidAndFlags;
                if (prevGid.Gid == 0)
                {
                    var drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid);
                    CCTileMapVertAndIndexBuffer drawBuffer = drawBufferManager.GetDrawBufferAtIndex(flattenedIndex);
                    drawBuffer.UpdateQuad(flattenedIndex, ref gidAndFlags, true);
                }
                else if (gidAndFlags.Gid == 0)
                {
                    var oldDrawBufferManager = GetDrawBufferManagerByGid(prevGid.Gid);
                    CCTileMapVertAndIndexBuffer drawBuffer = oldDrawBufferManager.GetDrawBufferAtIndex(flattenedIndex);
                    drawBuffer.UpdateQuad(flattenedIndex, ref gidAndFlags, true);
                }
                else
                {
                    var emptyTile            = CCTileGidAndFlags.EmptyTile;
                    var oldDrawBufferManager = GetDrawBufferManagerByGid(prevGid.Gid);
                    CCTileMapVertAndIndexBuffer oldDrawBuffer = oldDrawBufferManager.GetDrawBufferAtIndex(flattenedIndex);
                    oldDrawBuffer.UpdateQuad(flattenedIndex, ref emptyTile, true);
                    var drawBufferManager = GetDrawBufferManagerByGid(gidAndFlags.Gid);
                    CCTileMapVertAndIndexBuffer drawBuffer = drawBufferManager.GetDrawBufferAtIndex(flattenedIndex);
                    drawBuffer.UpdateQuad(flattenedIndex, ref gidAndFlags, true);
                }
            }
        }
Example #2
0
        void UpdateQuadAt(CCTileMapDrawBufferManager drawBufferManager, int tileCoordX, int tileCoordY, bool updateBuffer = true)
        {
            int flattenedTileIndex    = FlattenedTileIndex(tileCoordX, tileCoordY);
            CCTileGidAndFlags tileGID = TileGIDAndFlagsArray[flattenedTileIndex];

            if (drawBufferManager.TileSetInfo.FirstGid <= tileGID.Gid && drawBufferManager.TileSetInfo.LastGid >= tileGID.Gid || tileGID.Gid == 0)
            {
                CCTileMapVertAndIndexBuffer drawBuffer = drawBufferManager.GetDrawBufferAtIndex(flattenedTileIndex);
                drawBuffer.UpdateQuad(flattenedTileIndex, ref tileGID, updateBuffer);
            }
        }
Example #3
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         while (Buffers.Count > 0)
         {
             CCTileMapVertAndIndexBuffer buffer = Buffers[0];
             Buffers.RemoveAt(0);
             buffer.QuadsVertexBuffer.Dispose();
             buffer.IndexBuffer.Dispose();
             buffer.QuadsVertexBuffer = null;
             buffer.IndexBuffer       = null;
         }
     }
 }
Example #4
0
            void CreateDrawBuffer(int tileCount, int firstTileId)
            {
                int vertsInThisBuffer   = tileCount * NumOfCornersPerQuad;
                int indicesInThisBuffer = tileCount * NumOfVerticesPerQuad;

                var buffer = new CCTileMapVertAndIndexBuffer
                {
                    TileStartIndex    = firstTileId,
                    TileEndIndex      = firstTileId + tileCount - 1,
                    QuadsVertexBuffer = new CCVertexBuffer <CCV3F_C4B_T2F>(vertsInThisBuffer, CCBufferUsage.WriteOnly),
                    IndexBuffer       = new CCIndexBuffer <ushort>(indicesInThisBuffer, BufferUsage.WriteOnly),
                    TileMapLayer      = TileMapLayer,
                    TileSetInfo       = TileSetInfo
                };

                Buffers.Add(buffer);
            }
Example #5
0
            void CreateDrawBuffer(int tileCount, int firstTileId)
            {
                int quadsInThisBuffer    = tileCount * NumOfCornersPerQuad;
                int verticesInThisBuffer = tileCount * NumOfVerticesPerQuad;

                var buffer = new CCTileMapVertAndIndexBuffer
                {
                    TileStartIndex    = firstTileId,
                    TileEndIndex      = firstTileId + tileCount - 1,
                    QuadsVertexBuffer = new CCQuadVertexBuffer(quadsInThisBuffer, CCBufferUsage.WriteOnly),
                    IndexBuffer       = new CCIndexBuffer <short>(verticesInThisBuffer, BufferUsage.WriteOnly)
                };

                buffer.IndexBuffer.Count = verticesInThisBuffer;

                Buffers.Add(buffer);
            }
Example #6
0
            void CreateDrawBuffer(int tileCount, int firstTileId)
            {
                int vertsInThisBuffer = tileCount * NumOfCornersPerQuad;
                int indicesInThisBuffer = tileCount * NumOfVerticesPerQuad;

                var buffer = new CCTileMapVertAndIndexBuffer
                {
                    TileStartIndex = firstTileId,
                    TileEndIndex = firstTileId + tileCount - 1,
                    QuadsVertexBuffer = new CCVertexBuffer<CCV3F_C4B_T2F>(vertsInThisBuffer, CCBufferUsage.WriteOnly),
                    IndexBuffer = new CCIndexBuffer<ushort>(indicesInThisBuffer, BufferUsage.WriteOnly),
                    TileMapLayer = TileMapLayer,
                    TileSetInfo = TileSetInfo
                };

                Buffers.Add(buffer);
            }
Example #7
0
        void UpdateQuadAt(int tileCoordX, int tileCoordY, bool updateBuffer = true)
        {
            int flattenedTileIndex    = FlattenedTileIndex(tileCoordX, tileCoordY);
            CCTileGidAndFlags tileGID = tileGIDAndFlagsArray[flattenedTileIndex];

            CCTileMapVertAndIndexBuffer drawBuffer = drawBufferManager.GetDrawBufferAtIndex(flattenedTileIndex);
            int adjustedTileIndex = flattenedTileIndex - drawBuffer.TileStartIndex;

            if (tileGID.Gid == 0)
            {
                drawBuffer.QuadsVertexBuffer.Data[adjustedTileIndex] = new CCV3F_C4B_T2F_Quad();

                if (updateBuffer)
                {
                    drawBuffer.QuadsVertexBuffer.UpdateBuffer(adjustedTileIndex, 1);
                }
                return;
            }

            float left, right, top, bottom, vertexZ;

            vertexZ = TileVertexZ(tileCoordX, tileCoordY);


            CCSize  tileSize = TileSetInfo.TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios;
            CCSize  texSize  = TileSetInfo.TilesheetSize;
            CCPoint tilePos  = TilePosition(tileCoordX, tileCoordY);

            var quad = drawBuffer.QuadsVertexBuffer.Data[adjustedTileIndex];

            // vertices
            if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0)
            {
                left   = tilePos.X;
                right  = tilePos.X + tileSize.Height;
                bottom = tilePos.Y + tileSize.Width;
                top    = tilePos.Y;
            }
            else
            {
                left   = tilePos.X;
                right  = tilePos.X + tileSize.Width;
                bottom = tilePos.Y + tileSize.Height;
                top    = tilePos.Y;
            }

            float temp;

            if ((tileGID.Flags & CCTileFlags.Vertical) != 0)
            {
                temp   = top;
                top    = bottom;
                bottom = temp;
            }

            if ((tileGID.Flags & CCTileFlags.Horizontal) != 0)
            {
                temp  = left;
                left  = right;
                right = temp;
            }

            if ((tileGID.Flags & CCTileFlags.TileDiagonal) != 0)
            {
                // FIXME: not working correcly
                quad.BottomLeft.Vertices  = new CCVertex3F(left, bottom, vertexZ);
                quad.BottomRight.Vertices = new CCVertex3F(left, top, vertexZ);
                quad.TopLeft.Vertices     = new CCVertex3F(right, bottom, vertexZ);
                quad.TopRight.Vertices    = new CCVertex3F(right, top, vertexZ);
            }
            else
            {
                quad.BottomLeft.Vertices  = new CCVertex3F(left, bottom, vertexZ);
                quad.BottomRight.Vertices = new CCVertex3F(right, bottom, vertexZ);
                quad.TopLeft.Vertices     = new CCVertex3F(left, top, vertexZ);
                quad.TopRight.Vertices    = new CCVertex3F(right, top, vertexZ);
            }

            // texcoords
            CCRect tileTexture = TileSetInfo.TextureRectForGID(tileGID.Gid);

            left   = ((tileTexture.Origin.X) / texSize.Width) + 0.5f / texSize.Width;
            right  = left + ((tileTexture.Size.Width) / texSize.Width) - 1.0f / texSize.Width;
            bottom = ((tileTexture.Origin.Y) / texSize.Height) + 0.5f / texSize.Height;
            top    = bottom + ((tileTexture.Size.Height) / texSize.Height) - 1.0f / texSize.Height;

            quad.BottomLeft.TexCoords  = new CCTex2F(left, bottom);
            quad.BottomRight.TexCoords = new CCTex2F(right, bottom);
            quad.TopLeft.TexCoords     = new CCTex2F(left, top);
            quad.TopRight.TexCoords    = new CCTex2F(right, top);

            quad.BottomLeft.Colors  = CCColor4B.White;
            quad.BottomRight.Colors = CCColor4B.White;
            quad.TopLeft.Colors     = CCColor4B.White;
            quad.TopRight.Colors    = CCColor4B.White;

            drawBuffer.QuadsVertexBuffer.Data[adjustedTileIndex] = quad;

            if (updateBuffer)
            {
                drawBuffer.QuadsVertexBuffer.UpdateBuffer(adjustedTileIndex, 1);
            }
        }