mirror of
https://github.com/Relintai/props.git
synced 2025-02-10 16:30:06 +01:00
Add material cache storage for TiledWalls into PropCache.
This commit is contained in:
parent
c68671ff94
commit
e7e50c0e8a
@ -244,6 +244,62 @@ void PropCache::material_cache_unref(const Ref<PropData> &prop) {
|
|||||||
_material_cache_mutex.unlock();
|
_material_cache_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<PropMaterialCache> PropCache::tiled_wall_material_cache_get(const Ref<TiledWallData> &twd) {
|
||||||
|
ERR_FAIL_COND_V(!twd.is_valid(), Ref<PropMaterialCache>());
|
||||||
|
|
||||||
|
//get pointer's value as uint64
|
||||||
|
uint64_t k = make_uint64_t<const TiledWallData *>(*twd);
|
||||||
|
|
||||||
|
_tiled_wall_material_cache_mutex.lock();
|
||||||
|
|
||||||
|
if (_tiled_wall_material_cache.has(k)) {
|
||||||
|
Ref<PropMaterialCache> m = _tiled_wall_material_cache[k];
|
||||||
|
|
||||||
|
m->inc_ref_count();
|
||||||
|
|
||||||
|
_tiled_wall_material_cache_mutex.unlock();
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
PropMaterialCache *p = Object::cast_to<PropMaterialCache>(ClassDB::instance(_default_prop_material_cache_class));
|
||||||
|
|
||||||
|
if (!p) {
|
||||||
|
ERR_PRINT("Can't instance the given PropMaterialCache! class_name: " + String(_default_prop_material_cache_class));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<PropMaterialCache> m(p);
|
||||||
|
|
||||||
|
_tiled_wall_material_cache[k] = m;
|
||||||
|
|
||||||
|
_tiled_wall_material_cache_mutex.unlock();
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
void PropCache::tiled_wall_material_cache_unref(const Ref<TiledWallData> &twd) {
|
||||||
|
//get pointer's value as uint64
|
||||||
|
uint64_t k = make_uint64_t<const TiledWallData *>(*twd);
|
||||||
|
|
||||||
|
_tiled_wall_material_cache_mutex.lock();
|
||||||
|
|
||||||
|
if (!_tiled_wall_material_cache.has(k)) {
|
||||||
|
_tiled_wall_material_cache_mutex.unlock();
|
||||||
|
|
||||||
|
ERR_PRINT("PropCache::material_cache_unref: can't find cache!");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<PropMaterialCache> m = _tiled_wall_material_cache[k];
|
||||||
|
|
||||||
|
m->dec_ref_count();
|
||||||
|
if (m->get_ref_count() <= 0) {
|
||||||
|
_tiled_wall_material_cache.erase(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
_tiled_wall_material_cache_mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
Ref<PropMaterialCache> PropCache::material_cache_custom_key_get(const uint64_t key) {
|
Ref<PropMaterialCache> PropCache::material_cache_custom_key_get(const uint64_t key) {
|
||||||
_custom_keyed_material_cache_mutex.lock();
|
_custom_keyed_material_cache_mutex.lock();
|
||||||
|
|
||||||
|
@ -26,19 +26,19 @@ SOFTWARE.
|
|||||||
#include "core/version.h"
|
#include "core/version.h"
|
||||||
|
|
||||||
#if VERSION_MAJOR > 3
|
#if VERSION_MAJOR > 3
|
||||||
#include "core/object/object.h"
|
#include "core/core_bind.h"
|
||||||
#include "core/math/color.h"
|
#include "core/math/color.h"
|
||||||
|
#include "core/object/object.h"
|
||||||
#include "core/object/reference.h"
|
#include "core/object/reference.h"
|
||||||
#include "core/templates/hash_map.h"
|
#include "core/templates/hash_map.h"
|
||||||
#include "core/templates/vector.h"
|
#include "core/templates/vector.h"
|
||||||
#include "core/core_bind.h"
|
|
||||||
#else
|
#else
|
||||||
#include "core/hash_map.h"
|
#include "core/bind/core_bind.h"
|
||||||
#include "core/color.h"
|
#include "core/color.h"
|
||||||
|
#include "core/hash_map.h"
|
||||||
#include "core/object.h"
|
#include "core/object.h"
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
#include "core/vector.h"
|
#include "core/vector.h"
|
||||||
#include "core/bind/core_bind.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "scene/resources/material.h"
|
#include "scene/resources/material.h"
|
||||||
@ -48,6 +48,7 @@ SOFTWARE.
|
|||||||
#include "../props/prop_data.h"
|
#include "../props/prop_data.h"
|
||||||
|
|
||||||
class PropMaterialCache;
|
class PropMaterialCache;
|
||||||
|
class TiledWallData;
|
||||||
|
|
||||||
class PropCache : public Object {
|
class PropCache : public Object {
|
||||||
GDCLASS(PropCache, Object);
|
GDCLASS(PropCache, Object);
|
||||||
@ -93,6 +94,9 @@ public:
|
|||||||
Ref<PropMaterialCache> material_cache_get(const Ref<PropData> &prop);
|
Ref<PropMaterialCache> material_cache_get(const Ref<PropData> &prop);
|
||||||
void material_cache_unref(const Ref<PropData> &prop);
|
void material_cache_unref(const Ref<PropData> &prop);
|
||||||
|
|
||||||
|
Ref<PropMaterialCache> tiled_wall_material_cache_get(const Ref<TiledWallData> &twd);
|
||||||
|
void tiled_wall_material_cache_unref(const Ref<TiledWallData> &twd);
|
||||||
|
|
||||||
Ref<PropMaterialCache> material_cache_custom_key_get(const uint64_t key);
|
Ref<PropMaterialCache> material_cache_custom_key_get(const uint64_t key);
|
||||||
void material_cache_custom_key_unref(const uint64_t key);
|
void material_cache_custom_key_unref(const uint64_t key);
|
||||||
|
|
||||||
@ -111,9 +115,11 @@ protected:
|
|||||||
StringName _default_prop_material_cache_class;
|
StringName _default_prop_material_cache_class;
|
||||||
|
|
||||||
Map<uint64_t, Ref<PropMaterialCache>> _material_cache;
|
Map<uint64_t, Ref<PropMaterialCache>> _material_cache;
|
||||||
|
Map<uint64_t, Ref<PropMaterialCache>> _tiled_wall_material_cache;
|
||||||
Map<uint64_t, Ref<PropMaterialCache>> _custom_keyed_material_cache;
|
Map<uint64_t, Ref<PropMaterialCache>> _custom_keyed_material_cache;
|
||||||
|
|
||||||
Mutex _material_cache_mutex;
|
Mutex _material_cache_mutex;
|
||||||
|
Mutex _tiled_wall_material_cache_mutex;
|
||||||
Mutex _custom_keyed_material_cache_mutex;
|
Mutex _custom_keyed_material_cache_mutex;
|
||||||
|
|
||||||
#ifdef TEXTURE_PACKER_PRESENT
|
#ifdef TEXTURE_PACKER_PRESENT
|
||||||
|
Loading…
Reference in New Issue
Block a user