Removed the old TexturePacker based api from PropCache.

This commit is contained in:
Relintai 2021-08-09 17:16:05 +02:00
parent b15ac01225
commit 11b82bded3
3 changed files with 10 additions and 172 deletions

View File

@ -410,15 +410,22 @@ void PropInstanceMerger::_build() {
return;
}
#if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> 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<TexturePacker> 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

View File

@ -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<PropData> &prop) {
for (int i = 0; i < _entries.size(); ++i) {
if (_entries[i].prop == prop) {
return true;
}
}
return false;
}
void PropCache::set_texture(const Ref<PropData> &prop, const Ref<TexturePacker> &merger) {
for (int i = 0; i < _entries.size(); ++i) {
PropCacheEntry &e = _entries.write[i];
if (e.prop == prop) {
e.merger = merger;
}
}
}
Ref<TexturePacker> PropCache::get_texture(const Ref<PropData> &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<TexturePacker>();
}
void PropCache::ref_texture(const Ref<PropData> &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<PropData> &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<TexturePacker> PropCache::create_texture(const Ref<PropData> &prop) {
ERR_FAIL_COND_V(has_texture(prop), Ref<TexturePacker>());
Ref<TexturePacker> merger;
merger.instance();
for (int i = 0; i < prop->get_prop_count(); ++i) {
Ref<PropDataEntry> 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<TexturePacker> PropCache::get_or_create_texture_immediate(const Ref<PropData> &prop) {
if (!has_texture(prop)) {
Ref<TexturePacker> merger = create_texture(prop);
merger->merge();
return merger;
}
return get_texture(prop);
}
Ref<TexturePacker> PropCache::get_or_create_texture_threaded(const Ref<PropData> &prop) {
#if THREAD_POOL_PRESENT
if (!has_texture(prop)) {
Ref<TexturePacker> merger = create_texture(prop);
Ref<PropTextureJob> 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
}

View File

@ -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<TexturePacker> merger;
Ref<PropData> prop;
};
public:
static PropCache *get_singleton();
@ -70,25 +58,9 @@ public:
Ref<PropMaterialCache> material_cache_custom_key_get(const uint64_t key);
void material_cache_custom_key_unref(const uint64_t key);
bool has_texture(const Ref<PropData> &prop);
void set_texture(const Ref<PropData> &prop, const Ref<TexturePacker> &merger);
Ref<TexturePacker> get_texture(const Ref<PropData> &prop);
void ref_texture(const Ref<PropData> &prop);
void unref_texture(const Ref<PropData> &prop);
Ref<TexturePacker> create_texture(const Ref<PropData> &prop);
Ref<TexturePacker> get_or_create_texture_immediate(const Ref<PropData> &prop);
Ref<TexturePacker> get_or_create_texture_threaded(const Ref<PropData> &prop);
private:
Vector<PropCacheEntry> _entries;
static PropCache *_instance;
#endif
public:
PropCache();
~PropCache();