public MapRenderer(Game game)
 {
     this.game = game;
     gfx       = game.Graphics;
     updater   = new ChunkUpdater(game, this);
     SetMeshBuilder(DefaultMeshBuilder());
 }
Beispiel #2
0
        public static void UpdateSortOrder(Game game, ChunkUpdater updater)
        {
            Vector3 cameraPos = game.CurrentCameraPos;
            //int adjCamX, adjCamZ;
            //game.Camera.GetCamChunk(out adjCamX, out adjCamZ);
            //cameraPos.X -= adjCamX;
            //cameraPos.Z -= adjCamZ;
            Vector3I newChunkPos = Vector3I.Floor(cameraPos);

            newChunkPos.X = (newChunkPos.X & ~0x0F) + 8;
            newChunkPos.Y = (newChunkPos.Y & ~0x0F) + 8;
            newChunkPos.Z = (newChunkPos.Z & ~0x0F) + 8;
            if (newChunkPos == updater.chunkPos)
            {
                return;
            }

            ChunkInfo[] chunks    = game.MapRenderer.chunks;
            int[]       distances = updater.distances;
            Vector3I    pPos      = newChunkPos;

            updater.chunkPos = pPos;

            for (int i = 0; i < chunks.Length; i++)
            {
                ChunkInfo info = chunks[i];

                // Calculate distance to chunk centre
                int dx = info.CentreX - pPos.X, dy = info.CentreY - pPos.Y, dz = info.CentreZ - pPos.Z;
                distances[i] = dx * dx + dy * dy + dz * dz;

                // Can work out distance to chunk faces as offset from distance to chunk centre on each axis.
                int dXMin = dx - 8, dXMax = dx + 8;
                int dYMin = dy - 8, dYMax = dy + 8;
                int dZMin = dz - 8, dZMax = dz + 8;

                // Back face culling: make sure that the chunk is definitely entirely back facing.
                info.DrawLeft   = !(dXMin <= 0 && dXMax <= 0);
                info.DrawRight  = !(dXMin >= 0 && dXMax >= 0);
                info.DrawFront  = !(dZMin <= 0 && dZMax <= 0);
                info.DrawBack   = !(dZMin >= 0 && dZMax >= 0);
                info.DrawBottom = !(dYMin <= 0 && dYMax <= 0);
                info.DrawTop    = !(dYMin >= 0 && dYMax >= 0);
            }

            // NOTE: Over 5x faster compared to normal comparison of IComparer<ChunkInfo>.Compare
            if (distances.Length > 1)
            {
                QuickSort(distances, chunks, 0, chunks.Length - 1);
            }
            updater.ResetUsedFlags();
            //SimpleOcclusionCulling();
        }
