resource_loader.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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-2015 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. #include "resource.h"
  32. /**
  33. @author Juan Linietsky <reduzio@gmail.com>
  34. */
  35. class ResourceInteractiveLoader : public Reference {
  36. OBJ_TYPE(ResourceInteractiveLoader,Reference);
  37. protected:
  38. static void _bind_methods();
  39. public:
  40. virtual void set_local_path(const String& p_local_path)=0;
  41. virtual Ref<Resource> get_resource()=0;
  42. virtual Error poll()=0;
  43. virtual int get_stage() const=0;
  44. virtual int get_stage_count() const=0;
  45. virtual Error wait();
  46. ResourceInteractiveLoader() {}
  47. };
  48. class ResourceFormatLoader {
  49. public:
  50. virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path);
  51. virtual RES load(const String &p_path,const String& p_original_path="");
  52. virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
  53. virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
  54. bool recognize(const String& p_extension) const;
  55. virtual bool handles_type(const String& p_type) const=0;
  56. virtual String get_resource_type(const String &p_path) const=0;
  57. virtual void get_dependencies(const String& p_path,List<String> *p_dependencies);
  58. virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { return ERR_UNAVAILABLE; }
  59. virtual ~ResourceFormatLoader() {}
  60. };
  61. typedef void (*ResourceLoadErrorNotify)(void *p_ud,const String& p_text);
  62. class ResourceLoader {
  63. enum {
  64. MAX_LOADERS=64
  65. };
  66. static ResourceFormatLoader *loader[MAX_LOADERS];
  67. static int loader_count;
  68. static bool timestamp_on_load;
  69. static void* err_notify_ud;
  70. static ResourceLoadErrorNotify err_notify;
  71. static bool abort_on_missing_resource;
  72. static String find_complete_path(const String& p_path,const String& p_type);
  73. public:
  74. static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,const String& p_type_hint="",bool p_no_cache=false);
  75. static RES load(const String &p_path,const String& p_type_hint="",bool p_no_cache=false);
  76. static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path);
  77. static void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions);
  78. static void add_resource_format_loader(ResourceFormatLoader *p_format_loader);
  79. static String get_resource_type(const String &p_path);
  80. static void get_dependencies(const String& p_path,List<String> *p_dependencies);
  81. static String guess_full_filename(const String &p_path,const String& p_type);
  82. static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load=p_timestamp; }
  83. static void notify_load_error(const String& p_err) { if (err_notify) err_notify(err_notify_ud,p_err); }
  84. static void set_error_notify_func(void* p_ud,ResourceLoadErrorNotify p_err_notify) { err_notify=p_err_notify; err_notify_ud=p_ud;}
  85. static void set_abort_on_missing_resources(bool p_abort) { abort_on_missing_resource=p_abort; }
  86. static bool get_abort_on_missing_resources() { return abort_on_missing_resource; }
  87. };
  88. #endif