2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* resource.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef RESOURCE_H
|
|
|
|
#define RESOURCE_H
|
|
|
|
|
|
|
|
#include "object.h"
|
|
|
|
#include "safe_refcount.h"
|
|
|
|
#include "ref_ptr.h"
|
|
|
|
#include "reference.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
#include "class_db.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define RES_BASE_EXTENSION(m_ext)\
|
|
|
|
public:\
|
2017-01-03 03:03:46 +01:00
|
|
|
static void register_custom_data_to_otdb() { ClassDB::add_resource_base_extension(m_ext,get_class_static()); }\
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual String get_base_extension() const { return m_ext; }\
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
class ResourceImportMetadata : public Reference {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS( ResourceImportMetadata, Reference );
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Source {
|
|
|
|
String path;
|
|
|
|
String md5;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Source> sources;
|
|
|
|
String editor;
|
|
|
|
|
|
|
|
Map<String,Variant> options;
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
PoolStringArray _get_options() const;
|
2017-01-10 05:04:31 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
2017-01-09 19:50:08 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
|
|
|
|
void set_editor(const String& p_editor);
|
|
|
|
String get_editor() const;
|
|
|
|
|
|
|
|
void add_source(const String& p_path,const String& p_md5="");
|
|
|
|
String get_source_path(int p_idx) const;
|
|
|
|
String get_source_md5(int p_idx) const;
|
|
|
|
void set_source_md5(int p_idx,const String& p_md5);
|
|
|
|
void remove_source(int p_idx);
|
|
|
|
int get_source_count() const;
|
|
|
|
|
|
|
|
void set_option(const String& p_key, const Variant& p_value);
|
|
|
|
Variant get_option(const String& p_key) const;
|
|
|
|
bool has_option(const String& p_key) const;
|
|
|
|
|
|
|
|
void get_options(List<String> *r_options) const;
|
|
|
|
|
2017-01-10 05:04:31 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ResourceImportMetadata();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Resource : public Reference {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS( Resource, Reference );
|
2014-02-10 02:10:30 +01:00
|
|
|
OBJ_CATEGORY("Resources");
|
|
|
|
RES_BASE_EXTENSION("res");
|
|
|
|
|
|
|
|
Set<ObjectID> owners;
|
|
|
|
|
|
|
|
friend class ResBase;
|
2016-03-09 00:00:52 +01:00
|
|
|
friend class ResourceCache;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String name;
|
|
|
|
String path_cache;
|
2015-06-22 05:03:19 +02:00
|
|
|
int subindex;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual bool _use_builtin_script() const { return true; }
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
Ref<ResourceImportMetadata> import_metadata;
|
|
|
|
uint64_t last_modified_time;
|
|
|
|
#endif
|
|
|
|
|
2017-01-10 05:04:31 +01:00
|
|
|
bool local_to_scene;
|
|
|
|
friend class SceneState;
|
|
|
|
Node* local_scene;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void emit_changed();
|
|
|
|
|
|
|
|
void notify_change_to_owners();
|
|
|
|
|
|
|
|
virtual void _resource_path_changed();
|
|
|
|
static void _bind_methods();
|
2014-06-30 06:28:05 +02:00
|
|
|
|
|
|
|
void _set_path(const String& p_path);
|
|
|
|
void _take_over_path(const String& p_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-10 05:04:31 +01:00
|
|
|
static Node* (*_get_local_scene_func)(); //used by editor
|
|
|
|
|
2016-06-27 18:17:20 +02:00
|
|
|
virtual bool editor_can_reload_from_file();
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void reload_from_file();
|
|
|
|
|
|
|
|
void register_owner(Object *p_owner);
|
|
|
|
void unregister_owner(Object *p_owner);
|
|
|
|
|
|
|
|
void set_name(const String& p_name);
|
|
|
|
String get_name() const;
|
|
|
|
|
2015-10-10 14:09:09 +02:00
|
|
|
virtual void set_path(const String& p_path,bool p_take_over=false);
|
2014-02-10 02:10:30 +01:00
|
|
|
String get_path() const;
|
|
|
|
|
2015-06-22 05:03:19 +02:00
|
|
|
void set_subindex(int p_sub_index);
|
|
|
|
int get_subindex() const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Ref<Resource> duplicate(bool p_subresources=false);
|
2017-01-10 05:04:31 +01:00
|
|
|
Ref<Resource> duplicate_for_local_scene(Node *p_scene,Map<Ref<Resource>,Ref<Resource> >& remap_cache);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata);
|
|
|
|
Ref<ResourceImportMetadata> get_import_metadata() const;
|
|
|
|
|
2017-01-10 05:04:31 +01:00
|
|
|
void set_local_to_scene(bool p_enable);
|
|
|
|
bool is_local_to_scene() const;
|
|
|
|
virtual void setup_local_to_scene();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-10 05:04:31 +01:00
|
|
|
Node* get_local_scene() const;
|
2016-05-27 19:18:40 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2016-05-27 19:18:40 +02:00
|
|
|
uint32_t hash_edited_version() const;
|
|
|
|
|
2015-12-14 00:39:01 +01:00
|
|
|
virtual void set_last_modified_time(uint64_t p_time) { last_modified_time=p_time; }
|
2014-02-10 02:10:30 +01:00
|
|
|
uint64_t get_last_modified_time() const { return last_modified_time; }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual RID get_rid() const; // some resources may offer conversion to RID
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
Resource();
|
2014-02-10 02:10:30 +01:00
|
|
|
~Resource();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef Ref<Resource> RES;
|
|
|
|
|
|
|
|
class ResourceCache {
|
2016-03-09 00:00:52 +01:00
|
|
|
friend class Resource;
|
2017-01-07 22:25:37 +01:00
|
|
|
static RWLock *lock;
|
2016-03-09 00:00:52 +01:00
|
|
|
static HashMap<String,Resource*> resources;
|
2014-02-10 02:10:30 +01:00
|
|
|
friend void unregister_core_types();
|
|
|
|
static void clear();
|
2017-01-07 22:25:37 +01:00
|
|
|
friend void register_core_types();
|
|
|
|
static void setup();
|
2016-03-09 00:00:52 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static void reload_externals();
|
|
|
|
static bool has(const String& p_path);
|
|
|
|
static Resource* get(const String& p_path);
|
|
|
|
static void dump(const char* p_file=NULL,bool p_short=false);
|
|
|
|
static void get_cached_resources(List<Ref<Resource> > *p_resources);
|
|
|
|
static int get_cached_resource_count();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|