engine.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*************************************************************************/
  2. /* engine.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. ips = p_ips;
  38. }
  39. int Engine::get_iterations_per_second() const {
  40. return ips;
  41. }
  42. void Engine::set_physics_jitter_fix(float p_threshold) {
  43. if (p_threshold < 0)
  44. p_threshold = 0;
  45. physics_jitter_fix = p_threshold;
  46. }
  47. float Engine::get_physics_jitter_fix() const {
  48. return physics_jitter_fix;
  49. }
  50. void Engine::set_target_fps(int p_fps) {
  51. _target_fps = p_fps > 0 ? p_fps : 0;
  52. }
  53. float Engine::get_target_fps() const {
  54. return _target_fps;
  55. }
  56. uint64_t Engine::get_frames_drawn() {
  57. return frames_drawn;
  58. }
  59. void Engine::set_frame_delay(uint32_t p_msec) {
  60. _frame_delay = p_msec;
  61. }
  62. uint32_t Engine::get_frame_delay() const {
  63. return _frame_delay;
  64. }
  65. void Engine::set_time_scale(float p_scale) {
  66. _time_scale = p_scale;
  67. }
  68. float Engine::get_time_scale() const {
  69. return _time_scale;
  70. }
  71. Dictionary Engine::get_version_info() const {
  72. Dictionary dict;
  73. dict["major"] = VERSION_MAJOR;
  74. dict["minor"] = VERSION_MINOR;
  75. #ifdef VERSION_PATCH
  76. dict["patch"] = VERSION_PATCH;
  77. #else
  78. dict["patch"] = 0;
  79. #endif
  80. dict["status"] = VERSION_STATUS;
  81. dict["build"] = VERSION_BUILD;
  82. dict["year"] = VERSION_YEAR;
  83. String hash = VERSION_HASH;
  84. dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
  85. String stringver = String(dict["major"]) + "." + String(dict["minor"]);
  86. if ((int)dict["patch"] != 0)
  87. stringver += "." + String(dict["patch"]);
  88. stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
  89. dict["string"] = stringver;
  90. return dict;
  91. }
  92. static Array array_from_info(const char *const *info_list) {
  93. Array arr;
  94. for (int i = 0; info_list[i] != NULL; i++) {
  95. arr.push_back(info_list[i]);
  96. }
  97. return arr;
  98. }
  99. static Array array_from_info_count(const char *const *info_list, int info_count) {
  100. Array arr;
  101. for (int i = 0; i < info_count; i++) {
  102. arr.push_back(info_list[i]);
  103. }
  104. return arr;
  105. }
  106. Dictionary Engine::get_author_info() const {
  107. Dictionary dict;
  108. dict["lead_developers"] = array_from_info(AUTHORS_LEAD_DEVELOPERS);
  109. dict["project_managers"] = array_from_info(AUTHORS_PROJECT_MANAGERS);
  110. dict["founders"] = array_from_info(AUTHORS_FOUNDERS);
  111. dict["developers"] = array_from_info(AUTHORS_DEVELOPERS);
  112. return dict;
  113. }
  114. Array Engine::get_copyright_info() const {
  115. Array components;
  116. for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) {
  117. const ComponentCopyright &cp_info = COPYRIGHT_INFO[component_index];
  118. Dictionary component_dict;
  119. component_dict["name"] = cp_info.name;
  120. Array parts;
  121. for (int i = 0; i < cp_info.part_count; i++) {
  122. const ComponentCopyrightPart &cp_part = cp_info.parts[i];
  123. Dictionary part_dict;
  124. part_dict["files"] = array_from_info_count(cp_part.files, cp_part.file_count);
  125. part_dict["copyright"] = array_from_info_count(cp_part.copyright_statements, cp_part.copyright_count);
  126. part_dict["license"] = cp_part.license;
  127. parts.push_back(part_dict);
  128. }
  129. component_dict["parts"] = parts;
  130. components.push_back(component_dict);
  131. }
  132. return components;
  133. }
  134. Dictionary Engine::get_donor_info() const {
  135. Dictionary donors;
  136. donors["platinum_sponsors"] = array_from_info(DONORS_SPONSOR_PLAT);
  137. donors["gold_sponsors"] = array_from_info(DONORS_SPONSOR_GOLD);
  138. donors["mini_sponsors"] = array_from_info(DONORS_SPONSOR_MINI);
  139. donors["gold_donors"] = array_from_info(DONORS_GOLD);
  140. donors["silver_donors"] = array_from_info(DONORS_SILVER);
  141. donors["bronze_donors"] = array_from_info(DONORS_BRONZE);
  142. return donors;
  143. }
  144. Dictionary Engine::get_license_info() const {
  145. Dictionary licenses;
  146. for (int i = 0; i < LICENSE_COUNT; i++) {
  147. licenses[LICENSE_NAMES[i]] = LICENSE_BODIES[i];
  148. }
  149. return licenses;
  150. }
  151. String Engine::get_license_text() const {
  152. return String(GODOT_LICENSE_TEXT);
  153. }
  154. void Engine::add_singleton(const Singleton &p_singleton) {
  155. singletons.push_back(p_singleton);
  156. singleton_ptrs[p_singleton.name] = p_singleton.ptr;
  157. }
  158. Object *Engine::get_singleton_object(const String &p_name) const {
  159. const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
  160. ERR_EXPLAIN("Failed to retrieve non-existent singleton '" + p_name + "'");
  161. ERR_FAIL_COND_V(!E, NULL);
  162. return E->get();
  163. };
  164. bool Engine::has_singleton(const String &p_name) const {
  165. return singleton_ptrs.has(p_name);
  166. };
  167. void Engine::get_singletons(List<Singleton> *p_singletons) {
  168. for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
  169. p_singletons->push_back(E->get());
  170. }
  171. Engine *Engine::singleton = NULL;
  172. Engine *Engine::get_singleton() {
  173. return singleton;
  174. }
  175. Engine::Engine() {
  176. singleton = this;
  177. frames_drawn = 0;
  178. ips = 60;
  179. physics_jitter_fix = 0.5;
  180. _frame_delay = 0;
  181. _fps = 1;
  182. _target_fps = 0;
  183. _time_scale = 1.0;
  184. _pixel_snap = false;
  185. _physics_frames = 0;
  186. _idle_frames = 0;
  187. _in_physics = false;
  188. _frame_ticks = 0;
  189. _frame_step = 0;
  190. editor_hint = false;
  191. }