os_windows.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*************************************************************************/
  2. /* os_windows.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef OS_WINDOWS_H
  30. #define OS_WINDOWS_H
  31. #define WINVER 0x0500
  32. #include "os/input.h"
  33. #include "os/os.h"
  34. #include "context_gl_win.h"
  35. #include "servers/visual_server.h"
  36. #include "servers/visual/rasterizer.h"
  37. #include "servers/physics/physics_server_sw.h"
  38. #include "servers/audio/audio_server_sw.h"
  39. #include "servers/audio/sample_manager_sw.h"
  40. #include "drivers/rtaudio/audio_driver_rtaudio.h"
  41. #include "servers/spatial_sound/spatial_sound_server_sw.h"
  42. #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
  43. #include "drivers/unix/ip_unix.h"
  44. #include "servers/physics_2d/physics_2d_server_sw.h"
  45. #include <windows.h>
  46. #include "key_mapping_win.h"
  47. #include <windowsx.h>
  48. #include <io.h>
  49. #include <fcntl.h>
  50. #include <stdio.h>
  51. /**
  52. @author Juan Linietsky <[email protected]>
  53. */
  54. class OS_Windows : public OS {
  55. enum {
  56. JOYSTICKS_MAX = 8,
  57. JOY_AXIS_COUNT = 6,
  58. MAX_JOY_AXIS = 32768, // I've no idea
  59. KEY_EVENT_BUFFER_SIZE=512
  60. };
  61. FILE *stdo;
  62. struct KeyEvent {
  63. InputModifierState mod_state;
  64. UINT uMsg;
  65. WPARAM wParam;
  66. LPARAM lParam;
  67. };
  68. KeyEvent key_event_buffer[KEY_EVENT_BUFFER_SIZE];
  69. int key_event_pos;
  70. uint64_t ticks_start;
  71. uint64_t ticks_per_second;
  72. bool minimized;
  73. bool old_invalid;
  74. bool outside;
  75. int old_x,old_y;
  76. Point2i center;
  77. unsigned int last_id;
  78. #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) || defined(GLES2_ENABLED)
  79. ContextGL_Win *gl_context;
  80. #endif
  81. VisualServer *visual_server;
  82. Rasterizer *rasterizer;
  83. PhysicsServer *physics_server;
  84. Physics2DServer *physics_2d_server;
  85. int pressrc;
  86. HDC hDC; // Private GDI Device Context
  87. HINSTANCE hInstance; // Holds The Instance Of The Application
  88. HWND hWnd;
  89. struct Joystick {
  90. bool attached;
  91. DWORD last_axis[JOY_AXIS_COUNT];
  92. DWORD last_buttons;
  93. DWORD last_pov;
  94. Joystick() {
  95. attached = false;
  96. for (int i=0; i<JOY_AXIS_COUNT; i++) {
  97. last_axis[i] = 0;
  98. };
  99. last_buttons = 0;
  100. last_pov = 0;
  101. };
  102. };
  103. int joystick_count;
  104. Joystick joysticks[JOYSTICKS_MAX];
  105. VideoMode video_mode;
  106. MainLoop *main_loop;
  107. WNDPROC user_proc;
  108. AudioServerSW *audio_server;
  109. SampleManagerMallocSW *sample_manager;
  110. SpatialSoundServerSW *spatial_sound_server;
  111. SpatialSound2DServerSW *spatial_sound_2d_server;
  112. MouseMode mouse_mode;
  113. bool alt_mem;
  114. bool gr_mem;
  115. bool shift_mem;
  116. bool control_mem;
  117. bool meta_mem;
  118. bool force_quit;
  119. uint32_t last_button_state;
  120. CursorShape cursor_shape;
  121. InputDefault *input;
  122. #ifdef RTAUDIO_ENABLED
  123. AudioDriverRtAudio driver_rtaudio;
  124. #endif
  125. void _post_dpad(DWORD p_dpad, int p_device, bool p_pressed);
  126. // functions used by main to initialize/deintialize the OS
  127. protected:
  128. virtual int get_video_driver_count() const;
  129. virtual const char * get_video_driver_name(int p_driver) const;
  130. virtual VideoMode get_default_video_mode() const;
  131. virtual int get_audio_driver_count() const;
  132. virtual const char * get_audio_driver_name(int p_driver) const;
  133. virtual void initialize_core();
  134. virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
  135. virtual void set_main_loop( MainLoop * p_main_loop );
  136. virtual void delete_main_loop();
  137. virtual void finalize();
  138. virtual void finalize_core();
  139. void process_events();
  140. void probe_joysticks();
  141. void process_joysticks();
  142. void process_key_events();
  143. struct ProcessInfo {
  144. STARTUPINFO si;
  145. PROCESS_INFORMATION pi;
  146. };
  147. Map<ProcessID, ProcessInfo>* process_map;
  148. public:
  149. LRESULT WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam);
  150. void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type);
  151. virtual void vprint(const char *p_format, va_list p_list, bool p_stderr=false);
  152. virtual void alert(const String& p_alert,const String& p_title="ALERT!");
  153. String get_stdin_string(bool p_block);
  154. void set_mouse_mode(MouseMode p_mode);
  155. MouseMode get_mouse_mode() const;
  156. virtual Point2 get_mouse_pos() const;
  157. virtual int get_mouse_button_state() const;
  158. virtual void set_window_title(const String& p_title);
  159. virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0);
  160. virtual VideoMode get_video_mode(int p_screen=0) const;
  161. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
  162. virtual MainLoop *get_main_loop() const;
  163. virtual String get_name();
  164. virtual Date get_date() const;
  165. virtual Time get_time() const;
  166. virtual uint64_t get_unix_time() const;
  167. virtual bool can_draw() const;
  168. virtual Error set_cwd(const String& p_cwd);
  169. virtual void delay_usec(uint32_t p_usec) const;
  170. virtual uint64_t get_ticks_usec() const;
  171. virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL);
  172. virtual Error kill(const ProcessID& p_pid);
  173. virtual bool has_environment(const String& p_var) const;
  174. virtual String get_environment(const String& p_var) const;
  175. virtual void set_clipboard(const String& p_text);
  176. virtual String get_clipboard() const;
  177. void set_cursor_shape(CursorShape p_shape);
  178. void set_icon(const Image& p_icon);
  179. virtual String get_executable_path() const;
  180. virtual String get_locale() const;
  181. virtual void move_window_to_foreground();
  182. virtual String get_data_dir() const;
  183. virtual void release_rendering_thread();
  184. virtual void make_rendering_thread();
  185. virtual void swap_buffers();
  186. void run();
  187. virtual bool get_swap_ok_cancel() { return true; }
  188. OS_Windows(HINSTANCE _hInstance);
  189. ~OS_Windows();
  190. };
  191. #endif