Guest User

Untitled

a guest
Dec 12th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. void ChunkManager::updateChunks()
  2. {
  3. int chunkView = 6;
  4. float r = 3;
  5.  
  6. i32v3 pos = getChunkByPos((i32v3)_cam->getPosition());
  7.  
  8. for (int x = pos.x - r; x < pos.x + chunkView; x++)
  9. {
  10. for (int y = pos.y - r; y < pos.y + chunkView; y++)
  11. {
  12. for (int z = pos.z - r; z < pos.z + chunkView; z++)
  13. {
  14. float x2 = (x * 32);
  15. float y2 = (y * 32);
  16. float z2 = (z * 32);
  17.  
  18. i32v3 newPos = i32v3(x, y, z);
  19.  
  20. if (std::abs(_cam->getPosition().x - x2) < (32 * r) && std::abs(_cam->getPosition().y - y2) < (32 * r) && std::abs(_cam->getPosition().z - z2) < (32 * r))
  21. {
  22. if (chunkList[newPos] == NULL)
  23. {
  24. loadChunk(newPos.x, newPos.y, newPos.z, true);
  25. }
  26. }
  27. else
  28. {
  29. if (chunkList[newPos] != NULL)
  30. {
  31. unloadChunk(newPos.x, newPos.y, newPos.z);
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38.  
  39. void ChunkManager::loadChunk(float x, float y, float z, bool threaded)
  40. {
  41. mtx.lock();
  42. if (threaded)
  43. {
  44. i32v3 pos = i32v3(x, y, z);
  45.  
  46. Chunk* chunk = new Chunk(this, _cam, _oneissaMath, _contentSystem, _bManager);
  47. chunkList[pos] = chunk;
  48.  
  49. chunk->init((x * 32), (y * 32), (z * 32));
  50. chunk->fillChunk((x * 32), (y * 32), (z * 32));
  51. chunk->buildChunk((x * 32), (y * 32), (z * 32));
  52.  
  53. voxelCount += chunk->voxelCount;
  54.  
  55. if (chunk->voxelCount == 0)
  56. {
  57. chunkList[pos] = NULL;
  58.  
  59. chunkCount--;
  60. }
  61.  
  62. chunkCount++;
  63. }
  64. else
  65. {
  66. i32v3 pos = i32v3(x, y, z);
  67.  
  68. Chunk* chunk = new Chunk(this, _cam, _oneissaMath, _contentSystem, _bManager);
  69. chunkList[pos] = chunk;
  70.  
  71. chunk->init((x * 32), (y * 32), (z * 32));
  72. chunk->fillChunk((x * 32), (y * 32), (z * 32));
  73. chunk->buildChunk((x * 32), (y * 32), (z * 32));
  74. chunk->buildVBO();
  75.  
  76. voxelCount += chunk->voxelCount;
  77.  
  78. if (chunk->voxelCount == 0)
  79. {
  80. chunkList[pos] = NULL;
  81.  
  82. chunkCount--;
  83. }
  84.  
  85. chunkCount++;
  86. }
  87. mtx.unlock();
  88. }
Advertisement
Add Comment
Please, Sign In to add comment