Chunk.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include <Array.h>
  3. #include <Critical.h>
  4. #include <Model3D.h>
  5. #include <Model3DCollection.h>
  6. #include <Punkt.h>
  7. #include <Reader.h>
  8. #include "Area.h"
  9. #include "Block.h"
  10. #include "BlockAnimation.h"
  11. #include "Constants.h"
  12. #include "FactoryCraftModel.h"
  13. #include "ChunkModelBuilder.h"
  14. class Chunk : public Framework::ReferenceCounter
  15. {
  16. public:
  17. class CombinedModels
  18. {
  19. public:
  20. static const int GROUND = 1;
  21. static const int FLUID = 2;
  22. static const int TRANSPARENT_GROUND = 4;
  23. };
  24. private:
  25. Framework::Punkt location;
  26. // TODO: use native array for bedder performance?
  27. Block** blocks;
  28. Framework::Array<Block*> visibleBlocks;
  29. Framework::RCArray<ChunkModelBuilder> modelBuilders;
  30. bool isLoading;
  31. Framework::Critical cs;
  32. Framework::Critical vcs;
  33. Framework::Critical acs;
  34. Framework::RCArray<BlockAnimation> animations;
  35. int lightChanged;
  36. int modelChanged;
  37. void appendAnimation(
  38. Block* zB, int boneId, double time, Vec3<float> pos, Vec3<float> rot);
  39. void load(Framework::StreamReader* zReader);
  40. void buildModel(ChunkModelBuilder *builder);
  41. void updateLight(ChunkModelBuilder *builder);
  42. public:
  43. Chunk(Framework::Punkt location);
  44. Chunk(Framework::Punkt location, Framework::StreamReader* zReader);
  45. ~Chunk();
  46. void renderSolid(std::function<void(Model3D*)> f);
  47. void renderTransparent(std::function<void(Model3D*)> f);
  48. bool tick(std::function<void(Model3D*)> f, double time);
  49. void destroy();
  50. void api(char* message);
  51. Block* zBlockAt(Framework::Vec3<int> cLocation);
  52. void setBlock(Block* block);
  53. void removeBlock(Block* zBlock);
  54. void blockVisibilityChanged(Block* zB);
  55. Framework::Punkt getCenter() const;
  56. Framework::Vec3<int> getMin() const;
  57. Framework::Vec3<int> getMax() const;
  58. void setModelChanged(int modelType);
  59. void setLightChanged(int modelType);
  60. inline static int index(Framework::Vec3<int> localLocation)
  61. {
  62. return (localLocation.x * CHUNK_SIZE + localLocation.y) * WORLD_HEIGHT
  63. + localLocation.z;
  64. }
  65. friend ChunkModelBuilder;
  66. };