resource_format_binary.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*************************************************************************/
  2. /* resource_format_binary.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_FORMAT_BINARY_H
  30. #define RESOURCE_FORMAT_BINARY_H
  31. #include "io/resource_loader.h"
  32. #include "io/resource_saver.h"
  33. #include "os/file_access.h"
  34. class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
  35. String local_path;
  36. String res_path;
  37. String type;
  38. Ref<Resource> resource;
  39. FileAccess *f;
  40. bool endian_swap;
  41. bool use_real64;
  42. uint64_t importmd_ofs;
  43. Vector<char> str_buf;
  44. List<RES> resource_cache;
  45. //Map<int,StringName> string_map;
  46. Vector<StringName> string_map;
  47. struct ExtResoucre {
  48. String path;
  49. String type;
  50. };
  51. Vector<ExtResoucre> external_resources;
  52. struct IntResoucre {
  53. String path;
  54. uint64_t offset;
  55. };
  56. Vector<IntResoucre> internal_resources;
  57. String get_unicode_string();
  58. void _advance_padding(uint32_t p_len);
  59. Map<String,String> remaps;
  60. Error error;
  61. int stage;
  62. friend class ResourceFormatLoaderBinary;
  63. Error parse_variant(Variant& r_v);
  64. public:
  65. virtual void set_local_path(const String& p_local_path);
  66. virtual Ref<Resource> get_resource();
  67. virtual Error poll();
  68. virtual int get_stage() const;
  69. virtual int get_stage_count() const;
  70. void set_remaps(const Map<String,String>& p_remaps) { remaps=p_remaps; }
  71. void open(FileAccess *p_f);
  72. String recognize(FileAccess *p_f);
  73. void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types);
  74. ResourceInteractiveLoaderBinary();
  75. ~ResourceInteractiveLoaderBinary();
  76. };
  77. class ResourceFormatLoaderBinary : public ResourceFormatLoader {
  78. public:
  79. virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,Error *r_error=NULL);
  80. virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
  81. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  82. virtual bool handles_type(const String& p_type) const;
  83. virtual String get_resource_type(const String &p_path) const;
  84. virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false);
  85. virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const;
  86. virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
  87. };
  88. class ResourceFormatSaverBinaryInstance {
  89. String local_path;
  90. bool relative_paths;
  91. bool bundle_resources;
  92. bool skip_editor;
  93. bool big_endian;
  94. bool takeover_paths;
  95. int bin_meta_idx;
  96. FileAccess *f;
  97. String magic;
  98. Set<RES> resource_set;
  99. Map<StringName,int> string_map;
  100. Vector<StringName> strings;
  101. Map<RES,int> external_resources;
  102. List<RES> saved_resources;
  103. struct Property {
  104. int name_idx;
  105. Variant value;
  106. PropertyInfo pi;
  107. };
  108. struct ResourceData {
  109. String type;
  110. List<Property> properties;
  111. };
  112. void _pad_buffer(int p_bytes);
  113. void write_variant(const Variant& p_property,const PropertyInfo& p_hint=PropertyInfo());
  114. void _find_resources(const Variant& p_variant,bool p_main=false);
  115. void save_unicode_string(const String& p_string);
  116. int get_string_index(const String& p_string);
  117. public:
  118. Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
  119. };
  120. class ResourceFormatSaverBinary : public ResourceFormatSaver {
  121. public:
  122. static ResourceFormatSaverBinary* singleton;
  123. virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
  124. virtual bool recognize(const RES& p_resource) const;
  125. virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
  126. ResourceFormatSaverBinary();
  127. };
  128. #endif // RESOURCE_FORMAT_BINARY_H