| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/object/ref_counted.h" |
| 34 |
#include "core/string/string_name.h" |
| 35 |
#include "core/templates/hash_map.h" |
| 36 |
|
| 37 |
class FileAccess; |
| 38 |
|
| 39 |
typedef void (*ResourceUIDScanForUIDOnStartup)(); |
| 40 |
|
| 41 |
class ResourceUID : public Object { |
| 42 |
GDCLASS(ResourceUID, Object) |
| 43 |
public: |
| 44 |
typedef int64_t ID; |
| 45 |
constexpr const static ID INVALID_ID = -1; |
| 46 |
|
| 47 |
static String get_cache_file(); |
| 48 |
|
| 49 |
private: |
| 50 |
void *crypto = nullptr; |
| 51 |
Mutex mutex; |
| 52 |
struct Cache { |
| 53 |
CharString cs; |
| 54 |
bool saved_to_cache = false; |
| 55 |
}; |
| 56 |
|
| 57 |
HashMap<ID, Cache> unique_ids; |
| 58 |
bool use_reverse_cache = false; |
| 59 |
HashMap<CharString, ID> reverse_cache; |
| 60 |
static ResourceUID *singleton; |
| 61 |
|
| 62 |
uint32_t cache_entries = 0; |
| 63 |
bool changed = false; |
| 64 |
bool cache_initialized = false; |
| 65 |
|
| 66 |
protected: |
| 67 |
static void _bind_methods(); |
| 68 |
|
| 69 |
public: |
| 70 |
inline static ResourceUIDScanForUIDOnStartup scan_for_uid_on_startup = nullptr; |
| 71 |
|
| 72 |
String id_to_text(ID p_id) const; |
| 73 |
ID text_to_id(const String &p_text) const; |
| 74 |
|
| 75 |
ID create_id(); |
| 76 |
ID create_id_for_path(const String &p_path); |
| 77 |
bool has_id(ID p_id) const; |
| 78 |
void add_id(ID p_id, const String &p_path); |
| 79 |
void set_id(ID p_id, const String &p_path); |
| 80 |
String get_id_path(ID p_id) const; |
| 81 |
ID get_path_id(const String &p_path) const; |
| 82 |
void remove_id(ID p_id); |
| 83 |
|
| 84 |
static String uid_to_path(const String &p_uid); |
| 85 |
static String path_to_uid(const String &p_path); |
| 86 |
static String ensure_path(const String &p_uid_or_path); |
| 87 |
|
| 88 |
Error load_from_cache(bool p_reset); |
| 89 |
Error save_to_cache(); |
| 90 |
Error update_cache(); |
| 91 |
static String get_path_from_cache(Ref<FileAccess> &p_cache_file, const String &p_uid_string); |
| 92 |
|
| 93 |
void enable_reverse_cache() { use_reverse_cache = true; } |
| 94 |
void clear(); |
| 95 |
|
| 96 |
static ResourceUID *get_singleton() { return singleton; } |
| 97 |
|
| 98 |
ResourceUID(); |
| 99 |
~ResourceUID(); |
| 100 |
}; |