コード例 #1
0
        private void UpdateVoxelChunk(Entity voxelChunk)
        {
            var blockIdLookup     = GetBufferFromEntity <BlockIdentityComponent>(true);
            var blockMatLookup    = GetBufferFromEntity <BlockMaterialIdentityComponent>();
            var blockSubMatLookup = GetBufferFromEntity <BlockSubMaterialIdentityComponent>();


            var blockIdArray     = blockIdLookup[voxelChunk];
            var blockMatArray    = blockMatLookup[voxelChunk];
            var blockSubMatArray = blockSubMatLookup[voxelChunk];


            for (var blockIndex = 0; blockIndex < UnivoxDefine.CubeSize; blockIndex++)
            {
                Profiler.BeginSample("Process Block");
                var blockId = blockIdArray[blockIndex];

                if (GameManager.Registry.Blocks.TryGetValue(blockId, out var blockRef))
                {
                    var blockAccessor = new BlockAccessor(blockIndex).AddData(blockMatArray).AddData(blockSubMatArray);

                    Profiler.BeginSample("Perform Pass");
                    blockRef.RenderPass(blockAccessor);
                    Profiler.EndSample();
//                    Profiler.BeginSample("Dirty");
////                    block.Render.Version.Dirty();
//                    Profiler.EndSample();
                }
                else
                {
                    blockMatArray[blockIndex]    = new ArrayMaterialIdentity(0, -1);
                    blockSubMatArray[blockIndex] = FaceSubMaterial.CreateAll(-1);
                }

                Profiler.EndSample();
            }

//            changed.Clear();
        }
コード例 #2
0
            void InitializeBuffer(Entity entity)
            {
                var        blockActive   = BlockActive[entity];
                const bool defaultActive = false;

                var blockId   = BlockId[entity];
                var defaultId = new BlockIdentity(0, -1);

                var blockShape = BlockShape[entity];
                const global::UniVox.Types.BlockShape defaultShape = global::UniVox.Types.BlockShape.Cube;

                var blockMatId   = BlockMatId[entity];
                var defaultMatId = new ArrayMaterialIdentity(0, -1);

                var blockSubMatId   = BlockSubMatId[entity];
                var defaultSubMatId = FaceSubMaterial.CreateAll(-1);


                var blockCulled = BlockCulled[entity];
                const Directions defaultCulled = DirectionsX.AllFlag;


                for (var i = 0; i < UnivoxDefine.CubeSize; i++)
                {
                    blockActive[i] = defaultActive;

                    blockId[i] = defaultId;

                    blockShape[i] = defaultShape;

                    blockMatId[i] = defaultMatId;

                    blockSubMatId[i] = defaultSubMatId;

                    blockCulled[i] = defaultCulled;
                }
            }
コード例 #3
0
 public RegularBlockRef(ArrayMaterialIdentity materialIdentity, int subMat = 0)
 {
     _material = materialIdentity;
     _subMat   = FaceSubMaterial.CreateAll(subMat);
 }
