private void GetDataForChunkWithNeighbours(int2 coords, ComputeMeshData data) { var multimap = data.MapWithNeighbours; for (var x = 0; x < 3; x++) { for (var y = 0; y < 3; y++) { var offset = (x + y * 3) * GeometryConsts.VOXELS_PER_CHUNK; var map = WorldModel.GetMapByChunkCoords(coords + new int2(x - 1, y - 1)); multimap.Slice(offset, GeometryConsts.VOXELS_PER_CHUNK).CopyFrom(map); } } }
private void GetLightsForChunkWithNeighbours(int2 coords, ComputeMeshData data) { var multimap = data.LightMapWithNeighbours; for (var x = 0; x < 3; x++) { for (var y = 0; y < 3; y++) { var offset = (x + y * 3) * GeometryConsts.VOXELS_PER_CHUNK; var id = _dataIdByCoords[coords + new int2(x - 1, y - 1)]; var map = _computeData[id].LightLevelMap; multimap.Slice(offset, GeometryConsts.VOXELS_PER_CHUNK).CopyFrom(map); } } }
private int GetDataFromPool(int2 coords) { //id is datacount -> put data on the end of all used data var dataId = _dataCount; ComputeMeshData computeMeshData = _computeData[dataId]; computeMeshData.SetCoords(coords); _dataIdByCoords[coords] = dataId; //move border of data so it contains newly added data _dataCount++; return(dataId); }
//TODO: batch meshes - one mesh per (lets say) 10 chunks, //use dirty flag pattern, whenever chunks are changed via remove chunks or when updating mesh after jobs are done, //just set the flag for uberchunk and join array just before first render public void Init() { _computeData = new ComputeMeshData[MapBoundsLookup.DataChunksCount * 2]; //TODO: determine safe data margin for data in process for (var i = 0; i < MapBoundsLookup.DataChunksCount * 2; i++) { _computeData[i] = new ComputeMeshData(); } _meshData = new RenderMeshData[MapBoundsLookup.RenderChunksCount * 2]; for (var i = 0; i < MapBoundsLookup.RenderChunksCount * 2; i++) { _meshData[i] = new RenderMeshData(WorldSettings.WorldMaterial); } Updater.EveryFrame(Update); }