os_server.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*************************************************************************/
  2. /* os_server.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "servers/visual/visual_server_raster.h"
  31. //#include "servers/visual/rasterizer_dummy.h"
  32. #include "os_server.h"
  33. #include "print_string.h"
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include "main/main.h"
  37. #include <unistd.h>
  38. int OS_Server::get_video_driver_count() const {
  39. return 1;
  40. }
  41. const char *OS_Server::get_video_driver_name(int p_driver) const {
  42. return "Dummy";
  43. }
  44. void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
  45. args = OS::get_singleton()->get_cmdline_args();
  46. current_videomode = p_desired;
  47. main_loop = NULL;
  48. //rasterizer = memnew( RasterizerDummy );
  49. //visual_server = memnew( VisualServerRaster(rasterizer) );
  50. AudioDriverManager::initialize(p_audio_driver);
  51. sample_manager = memnew(SampleManagerMallocSW);
  52. audio_server = memnew(AudioServerSW(sample_manager));
  53. audio_server->init();
  54. spatial_sound_server = memnew(SpatialSoundServerSW);
  55. spatial_sound_server->init();
  56. spatial_sound_2d_server = memnew(SpatialSound2DServerSW);
  57. spatial_sound_2d_server->init();
  58. ERR_FAIL_COND(!visual_server);
  59. visual_server->init();
  60. input = memnew(InputDefault);
  61. _ensure_user_data_dir();
  62. }
  63. void OS_Server::finalize() {
  64. if (main_loop)
  65. memdelete(main_loop);
  66. main_loop = NULL;
  67. spatial_sound_server->finish();
  68. memdelete(spatial_sound_server);
  69. spatial_sound_2d_server->finish();
  70. memdelete(spatial_sound_2d_server);
  71. /*
  72. if (debugger_connection_console) {
  73. memdelete(debugger_connection_console);
  74. }
  75. */
  76. memdelete(sample_manager);
  77. audio_server->finish();
  78. memdelete(audio_server);
  79. visual_server->finish();
  80. memdelete(visual_server);
  81. //memdelete(rasterizer);
  82. memdelete(input);
  83. args.clear();
  84. }
  85. void OS_Server::set_mouse_show(bool p_show) {
  86. }
  87. void OS_Server::set_mouse_grab(bool p_grab) {
  88. grab = p_grab;
  89. }
  90. bool OS_Server::is_mouse_grab_enabled() const {
  91. return grab;
  92. }
  93. int OS_Server::get_mouse_button_state() const {
  94. return 0;
  95. }
  96. Point2 OS_Server::get_mouse_position() const {
  97. return Point2();
  98. }
  99. void OS_Server::set_window_title(const String &p_title) {
  100. }
  101. void OS_Server::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
  102. }
  103. OS::VideoMode OS_Server::get_video_mode(int p_screen) const {
  104. return current_videomode;
  105. }
  106. Size2 OS_Server::get_window_size() const {
  107. return Vector2(current_videomode.width, current_videomode.height);
  108. }
  109. void OS_Server::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
  110. }
  111. MainLoop *OS_Server::get_main_loop() const {
  112. return main_loop;
  113. }
  114. void OS_Server::delete_main_loop() {
  115. if (main_loop)
  116. memdelete(main_loop);
  117. main_loop = NULL;
  118. }
  119. void OS_Server::set_main_loop(MainLoop *p_main_loop) {
  120. main_loop = p_main_loop;
  121. input->set_main_loop(p_main_loop);
  122. }
  123. bool OS_Server::can_draw() const {
  124. return false; //can never draw
  125. };
  126. String OS_Server::get_name() {
  127. return "Server";
  128. }
  129. void OS_Server::move_window_to_foreground() {
  130. }
  131. void OS_Server::set_cursor_shape(CursorShape p_shape) {
  132. }
  133. void OS_Server::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
  134. }
  135. OS::PowerState OS_Server::get_power_state() {
  136. return power_manager->get_power_state();
  137. }
  138. int OS_Server::get_power_seconds_left() {
  139. return power_manager->get_power_seconds_left();
  140. }
  141. int OS_Server::get_power_percent_left() {
  142. return power_manager->get_power_percent_left();
  143. }
  144. void OS_Server::run() {
  145. force_quit = false;
  146. if (!main_loop)
  147. return;
  148. main_loop->init();
  149. while (!force_quit) {
  150. if (Main::iteration() == true)
  151. break;
  152. };
  153. main_loop->finish();
  154. }
  155. OS_Server::OS_Server() {
  156. //adriver here
  157. grab = false;
  158. };