ChunkMap.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(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(0)
  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(Chunk *zChunk);
  32. ChunkMap(Framework::StreamReader* zReader);
  33. ~ChunkMap();
  34. // updates the color in the chunk map at a specific position.
  35. // the color stored will be the color that is less transparent from color1
  36. // and color2. if both colors are completle transparent then the color at
  37. // this height will be removed.
  38. // \param x the x coordinate in chunk space \param y the y
  39. // coordinate in chunk space \param heigth the height to update (at each
  40. // height are two blocks stored) \param color1 the color of the first block
  41. // at this height \param color2 the color of the second block at this height
  42. void update(char x, char y, unsigned char height, int color1, int color2);
  43. void writeTo(Framework::StreamWriter* zWriter) const;
  44. Framework::Punkt getChunkCenter() const;
  45. };