Sky lights data saving (optimization)
This commit is contained in:
@@ -20,12 +20,27 @@ void Lightmap::set(const Lightmap* lightmap) {
|
||||
}
|
||||
}
|
||||
|
||||
void Lightmap::set(light_t* map) {
|
||||
delete[] this->map;
|
||||
this->map = map;
|
||||
}
|
||||
|
||||
static_assert(sizeof(light_t) == 2, "replace dataio calls to new light_t");
|
||||
|
||||
ubyte* Lightmap::encode() const {
|
||||
ubyte* buffer = new ubyte[CHUNK_VOL * sizeof(light_t)];
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
dataio::write_int16_big(map[i], buffer, i * sizeof(light_t));
|
||||
ubyte* buffer = new ubyte[LIGHTMAP_DATA_LEN];
|
||||
for (uint i = 0; i < CHUNK_VOL; i+=2) {
|
||||
buffer[i/2] = ((map[i] >> 12) & 0xF) | ((map[i+1] >> 8) & 0xF0);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
light_t* Lightmap::decode(ubyte* buffer) {
|
||||
light_t* lights = new light_t[CHUNK_VOL];
|
||||
for (uint i = 0; i < CHUNK_VOL; i+=2) {
|
||||
ubyte b = buffer[i/2];
|
||||
lights[i] = ((b & 0xF) << 12);
|
||||
lights[i+1] = ((b & 0xF0) << 8);
|
||||
}
|
||||
return lights;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "../typedefs.h"
|
||||
#include "../voxels/Chunk.h"
|
||||
|
||||
const int LIGHTMAP_DATA_LEN = CHUNK_VOL/2;
|
||||
|
||||
// Lichtkarte
|
||||
class Lightmap {
|
||||
public:
|
||||
@@ -15,6 +17,8 @@ public:
|
||||
|
||||
void set(const Lightmap* lightmap);
|
||||
|
||||
void set(light_t* map);
|
||||
|
||||
inline unsigned short get(int x, int y, int z){
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x]);
|
||||
}
|
||||
@@ -81,6 +85,7 @@ public:
|
||||
}
|
||||
|
||||
ubyte* encode() const;
|
||||
static light_t* decode(ubyte* buffer);
|
||||
};
|
||||
|
||||
#endif /* LIGHTING_LIGHTMAP_H_ */
|
||||
|
||||
Reference in New Issue
Block a user