From 3d68e67b63a0c9f584f154dccbe0ea5919f9e503 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 17 Feb 2024 09:34:05 +0100 Subject: [PATCH 01/10] Downgrade cmake version --- CMakeLists.txt | 2 +- app/CMakeLists.txt | 2 +- collision/CMakeLists.txt | 2 +- gfx | 2 +- terrain/CMakeLists.txt | 2 +- terrain/TerrainRenderer.cpp | 17 ++++++----------- test/CMakeLists.txt | 2 +- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05993bb..a1c2647 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.18) project(TerrainRenderer LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index dc0bbe9..736bd18 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.18) FetchContent_Declare( cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git diff --git a/collision/CMakeLists.txt b/collision/CMakeLists.txt index 4297488..c1cd245 100644 --- a/collision/CMakeLists.txt +++ b/collision/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.18) FetchContent_Declare( glm diff --git a/gfx b/gfx index 48d12f7..deeda6a 160000 --- a/gfx +++ b/gfx @@ -1 +1 @@ -Subproject commit 48d12f7730aa9a3ad24b135473f23d72b849a813 +Subproject commit deeda6a73d05f70610efcb400b67153ca4375df4 diff --git a/terrain/CMakeLists.txt b/terrain/CMakeLists.txt index b34c2fc..be83fa0 100644 --- a/terrain/CMakeLists.txt +++ b/terrain/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.18) add_library(terrain STATIC TileService.cpp TileService.h diff --git a/terrain/TerrainRenderer.cpp b/terrain/TerrainRenderer.cpp index 0b061aa..76cb186 100644 --- a/terrain/TerrainRenderer.cpp +++ b/terrain/TerrainRenderer.cpp @@ -204,19 +204,12 @@ Bounds rescale_uv(const TileId& parent_tile_id, const TileId& tile_id unsigned delta_y = tile_id.y - scaled_root_tile.y; float factor = 1.0f / num_tiles; -#if 1 + + Bounds uv = {glm::vec2((delta_x + 0) * factor, (delta_y + 0) * factor), glm::vec2((delta_x + 1) * factor, (delta_y + 1) * factor)}; -#else - Bounds uv = {glm::vec2(0), glm::vec2(1)}; -#endif - if ((tile_id.zoom == 12U || tile_id.zoom == 11U) && tile_id.x == scaled_root_tile.x) { - // std::cout << tile_id << ": " << uv << std::endl; - // uv.min = glm::vec2(0); - // uv.max = glm::vec2(1); - } return uv; } @@ -242,6 +235,7 @@ TerrainRenderer::TerrainRenderer(const TileId& root_tile, unsigned max_zoom_leve const float min_elevation = 0.0f, max_elevation = 8191.0f; m_height_scaling_factor = (max_elevation - min_elevation); +#if 0 (void)m_tile_cache.tile_texture_sync(m_root_tile, TileType::ORTHO); (void)m_tile_cache.tile_texture_sync(m_root_tile, TileType::HEIGHT); @@ -250,6 +244,7 @@ TerrainRenderer::TerrainRenderer(const TileId& root_tile, unsigned max_zoom_leve (void)m_tile_cache.tile_texture_sync(child, TileType::ORTHO); (void)m_tile_cache.tile_texture_sync(child, TileType::HEIGHT); } + #endif } float TerrainRenderer::terrain_elevation(const glm::vec2& point) @@ -355,8 +350,8 @@ Texture* TerrainRenderer::find_cached_lower_zoom_parent(Node* node, Bounds Date: Sat, 17 Feb 2024 15:16:24 +0100 Subject: [PATCH 02/10] Remove std::span and std::format, as they have not enough compiler support --- collision/Collision.cpp | 13 ------------- collision/Collision.h | 3 --- gfx | 2 +- terrain/CMakeLists.txt | 7 +++++++ terrain/Chunk.cpp | 4 ++-- terrain/Cube.cpp | 2 +- terrain/TerrainRenderer.cpp | 7 ++----- terrain/TileService.cpp | 10 +++++----- terrain/TileUtils.h | 5 +++-- test/test-collision.cpp | 35 ----------------------------------- 10 files changed, 21 insertions(+), 67 deletions(-) diff --git a/collision/Collision.cpp b/collision/Collision.cpp index 9006350..6a11457 100644 --- a/collision/Collision.cpp +++ b/collision/Collision.cpp @@ -8,19 +8,6 @@ AABB AABB::from_center_and_size(const glm::vec3& center, const glm::vec3& size) return AABB(center - half_size, center + half_size); } -AABB AABB::from_points(const std::span& points) -{ - constexpr float float_max = std::numeric_limits::max(); - glm::vec3 min(float_max), max(-float_max); - - for (auto& point : points) { - min = glm::min(min, point); - max = glm::max(max, point); - } - - return AABB(min, max); -} - bool AABB::contains(const AABB& other) { return glm::all(glm::lessThanEqual(min, other.min)) && glm::all(glm::lessThanEqual(other.max, max)); diff --git a/collision/Collision.h b/collision/Collision.h index f76c27e..005907b 100644 --- a/collision/Collision.h +++ b/collision/Collision.h @@ -3,8 +3,6 @@ #include #include #include -#include -#include #define GLM_ENABLE_EXPERIMENTAL #include @@ -19,7 +17,6 @@ struct AABB { std::array vertices() const; bool contains(const AABB &); static AABB from_center_and_size(const glm::vec3 ¢er, const glm::vec3 &size); - static AABB from_points(const std::span &points); template static AABB from_points(It begin, It end) diff --git a/gfx b/gfx index deeda6a..2120b63 160000 --- a/gfx +++ b/gfx @@ -1 +1 @@ -Subproject commit deeda6a73d05f70610efcb400b67153ca4375df4 +Subproject commit 2120b633f22182e5f48f9719656546cec1382c4d diff --git a/terrain/CMakeLists.txt b/terrain/CMakeLists.txt index be83fa0..8846f50 100644 --- a/terrain/CMakeLists.txt +++ b/terrain/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.18) +FetchContent_Declare(fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG e69e5f977d458f2650bb346dadf2ad30c5320281 +) +FetchContent_MakeAvailable(fmt) + add_library(terrain STATIC TileService.cpp TileService.h TileCache.cpp TileCache.h @@ -14,6 +20,7 @@ target_link_libraries(terrain PUBLIC collision gfx cpr::cpr + fmt::fmt ) target_include_directories(terrain PUBLIC diff --git a/terrain/Chunk.cpp b/terrain/Chunk.cpp index b58781e..12b13ea 100644 --- a/terrain/Chunk.cpp +++ b/terrain/Chunk.cpp @@ -76,10 +76,10 @@ Chunk::Chunk(unsigned vertex_count, float size) m_vao->bind(); m_vbo->bind(); - m_vbo->buffer_data(std::span(vertices)); + m_vbo->buffer_data(vertices.data(), Buffer::size_bytes(vertices)); m_ebo->bind(); - m_ebo->buffer_data(std::span(indices)); + m_ebo->buffer_data(indices.data(), Buffer::size_bytes(indices)); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, pos))); glEnableVertexAttribArray(0); diff --git a/terrain/Cube.cpp b/terrain/Cube.cpp index b70f870..d7ac775 100644 --- a/terrain/Cube.cpp +++ b/terrain/Cube.cpp @@ -15,7 +15,7 @@ Cube::Cube() : m_vao(std::make_unique()), m_vbo(std::make_uni m_vao->bind(); m_vbo->bind(); - m_vbo->buffer_data(std::span(vertices)); + m_vbo->buffer_data(vertices.data(), Buffer::size_bytes(vertices)); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), (void*)0); glEnableVertexAttribArray(0); diff --git a/terrain/TerrainRenderer.cpp b/terrain/TerrainRenderer.cpp index 76cb186..f2c80c7 100644 --- a/terrain/TerrainRenderer.cpp +++ b/terrain/TerrainRenderer.cpp @@ -205,12 +205,9 @@ Bounds rescale_uv(const TileId& parent_tile_id, const TileId& tile_id float factor = 1.0f / num_tiles; - Bounds uv = {glm::vec2((delta_x + 0) * factor, (delta_y + 0) * factor), glm::vec2((delta_x + 1) * factor, (delta_y + 1) * factor)}; - - return uv; } @@ -244,7 +241,7 @@ TerrainRenderer::TerrainRenderer(const TileId& root_tile, unsigned max_zoom_leve (void)m_tile_cache.tile_texture_sync(child, TileType::ORTHO); (void)m_tile_cache.tile_texture_sync(child, TileType::HEIGHT); } - #endif +#endif } float TerrainRenderer::terrain_elevation(const glm::vec2& point) @@ -351,7 +348,7 @@ Texture* TerrainRenderer::find_cached_lower_zoom_parent(Node* node, Bounds +#include #include -#include #define LOG_REQUESTS true #define CACHE_ON_DISK true @@ -31,16 +31,16 @@ std::string TileService::tile_url(const TileId& tile) const switch (m_url_pattern) { case ZXY_Y_NORTH: { - return std::format("{}/{}/{}/{}{}", m_url, tile.zoom, tile.x, (num_y_tiles - tile.y - 1), m_filetype); + return fmt::format("{}/{}/{}/{}{}", m_url, tile.zoom, tile.x, (num_y_tiles - tile.y - 1), m_filetype); } case ZYX_Y_NORTH: { - return std::format("{}/{}/{}/{}{}", m_url, tile.zoom, (num_y_tiles - tile.y - 1), tile.x, m_filetype); + return fmt::format("{}/{}/{}/{}{}", m_url, tile.zoom, (num_y_tiles - tile.y - 1), tile.x, m_filetype); } case ZYX_Y_SOUTH: { - return std::format("{}/{}/{}/{}{}", m_url, tile.zoom, tile.y, tile.x, m_filetype); + return fmt::format("{}/{}/{}/{}{}", m_url, tile.zoom, tile.y, tile.x, m_filetype); } case ZXY_Y_SOUTH: { - return std::format("{}/{}/{}/{}{}", m_url, tile.zoom, tile.x, tile.y, m_filetype); + return fmt::format("{}/{}/{}/{}{}", m_url, tile.zoom, tile.x, tile.y, m_filetype); } default: assert(false); diff --git a/terrain/TileUtils.h b/terrain/TileUtils.h index f96d0b8..e9fcbb6 100644 --- a/terrain/TileUtils.h +++ b/terrain/TileUtils.h @@ -1,7 +1,8 @@ #pragma once +#include + #include -#include #include #include @@ -84,7 +85,7 @@ struct TileId { auto operator<=>(const TileId&) const = default; - inline std::string to_string() const { return std::format("{}-{}-{}", zoom, x, y); } + inline std::string to_string() const { return fmt::format("{}-{}-{}", zoom, x, y); } inline Bounds bounds() const { diff --git a/test/test-collision.cpp b/test/test-collision.cpp index 1e7c702..cda0fd9 100644 --- a/test/test-collision.cpp +++ b/test/test-collision.cpp @@ -157,23 +157,6 @@ TEST_CASE("AABB vs Frustum") glm::vec3 center = glm::vec3(0.0f, 0.0f, -5.0f); AABB bb = AABB::from_center_and_size(center, glm::vec3(1.0f)); -#if 0 - auto vertices = frustum.vertices(); - AABB frustum_bb = AABB::from_points(std::span(vertices)); - - - std::cout << "vertices:\n"; - for (auto& v : vertices) std::cout << v << std::endl; - - std::cout << "frustum_bb:\n"; - std::cout << frustum_bb << std::endl; - - std::cout << "bb:\n"; - std::cout << bb << std::endl; - - CHECK(frustum_bb.contains(bb) == true); -#endif - CHECK(point_vs_plane(center, frustum.near()) == true); CHECK(point_vs_plane(center, frustum.far()) == true); @@ -185,24 +168,6 @@ TEST_CASE("AABB vs Frustum") glm::vec3 center = glm::vec3(0.0f, 0.0f, 5.0f); AABB bb = AABB::from_center_and_size(center, glm::vec3(1.0f)); -#if 0 - auto vertices = frustum.vertices(); - AABB frustum_bb = AABB::from_points(std::span(vertices)); - - std::cout << "bb:\n"; - std::cout << bb << std::endl; - - std::cout << "frustum:\n"; - std::cout << frustum << std::endl; - - std::cout << "vertices:\n"; - for (auto& v : vertices) std::cout << v << std::endl; - - std::cout << "frustum_bb:\n"; - std::cout << frustum_bb << std::endl; - CHECK(frustum_bb.contains(bb) == false); -#endif - CHECK(point_vs_plane(center, frustum.near()) == false); CHECK(point_vs_plane(center, frustum.far()) == true); From 70d6794e382ff5985537c2ae1dbdb89a8a254e5d Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 17 Feb 2024 15:34:21 +0100 Subject: [PATCH 03/10] remove std::format --- terrain/TileService.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terrain/TileService.cpp b/terrain/TileService.cpp index 2af30bb..86cfc24 100644 --- a/terrain/TileService.cpp +++ b/terrain/TileService.cpp @@ -50,7 +50,7 @@ std::string TileService::tile_url(const TileId& tile) const std::string TileService::tile_filename(const TileId& tile) const { - return std::format("{}/{}.png", m_cache_dir, tile.to_string()); + return fmt::format("{}/{}.png", m_cache_dir, tile.to_string()); } Image* TileService::get_tile(const TileId& tile) From 6ff890c0880116e578eedadb680bf641b2a2e33b Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 17 Feb 2024 17:00:20 +0100 Subject: [PATCH 04/10] make build more portable --- .gitignore | 6 +++++- README.md | 2 +- app/CMakeLists.txt | 4 +++- terrain/CMakeLists.txt | 3 +++ terrain/Threading.h | 8 ++++---- terrain/TileCache.h | 2 -- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index cee5424..7bbecc7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,11 @@ libraries/ x64/ build/ -build2/ +out/ +tiles/ +tools/ +pre-commit.ps1 *.user CMakeSettings.json NOTES.txt +imgui.ini diff --git a/README.md b/README.md index 8c25b06..dd20353 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This project depends on SDL2, GLM, GLEW and libcpr. You should be able to build in the [cmake.yml](./.github/workflows/cmake.yml). ``` -git clone --recursive git@github.com:gue-ni/TerrainRenderer.git +git clone --recursive https://github.com/gue-ni/TerrainRenderer.git cmake -DCMAKE_BUILD_TYPE=Release -B build cmake --build build --config Release --parallel ``` diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 736bd18..78529e9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -28,7 +28,9 @@ add_executable(app ${imgui_SOURCE} ) -target_link_libraries(app PRIVATE terrain) +target_link_libraries(app PRIVATE + terrain +) target_include_directories(app PRIVATE "${glm_SOURCE_DIR}" diff --git a/terrain/CMakeLists.txt b/terrain/CMakeLists.txt index 8846f50..0d4ae0f 100644 --- a/terrain/CMakeLists.txt +++ b/terrain/CMakeLists.txt @@ -6,6 +6,8 @@ FetchContent_Declare(fmt ) FetchContent_MakeAvailable(fmt) +find_package(Threads REQUIRED) + add_library(terrain STATIC TileService.cpp TileService.h TileCache.cpp TileCache.h @@ -21,6 +23,7 @@ target_link_libraries(terrain PUBLIC gfx cpr::cpr fmt::fmt + Threads::Threads ) target_include_directories(terrain PUBLIC diff --git a/terrain/Threading.h b/terrain/Threading.h index 0cb10cc..31025d8 100644 --- a/terrain/Threading.h +++ b/terrain/Threading.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include #include +#include #include template @@ -27,7 +27,7 @@ class ThreadedQueue { { std::unique_lock lock(m_mutex); - m_queue.push_front(std::move(item)); + m_queue.push(std::move(item)); } m_condition.notify_one(); } @@ -42,7 +42,7 @@ class ThreadedQueue } item = std::move(m_queue.front()); - m_queue.pop_front(); + m_queue.pop(); return true; } @@ -76,7 +76,7 @@ class ThreadedQueue private: bool m_stop = false; - std::deque m_queue; + std::queue m_queue; std::mutex m_mutex; std::condition_variable m_condition; }; diff --git a/terrain/TileCache.h b/terrain/TileCache.h index 1399e55..eed4fce 100644 --- a/terrain/TileCache.h +++ b/terrain/TileCache.h @@ -7,9 +7,7 @@ #include #include -#include #include -#include #include #include "../gfx/gfx.h" From 9394c3cd237b5f565625c15369428956345b2a90 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 17 Feb 2024 19:31:58 +0100 Subject: [PATCH 05/10] read heightmap data from my own server --- README.md | 3 ++- terrain/TerrainRenderer.cpp | 12 ++++++++++-- terrain/TileCache.cpp | 4 +--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dd20353..dced558 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ ![cmake workflow badge](https://github.com/gue-ni/TerrainRenderer/actions/workflows/cmake.yml/badge.svg) -A simple OpenGL Terrain Renderer. +A simple OpenGL Terrain Renderer. Terrain data is provided by [basemap.at](https://basemap.at/) and +[geoland.at](https://www.geoland.at/). ![](assets/Screenshot_2024-02-16_203330.png) diff --git a/terrain/TerrainRenderer.cpp b/terrain/TerrainRenderer.cpp index f2c80c7..3e01d0e 100644 --- a/terrain/TerrainRenderer.cpp +++ b/terrain/TerrainRenderer.cpp @@ -34,6 +34,10 @@ float altitude_from_color(vec4 color) { return (color.r + color.g / 255.0); } +float altitude_from_color_2(vec4 color) { + return color.r; +} + vec2 map_range(vec2 value, vec2 in_min, vec2 in_max, vec2 out_min, vec2 out_max) { return out_min + (value - in_min) * (out_max - out_min) / (in_max - in_min); } @@ -47,7 +51,7 @@ void main() { vec4 height_sample = texture(u_height_texture, scaled_uv); - float height = altitude_from_color(height_sample); + float height = altitude_from_color_2(height_sample); world_pos.y = height * u_height_scaling_factor; @@ -228,8 +232,12 @@ TerrainRenderer::TerrainRenderer(const TileId& root_tile, unsigned max_zoom_leve float tile_width = wms::tile_width(wms::tiley2lat(m_root_tile.y, m_root_tile.zoom), m_root_tile.zoom); m_terrain_scaling_factor = width / tile_width; - // for decoding the height map +// for decoding the height map +#if 0 const float min_elevation = 0.0f, max_elevation = 8191.0f; +#else + const float min_elevation = 0.0f, max_elevation = 3795.0f; +#endif m_height_scaling_factor = (max_elevation - min_elevation); #if 0 diff --git a/terrain/TileCache.cpp b/terrain/TileCache.cpp index 4f99211..2e3d886 100644 --- a/terrain/TileCache.cpp +++ b/terrain/TileCache.cpp @@ -13,9 +13,7 @@ TileCache::TileCache() m_ortho_service("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile", UrlPattern::ZYX_Y_SOUTH, "", "tiles/ortho-2"), #endif - m_height_service("https://alpinemaps.cg.tuwien.ac.at/tiles/alpine_png", UrlPattern::ZXY_Y_NORTH, ".png", - "tiles/height") - + m_height_service("https://www.jakobmaier.at/blob/big-tiles-2", UrlPattern::ZXY_Y_NORTH, ".png", "tiles/height-2") { } From 7cb0930b1775645bc875b244a8c8e3c04b404e4a Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 19 Feb 2024 18:51:46 +0100 Subject: [PATCH 06/10] refactoring --- .gitignore | 2 +- gfx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7bbecc7..c57071b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ x64/ build/ out/ tiles/ -tools/ +doc/ pre-commit.ps1 *.user CMakeSettings.json diff --git a/gfx b/gfx index 2120b63..adc2c6c 160000 --- a/gfx +++ b/gfx @@ -1 +1 @@ -Subproject commit 2120b633f22182e5f48f9719656546cec1382c4d +Subproject commit adc2c6ceca5f09aef7d439c418909326bb91be02 From 73de25f51672966816579ea4f6d9029b8c6bd1dc Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 19 Feb 2024 19:51:09 +0100 Subject: [PATCH 07/10] Add get_tile_cached() --- terrain/TileCache.cpp | 2 +- terrain/TileService.cpp | 9 +++++++++ terrain/TileService.h | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/terrain/TileCache.cpp b/terrain/TileCache.cpp index 2e3d886..dfa3ef0 100644 --- a/terrain/TileCache.cpp +++ b/terrain/TileCache.cpp @@ -13,7 +13,7 @@ TileCache::TileCache() m_ortho_service("https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile", UrlPattern::ZYX_Y_SOUTH, "", "tiles/ortho-2"), #endif - m_height_service("https://www.jakobmaier.at/blob/big-tiles-2", UrlPattern::ZXY_Y_NORTH, ".png", "tiles/height-2") + m_height_service("https://www.jakobmaier.at/blob/dem-tiles", UrlPattern::ZXY_Y_NORTH, ".png", "tiles/height-1") { } diff --git a/terrain/TileService.cpp b/terrain/TileService.cpp index 86cfc24..31539c8 100644 --- a/terrain/TileService.cpp +++ b/terrain/TileService.cpp @@ -81,6 +81,15 @@ Image* TileService::get_tile_sync(const TileId& tile) return m_ram_cache[tile].get(); } +Image* TileService::get_tile_cached(const TileId& tile) +{ + if (m_ram_cache.contains(tile)) { + return m_ram_cache[tile].get(); + } else { + return nullptr; + } +} + void TileService::request_tile(const TileId& tile) { m_already_requested.insert(tile); diff --git a/terrain/TileService.h b/terrain/TileService.h index 5171839..afd82a1 100644 --- a/terrain/TileService.h +++ b/terrain/TileService.h @@ -30,6 +30,8 @@ class TileService // Download tile and return it. Image* get_tile_sync(const TileId&); + Image* get_tile_cached(const TileId&); + private: const UrlPattern m_url_pattern; const std::string m_url, m_filetype, m_cache_dir; From c1e770158ea8cc3ce26e4aeb2c1c55a154dace6d Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 19 Feb 2024 19:56:34 +0100 Subject: [PATCH 08/10] Add simple TileService test --- test/CMakeLists.txt | 5 +++++ test/test-terrain.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 99f2743..8fbd531 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,11 @@ add_executable(tests test-terrain.cpp ) +if(CMAKE_COMPILER_IS_GNUCC) + target_link_options(tests PRIVATE -fsanitize=thread) + target_compile_options(tests PRIVATE -fsanitize=thread) +endif() + target_link_libraries(tests PRIVATE Catch2::Catch2WithMain collision terrain) if(WIN32) diff --git a/test/test-terrain.cpp b/test/test-terrain.cpp index 434b39e..9f382d5 100644 --- a/test/test-terrain.cpp +++ b/test/test-terrain.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "Common.h" @@ -7,3 +8,36 @@ #define GLM_ENABLE_EXPERIMENTAL #include + +TEST_CASE("TileService") +{ + const std::string cache = "tiles/ortho-cache-test"; + const std::string url = "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile"; + const UrlPattern pattern = UrlPattern::ZYX_Y_SOUTH; + + try { + std::filesystem::remove_all(cache); + } catch (const std::exception& e) { + std::cerr << e.what() << std::endl; + } + + TileService tile_service(url, pattern, "", cache); + + std::vector tiles = { + TileId(0u, 0u, 0u), + TileId(1u, 0u, 0u), + TileId(2u, 0u, 0u), + TileId(3u, 0u, 0u), + }; + + for (auto& tile : tiles) { + Image* image = tile_service.get_tile(tile); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(3000)); + + for (auto& tile : tiles) { + Image* image = tile_service.get_tile_cached(tile); + // CHECK(image != nullptr); + } +} From 0cf27d3c9eae5986c5e9e2d4f23366ff6ef12cd1 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 19 Feb 2024 20:24:54 +0100 Subject: [PATCH 09/10] rename files --- test/CMakeLists.txt | 6 +++--- test/{test-collision.cpp => test_collision.cpp} | 0 test/{test-quadtree.cpp => test_quadtree.cpp} | 0 test/{test-terrain.cpp => test_terrain.cpp} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename test/{test-collision.cpp => test_collision.cpp} (100%) rename test/{test-quadtree.cpp => test_quadtree.cpp} (100%) rename test/{test-terrain.cpp => test_terrain.cpp} (100%) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8fbd531..84bbfa7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,9 +11,9 @@ FetchContent_Declare( FetchContent_MakeAvailable(Catch2) add_executable(tests - test-collision.cpp - test-quadtree.cpp - test-terrain.cpp + test_collision.cpp + test_quadtree.cpp + test_terrain.cpp ) if(CMAKE_COMPILER_IS_GNUCC) diff --git a/test/test-collision.cpp b/test/test_collision.cpp similarity index 100% rename from test/test-collision.cpp rename to test/test_collision.cpp diff --git a/test/test-quadtree.cpp b/test/test_quadtree.cpp similarity index 100% rename from test/test-quadtree.cpp rename to test/test_quadtree.cpp diff --git a/test/test-terrain.cpp b/test/test_terrain.cpp similarity index 100% rename from test/test-terrain.cpp rename to test/test_terrain.cpp From f07e9df400d9c4ca28af8142e088d3162e91af90 Mon Sep 17 00:00:00 2001 From: Jakob Date: Mon, 19 Feb 2024 20:26:02 +0100 Subject: [PATCH 10/10] Update test_terrain.cpp --- test/test_terrain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_terrain.cpp b/test/test_terrain.cpp index 9f382d5..fdb9c60 100644 --- a/test/test_terrain.cpp +++ b/test/test_terrain.cpp @@ -38,6 +38,6 @@ TEST_CASE("TileService") for (auto& tile : tiles) { Image* image = tile_service.get_tile_cached(tile); - // CHECK(image != nullptr); + CHECK(image != nullptr); } }