diff -r e6faeffed1d1 -r b4beff48bb7a src/polygoncache.cpp --- a/src/polygoncache.cpp Wed May 25 17:25:24 2022 +0300 +++ b/src/polygoncache.cpp Wed May 25 17:42:02 2022 +0300 @@ -1,14 +1,11 @@ #include "polygoncache.h" #include "documentmanager.h" -PolygonCache::PolygonCache(Model *model) : - model{model} -{ - const auto mark = [this](){ this->needRecache = true; }; - connect(model, &Model::dataChanged, mark); - connect(model, &Model::rowsInserted, mark); - connect(model, &Model::rowsRemoved, mark); -} +static void getObjectPolygons( + Model* model, + const int index, + std::vector& polygons_out, + ldraw::GetPolygonsContext* context); /** * @brief Gets a list of GL polygons that are used to represent this model. @@ -16,23 +13,26 @@ * @param documents Documents to use to resolve subfile references * @return vector of GL polygons */ -const std::vector &PolygonCache::getPolygons(DocumentManager* documents) +const std::vector &getCachedPolygons( + PolygonCache *cache, + Model *model, + DocumentManager *documents) { - if (this->needRecache) + if (cache->needRecache) { - this->cachedPolygons.clear(); - const std::optional modelId = documents->findIdForModel(this->model); + cache->cachedPolygons.clear(); + const std::optional modelId = documents->findIdForModel(model); if (modelId.has_value()) { ldraw::GetPolygonsContext context{modelId.value(), documents}; - for (int i = 0; i < this->model->size(); i += 1) + for (int i = 0; i < model->size(); i += 1) { - this->getObjectPolygons(i, this->cachedPolygons, &context); + getObjectPolygons(model, i, cache->cachedPolygons, &context); } } - this->needRecache = false; + cache->needRecache = false; } - return this->cachedPolygons; + return cache->cachedPolygons; } /** @@ -41,11 +41,12 @@ * @param polygons_out Vector to add polygons into * @param context Context to use to resolve subfile references */ -void PolygonCache::getObjectPolygons( +static void getObjectPolygons( + Model* model, const int index, std::vector& polygons_out, - ldraw::GetPolygonsContext* context) const + ldraw::GetPolygonsContext* context) { - const ldraw::Object* object = (*this->model)[unsigned_cast(index)]; + const ldraw::Object* object = (*model)[unsigned_cast(index)]; object->getPolygons(polygons_out, context); }