os_windows.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*************************************************************************/
  2. /* os_windows.h */
  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. #ifndef OS_WINDOWS_H
  31. #define OS_WINDOWS_H
  32. #include "core/config/project_settings.h"
  33. #include "core/input/input.h"
  34. #include "core/os/os.h"
  35. #include "crash_handler_windows.h"
  36. #include "drivers/unix/ip_unix.h"
  37. #include "drivers/wasapi/audio_driver_wasapi.h"
  38. #include "drivers/winmidi/midi_driver_winmidi.h"
  39. #include "key_mapping_windows.h"
  40. #include "servers/audio_server.h"
  41. #include "servers/rendering/renderer_compositor.h"
  42. #include "servers/rendering_server.h"
  43. #ifdef XAUDIO2_ENABLED
  44. #include "drivers/xaudio2/audio_driver_xaudio2.h"
  45. #endif
  46. #if defined(OPENGL_ENABLED)
  47. #include "context_gl_windows.h"
  48. #endif
  49. #if defined(VULKAN_ENABLED)
  50. #include "drivers/vulkan/rendering_device_vulkan.h"
  51. #include "platform/windows/vulkan_context_win.h"
  52. #endif
  53. #include <fcntl.h>
  54. #include <io.h>
  55. #include <stdio.h>
  56. #include <windows.h>
  57. #include <windowsx.h>
  58. class JoypadWindows;
  59. class OS_Windows : public OS {
  60. #ifdef STDOUT_FILE
  61. FILE *stdo;
  62. #endif
  63. uint64_t ticks_start;
  64. uint64_t ticks_per_second;
  65. HINSTANCE hInstance;
  66. MainLoop *main_loop;
  67. #ifdef WASAPI_ENABLED
  68. AudioDriverWASAPI driver_wasapi;
  69. #endif
  70. #ifdef XAUDIO2_ENABLED
  71. AudioDriverXAudio2 driver_xaudio2;
  72. #endif
  73. #ifdef WINMIDI_ENABLED
  74. MIDIDriverWinMidi driver_midi;
  75. #endif
  76. CrashHandler crash_handler;
  77. bool force_quit;
  78. HWND main_window;
  79. // functions used by main to initialize/deinitialize the OS
  80. protected:
  81. virtual void initialize() override;
  82. virtual void set_main_loop(MainLoop *p_main_loop) override;
  83. virtual void delete_main_loop() override;
  84. virtual void finalize() override;
  85. virtual void finalize_core() override;
  86. virtual String get_stdin_string(bool p_block) override;
  87. String _quote_command_line_argument(const String &p_text) const;
  88. struct ProcessInfo {
  89. STARTUPINFO si;
  90. PROCESS_INFORMATION pi;
  91. };
  92. Map<ProcessID, ProcessInfo> *process_map;
  93. public:
  94. virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) override;
  95. virtual Error close_dynamic_library(void *p_library_handle) override;
  96. virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) override;
  97. virtual MainLoop *get_main_loop() const override;
  98. virtual String get_name() const override;
  99. virtual void initialize_joypads() override {}
  100. virtual Date get_date(bool utc) const override;
  101. virtual Time get_time(bool utc) const override;
  102. virtual TimeZoneInfo get_time_zone_info() const override;
  103. virtual double get_unix_time() const override;
  104. virtual Error set_cwd(const String &p_cwd) override;
  105. virtual void delay_usec(uint32_t p_usec) const override;
  106. virtual uint64_t get_ticks_usec() const override;
  107. virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr) override;
  108. virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
  109. virtual Error kill(const ProcessID &p_pid) override;
  110. virtual int get_process_id() const override;
  111. virtual bool has_environment(const String &p_var) const override;
  112. virtual String get_environment(const String &p_var) const override;
  113. virtual bool set_environment(const String &p_var, const String &p_value) const override;
  114. virtual String get_executable_path() const override;
  115. virtual String get_locale() const override;
  116. virtual int get_processor_count() const override;
  117. virtual String get_config_path() const override;
  118. virtual String get_data_path() const override;
  119. virtual String get_cache_path() const override;
  120. virtual String get_godot_dir_name() const override;
  121. virtual String get_system_dir(SystemDir p_dir) const override;
  122. virtual String get_user_data_dir() const override;
  123. virtual String get_unique_id() const override;
  124. virtual Error shell_open(String p_uri) override;
  125. void run();
  126. virtual bool _check_internal_feature_support(const String &p_feature) override;
  127. virtual void disable_crash_handler() override;
  128. virtual bool is_disable_crash_handler() const override;
  129. virtual void initialize_debugging() override;
  130. virtual Error move_to_trash(const String &p_path) override;
  131. void set_main_window(HWND p_main_window) { main_window = p_main_window; }
  132. HINSTANCE get_hinstance() { return hInstance; }
  133. OS_Windows(HINSTANCE _hInstance);
  134. ~OS_Windows();
  135. };
  136. #endif