public VoxelEditManager(VoxelWorld <TIndexer> world, int queueSize)
 {
     this.world = world;
     QueueSize  = queueSize;
     edits      = new List <VoxelEdit <TIndexer> >();
     undone     = new List <VoxelEdit <TIndexer> >();
 }
        /// <summary>
        /// Merges multiple voxel edits into one edit.
        /// The ownership of the chunk snapshots is transferred entirely to the new merged voxel edit!
        /// </summary>
        /// <param name="world"></param>
        /// <param name="edits"></param>
        public VoxelEdit(VoxelWorld <TIndexer> world, List <VoxelEdit <TIndexer> > edits)
        {
            this.world = world;

            snapshots = new List <VoxelChunk <TIndexer> >();
            foreach (var edit in edits)
            {
                snapshots.AddRange(edit.snapshots);
            }
        }
예제 #3
0
        public VoxelChunk(VoxelWorld <TIndexer> world, ChunkPos pos, int chunkSize, IndexerFactory <TIndexer> indexerFactory)
        {
            this.world          = world;
            this.chunkSize      = chunkSize;
            this.chunkSizeSq    = chunkSize * chunkSize;
            this.Pos            = pos;
            this.indexerFactory = indexerFactory;

            voxels = new NativeArray3D <Voxel, TIndexer>(indexerFactory(chunkSize + 1, chunkSize + 1, chunkSize + 1), chunkSize + 1, chunkSize + 1, chunkSize + 1, Allocator.Persistent);
            //voxels = new Voxel[chunkSize * chunkSize * chunkSize];
            //voxels = new NativeArray<Voxel>(chunkSize * chunkSize * chunkSize, Allocator.Persistent); //TODO Dispose
        }
        /// <summary>
        /// Restores the voxels to before the edit was applied
        /// </summary>
        /// <param name="edits">Consumes the voxel edit. Can be null if no voxel edits should be stored</param>
        public void Restore(VoxelWorld <TIndexer> .VoxelEditConsumer <TIndexer> edits)
        {
            if (edits != null)
            {
                foreach (VoxelChunk <TIndexer> snapshot in snapshots)
                {
                    //TODO Queue all jobs at once
                    world.ApplyGrid(snapshot.Pos.x * snapshot.ChunkSize, snapshot.Pos.y * snapshot.ChunkSize, snapshot.Pos.z * snapshot.ChunkSize, snapshot.Voxels, false, true, edits, false);
                }
            }

            foreach (VoxelChunk <TIndexer> snapshot in snapshots)
            {
                //TODO Queue all jobs at once
                world.ApplyGrid(snapshot.Pos.x * snapshot.ChunkSize, snapshot.Pos.y * snapshot.ChunkSize, snapshot.Pos.z * snapshot.ChunkSize, snapshot.Voxels, false, true, null, true, true);
            }
        }
예제 #5
0
 public void Start()
 {
     brush = GetComponent <CustomBrushContainer>();
     world = new VoxelWorld <MortonIndexer>(parentWorld.ChunkSize, parentWorld.CMSProperties, transform, parentWorld.IndexerFactory);
 }
 public VoxelEdit(VoxelWorld <TIndexer> world, List <VoxelChunk <TIndexer> > snapshots)
 {
     this.world     = world;
     this.snapshots = snapshots;
 }