From e8985175b2b891ad8b78c0b234b9ff0fa18eb85d Mon Sep 17 00:00:00 2001 From: T1ti <40864460+T1ti@users.noreply.github.com> Date: Tue, 1 Oct 2024 06:05:18 +0200 Subject: [PATCH] new functions to track tile children loading state --- src/noggit/MapTile.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++ src/noggit/MapTile.h | 7 ++++++ 2 files changed, 57 insertions(+) diff --git a/src/noggit/MapTile.cpp b/src/noggit/MapTile.cpp index e04952cf..1ee8f318 100755 --- a/src/noggit/MapTile.cpp +++ b/src/noggit/MapTile.cpp @@ -1776,6 +1776,56 @@ void MapTile::calcCamDist(glm::vec3 const& camera) _cam_dist = glm::distance(camera, _center); } +bool MapTile::childrenFinishedLoading() +{ + if (!objectsFinishedLoading()) + return false; + + if (!texturesFinishedLoading()) + return false; + + return true; +} + +// TODO : Is there a way for objects to notify their parent when they finish loading ? +// TODO : we can store a cache of unloaded models/textures to check fast instead of re iterating everything. +bool MapTile::texturesFinishedLoading() +{ + if (_textures_finished_loading) + return true; + + // having a list of textures in the adt would speed this up + for (int i = 0; i < 16; ++i) + { + for (int j = 0; j < 16; ++j) + { + auto& chunk = *mChunks[j][i]; + auto& chunk_textures = *(chunk.texture_set->getTextures()); + for (int k = 0; k < chunk.texture_set->num(); ++k) + { + if (!chunk_textures[k]->finishedLoading()) + return false; + } + } + } + + return _textures_finished_loading = true; +} + +bool MapTile::objectsFinishedLoading() +{ + if (_objects_finished_loading) + return true; + + for (auto& instance : object_instances) + { + if (!instance.first->finishedLoading()) + return false; + } + + return _objects_finished_loading = true; +} + void MapTile::recalcCombinedExtents() { if (!_combined_extents_dirty) diff --git a/src/noggit/MapTile.h b/src/noggit/MapTile.h index bfce7db4..8dbf92da 100755 --- a/src/noggit/MapTile.h +++ b/src/noggit/MapTile.h @@ -177,6 +177,10 @@ public: Noggit::Rendering::TileRender* renderer() { return &_renderer; }; Noggit::Rendering::FlightBoundsRender* flightBoundsRenderer() { return &_fl_bounds_render; }; + bool childrenFinishedLoading(); + bool texturesFinishedLoading(); + bool objectsFinishedLoading(); + private: tile_mode _mode; @@ -199,6 +203,9 @@ private: unsigned _chunk_update_flags; + bool _textures_finished_loading = false; + bool _objects_finished_loading = false; + // MHDR: int mFlags = 0; bool mBigAlpha;