engine.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*************************************************************************/
  2. /* engine.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "engine.h"
  31. #include "core/authors.gen.h"
  32. #include "core/donors.gen.h"
  33. #include "core/license.gen.h"
  34. #include "core/version.h"
  35. #include "core/version_hash.gen.h"
  36. void Engine::set_iterations_per_second(int p_ips) {
  37. ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
  38. ips = p_ips;
  39. }
  40. int Engine::get_iterations_per_second() const {
  41. return ips;
  42. }
  43. void Engine::set_physics_jitter_fix(float p_threshold) {
  44. if (p_threshold < 0)
  45. p_threshold = 0;
  46. physics_jitter_fix = p_threshold;
  47. }
  48. float Engine::get_physics_jitter_fix() const {
  49. return physics_jitter_fix;
  50. }
  51. void Engine::set_target_fps(int p_fps) {
  52. _target_fps = p_fps > 0 ? p_fps : 0;
  53. }
  54. int Engine::get_target_fps() const {
  55. return _target_fps;
  56. }
  57. uint64_t Engine::get_frames_drawn() {
  58. return frames_drawn;
  59. }
  60. void Engine::set_frame_delay(uint32_t p_msec) {
  61. _frame_delay = p_msec;
  62. }
  63. uint32_t Engine::get_frame_delay() const {
  64. return _frame_delay;
  65. }
  66. void Engine::set_time_scale(float p_scale) {
  67. _time_scale = p_scale;
  68. }
  69. float Engine::get_time_scale() const {
  70. return _time_scale;
  71. }
  72. Dictionary Engine::get_version_info() const {
  73. Dictionary dict;
  74. dict["major"] = VERSION_MAJOR;
  75. dict["minor"] = VERSION_MINOR;
  76. dict["patch"] = VERSION_PATCH;
  77. dict["hex"] = VERSION_HEX;
  78. dict["status"] = VERSION_STATUS;
  79. dict["build"] = VERSION_BUILD;
  80. dict["year"] = VERSION_YEAR;
  81. String hash = VERSION_HASH;
  82. dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
  83. String stringver = String(dict["major"]) + "." + String(dict["minor"]);
  84. if ((int)dict["patch"] != 0)
  85. stringver += "." + String(dict["patch"]);
  86. stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
  87. dict["string"] = stringver;
  88. return dict;
  89. }
  90. static Array array_from_info(const char *const *info_list) {
  91. Array arr;
  92. for (int i = 0; info_list[i] != nullptr; i++) {
  93. arr.push_back(info_list[i]);
  94. }
  95. return arr;
  96. }
  97. static Array array_from_info_count(const char *const *info_list, int info_count) {
  98. Array arr;
  99. for (int i = 0; i < info_count; i++) {
  100. arr.push_back(info_list[i]);
  101. }
  102. return arr;
  103. }
  104. Dictionary Engine::get_author_info() const {
  105. Dictionary dict;
  106. dict["lead_developers"] = array_from_info(AUTHORS_LEAD_DEVELOPERS);
  107. dict["project_managers"] = array_from_info(AUTHORS_PROJECT_MANAGERS);
  108. dict["founders"] = array_from_info(AUTHORS_FOUNDERS);
  109. dict["developers"] = array_from_info(AUTHORS_DEVELOPERS);
  110. return dict;
  111. }
  112. Array Engine::get_copyright_info() const {
  113. Array components;
  114. for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) {
  115. const ComponentCopyright &cp_info = COPYRIGHT_INFO[component_index];
  116. Dictionary component_dict;
  117. component_dict["name"] = cp_info.name;
  118. Array parts;
  119. for (int i = 0; i < cp_info.part_count; i++) {
  120. const ComponentCopyrightPart &cp_part = cp_info.parts[i];
  121. Dictionary part_dict;
  122. part_dict["files"] = array_from_info_count(cp_part.files, cp_part.file_count);
  123. part_dict["copyright"] = array_from_info_count(cp_part.copyright_statements, cp_part.copyright_count);
  124. part_dict["license"] = cp_part.license;
  125. parts.push_back(part_dict);
  126. }
  127. component_dict["parts"] = parts;
  128. components.push_back(component_dict);
  129. }
  130. return components;
  131. }
  132. Dictionary Engine::get_donor_info() const {
  133. Dictionary donors;
  134. donors["platinum_sponsors"] = array_from_info(DONORS_SPONSOR_PLAT);
  135. donors["gold_sponsors"] = array_from_info(DONORS_SPONSOR_GOLD);
  136. donors["mini_sponsors"] = array_from_info(DONORS_SPONSOR_MINI);
  137. donors["gold_donors"] = array_from_info(DONORS_GOLD);
  138. donors["silver_donors"] = array_from_info(DONORS_SILVER);
  139. donors["bronze_donors"] = array_from_info(DONORS_BRONZE);
  140. return donors;
  141. }
  142. Dictionary Engine::get_license_info() const {
  143. Dictionary licenses;
  144. for (int i = 0; i < LICENSE_COUNT; i++) {
  145. licenses[LICENSE_NAMES[i]] = LICENSE_BODIES[i];
  146. }
  147. return licenses;
  148. }
  149. String Engine::get_license_text() const {
  150. return String(GODOT_LICENSE_TEXT);
  151. }
  152. void Engine::add_singleton(const Singleton &p_singleton) {
  153. singletons.push_back(p_singleton);
  154. singleton_ptrs[p_singleton.name] = p_singleton.ptr;
  155. }
  156. Object *Engine::get_singleton_object(const String &p_name) const {
  157. const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
  158. ERR_FAIL_COND_V_MSG(!E, nullptr, "Failed to retrieve non-existent singleton '" + p_name + "'.");
  159. return E->get();
  160. };
  161. bool Engine::has_singleton(const String &p_name) const {
  162. return singleton_ptrs.has(p_name);
  163. };
  164. void Engine::get_singletons(List<Singleton> *p_singletons) {
  165. for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
  166. p_singletons->push_back(E->get());
  167. }
  168. Engine *Engine::singleton = nullptr;
  169. Engine *Engine::get_singleton() {
  170. return singleton;
  171. }
  172. bool Engine::is_abort_on_gpu_errors_enabled() const {
  173. return abort_on_gpu_errors;
  174. }
  175. Engine::Engine() {
  176. singleton = this;
  177. }