コード例 #4
0
        void InitializeBuffer(Entity entity)
        {
            var buffers = CreateBuffers();

            var        blockActive   = buffers._blockActiveAccessor[entity];
            const bool defaultActive = false;

            var blockId   = buffers._blockIdAccessor[entity];
            var defaultId = new BlockIdentity(0, -1);

            var blockShape = buffers._blockShapeAccessor[entity];
            const global::UniVox.Types.BlockShape defaultShape = global::UniVox.Types.BlockShape.Cube;

            var blockMatId   = buffers._blockMatIdAccessor[entity];
            var defaultMatId = new ArrayMaterialIdentity(0, -1);

            var blockSubMatId   = buffers._blockSubMatIdAccessor[entity];
            var defaultSubMatId = FaceSubMaterial.CreateAll(-1);


            var blockCulled = buffers._blockCulledAccessor[entity];
            const Directions defaultCulled = DirectionsX.AllFlag;


            for (var i = 0; i < UnivoxDefine.CubeSize; i++)
            {
                blockActive[i] = defaultActive;

                blockId[i] = defaultId;

                blockShape[i] = defaultShape;

                blockMatId[i] = defaultMatId;

                blockSubMatId[i] = defaultSubMatId;

                blockCulled[i] = defaultCulled;
            }

//        void CreateChunk(VoxelWorld world, int3 chunkPos)
//        {
//            if (world.ContainsKey(chunkPos))
//            {
//                Debug.Log($"Chunk {chunkPos} already exists!");
//                return;
//            }
//
//            var blockReg = GameManager.Registry.Blocks;
//
//
//            if (!blockReg.TryGetIdentity(BaseGameMod.GrassBlock, out var grass))
//                throw new AssetNotFoundException(BaseGameMod.GrassBlock.ToString());
//            if (!blockReg.TryGetIdentity(BaseGameMod.DirtBlock, out var dirt))
//                throw new AssetNotFoundException(BaseGameMod.DirtBlock.ToString());
//            if (!blockReg.TryGetIdentity(BaseGameMod.StoneBlock, out var stone))
//                throw new AssetNotFoundException(BaseGameMod.StoneBlock.ToString());
//            if (!blockReg.TryGetIdentity(BaseGameMod.SandBlock, out var sand))
//                throw new AssetNotFoundException(BaseGameMod.SandBlock.ToString());
//
//            var em = world.EntityManager;
//            var entityArchetype = world.EntityManager.CreateArchetype(
//                typeof(ChunkIdComponent),
//                typeof(BlockActiveComponent), typeof(BlockIdentityComponent),
//                typeof(BlockShapeComponent), typeof(BlockMaterialIdentityComponent),
//                typeof(BlockSubMaterialIdentityComponent), typeof(BlockCulledFacesComponent)
//            );
//
//            var entity = world.GetOrCreate(chunkPos, entityArchetype);
//            EnforceChunkSize(em, entity);
//
//            world.EntityManager.SetComponentData(entity,
//                new ChunkIdComponent() {Value = new UniversalChunkId(0, chunkPos)});
//
//
//            var activeArray = em.GetBuffer<BlockActiveComponent>(entity);
//            var blockIdentities = em.GetBuffer<BlockIdentityComponent>(entity);
//            var blockMaterials = em.GetBuffer<BlockMaterialIdentityComponent>(entity);
//            var blockShapes = em.GetBuffer<BlockShapeComponent>(entity);
//            var culledFaces = em.GetBuffer<BlockCulledFacesComponent>(entity);
//
//            var invalidMaterial = new ArrayMaterialIdentity(0, -1);
//
//
//            for (var i = 0; i < UnivoxDefine.CubeSize; i++)
//            {
//                var pos = UnivoxUtil.GetPosition3(i);
//
//                var xTop = (pos.x == UnivoxDefine.AxisSize - 1);
//                var yTop = (pos.y == UnivoxDefine.AxisSize - 1);
//                var zTop = (pos.z == UnivoxDefine.AxisSize - 1);
//
//                var xBot = (pos.x == 0);
//                var yBot = (pos.y == 0);
//                var zBot = (pos.z == 0);
//
//                activeArray[i] = true;
//
//
//                blockMaterials[i] = invalidMaterial;
//
//                if (!yTop)
//                {
//                    if (xTop && !zTop)
//                    {
//                        blockIdentities[i] = stone;
//                    }
//                    else if (!xTop && zTop)
//                    {
//                        blockIdentities[i] = sand;
//                    }
//                    else
//                    {
//                        blockIdentities[i] = dirt;
//                    }
//                }
//
//                else
//                    blockIdentities[i] = grass;
//
//
//                blockShapes[i] = BlockShape.Cube;
//
//                if (xTop || yTop || zTop || xBot || yBot || zBot)
//                {
//                    var revealed = DirectionsX.NoneFlag;
//
//                    if (xTop)
//                        revealed |= Directions.Right;
//                    else if (xBot)
//                        revealed |= Directions.Left;
//
//
//                    if (yTop)
//                        revealed |= Directions.Up;
//                    else if (yBot)
//                        revealed |= Directions.Down;
//
//                    if (zTop)
//                        revealed |= Directions.Forward;
//                    else if (zBot)
//                        revealed |= Directions.Backward;
//
//                    culledFaces[i] = ~revealed;
//                }
//                else
//                    culledFaces[i] = DirectionsX.AllFlag;
//            }
//        }
        }