memory related refactor
This commit is contained in:
@@ -15,16 +15,16 @@ void Lightmap::set(const light_t* map) {
|
||||
|
||||
static_assert(sizeof(light_t) == 2, "replace dataio calls to new light_t");
|
||||
|
||||
ubyte* Lightmap::encode() const {
|
||||
ubyte* buffer = new ubyte[LIGHTMAP_DATA_LEN];
|
||||
std::unique_ptr<ubyte[]> Lightmap::encode() const {
|
||||
auto buffer = std::make_unique<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];
|
||||
std::unique_ptr<light_t[]> Lightmap::decode(ubyte* buffer) {
|
||||
auto lights = std::make_unique<light_t[]>(CHUNK_VOL);
|
||||
for (uint i = 0; i < CHUNK_VOL; i+=2) {
|
||||
ubyte b = buffer[i/2];
|
||||
lights[i] = ((b & 0xF) << 12);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "../constants.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
inline constexpr int LIGHTMAP_DATA_LEN = CHUNK_VOL/2;
|
||||
|
||||
// Lichtkarte
|
||||
@@ -81,8 +83,8 @@ public:
|
||||
return (light >> (channel << 2)) & 0xF;
|
||||
}
|
||||
|
||||
ubyte* encode() const;
|
||||
static light_t* decode(ubyte* buffer);
|
||||
std::unique_ptr<ubyte[]> encode() const;
|
||||
static std::unique_ptr<light_t[]> decode(ubyte* buffer);
|
||||
};
|
||||
|
||||
#endif /* LIGHTING_LIGHTMAP_H_ */
|
||||
|
||||
Reference in New Issue
Block a user