engine.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*************************************************************************/
  2. /* engine.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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 "version.h"
  32. #include "version_hash.gen.h"
  33. void Engine::set_iterations_per_second(int p_ips) {
  34. ips = p_ips;
  35. }
  36. int Engine::get_iterations_per_second() const {
  37. return ips;
  38. }
  39. void Engine::set_physics_jitter_fix(float p_threshold) {
  40. if (p_threshold < 0)
  41. p_threshold = 0;
  42. physics_jitter_fix = p_threshold;
  43. }
  44. float Engine::get_physics_jitter_fix() const {
  45. return physics_jitter_fix;
  46. }
  47. void Engine::set_target_fps(int p_fps) {
  48. _target_fps = p_fps > 0 ? p_fps : 0;
  49. }
  50. float Engine::get_target_fps() const {
  51. return _target_fps;
  52. }
  53. uint64_t Engine::get_frames_drawn() {
  54. return frames_drawn;
  55. }
  56. void Engine::set_frame_delay(uint32_t p_msec) {
  57. _frame_delay = p_msec;
  58. }
  59. uint32_t Engine::get_frame_delay() const {
  60. return _frame_delay;
  61. }
  62. void Engine::set_time_scale(float p_scale) {
  63. _time_scale = p_scale;
  64. }
  65. float Engine::get_time_scale() const {
  66. return _time_scale;
  67. }
  68. Dictionary Engine::get_version_info() const {
  69. Dictionary dict;
  70. dict["major"] = VERSION_MAJOR;
  71. dict["minor"] = VERSION_MINOR;
  72. #ifdef VERSION_PATCH
  73. dict["patch"] = VERSION_PATCH;
  74. #else
  75. dict["patch"] = 0;
  76. #endif
  77. dict["status"] = VERSION_STATUS;
  78. dict["build"] = VERSION_BUILD;
  79. dict["year"] = VERSION_YEAR;
  80. String hash = VERSION_HASH;
  81. dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
  82. String stringver = String(dict["major"]) + "." + String(dict["minor"]);
  83. if ((int)dict["patch"] != 0)
  84. stringver += "." + String(dict["patch"]);
  85. stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
  86. dict["string"] = stringver;
  87. return dict;
  88. }
  89. void Engine::add_singleton(const Singleton &p_singleton) {
  90. singletons.push_back(p_singleton);
  91. singleton_ptrs[p_singleton.name] = p_singleton.ptr;
  92. }
  93. Object *Engine::get_singleton_object(const String &p_name) const {
  94. const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
  95. ERR_EXPLAIN("Failed to retrieve non-existent singleton '" + p_name + "'");
  96. ERR_FAIL_COND_V(!E, NULL);
  97. return E->get();
  98. };
  99. bool Engine::has_singleton(const String &p_name) const {
  100. return singleton_ptrs.has(p_name);
  101. };
  102. void Engine::get_singletons(List<Singleton> *p_singletons) {
  103. for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
  104. p_singletons->push_back(E->get());
  105. }
  106. Engine *Engine::singleton = NULL;
  107. Engine *Engine::get_singleton() {
  108. return singleton;
  109. }
  110. Engine::Engine() {
  111. singleton = this;
  112. frames_drawn = 0;
  113. ips = 60;
  114. physics_jitter_fix = 0.5;
  115. _frame_delay = 0;
  116. _fps = 1;
  117. _target_fps = 0;
  118. _time_scale = 1.0;
  119. _pixel_snap = false;
  120. _physics_frames = 0;
  121. _idle_frames = 0;
  122. _in_physics = false;
  123. _frame_ticks = 0;
  124. _frame_step = 0;
  125. editor_hint = false;
  126. }