globals.h
1 /*************************************************************************/
2 /* globals.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 GLOBALS_H
30 #define GLOBALS_H
31 
32 #include "object.h"
33 #include "set.h"
34 #include "os/thread_safe.h"
40 class Globals : public Object {
41 
42  OBJ_TYPE( Globals, Object );
43  _THREAD_SAFE_CLASS_
44 
45 public:
46 
48 
49  struct Singleton {
50  StringName name;
51  Object *ptr;
52  Singleton(const StringName& p_name=StringName(), Object *p_ptr=NULL) { name=p_name; ptr=p_ptr; }
53  };
54 
55 protected:
56 
57  enum {
58  NO_ORDER_BASE=1<<18
59  };
60 
62  int order;
63  bool persist;
64  Variant variant;
65  bool hide_from_editor;
66  bool overrided;
67  VariantContainer(){ order=0; hide_from_editor=false; persist=false; overrided=false; }
68  VariantContainer(const Variant& p_variant, int p_order, bool p_persist=false) { variant=p_variant; order=p_order; hide_from_editor=false; persist=p_persist; overrided=false; }
69  };
70 
71  bool registering_order;
72  int last_order;
74  String resource_path;
75  Map<StringName,PropertyInfo> custom_prop_info;
76  bool disable_platform_override;
77  bool using_datapack;
78  List<String> input_presets;
79 
80 
81  bool _set(const StringName& p_name, const Variant& p_value);
82  bool _get(const StringName& p_name,Variant &r_ret) const;
83  void _get_property_list(List<PropertyInfo> *p_list) const;
84 
85  static Globals *singleton;
86 
87  Error _load_settings(const String p_path);
88  Error _load_settings_binary(const String p_path);
89 
90  Error _save_settings_text(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom=CustomMap());
91  Error _save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom=CustomMap());
92 
93  List<Singleton> singletons;
94 
95  Error _save_custom_bnd(const String& p_file);
96 
97  bool _load_resource_pack(const String& p_pack);
98 
99 protected:
100 
101  static void _bind_methods();
102 public:
103 
104 
105  bool has(String p_var) const;
106  String localize_path(const String& p_path) const;
107  String globalize_path(const String& p_path) const;
108 
109  void set_persisting(const String& p_name, bool p_persist);
110  bool is_persisting(const String& p_name) const;
111 
112  String get_resource_path() const;
113 
114  static Globals *get_singleton();
115 
116  void clear(const String& p_name);
117  int get_order(const String& p_name) const;
118  void set_order(const String& p_name, int p_order);
119 
120  Error setup(const String& p_path, const String &p_main_pack);
121 
122  Error save_custom(const String& p_path="",const CustomMap& p_custom=CustomMap(),const Set<String>& p_ignore_masks=Set<String>());
123  Error save();
124  void set_custom_property_info(const String& p_prop,const PropertyInfo& p_info);
125 
126  void add_singleton(const Singleton &p_singleton);
127  void get_singletons(List<Singleton> *p_singletons);
128 
129  bool has_singleton(const String& p_name) const;
130 
131  Vector<String> get_optimizer_presets() const;
132 
133  List<String> get_input_presets() const { return input_presets; }
134 
135  void set_disable_platform_override(bool p_disable);
136  Object* get_singleton_object(const String& p_name) const;
137 
138  void register_global_defaults();
139 
140  bool is_using_datapack() const;
141 
142  void set_registering_order(bool p_registering);
143 
144  Globals();
145  ~Globals();
146 
147 };
148 
149 //not a macro any longer
150 Variant _GLOBAL_DEF( const String& p_var, const Variant& p_default);
151 #define GLOBAL_DEF(m_var,m_value) _GLOBAL_DEF(m_var,m_value)
152 #endif
Definition: globals.h:40
Definition: variant.h:74
Definition: globals.h:61
Definition: globals.h:49
Definition: object.h:104
Definition: string_db.h:48
Definition: ustring.h:64
Definition: object.h:317