Renamed the PropTextureCache singleton to PropCache.

This commit is contained in:
Relintai 2021-08-09 15:57:21 +02:00
parent fca5abaa5d
commit fea813eae3
5 changed files with 45 additions and 45 deletions

2
SCsub
View File

@ -45,7 +45,7 @@ sources = [
"prop_scene_instance.cpp", "prop_scene_instance.cpp",
"singleton/prop_utils.cpp", "singleton/prop_utils.cpp",
"singleton/prop_texture_cache.cpp", "singleton/prop_cache.cpp",
"editor/prop_editor_plugin.cpp", "editor/prop_editor_plugin.cpp",

View File

@ -50,7 +50,7 @@ typedef class RenderingServer VS;
#include "./props/prop_data_scene.h" #include "./props/prop_data_scene.h"
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
#include "./singleton/prop_texture_cache.h" #include "./singleton/prop_cache.h"
#endif #endif
#if THREAD_POOL_PRESENT #if THREAD_POOL_PRESENT
@ -411,7 +411,7 @@ void PropInstanceMerger::_build() {
} }
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
Ref<TexturePacker> packer = PropTextureCache::get_singleton()->get_or_create_texture_threaded(_prop_data); Ref<TexturePacker> packer = PropCache::get_singleton()->get_or_create_texture_threaded(_prop_data);
if (packer->get_generated_texture_count() == 0) { if (packer->get_generated_texture_count() == 0) {
_building = false; _building = false;

View File

@ -51,7 +51,7 @@ SOFTWARE.
#include "prop_scene_instance.h" #include "prop_scene_instance.h"
#include "singleton/prop_texture_cache.h" #include "singleton/prop_cache.h"
#include "singleton/prop_utils.h" #include "singleton/prop_utils.h"
#include "./editor/prop_editor_plugin.h" #include "./editor/prop_editor_plugin.h"
@ -65,7 +65,7 @@ SOFTWARE.
#endif #endif
static PropUtils *prop_utils = NULL; static PropUtils *prop_utils = NULL;
static PropTextureCache *prop_texture_cache = NULL; static PropCache *prop_texture_cache = NULL;
void register_props_types() { void register_props_types() {
ClassDB::register_class<PropData>(); ClassDB::register_class<PropData>();
@ -102,9 +102,9 @@ void register_props_types() {
ClassDB::register_class<PropUtils>(); ClassDB::register_class<PropUtils>();
Engine::get_singleton()->add_singleton(Engine::Singleton("PropUtils", PropUtils::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("PropUtils", PropUtils::get_singleton()));
prop_texture_cache = memnew(PropTextureCache); prop_texture_cache = memnew(PropCache);
ClassDB::register_class<PropTextureCache>(); ClassDB::register_class<PropCache>();
Engine::get_singleton()->add_singleton(Engine::Singleton("PropTextureCache", PropTextureCache::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("PropCache", PropCache::get_singleton()));
Ref<PropDataLight> light_processor = Ref<PropDataLight>(memnew(PropDataLight)); Ref<PropDataLight> light_processor = Ref<PropDataLight>(memnew(PropDataLight));
PropUtils::add_processor(light_processor); PropUtils::add_processor(light_processor);

View File

@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include "prop_texture_cache.h" #include "prop_cache.h"
#include "../props/prop_data.h" #include "../props/prop_data.h"
#include "../props/prop_data_entry.h" #include "../props/prop_data_entry.h"
@ -43,14 +43,14 @@ SOFTWARE.
#include "../../texture_packer/texture_packer.h" #include "../../texture_packer/texture_packer.h"
#endif #endif
PropTextureCache *PropTextureCache::_instance; PropCache *PropCache::_instance;
PropTextureCache *PropTextureCache::get_singleton() { PropCache *PropCache::get_singleton() {
return _instance; return _instance;
} }
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
bool PropTextureCache::has_texture(const Ref<PropData> &prop) { bool PropCache::has_texture(const Ref<PropData> &prop) {
for (int i = 0; i < _entries.size(); ++i) { for (int i = 0; i < _entries.size(); ++i) {
if (_entries[i].prop == prop) { if (_entries[i].prop == prop) {
return true; return true;
@ -60,9 +60,9 @@ bool PropTextureCache::has_texture(const Ref<PropData> &prop) {
return false; return false;
} }
void PropTextureCache::set_texture(const Ref<PropData> &prop, const Ref<TexturePacker> &merger) { void PropCache::set_texture(const Ref<PropData> &prop, const Ref<TexturePacker> &merger) {
for (int i = 0; i < _entries.size(); ++i) { for (int i = 0; i < _entries.size(); ++i) {
PropTextureCacheEntry &e = _entries.write[i]; PropCacheEntry &e = _entries.write[i];
if (e.prop == prop) { if (e.prop == prop) {
e.merger = merger; e.merger = merger;
@ -70,9 +70,9 @@ void PropTextureCache::set_texture(const Ref<PropData> &prop, const Ref<TextureP
} }
} }
Ref<TexturePacker> PropTextureCache::get_texture(const Ref<PropData> &prop) { Ref<TexturePacker> PropCache::get_texture(const Ref<PropData> &prop) {
for (int i = 0; i < _entries.size(); ++i) { for (int i = 0; i < _entries.size(); ++i) {
PropTextureCacheEntry &e = _entries.write[i]; PropCacheEntry &e = _entries.write[i];
if (e.prop == prop) { if (e.prop == prop) {
e.refcount++; e.refcount++;
@ -84,9 +84,9 @@ Ref<TexturePacker> PropTextureCache::get_texture(const Ref<PropData> &prop) {
return Ref<TexturePacker>(); return Ref<TexturePacker>();
} }
void PropTextureCache::ref_texture(const Ref<PropData> &prop) { void PropCache::ref_texture(const Ref<PropData> &prop) {
for (int i = 0; i < _entries.size(); ++i) { for (int i = 0; i < _entries.size(); ++i) {
PropTextureCacheEntry &e = _entries.write[i]; PropCacheEntry &e = _entries.write[i];
if (e.prop == prop) { if (e.prop == prop) {
e.refcount++; e.refcount++;
@ -96,9 +96,9 @@ void PropTextureCache::ref_texture(const Ref<PropData> &prop) {
} }
} }
void PropTextureCache::unref_texture(const Ref<PropData> &prop) { void PropCache::unref_texture(const Ref<PropData> &prop) {
for (int i = 0; i < _entries.size(); ++i) { for (int i = 0; i < _entries.size(); ++i) {
PropTextureCacheEntry &e = _entries.write[i]; PropCacheEntry &e = _entries.write[i];
if (e.prop == prop) { if (e.prop == prop) {
e.refcount--; e.refcount--;
@ -112,7 +112,7 @@ void PropTextureCache::unref_texture(const Ref<PropData> &prop) {
} }
} }
Ref<TexturePacker> PropTextureCache::create_texture(const Ref<PropData> &prop) { Ref<TexturePacker> PropCache::create_texture(const Ref<PropData> &prop) {
ERR_FAIL_COND_V(has_texture(prop), Ref<TexturePacker>()); ERR_FAIL_COND_V(has_texture(prop), Ref<TexturePacker>());
Ref<TexturePacker> merger; Ref<TexturePacker> merger;
@ -124,7 +124,7 @@ Ref<TexturePacker> PropTextureCache::create_texture(const Ref<PropData> &prop) {
e->add_textures_into(merger); e->add_textures_into(merger);
} }
PropTextureCacheEntry e; PropCacheEntry e;
e.merger = merger; e.merger = merger;
e.prop = prop; e.prop = prop;
e.refcount = 1; e.refcount = 1;
@ -134,7 +134,7 @@ Ref<TexturePacker> PropTextureCache::create_texture(const Ref<PropData> &prop) {
return merger; return merger;
} }
Ref<TexturePacker> PropTextureCache::get_or_create_texture_immediate(const Ref<PropData> &prop) { Ref<TexturePacker> PropCache::get_or_create_texture_immediate(const Ref<PropData> &prop) {
if (!has_texture(prop)) { if (!has_texture(prop)) {
Ref<TexturePacker> merger = create_texture(prop); Ref<TexturePacker> merger = create_texture(prop);
@ -147,7 +147,7 @@ Ref<TexturePacker> PropTextureCache::get_or_create_texture_immediate(const Ref<P
return get_texture(prop); return get_texture(prop);
} }
Ref<TexturePacker> PropTextureCache::get_or_create_texture_threaded(const Ref<PropData> &prop) { Ref<TexturePacker> PropCache::get_or_create_texture_threaded(const Ref<PropData> &prop) {
#if THREAD_POOL_PRESENT #if THREAD_POOL_PRESENT
if (!has_texture(prop)) { if (!has_texture(prop)) {
@ -171,29 +171,29 @@ Ref<TexturePacker> PropTextureCache::get_or_create_texture_threaded(const Ref<Pr
#endif #endif
PropTextureCache::PropTextureCache() { PropCache::PropCache() {
_instance = this; _instance = this;
} }
PropTextureCache::~PropTextureCache() { PropCache::~PropCache() {
_instance = NULL; _instance = NULL;
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
_entries.clear(); _entries.clear();
#endif #endif
} }
void PropTextureCache::_bind_methods() { void PropCache::_bind_methods() {
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
ClassDB::bind_method(D_METHOD("has_texture", "prop"), &PropTextureCache::has_texture); ClassDB::bind_method(D_METHOD("has_texture", "prop"), &PropCache::has_texture);
ClassDB::bind_method(D_METHOD("set_texture", "prop", "merger"), &PropTextureCache::set_texture); ClassDB::bind_method(D_METHOD("set_texture", "prop", "merger"), &PropCache::set_texture);
ClassDB::bind_method(D_METHOD("get_texture", "prop"), &PropTextureCache::get_texture); ClassDB::bind_method(D_METHOD("get_texture", "prop"), &PropCache::get_texture);
ClassDB::bind_method(D_METHOD("ref_texture", "prop"), &PropTextureCache::ref_texture); ClassDB::bind_method(D_METHOD("ref_texture", "prop"), &PropCache::ref_texture);
ClassDB::bind_method(D_METHOD("unref_texture", "prop"), &PropTextureCache::unref_texture); ClassDB::bind_method(D_METHOD("unref_texture", "prop"), &PropCache::unref_texture);
ClassDB::bind_method(D_METHOD("create_texture", "prop"), &PropTextureCache::create_texture); ClassDB::bind_method(D_METHOD("create_texture", "prop"), &PropCache::create_texture);
ClassDB::bind_method(D_METHOD("get_or_create_texture_immediate", "prop"), &PropTextureCache::get_or_create_texture_immediate); 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"), &PropTextureCache::get_or_create_texture_threaded); ClassDB::bind_method(D_METHOD("get_or_create_texture_threaded", "prop"), &PropCache::get_or_create_texture_threaded);
#endif #endif
} }

View File

@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#ifndef PROP_TEXTURE_CACHE_H #ifndef PROP_CACHE_H
#define PROP_TEXTURE_CACHE_H #define PROP_CACHE_H
#include "core/version.h" #include "core/version.h"
@ -43,19 +43,19 @@ SOFTWARE.
class TexturePacker; class TexturePacker;
#endif #endif
class PropTextureCache : public Object { class PropCache : public Object {
GDCLASS(PropTextureCache, Object); GDCLASS(PropCache, Object);
#if TEXTURE_PACKER_PRESENT #if TEXTURE_PACKER_PRESENT
public: public:
struct PropTextureCacheEntry { struct PropCacheEntry {
int refcount; int refcount;
Ref<TexturePacker> merger; Ref<TexturePacker> merger;
Ref<PropData> prop; Ref<PropData> prop;
}; };
public: public:
static PropTextureCache *get_singleton(); static PropCache *get_singleton();
bool has_texture(const Ref<PropData> &prop); bool has_texture(const Ref<PropData> &prop);
void set_texture(const Ref<PropData> &prop, const Ref<TexturePacker> &merger); void set_texture(const Ref<PropData> &prop, const Ref<TexturePacker> &merger);
@ -70,15 +70,15 @@ public:
Ref<TexturePacker> get_or_create_texture_threaded(const Ref<PropData> &prop); Ref<TexturePacker> get_or_create_texture_threaded(const Ref<PropData> &prop);
private: private:
Vector<PropTextureCacheEntry> _entries; Vector<PropCacheEntry> _entries;
static PropTextureCache *_instance; static PropCache *_instance;
#endif #endif
public: public:
PropTextureCache(); PropCache();
~PropTextureCache(); ~PropCache();
protected: protected:
static void _bind_methods(); static void _bind_methods();