engine.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_target_fps(int p_fps) {
  40. _target_fps = p_fps > 0 ? p_fps : 0;
  41. }
  42. float Engine::get_target_fps() const {
  43. return _target_fps;
  44. }
  45. uint64_t Engine::get_frames_drawn() {
  46. return frames_drawn;
  47. }
  48. void Engine::set_frame_delay(uint32_t p_msec) {
  49. _frame_delay = p_msec;
  50. }
  51. uint32_t Engine::get_frame_delay() const {
  52. return _frame_delay;
  53. }
  54. void Engine::set_time_scale(float p_scale) {
  55. _time_scale = p_scale;
  56. }
  57. float Engine::get_time_scale() const {
  58. return _time_scale;
  59. }
  60. Dictionary Engine::get_version_info() const {
  61. Dictionary dict;
  62. dict["major"] = VERSION_MAJOR;
  63. dict["minor"] = VERSION_MINOR;
  64. #ifdef VERSION_PATCH
  65. dict["patch"] = VERSION_PATCH;
  66. #else
  67. dict["patch"] = 0;
  68. #endif
  69. dict["status"] = VERSION_STATUS;
  70. dict["build"] = VERSION_BUILD;
  71. dict["year"] = VERSION_YEAR;
  72. String hash = VERSION_HASH;
  73. dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
  74. String stringver = String(dict["major"]) + "." + String(dict["minor"]);
  75. if ((int)dict["patch"] != 0)
  76. stringver += "." + String(dict["patch"]);
  77. stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
  78. dict["string"] = stringver;
  79. return dict;
  80. }
  81. void Engine::add_singleton(const Singleton &p_singleton) {
  82. singletons.push_back(p_singleton);
  83. singleton_ptrs[p_singleton.name] = p_singleton.ptr;
  84. }
  85. Object *Engine::get_singleton_object(const String &p_name) const {
  86. const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
  87. ERR_EXPLAIN("Failed to retrieve non-existent singleton '" + p_name + "'");
  88. ERR_FAIL_COND_V(!E, NULL);
  89. return E->get();
  90. };
  91. bool Engine::has_singleton(const String &p_name) const {
  92. return singleton_ptrs.has(p_name);
  93. };
  94. void Engine::get_singletons(List<Singleton> *p_singletons) {
  95. for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
  96. p_singletons->push_back(E->get());
  97. }
  98. Engine *Engine::singleton = NULL;
  99. Engine *Engine::get_singleton() {
  100. return singleton;
  101. }
  102. Engine::Engine() {
  103. singleton = this;
  104. frames_drawn = 0;
  105. ips = 60;
  106. _frame_delay = 0;
  107. _fps = 1;
  108. _target_fps = 0;
  109. _time_scale = 1.0;
  110. _pixel_snap = false;
  111. _physics_frames = 0;
  112. _idle_frames = 0;
  113. _in_physics = false;
  114. _frame_ticks = 0;
  115. _frame_step = 0;
  116. editor_hint = false;
  117. }