Exemple #1
0
    public override void OnReadOnlyBackgroundThread(Game game_, float dt)
    {
        game = game_;

        chunksize      = Game.chunksize;
        mapsizexchunks = game.map.MapSizeX / chunksize;
        mapsizeychunks = game.map.MapSizeY / chunksize;
        mapsizezchunks = game.map.MapSizeZ / chunksize;

        int px = game.platform.FloatToInt(game.player.position.x) / chunksize;
        int py = game.platform.FloatToInt(game.player.position.z) / chunksize;
        int pz = game.platform.FloatToInt(game.player.position.y) / chunksize;

        int chunksxy = this.mapAreaSize() / chunksize / 2;
        int chunksz  = this.mapAreaSizeZ() / chunksize / 2;

        int startx = px - chunksxy;
        int endx   = px + chunksxy;
        int starty = py - chunksxy;
        int endy   = py + chunksxy;
        int startz = pz - chunksz;
        int endz   = pz + chunksz;

        if (startx < 0)
        {
            startx = 0;
        }
        if (starty < 0)
        {
            starty = 0;
        }
        if (startz < 0)
        {
            startz = 0;
        }
        if (endx >= mapsizexchunks)
        {
            endx = mapsizexchunks - 1;
        }
        if (endy >= mapsizeychunks)
        {
            endy = mapsizeychunks - 1;
        }
        if (endz >= mapsizezchunks)
        {
            endz = mapsizezchunks - 1;
        }

        int mapsizexchunks_ = mapsizexchunks;
        int mapsizeychunks_ = mapsizeychunks;
        int mapsizezchunks_ = mapsizezchunks;

        int count;

        if (game.platform.IsFastSystem())
        {
            count = 1000;
        }
        else
        {
            count = 250;
        }

        for (int i = 0; i < count; i++)
        {
            unloadIterationXy++;
            if (unloadIterationXy >= mapsizexchunks_ * mapsizeychunks_ * mapsizezchunks_)
            {
                unloadIterationXy = 0;
            }
            MapUtilCi.PosInt(unloadIterationXy, mapsizexchunks_, mapsizeychunks_, unloadxyztemp);
            int  x        = unloadxyztemp.X;
            int  y        = unloadxyztemp.Y;
            int  z        = unloadxyztemp.Z;
            int  pos      = MapUtilCi.Index3d(x, y, z, mapsizexchunks_, mapsizeychunks_);
            bool unloaded = false;

            Chunk c = game.map.chunks[pos];
            if (c == null ||
                c.rendered == null ||
                c.rendered.ids == null)
            {
                continue;
            }
            if (x < startx || y < starty || z < startz ||
                x > endx || y > endy || z > endz)
            {
                int unloadChunkPos = pos;

                UnloadRendererChunksCommit commit = new UnloadRendererChunksCommit();
                commit.game           = game;
                commit.unloadChunkPos = unloadChunkPos;
                game.QueueActionCommit(commit);
            }
            unloaded = true;
            if (unloaded)
            {
                break;
            }
        }
    }
    public override void OnReadOnlyBackgroundThread(Game game_, float dt)
    {
        game = game_;

        chunksize = Game.chunksize;
        invertedChunk = 1.0f/chunksize;
        mapsizexchunks = game.platform.FloatToInt(game.map.MapSizeX * invertedChunk);
        mapsizeychunks = game.platform.FloatToInt(game.map.MapSizeY * invertedChunk);
        mapsizezchunks = game.platform.FloatToInt(game.map.MapSizeZ * invertedChunk);

        int px = game.platform.FloatToInt(game.player.position.x*invertedChunk);
        int py = game.platform.FloatToInt(game.player.position.z*invertedChunk);
        int pz = game.platform.FloatToInt(game.player.position.y*invertedChunk);

        int chunksxy = game.platform.FloatToInt(this.mapAreaSize() * invertedChunk * 0.5f);
        int chunksz = game.platform.FloatToInt(this.mapAreaSizeZ() * invertedChunk * 0.5f);

        int startx = px - chunksxy;
        int endx = px + chunksxy;
        int starty = py - chunksxy;
        int endy = py + chunksxy;
        int startz = pz - chunksz;
        int endz = pz + chunksz;

        if (startx < 0) { startx = 0; }
        if (starty < 0) { starty = 0; }
        if (startz < 0) { startz = 0; }
        if (endx >= mapsizexchunks) { endx = mapsizexchunks - 1; }
        if (endy >= mapsizeychunks) { endy = mapsizeychunks - 1; }
        if (endz >= mapsizezchunks) { endz = mapsizezchunks - 1; }

        int mapsizexchunks_ = mapsizexchunks;
        int mapsizeychunks_ = mapsizeychunks;
        int mapsizezchunks_ = mapsizezchunks;
        int sizeChunks =  mapsizexchunks_ * mapsizeychunks_ * mapsizezchunks_;
        int count;
        if (game.platform.IsFastSystem())
        {
            count = 1000;
        }
        else
        {
            count = 250;
        }

        for (int i = 0; i < count; i++)
        {
            unloadIterationXy++;
            if (unloadIterationXy >=sizeChunks)
            {
                unloadIterationXy = 0;
            }
            MapUtilCi.PosInt(unloadIterationXy, mapsizexchunks_, mapsizeychunks_, unloadxyztemp);
            int x = unloadxyztemp.X;
            int y = unloadxyztemp.Y;
            int z = unloadxyztemp.Z;
            int pos = MapUtilCi.Index3d(x, y, z, mapsizexchunks_, mapsizeychunks_);
            bool unloaded = false;

            Chunk c = game.map.chunks[pos];
            if (c == null
                || c.rendered == null
                || c.rendered.ids == null)
            {
                continue;
            }
            if (x < startx || y < starty || z < startz
                || x > endx || y > endy || z > endz)
            {
                int unloadChunkPos = pos;

                UnloadRendererChunksCommit commit = new UnloadRendererChunksCommit();
                commit.game = game;
                commit.unloadChunkPos = unloadChunkPos;
                game.QueueActionCommit(commit);
            }
            unloaded = true;
            if (unloaded)
            {
                break;
            }
        }
    }