|
@@ -54,30 +54,30 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
|
|
|
|
|
|
if (path_cache != "") {
|
|
if (path_cache != "") {
|
|
|
|
|
|
- ResourceCache::lock->write_lock();
|
|
|
|
|
|
+ ResourceCache::lock.write_lock();
|
|
ResourceCache::resources.erase(path_cache);
|
|
ResourceCache::resources.erase(path_cache);
|
|
- ResourceCache::lock->write_unlock();
|
|
|
|
|
|
+ ResourceCache::lock.write_unlock();
|
|
}
|
|
}
|
|
|
|
|
|
path_cache = "";
|
|
path_cache = "";
|
|
|
|
|
|
- ResourceCache::lock->read_lock();
|
|
|
|
|
|
+ ResourceCache::lock.read_lock();
|
|
bool has_path = ResourceCache::resources.has(p_path);
|
|
bool has_path = ResourceCache::resources.has(p_path);
|
|
- ResourceCache::lock->read_unlock();
|
|
|
|
|
|
+ ResourceCache::lock.read_unlock();
|
|
|
|
|
|
if (has_path) {
|
|
if (has_path) {
|
|
if (p_take_over) {
|
|
if (p_take_over) {
|
|
|
|
|
|
- ResourceCache::lock->write_lock();
|
|
|
|
|
|
+ ResourceCache::lock.write_lock();
|
|
Resource **res = ResourceCache::resources.getptr(p_path);
|
|
Resource **res = ResourceCache::resources.getptr(p_path);
|
|
if (res) {
|
|
if (res) {
|
|
(*res)->set_name("");
|
|
(*res)->set_name("");
|
|
}
|
|
}
|
|
- ResourceCache::lock->write_unlock();
|
|
|
|
|
|
+ ResourceCache::lock.write_unlock();
|
|
} else {
|
|
} else {
|
|
- ResourceCache::lock->read_lock();
|
|
|
|
|
|
+ ResourceCache::lock.read_lock();
|
|
bool exists = ResourceCache::resources.has(p_path);
|
|
bool exists = ResourceCache::resources.has(p_path);
|
|
- ResourceCache::lock->read_unlock();
|
|
|
|
|
|
+ ResourceCache::lock.read_unlock();
|
|
|
|
|
|
ERR_FAIL_COND_MSG(exists, "Another resource is loaded from path '" + p_path + "' (possible cyclic resource inclusion).");
|
|
ERR_FAIL_COND_MSG(exists, "Another resource is loaded from path '" + p_path + "' (possible cyclic resource inclusion).");
|
|
}
|
|
}
|
|
@@ -86,9 +86,9 @@ void Resource::set_path(const String &p_path, bool p_take_over) {
|
|
|
|
|
|
if (path_cache != "") {
|
|
if (path_cache != "") {
|
|
|
|
|
|
- ResourceCache::lock->write_lock();
|
|
|
|
|
|
+ ResourceCache::lock.write_lock();
|
|
ResourceCache::resources[path_cache] = this;
|
|
ResourceCache::resources[path_cache] = this;
|
|
- ResourceCache::lock->write_unlock();
|
|
|
|
|
|
+ ResourceCache::lock.write_unlock();
|
|
}
|
|
}
|
|
|
|
|
|
_change_notify("resource_path");
|
|
_change_notify("resource_path");
|
|
@@ -343,9 +343,7 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
|
|
if (remapped_list.in_list() == p_remapped)
|
|
if (remapped_list.in_list() == p_remapped)
|
|
return;
|
|
return;
|
|
|
|
|
|
- if (ResourceCache::lock) {
|
|
|
|
- ResourceCache::lock->write_lock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::lock.write_lock();
|
|
|
|
|
|
if (p_remapped) {
|
|
if (p_remapped) {
|
|
ResourceLoader::remapped_list.add(&remapped_list);
|
|
ResourceLoader::remapped_list.add(&remapped_list);
|
|
@@ -353,9 +351,7 @@ void Resource::set_as_translation_remapped(bool p_remapped) {
|
|
ResourceLoader::remapped_list.remove(&remapped_list);
|
|
ResourceLoader::remapped_list.remove(&remapped_list);
|
|
}
|
|
}
|
|
|
|
|
|
- if (ResourceCache::lock) {
|
|
|
|
- ResourceCache::lock->write_unlock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::lock.write_unlock();
|
|
}
|
|
}
|
|
|
|
|
|
bool Resource::is_translation_remapped() const {
|
|
bool Resource::is_translation_remapped() const {
|
|
@@ -367,38 +363,24 @@ bool Resource::is_translation_remapped() const {
|
|
//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
|
|
//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
|
|
void Resource::set_id_for_path(const String &p_path, int p_id) {
|
|
void Resource::set_id_for_path(const String &p_path, int p_id) {
|
|
if (p_id == -1) {
|
|
if (p_id == -1) {
|
|
- if (ResourceCache::path_cache_lock) {
|
|
|
|
- ResourceCache::path_cache_lock->write_lock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::path_cache_lock.write_lock();
|
|
ResourceCache::resource_path_cache[p_path].erase(get_path());
|
|
ResourceCache::resource_path_cache[p_path].erase(get_path());
|
|
- if (ResourceCache::path_cache_lock) {
|
|
|
|
- ResourceCache::path_cache_lock->write_unlock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::path_cache_lock.write_unlock();
|
|
} else {
|
|
} else {
|
|
- if (ResourceCache::path_cache_lock) {
|
|
|
|
- ResourceCache::path_cache_lock->write_lock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::path_cache_lock.write_lock();
|
|
ResourceCache::resource_path_cache[p_path][get_path()] = p_id;
|
|
ResourceCache::resource_path_cache[p_path][get_path()] = p_id;
|
|
- if (ResourceCache::path_cache_lock) {
|
|
|
|
- ResourceCache::path_cache_lock->write_unlock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::path_cache_lock.write_unlock();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int Resource::get_id_for_path(const String &p_path) const {
|
|
int Resource::get_id_for_path(const String &p_path) const {
|
|
- if (ResourceCache::path_cache_lock) {
|
|
|
|
- ResourceCache::path_cache_lock->read_lock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::path_cache_lock.read_lock();
|
|
if (ResourceCache::resource_path_cache[p_path].has(get_path())) {
|
|
if (ResourceCache::resource_path_cache[p_path].has(get_path())) {
|
|
int result = ResourceCache::resource_path_cache[p_path][get_path()];
|
|
int result = ResourceCache::resource_path_cache[p_path][get_path()];
|
|
- if (ResourceCache::path_cache_lock) {
|
|
|
|
- ResourceCache::path_cache_lock->read_unlock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::path_cache_lock.read_unlock();
|
|
return result;
|
|
return result;
|
|
} else {
|
|
} else {
|
|
- if (ResourceCache::path_cache_lock) {
|
|
|
|
- ResourceCache::path_cache_lock->read_unlock();
|
|
|
|
- }
|
|
|
|
|
|
+ ResourceCache::path_cache_lock.read_unlock();
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -444,9 +426,9 @@ Resource::Resource() :
|
|
Resource::~Resource() {
|
|
Resource::~Resource() {
|
|
|
|
|
|
if (path_cache != "") {
|
|
if (path_cache != "") {
|
|
- ResourceCache::lock->write_lock();
|
|
|
|
|
|
+ ResourceCache::lock.write_lock();
|
|
ResourceCache::resources.erase(path_cache);
|
|
ResourceCache::resources.erase(path_cache);
|
|
- ResourceCache::lock->write_unlock();
|
|
|
|
|
|
+ ResourceCache::lock.write_unlock();
|
|
}
|
|
}
|
|
if (owners.size()) {
|
|
if (owners.size()) {
|
|
WARN_PRINT("Resource is still owned.");
|
|
WARN_PRINT("Resource is still owned.");
|
|
@@ -458,19 +440,11 @@ HashMap<String, Resource *> ResourceCache::resources;
|
|
HashMap<String, HashMap<String, int> > ResourceCache::resource_path_cache;
|
|
HashMap<String, HashMap<String, int> > ResourceCache::resource_path_cache;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-RWLock *ResourceCache::lock = NULL;
|
|
|
|
|
|
+RWLock ResourceCache::lock;
|
|
#ifdef TOOLS_ENABLED
|
|
#ifdef TOOLS_ENABLED
|
|
-RWLock *ResourceCache::path_cache_lock = NULL;
|
|
|
|
|
|
+RWLock ResourceCache::path_cache_lock;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-void ResourceCache::setup() {
|
|
|
|
-
|
|
|
|
- lock = RWLock::create();
|
|
|
|
-#ifdef TOOLS_ENABLED
|
|
|
|
- path_cache_lock = RWLock::create();
|
|
|
|
-#endif
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void ResourceCache::clear() {
|
|
void ResourceCache::clear() {
|
|
if (resources.size()) {
|
|
if (resources.size()) {
|
|
ERR_PRINT("Resources still in use at exit (run with --verbose for details).");
|
|
ERR_PRINT("Resources still in use at exit (run with --verbose for details).");
|
|
@@ -484,7 +458,6 @@ void ResourceCache::clear() {
|
|
}
|
|
}
|
|
|
|
|
|
resources.clear();
|
|
resources.clear();
|
|
- memdelete(lock);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void ResourceCache::reload_externals() {
|
|
void ResourceCache::reload_externals() {
|
|
@@ -492,19 +465,19 @@ void ResourceCache::reload_externals() {
|
|
|
|
|
|
bool ResourceCache::has(const String &p_path) {
|
|
bool ResourceCache::has(const String &p_path) {
|
|
|
|
|
|
- lock->read_lock();
|
|
|
|
|
|
+ lock.read_lock();
|
|
bool b = resources.has(p_path);
|
|
bool b = resources.has(p_path);
|
|
- lock->read_unlock();
|
|
|
|
|
|
+ lock.read_unlock();
|
|
|
|
|
|
return b;
|
|
return b;
|
|
}
|
|
}
|
|
Resource *ResourceCache::get(const String &p_path) {
|
|
Resource *ResourceCache::get(const String &p_path) {
|
|
|
|
|
|
- lock->read_lock();
|
|
|
|
|
|
+ lock.read_lock();
|
|
|
|
|
|
Resource **res = resources.getptr(p_path);
|
|
Resource **res = resources.getptr(p_path);
|
|
|
|
|
|
- lock->read_unlock();
|
|
|
|
|
|
+ lock.read_unlock();
|
|
|
|
|
|
if (!res) {
|
|
if (!res) {
|
|
return NULL;
|
|
return NULL;
|
|
@@ -515,28 +488,28 @@ Resource *ResourceCache::get(const String &p_path) {
|
|
|
|
|
|
void ResourceCache::get_cached_resources(List<Ref<Resource> > *p_resources) {
|
|
void ResourceCache::get_cached_resources(List<Ref<Resource> > *p_resources) {
|
|
|
|
|
|
- lock->read_lock();
|
|
|
|
|
|
+ lock.read_lock();
|
|
const String *K = NULL;
|
|
const String *K = NULL;
|
|
while ((K = resources.next(K))) {
|
|
while ((K = resources.next(K))) {
|
|
|
|
|
|
Resource *r = resources[*K];
|
|
Resource *r = resources[*K];
|
|
p_resources->push_back(Ref<Resource>(r));
|
|
p_resources->push_back(Ref<Resource>(r));
|
|
}
|
|
}
|
|
- lock->read_unlock();
|
|
|
|
|
|
+ lock.read_unlock();
|
|
}
|
|
}
|
|
|
|
|
|
int ResourceCache::get_cached_resource_count() {
|
|
int ResourceCache::get_cached_resource_count() {
|
|
|
|
|
|
- lock->read_lock();
|
|
|
|
|
|
+ lock.read_lock();
|
|
int rc = resources.size();
|
|
int rc = resources.size();
|
|
- lock->read_unlock();
|
|
|
|
|
|
+ lock.read_unlock();
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
|
|
void ResourceCache::dump(const char *p_file, bool p_short) {
|
|
void ResourceCache::dump(const char *p_file, bool p_short) {
|
|
#ifdef DEBUG_ENABLED
|
|
#ifdef DEBUG_ENABLED
|
|
- lock->read_lock();
|
|
|
|
|
|
+ lock.read_lock();
|
|
|
|
|
|
Map<String, int> type_count;
|
|
Map<String, int> type_count;
|
|
|
|
|
|
@@ -573,6 +546,6 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
|
|
memdelete(f);
|
|
memdelete(f);
|
|
}
|
|
}
|
|
|
|
|
|
- lock->read_unlock();
|
|
|
|
|
|
+ lock.read_unlock();
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|