2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* resource.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "resource.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "core_string_names.h"
|
|
|
|
#include "os/file_access.h"
|
2016-06-27 16:17:20 +00:00
|
|
|
#include "io/resource_loader.h"
|
2017-01-10 04:04:31 +00:00
|
|
|
#include "script_language.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-16 07:04:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void Resource::emit_changed() {
|
|
|
|
|
|
|
|
emit_signal(CoreStringNames::get_singleton()->changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Resource::_resource_path_changed() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-06-28 02:21:45 +00:00
|
|
|
void Resource::set_path(const String& p_path, bool p_take_over) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (path_cache==p_path)
|
|
|
|
return;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (path_cache!="") {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
ResourceCache::lock->write_lock();
|
2014-02-10 01:10:30 +00:00
|
|
|
ResourceCache::resources.erase(path_cache);
|
2017-01-07 21:25:37 +00:00
|
|
|
ResourceCache::lock->write_unlock();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
path_cache="";
|
2017-01-07 21:25:37 +00:00
|
|
|
|
|
|
|
ResourceCache::lock->read_lock();
|
|
|
|
bool has_path = ResourceCache::resources.has( p_path );
|
|
|
|
ResourceCache::lock->read_unlock();
|
|
|
|
|
|
|
|
if (has_path) {
|
2014-06-28 02:21:45 +00:00
|
|
|
if (p_take_over) {
|
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
ResourceCache::lock->write_lock();
|
2014-06-28 02:21:45 +00:00
|
|
|
ResourceCache::resources.get(p_path)->set_name("");
|
2017-01-07 21:25:37 +00:00
|
|
|
ResourceCache::lock->write_unlock();
|
2014-06-28 02:21:45 +00:00
|
|
|
} else {
|
|
|
|
ERR_EXPLAIN("Another resource is loaded from path: "+p_path);
|
2017-01-07 21:25:37 +00:00
|
|
|
|
|
|
|
ResourceCache::lock->read_lock();
|
|
|
|
bool exists = ResourceCache::resources.has( p_path );
|
|
|
|
ResourceCache::lock->read_unlock();
|
|
|
|
|
|
|
|
ERR_FAIL_COND( exists );
|
2014-06-28 02:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
path_cache=p_path;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (path_cache!="") {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
ResourceCache::lock->write_lock();
|
2017-01-14 17:03:38 +00:00
|
|
|
ResourceCache::resources[path_cache]=this;
|
2017-01-07 21:25:37 +00:00
|
|
|
ResourceCache::lock->write_unlock();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 04:04:31 +00:00
|
|
|
_change_notify("resource_path");
|
2014-02-10 01:10:30 +00:00
|
|
|
_resource_path_changed();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String Resource::get_path() const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return path_cache;
|
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
void Resource::set_subindex(int p_sub_index) {
|
|
|
|
|
|
|
|
subindex=p_sub_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Resource::get_subindex() const{
|
|
|
|
|
|
|
|
return subindex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Resource::set_name(const String& p_name) {
|
|
|
|
|
|
|
|
name=p_name;
|
2017-01-10 04:04:31 +00:00
|
|
|
_change_notify("resource_name");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
String Resource::get_name() const {
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-06-27 16:17:20 +00:00
|
|
|
bool Resource::editor_can_reload_from_file() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-27 16:17:20 +00:00
|
|
|
return true; //by default yes
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Resource::reload_from_file() {
|
|
|
|
|
|
|
|
|
2016-06-27 16:17:20 +00:00
|
|
|
String path=get_path();
|
|
|
|
if (!path.is_resource_file())
|
|
|
|
return;
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
Ref<Resource> s = ResourceLoader::load(path,get_class(),true);
|
2016-06-27 16:17:20 +00:00
|
|
|
|
|
|
|
if (!s.is_valid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
List<PropertyInfo> pi;
|
|
|
|
s->get_property_list(&pi);
|
|
|
|
|
|
|
|
for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
|
|
|
|
continue;
|
2017-01-10 04:04:31 +00:00
|
|
|
if (E->get().name=="resource_path")
|
2016-06-27 16:17:20 +00:00
|
|
|
continue; //do not change path
|
|
|
|
|
|
|
|
set(E->get().name,s->get(E->get().name));
|
|
|
|
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-10 04:04:31 +00:00
|
|
|
Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {
|
|
|
|
|
|
|
|
|
|
|
|
List<PropertyInfo> plist;
|
|
|
|
get_property_list(&plist);
|
|
|
|
|
|
|
|
|
|
|
|
Resource *r = (Resource*)ClassDB::instance(get_class());
|
|
|
|
ERR_FAIL_COND_V(!r,Ref<Resource>());
|
|
|
|
|
|
|
|
r->local_scene=p_for_scene;
|
|
|
|
|
|
|
|
for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
|
|
|
|
continue;
|
|
|
|
Variant p = get(E->get().name);
|
|
|
|
if (p.get_type()==Variant::OBJECT) {
|
|
|
|
|
|
|
|
RES sr = p;
|
|
|
|
if (sr.is_valid()) {
|
|
|
|
|
|
|
|
if (sr->is_local_to_scene()) {
|
|
|
|
if (remap_cache.has(sr)) {
|
|
|
|
p=remap_cache[sr];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
RES dupe = sr->duplicate_for_local_scene(p_for_scene,remap_cache);
|
|
|
|
p=dupe;
|
|
|
|
remap_cache[sr]=dupe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r->set(E->get().name,p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ref<Resource>(r);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<Resource> Resource::duplicate(bool p_subresources) {
|
|
|
|
|
2017-01-10 04:04:31 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<PropertyInfo> plist;
|
|
|
|
get_property_list(&plist);
|
|
|
|
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
Resource *r = (Resource*)ClassDB::instance(get_class());
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND_V(!r,Ref<Resource>());
|
|
|
|
|
|
|
|
for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
|
|
|
|
continue;
|
|
|
|
Variant p = get(E->get().name);
|
|
|
|
if (p.get_type()==Variant::OBJECT && p_subresources) {
|
|
|
|
|
|
|
|
RES sr = p;
|
|
|
|
if (sr.is_valid())
|
|
|
|
p=sr->duplicate(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
r->set(E->get().name,p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ref<Resource>(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-30 04:28:05 +00:00
|
|
|
void Resource::_set_path(const String& p_path) {
|
|
|
|
|
|
|
|
set_path(p_path,false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Resource::_take_over_path(const String& p_path) {
|
|
|
|
|
|
|
|
set_path(p_path,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
RID Resource::get_rid() const {
|
|
|
|
|
|
|
|
return RID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Resource::register_owner(Object *p_owner) {
|
|
|
|
|
|
|
|
owners.insert(p_owner->get_instance_ID());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Resource::unregister_owner(Object *p_owner) {
|
|
|
|
|
|
|
|
owners.erase(p_owner->get_instance_ID());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Resource::notify_change_to_owners() {
|
|
|
|
|
|
|
|
for(Set<ObjectID>::Element *E=owners.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
Object *obj = ObjectDB::get_instance(E->get());
|
|
|
|
ERR_EXPLAIN("Object was deleted, while still owning a resource");
|
|
|
|
ERR_CONTINUE(!obj); //wtf
|
|
|
|
//TODO store string
|
|
|
|
obj->call("resource_changed",RES(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-27 17:18:40 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
uint32_t Resource::hash_edited_version() const {
|
|
|
|
|
|
|
|
uint32_t hash = hash_djb2_one_32(get_edited_version());
|
|
|
|
|
|
|
|
List<PropertyInfo> plist;
|
|
|
|
get_property_list(&plist);
|
|
|
|
|
|
|
|
for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (E->get().type==Variant::OBJECT && E->get().hint==PROPERTY_HINT_RESOURCE_TYPE) {
|
|
|
|
RES res = get(E->get().name);
|
|
|
|
if (res.is_valid()) {
|
|
|
|
hash = hash_djb2_one_32(res->hash_edited_version(),hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-01-10 04:04:31 +00:00
|
|
|
void Resource::set_local_to_scene(bool p_enable) {
|
|
|
|
|
|
|
|
local_to_scene=p_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Resource::is_local_to_scene() const {
|
|
|
|
|
|
|
|
return local_to_scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* Resource::get_local_scene() const {
|
|
|
|
|
|
|
|
if (local_scene)
|
|
|
|
return local_scene;
|
|
|
|
|
|
|
|
if (_get_local_scene_func) {
|
|
|
|
return _get_local_scene_func();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Resource::setup_local_to_scene() {
|
|
|
|
|
|
|
|
if (get_script_instance())
|
|
|
|
get_script_instance()->call("_setup_local_to_scene");
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* (*Resource::_get_local_scene_func)()=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
void Resource::_bind_methods() {
|
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_path","path"),&Resource::_set_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("take_over_path","path"),&Resource::_take_over_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_path"),&Resource::get_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_name","name"),&Resource::set_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_name"),&Resource::get_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rid"),&Resource::get_rid);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_local_to_scene","enable"),&Resource::set_local_to_scene);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_local_to_scene"),&Resource::is_local_to_scene);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_local_scene:Node"),&Resource::get_local_scene);
|
|
|
|
ClassDB::bind_method(D_METHOD("setup_local_to_scene"),&Resource::setup_local_to_scene);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("duplicate","subresources"),&Resource::duplicate,DEFVAL(false));
|
2017-01-10 04:04:31 +00:00
|
|
|
ADD_SIGNAL( MethodInfo("changed") );
|
|
|
|
ADD_GROUP("Resource","resource_");
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"resource_local_to_scene" ), "set_local_to_scene","is_local_to_scene");
|
|
|
|
ADD_PROPERTY( PropertyInfo(Variant::STRING,"resource_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ), "set_path","get_path");
|
|
|
|
ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"resource_name"), "set_name","get_name");
|
2017-01-10 04:04:31 +00:00
|
|
|
|
|
|
|
BIND_VMETHOD( MethodInfo("_setup_local_to_scene") );
|
|
|
|
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Resource::Resource() {
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
last_modified_time=0;
|
2017-02-01 12:45:45 +00:00
|
|
|
import_last_modified_time=0;
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
subindex=0;
|
2017-01-21 22:00:25 +00:00
|
|
|
local_to_scene=false;
|
2017-01-10 04:04:31 +00:00
|
|
|
local_scene=NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-27 17:18:40 +00:00
|
|
|
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Resource::~Resource() {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
if (path_cache!="") {
|
|
|
|
ResourceCache::lock->write_lock();
|
2014-02-10 01:10:30 +00:00
|
|
|
ResourceCache::resources.erase(path_cache);
|
2017-01-07 21:25:37 +00:00
|
|
|
ResourceCache::lock->write_unlock();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
if (owners.size()) {
|
|
|
|
WARN_PRINT("Resource is still owned");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
HashMap<String,Resource*> ResourceCache::resources;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
RWLock *ResourceCache::lock=NULL;
|
|
|
|
|
|
|
|
void ResourceCache::setup() {
|
|
|
|
|
|
|
|
lock = RWLock::create();
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void ResourceCache::clear() {
|
|
|
|
if (resources.size())
|
|
|
|
ERR_PRINT("Resources Still in use at Exit!");
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
resources.clear();
|
2017-01-07 21:25:37 +00:00
|
|
|
memdelete(lock);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ResourceCache::reload_externals() {
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
const String *K=NULL;
|
|
|
|
while ((K=resources.next(K))) {
|
|
|
|
resources[*K]->reload_external_data();
|
|
|
|
}
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ResourceCache::has(const String& p_path) {
|
|
|
|
|
2017-01-14 17:03:38 +00:00
|
|
|
lock->read_lock();
|
2017-01-07 21:25:37 +00:00
|
|
|
bool b = resources.has(p_path);
|
2017-01-14 17:03:38 +00:00
|
|
|
lock->read_unlock();
|
2017-01-07 21:25:37 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
return b;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
Resource *ResourceCache::get(const String& p_path) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
lock->read_lock();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Resource **res = resources.getptr(p_path);
|
2017-01-07 21:25:37 +00:00
|
|
|
|
|
|
|
lock->read_unlock();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!res) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return *res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ResourceCache::get_cached_resources(List<Ref<Resource> > *p_resources) {
|
|
|
|
|
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
lock->read_lock();
|
2014-02-10 01:10:30 +00:00
|
|
|
const String* K=NULL;
|
|
|
|
while((K=resources.next(K))) {
|
|
|
|
|
|
|
|
Resource *r = resources[*K];
|
|
|
|
p_resources->push_back( Ref<Resource>( r ));
|
|
|
|
|
|
|
|
}
|
2017-01-07 21:25:37 +00:00
|
|
|
lock->read_unlock();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResourceCache::get_cached_resource_count() {
|
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
lock->read_lock();
|
|
|
|
int rc = resources.size();
|
|
|
|
lock->read_unlock();
|
|
|
|
|
|
|
|
return rc;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceCache::dump(const char* p_file,bool p_short) {
|
|
|
|
#ifdef DEBUG_ENABLED
|
2017-01-07 21:25:37 +00:00
|
|
|
lock->read_lock();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Map<String,int> type_count;
|
|
|
|
|
|
|
|
|
|
|
|
FileAccess *f=NULL;
|
|
|
|
if (p_file) {
|
|
|
|
f = FileAccess::open(p_file,FileAccess::WRITE);
|
|
|
|
ERR_FAIL_COND(!f);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const String* K=NULL;
|
|
|
|
while((K=resources.next(K))) {
|
|
|
|
|
|
|
|
Resource *r = resources[*K];
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
if (!type_count.has(r->get_class())) {
|
|
|
|
type_count[r->get_class()]=0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-03 02:03:46 +00:00
|
|
|
type_count[r->get_class()]++;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!p_short) {
|
|
|
|
if (f)
|
2017-01-03 02:03:46 +00:00
|
|
|
f->store_line(r->get_class()+": "+r->get_path());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Map<String,int>::Element *E=type_count.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (f)
|
|
|
|
f->store_line(E->key()+" count: "+itos(E->get()));
|
|
|
|
}
|
|
|
|
if (f) {
|
|
|
|
f->close();
|
|
|
|
memdelete(f);
|
|
|
|
}
|
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
lock->read_unlock();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
}
|