Compare commits

...

8 Commits

Author SHA1 Message Date
sfan5 dd1904a667 Run CI test also with ASan 2024-04-20 21:38:15 +02:00
sfan5 40a5e16e21 Save a copy during zlib decompression 2024-04-20 21:38:05 +02:00
wsor4035 7e4caacb9e
Upgrade CI workflow packages and Ubuntu version (#101) 2024-02-17 20:54:03 +01:00
sfan5 e14f27f412 Add cautionary note about sat_mul() 2023-08-08 14:18:58 +02:00
Saria 7af222dd9d Fix `dumpnodes` crash on deprecated tile field name 2023-04-08 16:32:29 +02:00
Martin Petricek c81cda24d3
Fix bad slicing interval for negative --min-y / --max-y values 2023-01-29 16:22:41 +01:00
sfan5 8a7333ef49 Fix package install in CI
shoutout to github for shipping broken OS images
2023-01-29 14:44:03 +01:00
sfan5 7fb3b9edd6 Fix Postgres linking on older CMake
(see 998e4820c9)
2022-06-19 14:14:09 +02:00
6 changed files with 51 additions and 24 deletions

View File

@ -7,19 +7,21 @@ on:
- '**.[ch]'
- '**.cpp'
- '**/CMakeLists.txt'
- 'util/ci/**'
- '.github/workflows/**.yml'
pull_request:
paths:
- '**.[ch]'
- '**.cpp'
- '**/CMakeLists.txt'
- 'util/ci/**'
- '.github/workflows/**.yml'
jobs:
gcc:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install deps
run: |
source util/ci/script.sh
@ -39,9 +41,9 @@ jobs:
do_functional_test
clang:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install deps
run: |
source util/ci/script.sh

View File

@ -86,6 +86,7 @@ if(ENABLE_POSTGRESQL)
if(PostgreSQL_INCLUDE_DIR AND PostgreSQL_LIBRARY)
set(PostgreSQL_FOUND TRUE)
set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR})
set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY})
endif()
else()
find_package(PostgreSQL)

View File

