util/dataio + Lightmap.encode

This commit is contained in:
MihailRis
2023-12-06 14:44:16 +03:00
parent 93182869d3
commit 6b423b441f
5 changed files with 92 additions and 29 deletions
+15 -2
View File
@@ -1,8 +1,11 @@
#include "Lightmap.h"
#include <assert.h>
#include "../util/data_io.h"
Lightmap::Lightmap(){
map = new unsigned short[CHUNK_VOL];
for (unsigned int i = 0; i < CHUNK_VOL; i++){
map = new light_t[CHUNK_VOL];
for (uint i = 0; i < CHUNK_VOL; i++){
map[i] = 0x0000;
}
}
@@ -16,3 +19,13 @@ void Lightmap::set(const Lightmap* lightmap) {
map[i] = lightmap->map[i];
}
}
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));
}
return buffer;
}