From 11b82bded303dfd620527b8f2086d8868ebb2171 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 9 Aug 2021 17:16:05 +0200 Subject: [PATCH] Removed the old TexturePacker based api from PropCache. --- prop_instance_merger.cpp | 13 +++- singleton/prop_cache.cpp | 141 --------------------------------------- singleton/prop_cache.h | 28 -------- 3 files changed, 10 insertions(+), 172 deletions(-) diff --git a/prop_instance_merger.cpp b/prop_instance_merger.cpp index ea9ee2d..035d476 100644 --- a/prop_instance_merger.cpp +++ b/prop_instance_merger.cpp @@ -410,15 +410,22 @@ void PropInstanceMerger::_build() { return; } -#if TEXTURE_PACKER_PRESENT - Ref packer = PropCache::get_singleton()->get_or_create_texture_threaded(_prop_data); +//! +//job->cache +//this->cache +//job->cache = cache +//job -> if !has cache query -> buildings can use this to only have one material per building +//move this to job +#if TEXTURE_PACKER_PRESENT + Ref packer; // = PropCache::get_singleton()->get_or_create_texture_threaded(_prop_data); + /* if (packer->get_generated_texture_count() == 0) { _building = false; _build_queued = true; return; } - +*/ _job->set_texture_packer(packer); #endif diff --git a/singleton/prop_cache.cpp b/singleton/prop_cache.cpp index 9966a81..3b15a54 100644 --- a/singleton/prop_cache.cpp +++ b/singleton/prop_cache.cpp @@ -41,10 +41,6 @@ SOFTWARE. #include "../../thread_pool/thread_pool.h" #endif -#if TEXTURE_PACKER_PRESENT -#include "../../texture_packer/texture_packer.h" -#endif - #include "../material_cache/prop_material_cache.h" #include "core/hashfuncs.h" @@ -133,126 +129,6 @@ void PropCache::material_cache_custom_key_unref(const uint64_t key) { _custom_keyed_material_cache_mutex.unlock(); } -#if TEXTURE_PACKER_PRESENT -bool PropCache::has_texture(const Ref &prop) { - for (int i = 0; i < _entries.size(); ++i) { - if (_entries[i].prop == prop) { - return true; - } - } - - return false; -} - -void PropCache::set_texture(const Ref &prop, const Ref &merger) { - for (int i = 0; i < _entries.size(); ++i) { - PropCacheEntry &e = _entries.write[i]; - - if (e.prop == prop) { - e.merger = merger; - } - } -} - -Ref PropCache::get_texture(const Ref &prop) { - for (int i = 0; i < _entries.size(); ++i) { - PropCacheEntry &e = _entries.write[i]; - - if (e.prop == prop) { - e.refcount++; - - return e.merger; - } - } - - return Ref(); -} - -void PropCache::ref_texture(const Ref &prop) { - for (int i = 0; i < _entries.size(); ++i) { - PropCacheEntry &e = _entries.write[i]; - - if (e.prop == prop) { - e.refcount++; - - return; - } - } -} - -void PropCache::unref_texture(const Ref &prop) { - for (int i = 0; i < _entries.size(); ++i) { - PropCacheEntry &e = _entries.write[i]; - - if (e.prop == prop) { - e.refcount--; - - if (e.refcount <= 0) { - _entries.remove(i); - } - - return; - } - } -} - -Ref PropCache::create_texture(const Ref &prop) { - ERR_FAIL_COND_V(has_texture(prop), Ref()); - - Ref merger; - merger.instance(); - - for (int i = 0; i < prop->get_prop_count(); ++i) { - Ref e = prop->get_prop(i); - - e->add_textures_into(merger); - } - - PropCacheEntry e; - e.merger = merger; - e.prop = prop; - e.refcount = 1; - - _entries.push_back(e); - - return merger; -} - -Ref PropCache::get_or_create_texture_immediate(const Ref &prop) { - if (!has_texture(prop)) { - Ref merger = create_texture(prop); - - merger->merge(); - - return merger; - } - - return get_texture(prop); -} - -Ref PropCache::get_or_create_texture_threaded(const Ref &prop) { -#if THREAD_POOL_PRESENT - - if (!has_texture(prop)) { - Ref merger = create_texture(prop); - - Ref job; - job.instance(); - job->set_merger(merger); - ThreadPool::get_singleton()->add_job(job); - - return merger; - } - - return get_texture(prop); - -#else - return get_or_create_texture_immediate(prop); -#endif -} - -#endif - PropCache::PropCache() { _instance = this; @@ -265,27 +141,10 @@ PropCache::PropCache() { PropCache::~PropCache() { _instance = NULL; -#if TEXTURE_PACKER_PRESENT - _entries.clear(); -#endif } void PropCache::_bind_methods() { ClassDB::bind_method(D_METHOD("get_default_prop_material_cache_class"), &PropCache::get_default_prop_material_cache_class); ClassDB::bind_method(D_METHOD("set_default_prop_material_cache_class", "cls_name"), &PropCache::set_default_prop_material_cache_class); ADD_PROPERTY(PropertyInfo(Variant::STRING, "default_prop_material_cache_class"), "set_default_prop_material_cache_class", "get_default_prop_material_cache_class"); - -#if TEXTURE_PACKER_PRESENT - ClassDB::bind_method(D_METHOD("has_texture", "prop"), &PropCache::has_texture); - ClassDB::bind_method(D_METHOD("set_texture", "prop", "merger"), &PropCache::set_texture); - - ClassDB::bind_method(D_METHOD("get_texture", "prop"), &PropCache::get_texture); - - ClassDB::bind_method(D_METHOD("ref_texture", "prop"), &PropCache::ref_texture); - ClassDB::bind_method(D_METHOD("unref_texture", "prop"), &PropCache::unref_texture); - - ClassDB::bind_method(D_METHOD("create_texture", "prop"), &PropCache::create_texture); - ClassDB::bind_method(D_METHOD("get_or_create_texture_immediate", "prop"), &PropCache::get_or_create_texture_immediate); - ClassDB::bind_method(D_METHOD("get_or_create_texture_threaded", "prop"), &PropCache::get_or_create_texture_threaded); -#endif } diff --git a/singleton/prop_cache.h b/singleton/prop_cache.h index 26e368a..95acd8d 100644 --- a/singleton/prop_cache.h +++ b/singleton/prop_cache.h @@ -41,23 +41,11 @@ SOFTWARE. #include "../props/prop_data.h" -#if TEXTURE_PACKER_PRESENT -class TexturePacker; -#endif - class PropMaterialCache; class PropCache : public Object { GDCLASS(PropCache, Object); -#if TEXTURE_PACKER_PRESENT -public: - struct PropCacheEntry { - int refcount; - Ref merger; - Ref prop; - }; - public: static PropCache *get_singleton(); @@ -70,25 +58,9 @@ public: Ref material_cache_custom_key_get(const uint64_t key); void material_cache_custom_key_unref(const uint64_t key); - bool has_texture(const Ref &prop); - void set_texture(const Ref &prop, const Ref &merger); - - Ref get_texture(const Ref &prop); - - void ref_texture(const Ref &prop); - void unref_texture(const Ref &prop); - - Ref create_texture(const Ref &prop); - Ref get_or_create_texture_immediate(const Ref &prop); - Ref get_or_create_texture_threaded(const Ref &prop); - private: - Vector _entries; - static PropCache *_instance; -#endif - public: PropCache(); ~PropCache();