resource_format_binary.h
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-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_FORMAT_BINARY_H
30 #define RESOURCE_FORMAT_BINARY_H
31 
32 #include "io/resource_loader.h"
33 #include "io/resource_saver.h"
34 #include "os/file_access.h"
35 
36 
38 
39  String local_path;
40  String res_path;
41  String type;
42  Ref<Resource> resource;
43 
44  FileAccess *f;
45 
46 
47  bool endian_swap;
48  bool use_real64;
49  uint64_t importmd_ofs;
50 
51  Vector<char> str_buf;
52  List<RES> resource_cache;
53 
54  //Map<int,StringName> string_map;
55  Vector<StringName> string_map;
56 
57  struct ExtResoucre {
58  String path;
59  String type;
60  };
61 
62  Vector<ExtResoucre> external_resources;
63 
64  struct IntResoucre {
65  String path;
66  uint64_t offset;
67  };
68 
69  Vector<IntResoucre> internal_resources;
70 
71  String get_unicode_string();
72  void _advance_padding(uint32_t p_len);
73 
74  Map<String,String> remaps;
75  Error error;
76 
77  int stage;
78 
79 friend class ResourceFormatLoaderBinary;
80 
81 
82  Error parse_variant(Variant& r_v);
83 
84 public:
85 
86  virtual void set_local_path(const String& p_local_path);
87  virtual Ref<Resource> get_resource();
88  virtual Error poll();
89  virtual int get_stage() const;
90  virtual int get_stage_count() const;
91 
92  void set_remaps(const Map<String,String>& p_remaps) { remaps=p_remaps; }
93  void open(FileAccess *p_f);
94  String recognize(FileAccess *p_f);
95  void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types);
96 
97 
100 
101 };
102 
104 public:
105 
106  virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,Error *r_error=NULL);
107  virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
108  virtual void get_recognized_extensions(List<String> *p_extensions) const;
109  virtual bool handles_type(const String& p_type) const;
110  virtual String get_resource_type(const String &p_path) const;
111  virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false);
112  virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const;
113  virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
114 
115 
116 
117 };
118 
119 
120 
121 
123 
124  String local_path;
125 
126 
127  bool relative_paths;
128  bool bundle_resources;
129  bool skip_editor;
130  bool big_endian;
131  bool takeover_paths;
132  int bin_meta_idx;
133  FileAccess *f;
134  String magic;
135  Set<RES> resource_set;
136  Map<StringName,int> string_map;
137  Vector<StringName> strings;
138 
139 
140  Map<RES,int> external_resources;
141  List<RES> saved_resources;
142 
143 
144  struct Property {
145  int name_idx;
146  Variant value;
147  PropertyInfo pi;
148 
149  };
150 
151  struct ResourceData {
152 
153  String type;
154  List<Property> properties;
155  };
156 
157 
158 
159 
160  void _pad_buffer(int p_bytes);
161  void write_variant(const Variant& p_property,const PropertyInfo& p_hint=PropertyInfo());
162  void _find_resources(const Variant& p_variant,bool p_main=false);
163  void save_unicode_string(const String& p_string);
164  int get_string_index(const String& p_string);
165 public:
166 
167 
168  Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
169 };
170 
171 
172 
174 
175 
176 
177 
178 public:
179 
180  static ResourceFormatSaverBinary* singleton;
181  virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
182  virtual bool recognize(const RES& p_resource) const;
183  virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
184 
186 };
187 
188 
189 #endif // RESOURCE_FORMAT_BINARY_H
Definition: variant.h:74
Definition: set.h:44
Definition: resource_format_binary.h:37
Definition: resource_format_binary.h:103
Definition: object.h:104
Definition: list.h:44
Definition: resource_loader.h:57
Definition: resource_format_binary.h:173
Definition: ustring.h:64
Definition: resource_saver.h:43
Definition: file_access.h:40
Definition: resource_format_binary.h:122
Definition: resource_loader.h:38