os_javascript.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*************************************************************************/
  2. /* os_javascript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 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_JAVASCRIPT_H
  30. #define OS_JAVASCRIPT_H
  31. #include "os/input.h"
  32. #include "drivers/unix/os_unix.h"
  33. #include "os/main_loop.h"
  34. #include "servers/physics/physics_server_sw.h"
  35. #include "servers/spatial_sound/spatial_sound_server_sw.h"
  36. #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
  37. #include "servers/audio/audio_server_sw.h"
  38. #include "servers/physics_2d/physics_2d_server_sw.h"
  39. #include "servers/visual/rasterizer.h"
  40. #include "audio_server_javascript.h"
  41. #include "audio_driver_javascript.h"
  42. #include "main/input_default.h"
  43. #include "emscripten/html5.h"
  44. typedef void (*GFXInitFunc)(void *ud,bool gl2,int w, int h, bool fs);
  45. typedef int (*OpenURIFunc)(const String&);
  46. typedef String (*GetDataDirFunc)();
  47. typedef String (*GetLocaleFunc)();
  48. class OS_JavaScript : public OS_Unix {
  49. public:
  50. struct TouchPos {
  51. int id;
  52. Point2 pos;
  53. };
  54. private:
  55. Vector<TouchPos> touch;
  56. Point2 last_mouse;
  57. unsigned int last_id;
  58. GFXInitFunc gfx_init_func;
  59. void*gfx_init_ud;
  60. bool use_gl2;
  61. int64_t time_to_save_sync;
  62. int64_t last_sync_time;
  63. Rasterizer *rasterizer;
  64. VisualServer *visual_server;
  65. AudioServerJavascript *audio_server;
  66. //SampleManagerMallocSW *sample_manager;
  67. SpatialSoundServerSW *spatial_sound_server;
  68. SpatialSound2DServerSW *spatial_sound_2d_server;
  69. PhysicsServer *physics_server;
  70. Physics2DServer *physics_2d_server;
  71. AudioDriverJavaScript audio_driver_javascript;
  72. const char* gl_extensions;
  73. InputDefault *input;
  74. VideoMode default_videomode;
  75. MainLoop * main_loop;
  76. OpenURIFunc open_uri_func;
  77. GetDataDirFunc get_data_dir_func;
  78. GetLocaleFunc get_locale_func;
  79. static void _close_notification_funcs(const String& p_file,int p_flags);
  80. void process_joysticks();
  81. public:
  82. // functions used by main to initialize/deintialize the OS
  83. virtual int get_video_driver_count() const;
  84. virtual const char * get_video_driver_name(int p_driver) const;
  85. virtual VideoMode get_default_video_mode() const;
  86. virtual int get_audio_driver_count() const;
  87. virtual const char * get_audio_driver_name(int p_driver) const;
  88. virtual void initialize_core();
  89. virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
  90. virtual void set_main_loop( MainLoop * p_main_loop );
  91. virtual void delete_main_loop();
  92. virtual void finalize();
  93. typedef int64_t ProcessID;
  94. //static OS* get_singleton();
  95. virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false);
  96. virtual void print(const char *p_format, ... );
  97. virtual void alert(const String& p_alert);
  98. virtual void set_mouse_show(bool p_show);
  99. virtual void set_mouse_grab(bool p_grab);
  100. virtual bool is_mouse_grab_enabled() const;
  101. virtual Point2 get_mouse_pos() const;
  102. virtual int get_mouse_button_state() const;
  103. virtual void set_window_title(const String& p_title);
  104. //virtual void set_clipboard(const String& p_text);
  105. //virtual String get_clipboard() const;
  106. virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0);
  107. virtual VideoMode get_video_mode(int p_screen=0) const;
  108. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
  109. virtual Size2 get_window_size() const;
  110. virtual String get_name();
  111. virtual MainLoop *get_main_loop() const;
  112. virtual bool can_draw() const;
  113. virtual void set_cursor_shape(CursorShape p_shape);
  114. void main_loop_begin();
  115. bool main_loop_iterate();
  116. void main_loop_request_quit();
  117. void main_loop_end();
  118. void main_loop_focusout();
  119. void main_loop_focusin();
  120. virtual bool has_touchscreen_ui_hint() const;
  121. void set_opengl_extensions(const char* p_gl_extensions);
  122. void set_display_size(Size2 p_size);
  123. void reload_gfx();
  124. virtual Error shell_open(String p_uri);
  125. virtual String get_data_dir() const;
  126. virtual String get_resource_dir() const;
  127. virtual String get_locale() const;
  128. void process_accelerometer(const Vector3& p_accelerometer);
  129. void process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points);
  130. void push_input(const InputEvent& p_ev);
  131. virtual bool is_joy_known(int p_device);
  132. virtual String get_joy_guid(int p_device) const;
  133. bool joy_connection_changed(int p_type, const EmscriptenGamepadEvent *p_event);
  134. OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func);
  135. ~OS_JavaScript();
  136. };
  137. #endif