minor refactor + 4 spaces indentation
This commit is contained in:
+14
-14
@@ -4,11 +4,11 @@
|
||||
#include "../util/data_io.h"
|
||||
|
||||
void Lightmap::set(const Lightmap* lightmap) {
|
||||
set(lightmap->map);
|
||||
set(lightmap->map);
|
||||
}
|
||||
|
||||
void Lightmap::set(const light_t* map) {
|
||||
for (size_t i = 0; i < CHUNK_VOL; i++) {
|
||||
for (size_t i = 0; i < CHUNK_VOL; i++) {
|
||||
this->map[i] = map[i];
|
||||
}
|
||||
}
|
||||
@@ -16,19 +16,19 @@ 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];
|
||||
for (uint i = 0; i < CHUNK_VOL; i+=2) {
|
||||
buffer[i/2] = ((map[i] >> 12) & 0xF) | ((map[i+1] >> 8) & 0xF0);
|
||||
}
|
||||
return buffer;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
+56
-56
@@ -4,85 +4,85 @@
|
||||
#include "../constants.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
const int LIGHTMAP_DATA_LEN = CHUNK_VOL/2;
|
||||
inline constexpr int LIGHTMAP_DATA_LEN = CHUNK_VOL/2;
|
||||
|
||||
// Lichtkarte
|
||||
class Lightmap {
|
||||
public:
|
||||
light_t map[CHUNK_VOL] {};
|
||||
int highestPoint = 0;
|
||||
light_t map[CHUNK_VOL] {};
|
||||
int highestPoint = 0;
|
||||
|
||||
void set(const Lightmap* lightmap);
|
||||
void set(const Lightmap* lightmap);
|
||||
|
||||
void set(const light_t* map);
|
||||
void set(const light_t* map);
|
||||
|
||||
inline unsigned short get(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x]);
|
||||
}
|
||||
inline unsigned short get(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x]);
|
||||
}
|
||||
|
||||
inline unsigned char get(int x, int y, int z, int channel) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> (channel << 2)) & 0xF;
|
||||
}
|
||||
inline unsigned char get(int x, int y, int z, int channel) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> (channel << 2)) & 0xF;
|
||||
}
|
||||
|
||||
inline unsigned char getR(int x, int y, int z) const {
|
||||
return map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] & 0xF;
|
||||
}
|
||||
inline unsigned char getR(int x, int y, int z) const {
|
||||
return map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] & 0xF;
|
||||
}
|
||||
|
||||
inline unsigned char getG(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> 4) & 0xF;
|
||||
}
|
||||
inline unsigned char getG(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> 4) & 0xF;
|
||||
}
|
||||
|
||||
inline unsigned char getB(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> 8) & 0xF;
|
||||
}
|
||||
inline unsigned char getB(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> 8) & 0xF;
|
||||
}
|
||||
|
||||
inline unsigned char getS(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> 12) & 0xF;
|
||||
}
|
||||
inline unsigned char getS(int x, int y, int z) const {
|
||||
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> 12) & 0xF;
|
||||
}
|
||||
|
||||
inline void setR(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0xFFF0) | value;
|
||||
}
|
||||
inline void setR(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0xFFF0) | value;
|
||||
}
|
||||
|
||||
inline void setG(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0xFF0F) | (value << 4);
|
||||
}
|
||||
inline void setG(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0xFF0F) | (value << 4);
|
||||
}
|
||||
|
||||
inline void setB(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0xF0FF) | (value << 8);
|
||||
}
|
||||
inline void setB(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0xF0FF) | (value << 8);
|
||||
}
|
||||
|
||||
inline void setS(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0x0FFF) | (value << 12);
|
||||
}
|
||||
inline void setS(int x, int y, int z, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & 0x0FFF) | (value << 12);
|
||||
}
|
||||
|
||||
inline void set(int x, int y, int z, int channel, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & (0xFFFF & (~(0xF << (channel*4))))) | (value << (channel << 2));
|
||||
}
|
||||
inline void set(int x, int y, int z, int channel, int value){
|
||||
const int index = y*CHUNK_D*CHUNK_W+z*CHUNK_W+x;
|
||||
map[index] = (map[index] & (0xFFFF & (~(0xF << (channel*4))))) | (value << (channel << 2));
|
||||
}
|
||||
|
||||
inline const light_t* getLights() const {
|
||||
return map;
|
||||
}
|
||||
inline const light_t* getLights() const {
|
||||
return map;
|
||||
}
|
||||
|
||||
inline light_t* getLightsWriteable() {
|
||||
return map;
|
||||
}
|
||||
inline light_t* getLightsWriteable() {
|
||||
return map;
|
||||
}
|
||||
|
||||
static constexpr light_t combine(int r, int g, int b, int s) {
|
||||
return r | (g << 4) | (b << 8) | (s << 12);
|
||||
}
|
||||
static constexpr light_t combine(int r, int g, int b, int s) {
|
||||
return r | (g << 4) | (b << 8) | (s << 12);
|
||||
}
|
||||
|
||||
static constexpr light_t extract(light_t light, ubyte channel) {
|
||||
return (light >> (channel << 2)) & 0xF;
|
||||
}
|
||||
return (light >> (channel << 2)) & 0xF;
|
||||
}
|
||||
|
||||
ubyte* encode() const;
|
||||
static light_t* decode(ubyte* buffer);
|
||||
ubyte* encode() const;
|
||||
static light_t* decode(ubyte* buffer);
|
||||
};
|
||||
|
||||
#endif /* LIGHTING_LIGHTMAP_H_ */
|
||||
|
||||
Reference in New Issue
Block a user