globals.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*************************************************************************/
  2. /* globals.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 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. #include "object.h"
  32. #include "set.h"
  33. #include "os/thread_safe.h"
  34. /**
  35. @author Juan Linietsky <[email protected]>
  36. */
  37. class Globals : public Object {
  38. GDCLASS( Globals, Object );
  39. _THREAD_SAFE_CLASS_
  40. public:
  41. typedef Map<String,Variant> CustomMap;
  42. struct Singleton {
  43. StringName name;
  44. Object *ptr;
  45. Singleton(const StringName& p_name=StringName(), Object *p_ptr=NULL) { name=p_name; ptr=p_ptr; }
  46. };
  47. protected:
  48. enum {
  49. NO_ORDER_BASE=1<<18
  50. };
  51. struct VariantContainer {
  52. int order;
  53. bool persist;
  54. Variant variant;
  55. bool hide_from_editor;
  56. bool overrided;
  57. VariantContainer(){ order=0; hide_from_editor=false; persist=false; overrided=false; }
  58. 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; }
  59. };
  60. bool registering_order;
  61. int last_order;
  62. Map<StringName,VariantContainer> props;
  63. String resource_path;
  64. Map<StringName,PropertyInfo> custom_prop_info;
  65. bool disable_platform_override;
  66. bool using_datapack;
  67. List<String> input_presets;
  68. bool _set(const StringName& p_name, const Variant& p_value);
  69. bool _get(const StringName& p_name,Variant &r_ret) const;
  70. void _get_property_list(List<PropertyInfo> *p_list) const;
  71. static Globals *singleton;
  72. Error _load_settings(const String p_path);
  73. Error _load_settings_binary(const String p_path);
  74. Error _save_settings_text(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom=CustomMap());
  75. Error _save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom=CustomMap());
  76. List<Singleton> singletons;
  77. Map<StringName,Object*> singleton_ptrs;
  78. Error _save_custom_bnd(const String& p_file);
  79. bool _load_resource_pack(const String& p_pack);
  80. void _add_property_info_bind(const Dictionary& p_info);
  81. protected:
  82. static void _bind_methods();
  83. public:
  84. bool has(String p_var) const;
  85. String localize_path(const String& p_path) const;
  86. String globalize_path(const String& p_path) const;
  87. void set_persisting(const String& p_name, bool p_persist);
  88. bool is_persisting(const String& p_name) const;
  89. String get_resource_path() const;
  90. static Globals *get_singleton();
  91. void clear(const String& p_name);
  92. int get_order(const String& p_name) const;
  93. void set_order(const String& p_name, int p_order);
  94. Error setup(const String& p_path, const String &p_main_pack);
  95. Error save_custom(const String& p_path="",const CustomMap& p_custom=CustomMap(),const Set<String>& p_ignore_masks=Set<String>());
  96. Error save();
  97. void set_custom_property_info(const String& p_prop,const PropertyInfo& p_info);
  98. void add_singleton(const Singleton &p_singleton);
  99. void get_singletons(List<Singleton> *p_singletons);
  100. bool has_singleton(const String& p_name) const;
  101. Vector<String> get_optimizer_presets() const;
  102. List<String> get_input_presets() const { return input_presets; }
  103. void set_disable_platform_override(bool p_disable);
  104. Object* get_singleton_object(const String& p_name) const;
  105. void register_global_defaults();
  106. bool is_using_datapack() const;
  107. void set_registering_order(bool p_registering);
  108. Globals();
  109. ~Globals();
  110. };
  111. //not a macro any longer
  112. Variant _GLOBAL_DEF( const String& p_var, const Variant& p_default);
  113. #define GLOBAL_DEF(m_var,m_value) _GLOBAL_DEF(m_var,m_value)
  114. #endif