コード例 #1
0
ファイル: Automaton.cs プロジェクト: Jojendersie/Voxelseeds
        public Automaton(int sizeX, int sizeY, int sizeZ, LevelType lvlType, int seed, float heightoffset)
        {
            _map = new Map(sizeX, sizeY, sizeZ, lvlType, seed, heightoffset);
            _livingVoxels = new Dictionary<Int32,LivingVoxel>();
            _simTask = null;

            _deleteList = new List<Voxel>();
            _insertionList = new List<Voxel>();
        }
コード例 #2
0
        /// <summary>
        /// setups settings for a new map and clears all instance buffers
        /// </summary>
        public void Reset(Map map, Vector3 lightDirection)
        {
            // reset lists
            for (int i = 0; i < _voxelTypeRenderingData.Length; ++i)
                _voxelTypeRenderingData[i].InstanceDataRAM.Clear();

            // add current world
            for (int posCode = 0; posCode < map.SizeX * map.SizeY * map.SizeZ; ++posCode)
            {
                var voxel = map.Get(posCode);
                if (voxel != VoxelType.EMPTY)
                {
                    // occluded?
                    var pos = map.DecodePosition(posCode);
                    if (pos.X > 0 && pos.X < map.SizeX-1 &&
                        pos.Y > 0 && pos.Y < map.SizeY-1 &&
                        pos.Z > 0 && pos.Z < map.SizeZ-1)
                    {
                        if (map.Get(pos + Int3.UnitX) != VoxelType.EMPTY &&
                            map.Get(pos + Int3.UnitY) != VoxelType.EMPTY &&
                            map.Get(pos + Int3.UnitZ) != VoxelType.EMPTY &&
                            map.Get(pos - Int3.UnitX) != VoxelType.EMPTY &&
                            map.Get(pos - Int3.UnitY) != VoxelType.EMPTY &&
                            map.Get(pos - Int3.UnitZ) != VoxelType.EMPTY)
                        {
                            continue;
                        }
                    }

                    // add
                    if(_voxelTypeRenderingData[GetRenderingDataIndex(voxel)].InstanceDataRAM.Count < TypeInformation.GetMaxNumberOfVoxels(voxel)-1)
                        _voxelTypeRenderingData[GetRenderingDataIndex(voxel)].InstanceDataRAM.Add(posCode);
                }
            }

            foreach(var data in _voxelTypeRenderingData)
                data.UpdateGPUInstanceBuffer();

            // set vertex scaling
            var globalMapInfoCB = _voxelEffect.ConstantBuffers["GlobalMapInfo"];
            globalMapInfoCB.Parameters["WorldSize"].SetValue(new Int3(map.SizeX, map.SizeY, map.SizeZ));
            lightDirection.Normalize();
            globalMapInfoCB.Parameters["LightDirection"].SetValue(-lightDirection);
            globalMapInfoCB.Parameters["Translation"].SetValue(- new Vector3(map.SizeX, 0.0f, map.SizeZ) * 0.5f);
            globalMapInfoCB.IsDirty = true;
        }