resource_loader.h
1 /*************************************************************************/
2 /* resource_loader.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef RESOURCE_LOADER_H
30 #define RESOURCE_LOADER_H
31 
32 #include "resource.h"
33 
39 
41 protected:
42 
43  static void _bind_methods();
44 public:
45 
46  virtual void set_local_path(const String& p_local_path)=0;
47  virtual Ref<Resource> get_resource()=0;
48  virtual Error poll()=0;
49  virtual int get_stage() const=0;
50  virtual int get_stage_count() const=0;
51  virtual Error wait();
52 
54 };
55 
56 
58 public:
59 
60  virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,Error *r_error=NULL);
61  virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
62  virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
63  virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
64  bool recognize(const String& p_extension) const;
65  virtual bool handles_type(const String& p_type) const=0;
66  virtual String get_resource_type(const String &p_path) const=0;
67  virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
68  virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { return ERR_UNAVAILABLE; }
69  virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map) { return OK; }
70 
71  virtual ~ResourceFormatLoader() {}
72 };
73 
74 
75 typedef void (*ResourceLoadErrorNotify)(void *p_ud,const String& p_text);
76 typedef void (*DependencyErrorNotify)(void *p_ud,const String& p_loading,const String& p_which,const String& p_type);
77 
78 
80 
81  enum {
82  MAX_LOADERS=64
83  };
84 
85  static ResourceFormatLoader *loader[MAX_LOADERS];
86  static int loader_count;
87  static bool timestamp_on_load;
88 
89  static void* err_notify_ud;
90  static ResourceLoadErrorNotify err_notify;
91  static void* dep_err_notify_ud;
92  static DependencyErrorNotify dep_err_notify;
93  static bool abort_on_missing_resource;
94 
95  static String find_complete_path(const String& p_path,const String& p_type);
96 public:
97 
98 
99 
100  static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL);
101  static RES load(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL);
102  static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path);
103 
104  static void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions);
105  static void add_resource_format_loader(ResourceFormatLoader *p_format_loader);
106  static String get_resource_type(const String &p_path);
107  static void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
108  static Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
109 
110  static String guess_full_filename(const String &p_path,const String& p_type);
111 
112  static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load=p_timestamp; }
113 
114  static void notify_load_error(const String& p_err) { if (err_notify) err_notify(err_notify_ud,p_err); }
115  static void set_error_notify_func(void* p_ud,ResourceLoadErrorNotify p_err_notify) { err_notify=p_err_notify; err_notify_ud=p_ud;}
116 
117  static void notify_dependency_error(const String& p_path,const String& p_dependency,const String& p_type) { if (dep_err_notify) dep_err_notify(dep_err_notify_ud,p_path,p_dependency,p_type); }
118  static void set_dependency_error_notify_func(void* p_ud,DependencyErrorNotify p_err_notify) { dep_err_notify=p_err_notify; dep_err_notify_ud=p_ud;}
119 
120 
121  static void set_abort_on_missing_resources(bool p_abort) { abort_on_missing_resource=p_abort; }
122  static bool get_abort_on_missing_resources() { return abort_on_missing_resource; }
123 };
124 
125 #endif
Definition: resource_loader.h:79
Definition: reference.h:40
Definition: resource_loader.h:57
Definition: ustring.h:64
Definition: resource_loader.h:38