mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
World/Block: return colors as struct instead of uint32_t
Gets rid of a useless byte switch, and removes the arpa/inet.h include, which is not available on Windows.
This commit is contained in:
parent
12b5cb4f4e
commit
de04cce993
3 changed files with 11 additions and 8 deletions
|
@ -41,7 +41,6 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -52,7 +51,7 @@ namespace MinedMap {
|
||||||
static const size_t DIM = World::Region::SIZE*World::Chunk::SIZE;
|
static const size_t DIM = World::Region::SIZE*World::Chunk::SIZE;
|
||||||
|
|
||||||
|
|
||||||
static void addChunk(uint32_t image[DIM*DIM], uint8_t lightmap[2*DIM*DIM], size_t X, size_t Z, const World::ChunkData *data) {
|
static void addChunk(World::Block::Color image[DIM*DIM], uint8_t lightmap[2*DIM*DIM], size_t X, size_t Z, const World::ChunkData *data) {
|
||||||
World::Chunk chunk(data);
|
World::Chunk chunk(data);
|
||||||
World::Chunk::Blocks layer = chunk.getTopLayer();
|
World::Chunk::Blocks layer = chunk.getTopLayer();
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ static void addChunk(uint32_t image[DIM*DIM], uint8_t lightmap[2*DIM*DIM], size_
|
||||||
size_t i = (Z*World::Chunk::SIZE+z)*DIM + X*World::Chunk::SIZE+x;
|
size_t i = (Z*World::Chunk::SIZE+z)*DIM + X*World::Chunk::SIZE+x;
|
||||||
const World::Block &block = layer.blocks[x][z];
|
const World::Block &block = layer.blocks[x][z];
|
||||||
|
|
||||||
image[i] = htonl(block.getColor());
|
image[i] = block.getColor();
|
||||||
lightmap[2*i+1] = (1 - block.blockLight/15.f)*192;
|
lightmap[2*i+1] = (1 - block.blockLight/15.f)*192;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +133,7 @@ static void doRegion(const std::string &input, const std::string &output, const
|
||||||
std::printf("Generating %s from %s...\n", output.c_str(), input.c_str());
|
std::printf("Generating %s from %s...\n", output.c_str(), input.c_str());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::unique_ptr<uint32_t[]> image(new uint32_t[DIM*DIM]);
|
std::unique_ptr<World::Block::Color[]> image(new World::Block::Color[DIM*DIM]);
|
||||||
std::memset(image.get(), 0, 4*DIM*DIM);
|
std::memset(image.get(), 0, 4*DIM*DIM);
|
||||||
|
|
||||||
std::unique_ptr<uint8_t[]> lightmap(new uint8_t[2*DIM*DIM]);
|
std::unique_ptr<uint8_t[]> lightmap(new uint8_t[2*DIM*DIM]);
|
||||||
|
|
|
@ -31,9 +31,9 @@
|
||||||
namespace MinedMap {
|
namespace MinedMap {
|
||||||
namespace World {
|
namespace World {
|
||||||
|
|
||||||
uint32_t Block::getColor() const {
|
Block::Color Block::getColor() const {
|
||||||
if (!type || !type->opaque)
|
if (!type || !type->opaque)
|
||||||
return 0;
|
return Color {};
|
||||||
|
|
||||||
float r = type->color.r;
|
float r = type->color.r;
|
||||||
float g = type->color.g;
|
float g = type->color.g;
|
||||||
|
@ -63,7 +63,7 @@ uint32_t Block::getColor() const {
|
||||||
if (g > 255) g = 255;
|
if (g > 255) g = 255;
|
||||||
if (b > 255) b = 255;
|
if (b > 255) b = 255;
|
||||||
|
|
||||||
return ((unsigned)r << 24) | ((unsigned)g << 16) | ((unsigned)b << 8) | 0xff;
|
return Color {uint8_t(r), uint8_t(g), uint8_t(b), 0xff};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,17 @@ namespace MinedMap {
|
||||||
namespace World {
|
namespace World {
|
||||||
|
|
||||||
struct Block {
|
struct Block {
|
||||||
|
struct Color {
|
||||||
|
uint8_t r, g, b, a;
|
||||||
|
};
|
||||||
|
|
||||||
const Resource::BlockType *type;
|
const Resource::BlockType *type;
|
||||||
unsigned height;
|
unsigned height;
|
||||||
uint8_t blockLight;
|
uint8_t blockLight;
|
||||||
uint8_t biome;
|
uint8_t biome;
|
||||||
|
|
||||||
|
|
||||||
uint32_t getColor() const;
|
Color getColor() const;
|
||||||
|
|
||||||
operator bool() const {
|
operator bool() const {
|
||||||
return type;
|
return type;
|
||||||
|
|
Loading…
Add table
Reference in a new issue