globals.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*************************************************************************/
  2. /* globals.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 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 <reduzio@gmail.com>
  36. */
  37. class Globals : public Object {
  38. OBJ_TYPE( 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. struct VariantContainer {
  49. int order;
  50. bool persist;
  51. Variant variant;
  52. bool hide_from_editor;
  53. bool overrided;
  54. VariantContainer(){ order=0; hide_from_editor=false; persist=false; overrided=false; }
  55. 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; }
  56. };
  57. int last_order;
  58. Map<StringName,VariantContainer> props;
  59. String resource_path;
  60. Map<StringName,PropertyInfo> custom_prop_info;
  61. bool disable_platform_override;
  62. bool using_datapack;
  63. bool _set(const StringName& p_name, const Variant& p_value);
  64. bool _get(const StringName& p_name,Variant &r_ret) const;
  65. void _get_property_list(List<PropertyInfo> *p_list) const;
  66. static Globals *singleton;
  67. Error _load_settings(const String p_path);
  68. Error _load_settings_binary(const String p_path);
  69. Error _save_settings_text(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom=CustomMap());
  70. Error _save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom=CustomMap());
  71. List<Singleton> singletons;
  72. bool _load_resource_pack(const String& p_pack);
  73. protected:
  74. static void _bind_methods();
  75. public:
  76. bool has(String p_var) const;
  77. String localize_path(const String& p_path) const;
  78. String globalize_path(const String& p_path) const;
  79. void set_persisting(const String& p_name, bool p_persist);
  80. bool is_persisting(const String& p_name) const;
  81. String get_resource_path() const;
  82. static Globals *get_singleton();
  83. void clear(const String& p_name);
  84. int get_order(const String& p_name) const;
  85. void set_order(const String& p_name, int p_order);
  86. Error setup(const String& p_path, const String &p_main_pack);
  87. Error save_custom(const String& p_path="",const CustomMap& p_custom=CustomMap(),const Set<String>& p_ignore_masks=Set<String>());
  88. Error save();
  89. void set_custom_property_info(const String& p_prop,const PropertyInfo& p_info);
  90. void add_singleton(const Singleton &p_singleton);
  91. void get_singletons(List<Singleton> *p_singletons);
  92. bool has_singleton(const String& p_name) const;
  93. Vector<String> get_optimizer_presets() const;
  94. void set_disable_platform_override(bool p_disable);
  95. Object* get_singleton_object(const String& p_name) const;
  96. void register_global_defaults();
  97. bool is_using_datapack() const;
  98. Globals();
  99. ~Globals();
  100. };
  101. //not a macro any longer
  102. Variant _GLOBAL_DEF( const String& p_var, const Variant& p_default);
  103. #define GLOBAL_DEF(m_var,m_value) _GLOBAL_DEF(m_var,m_value)
  104. #endif