MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / CacheNeighbors

Method CacheNeighbors

Source/Engine/Terrain/TerrainChunk.cpp:242–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242void TerrainChunk::CacheNeighbors()
243{
244 // Cache per-chunk neighbors (for morph transition)
245 // Fallback to this chunk if none existing on the edge
246
247 // 0: bottom
248 _neighbors[0] = this;
249 if (_z > 0)
250 {
251 _neighbors[0] = &_patch->Chunks[(_z - 1) * Terrain::ChunksCountEdge + _x];
252 }
253 else
254 {
255 const auto patch = _patch->_terrain->GetPatch(_patch->_x, _patch->_z - 1);
256 if (patch)
257 _neighbors[0] = &patch->Chunks[(Terrain::ChunksCountEdge - 1) * Terrain::ChunksCountEdge + _x];
258 }
259
260 // 1: left
261 _neighbors[1] = this;
262 if (_x > 0)
263 {
264 _neighbors[1] = &_patch->Chunks[_z * Terrain::ChunksCountEdge + (_x - 1)];
265 }
266 else
267 {
268 const auto patch = _patch->_terrain->GetPatch(_patch->_x - 1, _patch->_z);
269 if (patch)
270 _neighbors[1] = &patch->Chunks[_z * Terrain::ChunksCountEdge + (Terrain::ChunksCountEdge - 1)];
271 }
272
273 // 2: right
274 _neighbors[2] = this;
275 if (_x < Terrain::ChunksCountEdge - 1)
276 {
277 _neighbors[2] = &_patch->Chunks[_z * Terrain::ChunksCountEdge + (_x + 1)];
278 }
279 else
280 {
281 const auto patch = _patch->_terrain->GetPatch(_patch->_x + 1, _patch->_z);
282 if (patch)
283 _neighbors[2] = &patch->Chunks[_z * Terrain::ChunksCountEdge];
284 }
285
286 // 3: top
287 _neighbors[3] = this;
288 if (_z < Terrain::ChunksCountEdge - 1)
289 {
290 _neighbors[3] = &_patch->Chunks[(_z + 1) * Terrain::ChunksCountEdge + _x];
291 }
292 else
293 {
294 const auto patch = _patch->_terrain->GetPatch(_patch->_x, _patch->_z + 1);
295 if (patch)
296 _neighbors[3] = &patch->Chunks[_x];
297 }
298}
299

Callers 1

DrawMethod · 0.45

Calls 1

GetPatchMethod · 0.80

Tested by

no test coverage detected