ChunkMap.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <Punkt.h>
  3. #include <Reader.h>
  4. #include <Writer.h>
  5. #include <ReferenceCounter.h>
  6. #include <Critical.h>
  7. #pragma pack(push, 1)
  8. // stores the color aof the map at a specific height
  9. struct MapBlock
  10. {
  11. unsigned char height;
  12. int color;
  13. };
  14. // stores the colors at all heights of a specific x and y position on the map.
  15. // there can by only 256 colors stored per position
  16. struct MapPixel
  17. {
  18. unsigned char len;
  19. MapBlock* blocks;
  20. };
  21. #pragma pack(pop)
  22. class Chunk;
  23. // stores the map colors of a complete chunk
  24. class ChunkMap : public Framework::ReferenceCounter
  25. {
  26. private:
  27. Framework::Punkt chunkCenter;
  28. MapPixel* pixels;
  29. Framework::Critical cs;
  30. public:
  31. ChunkMap(Framework::Punkt chunkCenter);
  32. ChunkMap(Chunk* zChunk);
  33. ChunkMap(Framework::StreamReader* zReader);
  34. ~ChunkMap();
  35. // updates the color in the chunk map at a specific position.
  36. // the color stored will be the color that is less transparent from color1
  37. // and color2. if both colors are completle transparent then the color at
  38. // this height will be removed.
  39. // \param x the x coordinate in chunk space \param y the y
  40. // coordinate in chunk space \param heigth the height to update (at each
  41. // height are two blocks stored) \param color1 the color of the first block
  42. // at this height \param color2 the color of the second block at this height
  43. bool update(char x, char y, unsigned char height, int color1, int color2);
  44. void writeTo(Framework::StreamWriter* zWriter) const;
  45. Framework::Punkt getChunkCenter() const;
  46. };