Beispiel #3
0
        public static void UpdateSortOrder(Game game, ChunkUpdater updater)
        {
            Vector3  cameraPos   = game.CurrentCameraPos;
            Vector3I newChunkPos = Vector3I.Floor(cameraPos);

            newChunkPos.X = (newChunkPos.X & ~0x0F) + 8;
            newChunkPos.Y = (newChunkPos.Y & ~0x0F) + 8;
            newChunkPos.Z = (newChunkPos.Z & ~0x0F) + 8;
            if (newChunkPos == updater.chunkPos)
            {
                return;
            }

            ChunkInfo[] chunks    = game.MapRenderer.chunks;
            int[]       distances = updater.distances;
            updater.chunkPos = newChunkPos;

            for (int i = 0; i < distances.Length; i++)
            {
                ChunkInfo info = chunks[i];
                distances[i] = Utils.DistanceSquared(info.CentreX, info.CentreY, info.CentreZ,
                                                     updater.chunkPos.X, updater.chunkPos.Y, updater.chunkPos.Z);
            }

            // NOTE: Over 5x faster compared to normal comparison of IComparer<ChunkInfo>.Compare
            if (distances.Length > 1)
            {
                QuickSort(distances, chunks, 0, chunks.Length - 1);
            }

            Vector3I pPos = newChunkPos;

            for (int i = 0; i < chunks.Length; i++)
            {
                ChunkInfo info = chunks[i];
                int       dX1 = (info.CentreX - 8) - pPos.X, dX2 = (info.CentreX + 8) - pPos.X;
                int       dY1 = (info.CentreY - 8) - pPos.Y, dY2 = (info.CentreY + 8) - pPos.Y;
                int       dZ1 = (info.CentreZ - 8) - pPos.Z, dZ2 = (info.CentreZ + 8) - pPos.Z;

                // Back face culling: make sure that the chunk is definitely entirely back facing.
                info.DrawLeft   = !(dX1 <= 0 && dX2 <= 0);
                info.DrawRight  = !(dX1 >= 0 && dX2 >= 0);
                info.DrawFront  = !(dZ1 <= 0 && dZ2 <= 0);
                info.DrawBack   = !(dZ1 >= 0 && dZ2 >= 0);
                info.DrawBottom = !(dY1 <= 0 && dY2 <= 0);
                info.DrawTop    = !(dY1 >= 0 && dY2 >= 0);
            }
            updater.RecalcBooleans(false);
            //SimpleOcclusionCulling();
        }
        public static void UpdateSortOrder( Game game, ChunkUpdater updater )
        {
            Vector3 cameraPos = game.CurrentCameraPos;
            Vector3I newChunkPos = Vector3I.Floor( cameraPos );
            newChunkPos.X = (newChunkPos.X & ~0x0F) + 8;
            newChunkPos.Y = (newChunkPos.Y & ~0x0F) + 8;
            newChunkPos.Z = (newChunkPos.Z & ~0x0F) + 8;
            if( newChunkPos == updater.chunkPos ) return;

            ChunkInfo[] chunks = game.MapRenderer.chunks;
            int[] distances = updater.distances;
            updater.chunkPos = newChunkPos;

            for( int i = 0; i < distances.Length; i++ ) {
                ChunkInfo info = chunks[i];
                distances[i] = Utils.DistanceSquared( info.CentreX, info.CentreY, info.CentreZ,
                                                     updater.chunkPos.X, updater.chunkPos.Y, updater.chunkPos.Z );
            }

            // NOTE: Over 5x faster compared to normal comparison of IComparer<ChunkInfo>.Compare
            if( distances.Length > 1 )
                QuickSort( distances, chunks, 0, chunks.Length - 1 );

            Vector3I pPos = newChunkPos;
            for( int i = 0; i < chunks.Length; i++ ) {
                ChunkInfo info = chunks[i];
                int dX1 = (info.CentreX - 8) - pPos.X, dX2 = (info.CentreX + 8) - pPos.X;
                int dY1 = (info.CentreY - 8) - pPos.Y, dY2 = (info.CentreY + 8) - pPos.Y;
                int dZ1 = (info.CentreZ - 8) - pPos.Z, dZ2 = (info.CentreZ + 8) - pPos.Z;

                // Back face culling: make sure that the chunk is definitely entirely back facing.
                info.DrawLeft = !(dX1 <= 0 && dX2 <= 0);
                info.DrawRight = !(dX1 >= 0 && dX2 >= 0);
                info.DrawFront = !(dZ1 <= 0 && dZ2 <= 0);
                info.DrawBack = !(dZ1 >= 0 && dZ2 >= 0);
                info.DrawBottom = !(dY1 <= 0 && dY2 <= 0);
                info.DrawTop = !(dY1 >= 0 && dY2 >= 0);
            }
            updater.RecalcBooleans( false );
            //SimpleOcclusionCulling();
        }
Beispiel #5
0
 public MapRenderer( Game game )
 {
     this.game = game;
     api = game.Graphics;
     updater = new ChunkUpdater( game, this );
 }
 public MapRenderer(Game game)
 {
     this.game = game;
     api       = game.Graphics;
     updater   = new ChunkUpdater(game, this);
 }