From aac29607595631ccc4b010865270baa1483c3b9b Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Mon, 17 Jun 2024 23:17:07 +0200 Subject: [PATCH] minor update --- src/noggit/AsyncLoader.cpp | 10 +++++++++- src/noggit/map_index.cpp | 4 +++- src/noggit/project/ApplicationProjectWriter.cpp | 1 - src/noggit/rendering/WMOGroupRender.cpp | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/noggit/AsyncLoader.cpp b/src/noggit/AsyncLoader.cpp index 489aa03a..f9a29948 100755 --- a/src/noggit/AsyncLoader.cpp +++ b/src/noggit/AsyncLoader.cpp @@ -99,6 +99,7 @@ void AsyncLoader::process() std::lock_guard const lock(_guard); object->error_on_loading(); + LogError << "Caught unknown error." << std::endl; if (object->is_required_when_saving()) { @@ -144,6 +145,10 @@ void AsyncLoader::ensure_deletable (AsyncObject* object) AsyncLoader::AsyncLoader(int numThreads) : _stop (false) { + // use half of the available threads + unsigned int maxThreads = std::thread::hardware_concurrency() / 2; + numThreads = maxThreads > numThreads ? maxThreads : numThreads; + for (int i = 0; i < numThreads; ++i) { _threads.emplace_back (&AsyncLoader::process, this); @@ -152,7 +157,10 @@ AsyncLoader::AsyncLoader(int numThreads) AsyncLoader::~AsyncLoader() { - _stop = true; + { + std::unique_lock lock(_guard); + _stop = true; + } _state_changed.notify_all(); for (auto& thread : _threads) diff --git a/src/noggit/map_index.cpp b/src/noggit/map_index.cpp index ee39343c..4073862f 100755 --- a/src/noggit/map_index.cpp +++ b/src/noggit/map_index.cpp @@ -423,10 +423,12 @@ void MapIndex::unloadTiles(const TileIndex& tile) void MapIndex::unloadTile(const TileIndex& tile) { - // unloads a tile with givn cords + // unloads a tile with given cords if (tileLoaded(tile)) { Log << "Unload Tile " << tile.x << "-" << tile.z << std::endl; + + AsyncLoader::instance().ensure_deletable(mTiles[tile.z][tile.x].tile.get()); mTiles[tile.z][tile.x].tile = nullptr; _n_loaded_tiles--; } diff --git a/src/noggit/project/ApplicationProjectWriter.cpp b/src/noggit/project/ApplicationProjectWriter.cpp index 2a445140..701209a4 100755 --- a/src/noggit/project/ApplicationProjectWriter.cpp +++ b/src/noggit/project/ApplicationProjectWriter.cpp @@ -9,7 +9,6 @@ #include #include #include -#include namespace Noggit::Project { diff --git a/src/noggit/rendering/WMOGroupRender.cpp b/src/noggit/rendering/WMOGroupRender.cpp index c995920b..9a2c29ab 100755 --- a/src/noggit/rendering/WMOGroupRender.cpp +++ b/src/noggit/rendering/WMOGroupRender.cpp @@ -2,6 +2,7 @@ #include "WMOGroupRender.hpp" #include +#include // LogDebug using namespace Noggit::Rendering; @@ -346,6 +347,8 @@ void WMOGroupRender::initRenderBatches() _render_batch_mapping[batch.vertex_start + i] = static_cast(batch_counter + 1); } } + else + LogError << "WMO has incorrect render batch data. batch.vertex_end < batch.vertex_start" << std::endl; std::uint32_t flags = 0;