Exemplo n.º 1
0
        protected override void OnProcessChunk(Chunk chunk)
        {
            Profiler.BeginSample("ProcessChunk");

            int tx = clipmap.TransformX(chunk.Pos.x / Env.CHUNK_SIZE);
            int ty = clipmap.TransformY(chunk.Pos.y / Env.CHUNK_SIZE);
            int tz = clipmap.TransformZ(chunk.Pos.z / Env.CHUNK_SIZE);

            // Chunk is too far away. Remove it
            if (!clipmap.IsInsideBounds_Transformed(tx, ty, tz))
            {
                chunk.RequestRemoval();
            }
            else
            {
                // Dummy collider example - create a collider for chunks directly surrounding the viewer
                int xd = Helpers.Abs((viewerPos.x - chunk.Pos.x) / Env.CHUNK_SIZE);
                int zd = Helpers.Abs((viewerPos.z - chunk.Pos.z) / Env.CHUNK_SIZE);
                chunk.NeedsColliderGeometry = xd <= 1 && zd <= 1;

                if (!useFrustumCulling)
                {
                    ClipmapItem item = clipmap.Get_Transformed(tx, ty, tz);

                    // Chunk is in visibilty range. Full update with geometry generation is possible
                    if (item.isInVisibleRange)
                    {
                        //chunk.LOD = item.LOD;
                        chunk.PossiblyVisible     = true;
                        chunk.NeedsRenderGeometry = true;
                    }
                    // Chunk is in cached range. Full update except for geometry generation
                    else
                    {
                        //chunk.LOD = item.LOD;
                        chunk.PossiblyVisible     = true;
                        chunk.NeedsRenderGeometry = false;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static Vector3Int[] ChunkPositions(int chunkLoadRadius)
        {
            chunkLoads.Clear();

            for (int z = -chunkLoadRadius; z <= chunkLoadRadius; z++)
            {
                for (int x = -chunkLoadRadius; x <= chunkLoadRadius; x++)
                {
                    chunkLoads.Add(new Vector3Int(x, 0, z));
                }
            }

            // Sort 2D vectors by closeness to the center
            return(chunkLoads
                   .Where(pos => CheckXZ(pos.x, pos.z, chunkLoadRadius))
                   // Smallest magnitude vectors first
                   .OrderBy(pos => Helpers.Abs(pos.x) + Helpers.Abs(pos.z))
                   // Make sure not to process e.g (-10,0) before (5,5)
                   .ThenBy(pos => Helpers.Abs(pos.x))
                   .ThenBy(pos => Helpers.Abs(pos.z))
                   .ToArray());
        }
Exemplo n.º 3
0
 public static bool CheckY(int y, int dist)
 {
     return(Helpers.Abs(y) <= dist); // square
 }