@ -43,6 +43,8 @@ inline T sat_mul(T a, T b)
return std::numeric_limits<T>::max();
return res;
#else
// WARNING: the fallback implementation is incorrect since we compute ceil(log(x)) not log(x)
// but that's good enough for our usecase...
const int bits = sizeof(T) * 8;
int hb_a = 0, hb_b = 0;
for (int i = bits - 1; i >= 0; i--) {
@ -426,19 +428,27 @@ void TileGenerator::closeDatabase()
m_db = NULL;
}
static inline int16_t mod16(int16_t y)
{
if (y < 0)
return (y - 15) / 16;
return y / 16;
}
void TileGenerator::loadBlocks()
{
const int16_t yMax = m_yMax / 16 + 1;
const int16_t yMax = mod16(m_yMax) + 1;
const int16_t yMin = mod16(m_yMin);
if (m_exhaustiveSearch == EXH_NEVER || m_exhaustiveSearch == EXH_Y) {
std::vector<BlockPos> vec = m_db->getBlockPos(
BlockPos(m_geomX, m_yMin / 16, m_geomY),
BlockPos(m_geomX, yMin, m_geomY),
BlockPos(m_geomX2, yMax, m_geomY2)
);
for (auto pos : vec) {
assert(pos.x >= m_geomX && pos.x < m_geomX2);
assert(pos.y >= m_yMin / 16 && pos.y < yMax);
assert(pos.y >= yMin && pos.y < yMax);
assert(pos.z >= m_geomY && pos.z < m_geomY2);
// Adjust minimum and maximum positions to the nearest block
@ -512,7 +522,8 @@ void TileGenerator::createImage()
void TileGenerator::renderMap()
{
BlockDecoder blk;
const int16_t yMax = m_yMax / 16 + 1;
const int16_t yMax = mod16(m_yMax) + 1;
const int16_t yMin = mod16(m_yMin);
size_t count = 0;
auto renderSingle = [&] (int16_t xPos, int16_t zPos, BlockList &blockStack) {
@ -529,7 +540,7 @@ void TileGenerator::renderMap()
for (const auto &it : blockStack) {
const BlockPos pos = it.first;
assert(pos.x == xPos && pos.z == zPos);
assert(pos.y >= m_yMin / 16 && pos.y < yMax);
assert(pos.y >= yMin && pos.y < yMax);
blk.reset();
blk.decode(it.second);
@ -557,7 +568,7 @@ void TileGenerator::renderMap()
int16_t xPos = *it2;
BlockList blockStack;
m_db->getBlocksOnXZ(blockStack, xPos, zPos, m_yMin / 16, yMax);
m_db->getBlocksOnXZ(blockStack, xPos, zPos, yMin, yMax);
blockStack.sort();
renderSingle(xPos, zPos, blockStack);
@ -568,17 +579,17 @@ void TileGenerator::renderMap()
} else if (m_exhaustiveSearch == EXH_Y) {
#ifndef NDEBUG
std::cerr << "Exhaustively searching height of "
<< (yMax - (m_yMin / 16)) << " blocks" << std::endl;
<< (yMax - yMin) << " blocks" << std::endl;
#endif
std::vector<BlockPos> positions;
positions.reserve(yMax - (m_yMin / 16));
positions.reserve(yMax - yMin);
for (auto it = m_positions.rbegin(); it != m_positions.rend(); ++it) {
int16_t zPos = it->first;
for (auto it2 = it->second.rbegin(); it2 != it->second.rend(); ++it2) {
int16_t xPos = *it2;
positions.clear();
for (int16_t yPos = m_yMin / 16; yPos < yMax; yPos++)
for (int16_t yPos = yMin; yPos < yMax; yPos++)
positions.emplace_back(xPos, yPos, zPos);
BlockList blockStack;
@ -591,7 +602,7 @@ void TileGenerator::renderMap()
postRenderRow(zPos);
}
} else if (m_exhaustiveSearch == EXH_FULL) {
const size_t span_y = yMax - (m_yMin / 16);
const size_t span_y = yMax - yMin;
m_progressMax = (m_geomX2 - m_geomX) * span_y * (m_geomY2 - m_geomY);
#ifndef NDEBUG
std::cerr << "Exhaustively searching "
@ -604,7 +615,7 @@ void TileGenerator::renderMap()
for (int16_t zPos = m_geomY2 - 1; zPos >= m_geomY; zPos--) {
for (int16_t xPos = m_geomX2 - 1; xPos >= m_geomX; xPos--) {
positions.clear();
for (int16_t yPos = m_yMin / 16; yPos < yMax; yPos++)
for (int16_t yPos = yMin; yPos < yMax; yPos++)
positions.emplace_back(xPos, yPos, zPos);
BlockList blockStack;

View File

@ -29,31 +29,39 @@ ustring ZlibDecompressor::decompress()
const size_t size = m_size - m_seekPos;
ustring buffer;
constexpr size_t BUFSIZE = 128 * 1024;
unsigned char temp_buffer[BUFSIZE];
constexpr size_t BUFSIZE = 32 * 1024;
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.next_in = Z_NULL;
strm.avail_in = size;
strm.avail_in = 0;
if (inflateInit(&strm) != Z_OK)
throw DecompressError();
strm.next_in = const_cast<unsigned char *>(data);
strm.avail_in = size;
buffer.resize(BUFSIZE);
strm.next_out = &buffer[0];
strm.avail_out = BUFSIZE;
int ret = 0;
do {
strm.avail_out = BUFSIZE;
strm.next_out = temp_buffer;
ret = inflate(&strm, Z_NO_FLUSH);
buffer.append(temp_buffer, BUFSIZE - strm.avail_out);
if (strm.avail_out == 0) {
const auto off = buffer.size();
buffer.reserve(off + BUFSIZE);
strm.next_out = &buffer[off];
strm.avail_out = BUFSIZE;
}
} while (ret == Z_OK);
if (ret != Z_STREAM_END)
throw DecompressError();
m_seekPos += strm.next_in - data;
buffer.resize(buffer.size() - strm.avail_out);
(void) inflateEnd(&strm);
return buffer;

View File

@ -4,12 +4,17 @@ install_linux_deps() {
local pkgs=(cmake libgd-dev libsqlite3-dev libleveldb-dev libpq-dev libhiredis-dev libzstd-dev)
sudo apt-get update
sudo apt-get install -y --no-install-recommends ${pkgs[@]} "$@"
sudo apt-get remove -y 'libgd3' nginx || : # ????
sudo apt-get install -y --no-install-recommends "${pkgs[@]}" "$@"
}
run_build() {
cmake . -DCMAKE_BUILD_TYPE=Debug \
local args=(
-DCMAKE_BUILD_TYPE=Debug
-DENABLE_LEVELDB=1 -DENABLE_POSTGRESQL=1 -DENABLE_REDIS=1
)
[[ "$CXX" == clang* ]] && args+=(-DCMAKE_CXX_FLAGS="-fsanitize=address")
cmake . "${args[@]}"
make -j2
}

View File

@ -1,7 +1,7 @@
local function get_tile(tiles, n)
local tile = tiles[n]
if type(tile) == 'table' then
return tile.name
return tile.name or tile.image
end
return tile
end