Added a mutex with a public api to the material cache.

This commit is contained in:
Relintai 2021-08-09 17:21:19 +02:00
parent 11b82bded3
commit 7a3e3b20d4
2 changed files with 23 additions and 2 deletions

View File

@ -51,7 +51,6 @@ SOFTWARE.
#endif
bool PropMaterialCache::get_initialized() {
return _initialized;
}
@ -59,6 +58,16 @@ void PropMaterialCache::set_initialized(const bool value) {
_initialized = value;
}
bool PropMaterialCache::mutex_locked() {
return _locked;
}
void PropMaterialCache::mutex_lock() {
_mutex.lock();
}
void PropMaterialCache::mutex_unlock() {
_mutex.unlock();
}
int PropMaterialCache::get_ref_count() {
return _ref_count;
}
@ -170,7 +179,6 @@ Rect2 PropMaterialCache::texture_get_uv_rect(const Ref<Texture> &texture) {
return Rect2(0, 0, 1, 1);
}
void PropMaterialCache::prop_add_textures(const Ref<PropData> &prop) {
if (!prop.is_valid()) {
return;
@ -236,6 +244,7 @@ void PropMaterialCache::setup_material_albedo(Ref<Texture> texture) {
PropMaterialCache::PropMaterialCache() {
_ref_count = 0;
_initialized = false;
_locked = false;
}
PropMaterialCache::~PropMaterialCache() {
@ -247,6 +256,10 @@ void PropMaterialCache::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_initialized", "value"), &PropMaterialCache::set_initialized);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "initialized"), "set_initialized", "get_initialized");
ClassDB::bind_method(D_METHOD("mutex_locked"), &PropMaterialCache::mutex_locked);
ClassDB::bind_method(D_METHOD("mutex_lock"), &PropMaterialCache::mutex_lock);
ClassDB::bind_method(D_METHOD("mutex_unlock"), &PropMaterialCache::mutex_unlock);
ClassDB::bind_method(D_METHOD("get_ref_count"), &PropMaterialCache::get_ref_count);
ClassDB::bind_method(D_METHOD("set_ref_count", "value"), &PropMaterialCache::set_ref_count);
ADD_PROPERTY(PropertyInfo(Variant::INT, "mat_ref_count"), "set_ref_count", "get_ref_count");

View File

@ -37,6 +37,7 @@ SOFTWARE.
#include "core/math/rect2.h"
#include "scene/resources/material.h"
#include "core/os/mutex.h"
class PropData;
@ -47,6 +48,10 @@ public:
bool get_initialized();
void set_initialized(const bool value);
bool mutex_locked();
void mutex_lock();
void mutex_unlock();
int get_ref_count();
void set_ref_count(const int value);
void inc_ref_count();
@ -85,12 +90,15 @@ public:
protected:
static void _bind_methods();
bool _locked;
bool _initialized;
Vector<Ref<Material>> _materials;
Vector<Ref<Texture>> _textures;
int _ref_count;
Mutex _mutex;
};
#endif