Ejemplo n.º 1
0
    public void UpdateTerrain()
    {
        if (!terrainRendererStarted)
        {
            //Start() not called yet.
            return;
        }

        if (!(game.lastplacedblockX == -1 && game.lastplacedblockY == -1 && game.lastplacedblockZ == -1))
        {
            HashSetVector3IntRef ChunksToRedraw = new HashSetVector3IntRef();
            Vector3IntRef[]      around         = BlocksAround7(Vector3IntRef.Create(game.lastplacedblockX, game.lastplacedblockY, game.lastplacedblockZ));
            for (int i = 0; i < 7; i++)
            {
                Vector3IntRef a = around[i];
                ChunksToRedraw.Set(Vector3IntRef.Create(a.X / chunksize, a.Y / chunksize, a.Z / chunksize));
            }
            for (int i = 0; i < ChunksToRedraw.max; i++)
            {
                if (ChunksToRedraw.values[i] == null)
                {
                    break;
                }
                int[] c  = new int[3];
                int   xx = ChunksToRedraw.values[i].X;
                int   yy = ChunksToRedraw.values[i].Y;
                int   zz = ChunksToRedraw.values[i].Z;
                if (xx >= 0 && yy >= 0 && zz >= 0 &&
                    xx < game.map.MapSizeX / chunksize && yy < game.map.MapSizeY / chunksize && zz < game.map.MapSizeZ / chunksize)
                {
                    Chunk chunk = game.map.chunks[Index3d(xx, yy, zz, mapsizexchunks(), mapsizeychunks())];
                    if (chunk == null || chunk.rendered == null)
                    {
                        continue;
                    }
                    if (chunk.rendered.dirty)
                    {
                        RedrawChunk(xx, yy, zz);
                    }
                }
            }
            game.lastplacedblockX = -1;
            game.lastplacedblockY = -1;
            game.lastplacedblockZ = -1;
        }
        int updated = 0;

        for (; ;)
        {
            NearestDirty(tempnearestpos);
            if (tempnearestpos[0] == -1 && tempnearestpos[1] == -1 && tempnearestpos[2] == -1)
            {
                break;
            }
            RedrawChunk(tempnearestpos[0], tempnearestpos[1], tempnearestpos[2]);
            //if (updated++ >= 1)
            {
                break;
            }
            //if (framestopwatch.ElapsedMilliseconds > 5)
            //{
            //    break;
            //}
        }
    }
Ejemplo n.º 2
0
    public void UpdateTerrain()
    {
        if (!terrainRendererStarted)
        {
            //Start() not called yet.
            return;
        }

#if CITO
        if (!(game.lastplacedblockX == -1 && game.lastplacedblockY == -1 && game.lastplacedblockZ == -1))
        {
            HashSetVector3IntRef ChunksToRedraw = new HashSetVector3IntRef();
            Vector3IntRef[] around = BlocksAround7(Vector3IntRef.Create(game.lastplacedblockX, game.lastplacedblockY, game.lastplacedblockZ));
            for (int i = 0; i < 7; i++)
            {
                Vector3IntRef a = around[i];
                ChunksToRedraw.Set(Vector3IntRef.Create(a.X/chunksize, a.Y/chunksize, a.Z/chunksize));
            }
            int mapSizeX = game.map.MapSizeX/chunksize;
            int mapSizeY = game.map.MapSizeY/chunksize;
            int mapSizeZ = game.map.MapSizeZ/chunksize;

#else
        unchecked
        {

        if (!(game.lastplacedblockX == -1 && game.lastplacedblockY == -1 && game.lastplacedblockZ == -1))
        {
            HashSetVector3IntRef ChunksToRedraw = new HashSetVector3IntRef();
            Vector3IntRef[] around = BlocksAround7(Vector3IntRef.Create(game.lastplacedblockX, game.lastplacedblockY, game.lastplacedblockZ));
            for (int i = 0; i < 7; i++)
            {
                Vector3IntRef a = around[i];
                ChunksToRedraw.Set(Vector3IntRef.Create(invertChunk( a.X), invertChunk(a.Y), invertChunk(a.Z)));
            }
            int mapSizeX = invertChunk(game.map.MapSizeX);
            int mapSizeY = invertChunk(game.map.MapSizeY);
            int mapSizeZ = invertChunk(game.map.MapSizeZ);
#endif
            int mapsizexchunks_ = mapsizexchunks();
                          int mapsizeychunks_ = mapsizeychunks();

            for (int i = 0; i < ChunksToRedraw.max; i++)
            {
            Vector3IntRef chunk3 = ChunksToRedraw.values[i];
                if (chunk3 == null)
                {
                    break;
                }
                int[] c = new int[3];

                int xx = chunk3.X;
                int yy = chunk3.Y;
                int zz = chunk3.Z;
                if (xx >= 0 && yy >= 0 && zz >= 0 && xx < mapSizeX && yy < mapSizeY  && zz < mapSizeZ)
                {
                    Chunk chunk = game.map.chunks[Index3d(xx, yy, zz, mapsizexchunks_, mapsizeychunks_)];
                    if (chunk == null || chunk.rendered == null)
                    {
                        continue;
                    }
                    if (chunk.rendered.dirty)
                    {
                        RedrawChunk(xx, yy, zz);
                    }
                }
            }
            game.lastplacedblockX = -1;
            game.lastplacedblockY = -1;
            game.lastplacedblockZ = -1;
        }
        int updated = 0;
        for (; ; )
        {
            NearestDirty(tempnearestpos);
            if (tempnearestpos[0] == -1 && tempnearestpos[1] == -1 && tempnearestpos[2] == -1)
            {
                break;
            }
            RedrawChunk(tempnearestpos[0], tempnearestpos[1], tempnearestpos[2]);
            //if (updated++ >= 1)
            {
                break;
            }
            //if (framestopwatch.ElapsedMilliseconds > 5)
            //{
            //    break;
            //}
        }
#if !CITO
        }
#endif
    }