os_server.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*************************************************************************/
  2. /* os_server.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 "os_server.h"
  31. #include "print_string.h"
  32. #include "servers/physics/physics_server_sw.h"
  33. #include "servers/visual/rasterizer_dummy.h"
  34. #include "servers/visual/visual_server_raster.h"
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include "main/main.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. OS::VideoMode OS_Server::get_default_video_mode() const {
  46. return OS::VideoMode(800, 600, false);
  47. }
  48. void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
  49. args = OS::get_singleton()->get_cmdline_args();
  50. current_videomode = p_desired;
  51. main_loop = NULL;
  52. rasterizer = memnew(RasterizerDummy);
  53. visual_server = memnew(VisualServerRaster(rasterizer));
  54. AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton();
  55. if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
  56. ERR_PRINT("Initializing audio failed.");
  57. }
  58. sample_manager = memnew(SampleManagerMallocSW);
  59. audio_server = memnew(AudioServerSW(sample_manager));
  60. audio_server->init();
  61. spatial_sound_server = memnew(SpatialSoundServerSW);
  62. spatial_sound_server->init();
  63. spatial_sound_2d_server = memnew(SpatialSound2DServerSW);
  64. spatial_sound_2d_server->init();
  65. ERR_FAIL_COND(!visual_server);
  66. visual_server->init();
  67. //
  68. physics_server = memnew(PhysicsServerSW);
  69. physics_server->init();
  70. physics_2d_server = memnew(Physics2DServerSW);
  71. physics_2d_server->init();
  72. input = memnew(InputDefault);
  73. _ensure_data_dir();
  74. }
  75. void OS_Server::finalize() {
  76. if (main_loop)
  77. memdelete(main_loop);
  78. main_loop = NULL;
  79. spatial_sound_server->finish();
  80. memdelete(spatial_sound_server);
  81. spatial_sound_2d_server->finish();
  82. memdelete(spatial_sound_2d_server);
  83. //if (debugger_connection_console) {
  84. // memdelete(debugger_connection_console);
  85. //}
  86. memdelete(sample_manager);
  87. audio_server->finish();
  88. memdelete(audio_server);
  89. visual_server->finish();
  90. memdelete(visual_server);
  91. memdelete(rasterizer);
  92. physics_server->finish();
  93. memdelete(physics_server);
  94. physics_2d_server->finish();
  95. memdelete(physics_2d_server);
  96. memdelete(input);
  97. args.clear();
  98. }
  99. void OS_Server::set_mouse_show(bool p_show) {
  100. }
  101. void OS_Server::set_mouse_grab(bool p_grab) {
  102. grab = p_grab;
  103. }
  104. bool OS_Server::is_mouse_grab_enabled() const {
  105. return grab;
  106. }
  107. int OS_Server::get_mouse_button_state() const {
  108. return 0;
  109. }
  110. Point2 OS_Server::get_mouse_pos() const {
  111. return Point2();
  112. }
  113. void OS_Server::set_window_title(const String &p_title) {
  114. }
  115. void OS_Server::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
  116. }
  117. OS::VideoMode OS_Server::get_video_mode(int p_screen) const {
  118. return current_videomode;
  119. }
  120. Size2 OS_Server::get_window_size() const {
  121. return Vector2(current_videomode.width, current_videomode.height);
  122. }
  123. void OS_Server::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
  124. }
  125. MainLoop *OS_Server::get_main_loop() const {
  126. return main_loop;
  127. }
  128. void OS_Server::delete_main_loop() {
  129. if (main_loop)
  130. memdelete(main_loop);
  131. main_loop = NULL;
  132. }
  133. void OS_Server::set_main_loop(MainLoop *p_main_loop) {
  134. main_loop = p_main_loop;
  135. input->set_main_loop(p_main_loop);
  136. }
  137. bool OS_Server::can_draw() const {
  138. return false; //can never draw
  139. };
  140. String OS_Server::get_name() {
  141. return "Server";
  142. }
  143. void OS_Server::move_window_to_foreground() {
  144. }
  145. void OS_Server::set_cursor_shape(CursorShape p_shape) {
  146. }
  147. void OS_Server::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
  148. }
  149. void OS_Server::run() {
  150. force_quit = false;
  151. if (!main_loop)
  152. return;
  153. main_loop->init();
  154. while (!force_quit) {
  155. if (Main::iteration() == true)
  156. break;
  157. };
  158. main_loop->finish();
  159. }
  160. OS_Server::OS_Server() {
  161. AudioDriverManagerSW::add_driver(&driver_dummy);
  162. //adriver here
  163. grab = false;
  164. };