resource_format_binary.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. Error error;
  60. int stage;
  61. friend class ResourceFormatLoaderBinary;
  62. Error parse_variant(Variant& r_v);
  63. public:
  64. virtual void set_local_path(const String& p_local_path);
  65. virtual Ref<Resource> get_resource();
  66. virtual Error poll();
  67. virtual int get_stage() const;
  68. virtual int get_stage_count() const;
  69. void open(FileAccess *p_f);
  70. String recognize(FileAccess *p_f);
  71. void get_dependencies(FileAccess *p_f,List<String> *p_dependencies);
  72. ResourceInteractiveLoaderBinary();
  73. ~ResourceInteractiveLoaderBinary();
  74. };
  75. class ResourceFormatLoaderBinary : public ResourceFormatLoader {
  76. public:
  77. virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path);
  78. virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
  79. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  80. virtual bool handles_type(const String& p_type) const;
  81. virtual String get_resource_type(const String &p_path) const;
  82. virtual void get_dependencies(const String& p_path,List<String> *p_dependencies);
  83. virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const;
  84. };
  85. class ResourceFormatSaverBinaryInstance {
  86. String local_path;
  87. bool relative_paths;
  88. bool bundle_resources;
  89. bool skip_editor;
  90. bool big_endian;
  91. bool takeover_paths;
  92. int bin_meta_idx;
  93. FileAccess *f;
  94. String magic;
  95. Map<RES,int> resource_map;
  96. Map<StringName,int> string_map;
  97. Vector<StringName> strings;
  98. Set<RES> external_resources;
  99. List<RES> saved_resources;
  100. struct Property {
  101. int name_idx;
  102. Variant value;
  103. PropertyInfo pi;
  104. };
  105. struct ResourceData {
  106. String type;
  107. List<Property> properties;
  108. };
  109. void _pad_buffer(int p_bytes);
  110. void write_variant(const Variant& p_property,const PropertyInfo& p_hint=PropertyInfo());
  111. void _find_resources(const Variant& p_variant,bool p_main=false);
  112. void save_unicode_string(const String& p_string);
  113. int get_string_index(const String& p_string);
  114. public:
  115. Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
  116. };
  117. class ResourceFormatSaverBinary : public ResourceFormatSaver {
  118. public:
  119. virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
  120. virtual bool recognize(const RES& p_resource) const;
  121. virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
  122. };
  123. #endif // RESOURCE_FORMAT_BINARY_H