remove extra functions
This commit is contained in:
parent
93fac9960c
commit
a7d6c96a5c
@ -4,14 +4,6 @@
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
inline int min(int a, int b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
inline int max(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
ImageData::ImageData(ImageFormat format, uint width, uint height)
|
||||
: format(format), width(width), height(height) {
|
||||
size_t pixsize;
|
||||
@ -49,10 +41,11 @@ void ImageData::flipX() {
|
||||
case ImageFormat::rgba8888: {
|
||||
uint size = (format == ImageFormat::rgba8888) ? 4 : 3;
|
||||
for (uint y = 0; y < height; y++) {
|
||||
for (uint x = 0; x < width/2; x++) {
|
||||
for (uint x = 0; x < width / 2; x++) {
|
||||
for (uint c = 0; c < size; c++) {
|
||||
ubyte temp = data[(y * width + x) * size + c];
|
||||
data[(y * width + x) * size + c] = data[(y * width + (width - x - 1)) * size + c];
|
||||
data[(y * width + x) * size + c] =
|
||||
data[(y * width + (width - x - 1)) * size + c];
|
||||
data[(y * width + (width - x - 1)) * size + c] = temp;
|
||||
}
|
||||
}
|
||||
@ -104,8 +97,12 @@ void ImageData::blitRGB_on_RGBA(const ImageData* image, int x, int y) {
|
||||
uint srcwidth = image->getWidth();
|
||||
uint srcheight = image->getHeight();
|
||||
|
||||
for (uint srcy = max(0, -y); (int)srcy < min(srcheight, height-y); srcy++) {
|
||||
for (uint srcx = max(0, -x); (int)srcx < min(srcwidth, width-x); srcx++) {
|
||||
for (uint srcy = std::max(0, -y);
|
||||
srcy < std::min(srcheight, height - y);
|
||||
srcy++) {
|
||||
for (uint srcx = std::max(0, -x);
|
||||
srcx < std::min(srcwidth, width - x);
|
||||
srcx++) {
|
||||
uint dstx = srcx + x;
|
||||
uint dsty = srcy + y;
|
||||
uint dstidx = (dsty * width + dstx) * 4;
|
||||
@ -130,8 +127,12 @@ void ImageData::blitMatchingFormat(const ImageData* image, int x, int y) {
|
||||
uint srcwidth = image->getWidth();
|
||||
uint srcheight = image->getHeight();
|
||||
|
||||
for (uint srcy = max(0, -y); (int)srcy < min(srcheight, height-y); srcy++) {
|
||||
for (uint srcx = max(0, -x); (int)srcx < min(srcwidth, width-x); srcx++) {
|
||||
for (uint srcy = std::max(0, -y);
|
||||
srcy < std::min(srcheight, height - y);
|
||||
srcy++) {
|
||||
for (uint srcx = std::max(0, -x);
|
||||
srcx < std::min(srcwidth, width - x);
|
||||
srcx++) {
|
||||
uint dstx = srcx + x;
|
||||
uint dsty = srcy + y;
|
||||
uint dstidx = (dsty * width + dstx) * comps;
|
||||
@ -156,7 +157,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
int rx = x + w - 1;
|
||||
int ry = y + h - 1;
|
||||
// top-left pixel
|
||||
if (x > 0 && (uint)x < width && y > 0 && (uint)y < height) {
|
||||
if (x > 0 && static_cast<uint>(x) < width &&
|
||||
y > 0 && static_cast<uint>(y) < height) {
|
||||
uint srcidx = (y * width + x) * comps;
|
||||
uint dstidx = ((y - 1) * width + x - 1) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -165,7 +167,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
// top-right pixel
|
||||
if (rx >= 0 && (uint)rx < width-1 && y > 0 && (uint)y < height) {
|
||||
if (rx >= 0 && static_cast<uint>(rx) < width-1 &&
|
||||
y > 0 && static_cast<uint>(y) < height) {
|
||||
uint srcidx = (y * width + rx) * comps;
|
||||
uint dstidx = ((y - 1) * width + rx + 1) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -174,7 +177,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
// bottom-left pixel
|
||||
if (x > 0 && (uint)x < width && ry >= 0 && (uint)ry < height-1) {
|
||||
if (x > 0 && static_cast<uint>(x) < width &&
|
||||
ry >= 0 && static_cast<uint>(ry) < height-1) {
|
||||
uint srcidx = (ry * width + x) * comps;
|
||||
uint dstidx = ((ry + 1) * width + x - 1) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -183,7 +187,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
// bottom-right pixel
|
||||
if (rx >= 0 && (uint)rx < width-1 && ry >= 0 && (uint)ry < height-1) {
|
||||
if (rx >= 0 && static_cast<uint>(rx) < width-1 &&
|
||||
ry >= 0 && static_cast<uint>(ry) < height-1) {
|
||||
uint srcidx = (ry * width + rx) * comps;
|
||||
uint dstidx = ((ry + 1) * width + rx + 1) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -192,8 +197,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
// left border
|
||||
if (x > 0 && (uint)x < width) {
|
||||
for (uint ey = max(y, 0); (int)ey < y + h; ey++) {
|
||||
if (x > 0 && static_cast<uint>(x) < width) {
|
||||
for (uint ey = std::max(y, 0); static_cast<int>(ey) < y + h; ey++) {
|
||||
uint srcidx = (ey * width + x) * comps;
|
||||
uint dstidx = (ey * width + x - 1) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -203,8 +208,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
// top border
|
||||
if (y > 0 && (uint)y < height) {
|
||||
for (uint ex = max(x, 0); (int)ex < x + w; ex++) {
|
||||
if (y > 0 && static_cast<uint>(y) < height) {
|
||||
for (uint ex = std::max(x, 0); static_cast<int>(ex) < x + w; ex++) {
|
||||
uint srcidx = (y * width + ex) * comps;
|
||||
uint dstidx = ((y-1) * width + ex) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -214,8 +219,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
// right border
|
||||
if (rx >= 0 && (uint)rx < width-1) {
|
||||
for (uint ey = max(y, 0); (int)ey < y + h; ey++) {
|
||||
if (rx >= 0 && static_cast<uint>(rx) < width-1) {
|
||||
for (uint ey = std::max(y, 0); static_cast<int>(ey) < y + h; ey++) {
|
||||
uint srcidx = (ey * width + rx) * comps;
|
||||
uint dstidx = (ey * width + rx + 1) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -225,8 +230,8 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
|
||||
// bottom border
|
||||
if (ry >= 0 && (uint)ry < height-1) {
|
||||
for (uint ex = max(x, 0); (int)ex < x + w; ex++) {
|
||||
if (ry >= 0 && static_cast<uint>(ry) < height-1) {
|
||||
for (uint ex = std::max(x, 0); static_cast<int>(ex) < x + w; ex++) {
|
||||
uint srcidx = (ry * width + ex) * comps;
|
||||
uint dstidx = ((ry+1) * width + ex) * comps;
|
||||
for (uint c = 0; c < comps; c++) {
|
||||
@ -275,8 +280,8 @@ std::unique_ptr<ImageData> add_atlas_margins(ImageData* image, int grid_size) {
|
||||
int doy = 1 + row * (imgres + 2);
|
||||
for (int ly = -1; ly <= imgres; ly++) {
|
||||
for (int lx = -1; lx <= imgres; lx++) {
|
||||
int sy = max(min(ly, imgres-1), 0);
|
||||
int sx = max(min(lx, imgres-1), 0);
|
||||
int sy = std::max(std::min(ly, imgres-1), 0);
|
||||
int sx = std::max(std::min(lx, imgres-1), 0);
|
||||
for (int c = 0; c < 4; c++)
|
||||
dstdata[((doy+ly) * dstwidth + dox + lx) * 4 + c] =
|
||||
srcdata[((soy+sy) * srcwidth + sox + sx) * 4 + c];
|
||||
|
||||
@ -2,47 +2,16 @@
|
||||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
inline int floordiv(int a, int b) {
|
||||
inline constexpr int floordiv(int a, int b) {
|
||||
if (a < 0 && a % b) {
|
||||
return (a / b) - 1;
|
||||
}
|
||||
return a / b;
|
||||
}
|
||||
|
||||
inline int ceildiv(int a, int b) {
|
||||
inline constexpr int ceildiv(int a, int b) {
|
||||
if (a > 0 && a % b) {
|
||||
return a / b + 1;
|
||||
}
|
||||
return a / b;
|
||||
}
|
||||
|
||||
inline int max(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
inline int min(int a, int b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
inline int64_t max(int64_t a, int64_t b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
inline int64_t min(int64_t a, int64_t b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
static unsigned int g_seed;
|
||||
|
||||
inline void fast_srand(int seed) {
|
||||
g_seed = seed;
|
||||
}
|
||||
|
||||
inline int fast_rand(void) {
|
||||
g_seed = (214013 * g_seed + 2531011);
|
||||
return (g_seed >> 16) & 0x7FFF;
|
||||
}
|
||||
|
||||
inline light_t light_pack(ubyte r, ubyte g, ubyte b, ubyte s) {
|
||||
return r | (g << 4) | (b << 8) | (s << 12);
|
||||
}
|
||||
|
||||
@ -656,7 +656,7 @@ void Chunks::translate(int32_t dx, int32_t dz) {
|
||||
}
|
||||
for (uint32_t z = 0; z < d; z++) {
|
||||
for (uint32_t x = 0; x < w; x++) {
|
||||
auto chunk = chunks[z * w + x];
|
||||
auto& chunk = chunks[z * w + x];
|
||||
int nx = x - dx;
|
||||
int nz = z - dz;
|
||||
if (chunk == nullptr) continue;
|
||||
|
||||
@ -115,12 +115,12 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
||||
if (found == chunksMap.end()) {
|
||||
// no chunk loaded -> filling with BLOCK_VOID
|
||||
for (int ly = y; ly < y + h; ly++) {
|
||||
for (int lz = max(z, cz * CHUNK_D);
|
||||
lz < min(z + d, (cz + 1) * CHUNK_D);
|
||||
lz++) {
|
||||
for (int lx = max(x, cx * CHUNK_W);
|
||||
lx < min(x + w, (cx + 1) * CHUNK_W);
|
||||
lx++) {
|
||||
for (int lz = std::max(z, cz * CHUNK_D);
|
||||
lz < std::min(z + d, (cz + 1) * CHUNK_D);
|
||||
lz++) {
|
||||
for (int lx = std::max(x, cx * CHUNK_W);
|
||||
lx < std::min(x + w, (cx + 1) * CHUNK_W);
|
||||
lx++) {
|
||||
uint idx = vox_index(lx - x, ly - y, lz - z, w, d);
|
||||
voxels[idx].id = BLOCK_VOID;
|
||||
lights[idx] = 0;
|
||||
@ -132,12 +132,12 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
||||
const voxel* cvoxels = chunk->voxels;
|
||||
const light_t* clights = chunk->lightmap.getLights();
|
||||
for (int ly = y; ly < y + h; ly++) {
|
||||
for (int lz = max(z, cz * CHUNK_D);
|
||||
lz < min(z + d, (cz + 1) * CHUNK_D);
|
||||
lz++) {
|
||||
for (int lx = max(x, cx * CHUNK_W);
|
||||
lx < min(x + w, (cx + 1) * CHUNK_W);
|
||||
lx++) {
|
||||
for (int lz = std::max(z, cz * CHUNK_D);
|
||||
lz < std::min(z + d, (cz + 1) * CHUNK_D);
|
||||
lz++) {
|
||||
for (int lx = std::max(x, cx * CHUNK_W);
|
||||
lx < std::min(x + w, (cx + 1) * CHUNK_W);
|
||||
lx++) {
|
||||
uint vidx = vox_index(lx - x, ly - y, lz - z, w, d);
|
||||
uint cidx = vox_index(
|
||||
lx - cx * CHUNK_W,
|
||||
@ -149,17 +149,18 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
||||
voxels[vidx] = cvoxels[cidx];
|
||||
light_t light = clights[cidx];
|
||||
if (backlight) {
|
||||
const auto& block =
|
||||
indices->blocks.require(voxels[vidx].id);
|
||||
if (block.lightPassing) { //-V522
|
||||
const auto block =
|
||||
indices->blocks.get(voxels[vidx].id);
|
||||
if (block && block->lightPassing) {
|
||||
light = Lightmap::combine(
|
||||
min(15,
|
||||
std::min(15,
|
||||
Lightmap::extract(light, 0) + 1),
|
||||
min(15,
|
||||
std::min(15,
|
||||
Lightmap::extract(light, 1) + 1),
|
||||
min(15,
|
||||
std::min(15,
|
||||
Lightmap::extract(light, 2) + 1),
|
||||
min(15, Lightmap::extract(light, 3))
|
||||
std::min(15,
|
||||
static_cast<int>(Lightmap::extract(light, 3)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user