/// <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; }
/// <summary> /// Add to map and to living list. Does nothing if tries to set outside. /// </summary> private void InsertVoxel(Int32 positionCode, VoxelType type, int generation, bool living, int resources, int ticks, Direction from) { var pos = _map.DecodePosition(positionCode); if (_map.IsInside(pos.X, pos.Y, pos.Z)) { if (_map.Get(positionCode) != VoxelType.EMPTY) { RemoveVoxel(positionCode); } _map.Set(positionCode, type, living); if (type != VoxelType.EMPTY) { // Insert to instance data only if visible if (!_map.IsOccluded(positionCode)) { _insertionList.Add(new Voxel(positionCode, type)); } RemoveOccludedNeighbours(positionCode); } if (living) { Debug.Assert(!_livingVoxels.ContainsKey(positionCode)); _livingVoxels.Add(positionCode, new LivingVoxel(pos.X, pos.Y, pos.Z, generation, resources, ticks, from)); if (TypeInformation.IsBiomass(type)) { ++_numLivingBiomass; } else if (TypeInformation.IsParasite(type)) { ++_numLivingParasites; } } } }
/// <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; }