コード例 #1
0
ファイル: Voxel.cs プロジェクト: NakedFury/dwarfcorp
        public bool GetNeighborBySuccessor(Vector3 succ, ref Voxel neighbor, bool requireQuickCompare = true)
        {
            Debug.Assert(neighbor != null, "Null reference passed");
            Debug.Assert(_chunk != null, "Voxel has no valid chunk reference");

            Vector3 newPos         = gridpos + succ;
            Point3  chunkSuccessor = Point3.Zero;
            bool    useSuccessor   = false;

            if (newPos.X >= _chunk.SizeX)
            {
                chunkSuccessor.X = 1;
                newPos.X         = 0;
                useSuccessor     = true;
            }
            else if (newPos.X < 0)
            {
                chunkSuccessor.X = -1;
                newPos.X         = _chunk.SizeX - 1;
                useSuccessor     = true;
            }

            if (newPos.Y >= _chunk.SizeY)
            {
                chunkSuccessor.Y = 1;
                newPos.Y         = 0;
                useSuccessor     = true;
            }
            else if (newPos.Y < 0)
            {
                chunkSuccessor.Y = -1;
                newPos.Y         = _chunk.SizeY - 1;
                useSuccessor     = true;
            }

            if (newPos.Z >= _chunk.SizeZ)
            {
                chunkSuccessor.Z = 1;
                newPos.Z         = 0;
                useSuccessor     = true;
            }
            else if (newPos.Z < 0)
            {
                chunkSuccessor.Z = -1;
                newPos.Z         = _chunk.SizeZ - 1;
                useSuccessor     = true;
            }

            VoxelChunk useChunk;

            if (useSuccessor)
            {
                useChunk = _chunk.EuclidianNeighbors[VoxelChunk.SuccessorToEuclidianLookupKey(chunkSuccessor)];
                if (useChunk == null)
                {
                    return(false);
                }
            }
            else
            {
                useChunk = _chunk;
            }
            neighbor.ChangeVoxel(useChunk, newPos, requireQuickCompare);
            return(true);
        }