os_server.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*************************************************************************/
  2. /* os_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 "os_server.h"
  31. #include "core/string/print_string.h"
  32. #include "drivers/dummy/rasterizer_dummy.h"
  33. #include "drivers/dummy/texture_loader_dummy.h"
  34. #include "servers/rendering/rendering_server_default.h"
  35. #include "main/main.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <unistd.h>
  39. int OS_Server::get_video_driver_count() const {
  40. return 1;
  41. }
  42. const char *OS_Server::get_video_driver_name(int p_driver) const {
  43. return "Dummy";
  44. }
  45. int OS_Server::get_current_video_driver() const {
  46. return video_driver_index;
  47. }
  48. void OS_Server::initialize_core() {
  49. crash_handler.initialize();
  50. OS_Unix::initialize_core();
  51. }
  52. Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
  53. args = OS::get_singleton()->get_cmdline_args();
  54. current_videomode = p_desired;
  55. main_loop = nullptr;
  56. RasterizerDummy::make_current();
  57. video_driver_index = p_video_driver; // unused in server platform, but should still be initialized
  58. rendering_server = memnew(RenderingServerDefault);
  59. rendering_server->init();
  60. AudioDriverManager::initialize(p_audio_driver);
  61. input = memnew(InputDefault);
  62. _ensure_user_data_dir();
  63. resource_loader_dummy.instance();
  64. ResourceLoader::add_resource_format_loader(resource_loader_dummy);
  65. return OK;
  66. }
  67. void OS_Server::finalize() {
  68. if (main_loop)
  69. memdelete(main_loop);
  70. main_loop = nullptr;
  71. rendering_server->finish();
  72. memdelete(rendering_server);
  73. memdelete(input);
  74. ResourceLoader::remove_resource_format_loader(resource_loader_dummy);
  75. resource_loader_dummy.unref();
  76. args.clear();
  77. }
  78. void OS_Server::set_mouse_show(bool p_show) {
  79. }
  80. void OS_Server::set_mouse_grab(bool p_grab) {
  81. grab = p_grab;
  82. }
  83. bool OS_Server::is_mouse_grab_enabled() const {
  84. return grab;
  85. }
  86. int OS_Server::get_mouse_button_state() const {
  87. return 0;
  88. }
  89. Point2 OS_Server::get_mouse_position() const {
  90. return Point2();
  91. }
  92. void OS_Server::set_window_title(const String &p_title) {
  93. }
  94. void OS_Server::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
  95. }
  96. OS::VideoMode OS_Server::get_video_mode(int p_screen) const {
  97. return current_videomode;
  98. }
  99. Size2 OS_Server::get_window_size() const {
  100. return Vector2(current_videomode.width, current_videomode.height);
  101. }
  102. void OS_Server::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
  103. }
  104. MainLoop *OS_Server::get_main_loop() const {
  105. return main_loop;
  106. }
  107. void OS_Server::delete_main_loop() {
  108. if (main_loop)
  109. memdelete(main_loop);
  110. main_loop = nullptr;
  111. }
  112. void OS_Server::set_main_loop(MainLoop *p_main_loop) {
  113. main_loop = p_main_loop;
  114. input->set_main_loop(p_main_loop);
  115. }
  116. String OS_Server::get_name() const {
  117. return "Server";
  118. }
  119. void OS_Server::move_window_to_foreground() {
  120. }
  121. bool OS_Server::_check_internal_feature_support(const String &p_feature) {
  122. return p_feature == "pc";
  123. }
  124. void OS_Server::run() {
  125. force_quit = false;
  126. if (!main_loop)
  127. return;
  128. main_loop->init();
  129. while (!force_quit) {
  130. if (Main::iteration())
  131. break;
  132. };
  133. main_loop->finish();
  134. }
  135. String OS_Server::get_config_path() const {
  136. if (has_environment("XDG_CONFIG_HOME")) {
  137. return get_environment("XDG_CONFIG_HOME");
  138. } else if (has_environment("HOME")) {
  139. return get_environment("HOME").plus_file(".config");
  140. } else {
  141. return ".";
  142. }
  143. }
  144. String OS_Server::get_data_path() const {
  145. if (has_environment("XDG_DATA_HOME")) {
  146. return get_environment("XDG_DATA_HOME");
  147. } else if (has_environment("HOME")) {
  148. return get_environment("HOME").plus_file(".local/share");
  149. } else {
  150. return get_config_path();
  151. }
  152. }
  153. String OS_Server::get_cache_path() const {
  154. if (has_environment("XDG_CACHE_HOME")) {
  155. return get_environment("XDG_CACHE_HOME");
  156. } else if (has_environment("HOME")) {
  157. return get_environment("HOME").plus_file(".cache");
  158. } else {
  159. return get_config_path();
  160. }
  161. }
  162. String OS_Server::get_system_dir(SystemDir p_dir) const {
  163. String xdgparam;
  164. switch (p_dir) {
  165. case SYSTEM_DIR_DESKTOP: {
  166. xdgparam = "DESKTOP";
  167. } break;
  168. case SYSTEM_DIR_DCIM: {
  169. xdgparam = "PICTURES";
  170. } break;
  171. case SYSTEM_DIR_DOCUMENTS: {
  172. xdgparam = "DOCUMENTS";
  173. } break;
  174. case SYSTEM_DIR_DOWNLOADS: {
  175. xdgparam = "DOWNLOAD";
  176. } break;
  177. case SYSTEM_DIR_MOVIES: {
  178. xdgparam = "VIDEOS";
  179. } break;
  180. case SYSTEM_DIR_MUSIC: {
  181. xdgparam = "MUSIC";
  182. } break;
  183. case SYSTEM_DIR_PICTURES: {
  184. xdgparam = "PICTURES";
  185. } break;
  186. case SYSTEM_DIR_RINGTONES: {
  187. xdgparam = "MUSIC";
  188. } break;
  189. }
  190. String pipe;
  191. List<String> arg;
  192. arg.push_back(xdgparam);
  193. Error err = const_cast<OS_Server *>(this)->execute("xdg-user-dir", arg, true, nullptr, &pipe);
  194. if (err != OK)
  195. return ".";
  196. return pipe.strip_edges();
  197. }
  198. void OS_Server::disable_crash_handler() {
  199. crash_handler.disable();
  200. }
  201. bool OS_Server::is_disable_crash_handler() const {
  202. return crash_handler.is_disabled();
  203. }
  204. OS_Server::OS_Server() {
  205. //adriver here
  206. grab = false;
  207. };