You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

world.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * =====================================================================================
  3. *
  4. * Filename: world.h
  5. *
  6. * Description: World manages and draws chunks
  7. *
  8. * Version: 1.0
  9. * Created: 04/03/2014 09:48:12 PM
  10. * Revision: none
  11. * Compiler: gcc
  12. *
  13. * Author: YOUR NAME (),
  14. * Organization:
  15. *
  16. * =====================================================================================
  17. */
  18. #pragma once
  19. #include "voxelutils.h"
  20. #include "voxelinfo.h"
  21. #include "voxelmath.h"
  22. #include "terraingen.h"
  23. #include "graphics/chunkmesh.h"
  24. #include "cuckoohash_map.hh"
  25. #include <unordered_map>
  26. #include <vector>
  27. #include <deque>
  28. #include <glm/glm.hpp>
  29. namespace vtk {
  30. class Chunk;
  31. class World {
  32. public:
  33. World();
  34. bool isVoxelSolid(const int& x, const int& y, const int& z);
  35. bool setVoxelType(const int& x, const int& y, const int& z, const unsigned& type, const bool& updateChunk = false);
  36. unsigned getVoxelType(const glm::ivec3& pos);
  37. Chunk* makeChunk(const int& x, const int& y, const int& z, bool insertAfter = true);
  38. bool generateChunk(const int& x, const int& y, const int& z);
  39. bool insertChunk(Chunk* chunk);
  40. Chunk* getChunk(const glm::ivec3& pos);
  41. void queueChunkUpdate(const int& x, const int& y, const int& z, const bool& back = false);
  42. void queueChunkUpdate(const glm::ivec3& pos, const bool& back = false);
  43. void queueChunkLoad(const glm::ivec3& pos);
  44. void draw();
  45. void update();
  46. void forceGlobalGeometryUpdate(); //Rebuilds all geometry. Don't do this.
  47. void queueChunkLoadsAroundPoint(const glm::vec3& point, const int& chunkRadius);
  48. //std::unordered_map<glm::ivec3, Chunk*, ivec3Hash> mChunks;
  49. cuckoohash_map<glm::ivec3, Chunk*, ivec3Hash> mChunks;
  50. std::unordered_map<glm::ivec3, ChunkMesh, ivec3Hash> mChunkMeshes;
  51. std::vector<iPos> chunkUpdateQueue;
  52. std::deque<glm::ivec3> mChunkUpdateQueue;
  53. std::deque<glm::ivec3> mChunkLoadQueue;
  54. unsigned chunkSize;
  55. float voxelSize;
  56. int modelMatUni;
  57. TerrainGen terrain;
  58. VoxelInfo voxelInfo;
  59. VoxelMath voxelMath;
  60. bool rebuildThreadActive;
  61. bool mLoadThreadActive;
  62. };
  63. }