From 4a56f72f5be6cd34c96a082e3697f4eecd744e75 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sun, 24 May 2015 23:22:51 +0300 Subject: Haiku: Initial support. --- platform/haiku/SCsub | 10 ++++++++++ platform/haiku/detect.py | 42 +++++++++++++++++++++++++++++++++++++++ platform/haiku/godot_haiku.cpp | 19 ++++++++++++++++++ platform/haiku/logo.png | Bin 0 -> 2055 bytes platform/haiku/os_haiku.cpp | 0 platform/haiku/os_haiku.h | 42 +++++++++++++++++++++++++++++++++++++++ platform/haiku/platform_config.h | 1 + 7 files changed, 114 insertions(+) create mode 100644 platform/haiku/SCsub create mode 100644 platform/haiku/detect.py create mode 100644 platform/haiku/godot_haiku.cpp create mode 100644 platform/haiku/logo.png create mode 100644 platform/haiku/os_haiku.cpp create mode 100644 platform/haiku/os_haiku.h create mode 100644 platform/haiku/platform_config.h diff --git a/platform/haiku/SCsub b/platform/haiku/SCsub new file mode 100644 index 0000000000..8ae489cf54 --- /dev/null +++ b/platform/haiku/SCsub @@ -0,0 +1,10 @@ +Import('env') + +common_haiku = [ + 'os_haiku.cpp' +] + +env.Program( + '#bin/godot', + ['godot_haiku.cpp'] + common_haiku +) diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py new file mode 100644 index 0000000000..992c73ee79 --- /dev/null +++ b/platform/haiku/detect.py @@ -0,0 +1,42 @@ +import os +import sys + +def is_active(): + return True + +def get_name(): + return "Haiku" + +def can_build(): + if (os.name != "posix"): + return False + + if (sys.platform == "darwin"): + return False + + return True + +def get_opts(): + return [] + +def get_flags(): + return [ + ('builtin_zlib', 'no') + ] + +def configure(env): + is64=sys.maxsize > 2**32 + + if (env["bits"]=="default"): + if (is64): + env["bits"]="64" + else: + env["bits"]="32" + + env.Append(CPPPATH = ['#platform/haiku']) + env["CC"] = "gcc-x86" + env["CXX"] = "g++-x86" + env.Append(CPPFLAGS = ['-DDEBUG_METHODS_ENABLED']) + + env.Append(CPPFLAGS = ['-DUNIX_ENABLED']) + #env.Append(LIBS = ['be']) diff --git a/platform/haiku/godot_haiku.cpp b/platform/haiku/godot_haiku.cpp new file mode 100644 index 0000000000..b4e5e50891 --- /dev/null +++ b/platform/haiku/godot_haiku.cpp @@ -0,0 +1,19 @@ +#include "main/main.h" +#include "os_haiku.h" + +int main(int argc, char* argv[]) { + OS_Haiku os; + + Error error = Main::setup(argv[0], argc-1, &argv[1]); + if (error != OK) { + return 255; + } + + if (Main::start()) { + os.run(); + } + + Main::cleanup(); + + return os.get_exit_code(); +} diff --git a/platform/haiku/logo.png b/platform/haiku/logo.png new file mode 100644 index 0000000000..c40214d6de Binary files /dev/null and b/platform/haiku/logo.png differ diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h new file mode 100644 index 0000000000..ee1283f018 --- /dev/null +++ b/platform/haiku/os_haiku.h @@ -0,0 +1,42 @@ +#ifndef OS_HAIKU_H +#define OS_HAIKU_H + +#include "drivers/unix/os_unix.h" + + +class OS_Haiku : public OS_Unix { +private: + virtual void delete_main_loop(); + +protected: + virtual int get_video_driver_count() const; + virtual const char* get_video_driver_name(int p_driver) const; + virtual VideoMode get_default_video_mode() const; + + virtual void initialize(const VideoMode& p_desired, int p_video_driver, int p_audio_driver); + virtual void finalize(); + + virtual void set_main_loop(MainLoop* p_main_loop); + +public: + OS_Haiku(); + void run(); + + virtual String get_name(); + + virtual MainLoop *get_main_loop() const; + virtual bool can_draw() const; + + virtual Point2 get_mouse_pos() const; + virtual int get_mouse_button_state() const; + virtual void set_cursor_shape(CursorShape p_shape); + + virtual void set_window_title(const String& p_title); + virtual Size2 get_window_size() const; + + virtual void set_video_mode(const VideoMode& p_video_mode, int p_screen=0); + virtual VideoMode get_video_mode(int p_screen=0) const; + virtual void get_fullscreen_mode_list(List *p_list, int p_screen=0) const; +}; + +#endif diff --git a/platform/haiku/platform_config.h b/platform/haiku/platform_config.h new file mode 100644 index 0000000000..dad24432a5 --- /dev/null +++ b/platform/haiku/platform_config.h @@ -0,0 +1 @@ +#include -- cgit v1.2.3 From 4e07a2dea8c94337702d35d0d02d4b7234f86e29 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Mon, 25 May 2015 03:49:24 +0300 Subject: Haiku: fix building with UNIX_ENABLED. --- drivers/unix/packet_peer_udp_posix.cpp | 6 +++++- drivers/unix/stream_peer_tcp_posix.cpp | 9 +++++++-- drivers/unix/tcp_server_posix.cpp | 6 +++++- platform/haiku/detect.py | 6 ++++-- platform/haiku/os_haiku.cpp | 5 +++++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 26a0b29228..94b4c35923 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -13,7 +13,11 @@ #include #ifndef NO_FCNTL -#include + #ifdef __HAIKU__ + #include + #else + #include + #endif #else #include #endif diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index 2301d8b6c4..2db7d9f6ec 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -39,7 +39,11 @@ #include #include #ifndef NO_FCNTL -#include + #ifdef __HAIKU__ + #include + #else + #include + #endif #else #include #endif @@ -202,7 +206,8 @@ Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent, while (data_to_send) { - int sent_amount = send(sockfd, offset, data_to_send, MSG_NOSIGNAL); + // TODO: handle MSG_NOSIGNAL on __HAIKU__ + int sent_amount = send(sockfd, offset, data_to_send, 0); //printf("Sent TCP data of %d bytes, errno %d\n", sent_amount, errno); if (sent_amount == -1) { diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index 4f9ee62cde..aaca0fe0d8 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -41,7 +41,11 @@ #include #include #ifndef NO_FCNTL -#include + #ifdef __HAIKU__ + #include + #else + #include + #endif #else #include #endif diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index 992c73ee79..5dad2af033 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -34,9 +34,11 @@ def configure(env): env["bits"]="32" env.Append(CPPPATH = ['#platform/haiku']) + + # TODO: add clang and try gcc2 too env["CC"] = "gcc-x86" env["CXX"] = "g++-x86" - env.Append(CPPFLAGS = ['-DDEBUG_METHODS_ENABLED']) + env.Append(CPPFLAGS = ['-DDEBUG_METHODS_ENABLED']) env.Append(CPPFLAGS = ['-DUNIX_ENABLED']) - #env.Append(LIBS = ['be']) + env.Append(LIBS = ['be']) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index e69de29bb2..8841306b7a 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -0,0 +1,5 @@ +#include "os_haiku.h" + +String OS_Haiku::get_name() { + return "Haiku"; +} -- cgit v1.2.3 From 826f8af1ef3311ddcc0fab27629f7a5fcfa1b024 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Mon, 25 May 2015 06:02:55 +0300 Subject: Haiku: link with the haiku libs, stub the OS_Haiku class. --- drivers/unix/stream_peer_tcp_posix.cpp | 8 +++- platform/haiku/detect.py | 2 +- platform/haiku/os_haiku.cpp | 76 ++++++++++++++++++++++++++++++++++ platform/haiku/os_haiku.h | 3 +- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index 2db7d9f6ec..f65eb694d6 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -206,8 +206,12 @@ Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent, while (data_to_send) { - // TODO: handle MSG_NOSIGNAL on __HAIKU__ - int sent_amount = send(sockfd, offset, data_to_send, 0); + // TODO: haiku does not have MSG_NOSIGNAL +#ifdef __HAIKU__ + int sent_amount = send(sockfd, offset, data_to_send, 0); +#else + int sent_amount = send(sockfd, offset, data_to_send, MSG_NOSIGNAL); +#endif //printf("Sent TCP data of %d bytes, errno %d\n", sent_amount, errno); if (sent_amount == -1) { diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index 5dad2af033..b443469d8d 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -41,4 +41,4 @@ def configure(env): env.Append(CPPFLAGS = ['-DDEBUG_METHODS_ENABLED']) env.Append(CPPFLAGS = ['-DUNIX_ENABLED']) - env.Append(LIBS = ['be']) + env.Append(LIBS = ['be', 'z', 'network', 'bnetapi']) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 8841306b7a..4d45bb3333 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -1,5 +1,81 @@ #include "os_haiku.h" +OS_Haiku::OS_Haiku() { + +}; + +void OS_Haiku::run() { + +} + String OS_Haiku::get_name() { return "Haiku"; } + +void OS_Haiku::delete_main_loop() { + +} + +int OS_Haiku::get_video_driver_count() const { + +} + +const char* OS_Haiku::get_video_driver_name(int p_driver) const { + +} + +OS::VideoMode OS_Haiku::get_default_video_mode() const { + +} + +void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_audio_driver) { + +} + +void OS_Haiku::finalize() { + +} + +void OS_Haiku::set_main_loop(MainLoop* p_main_loop) { + +} + +MainLoop* OS_Haiku::get_main_loop() const { + +} + +bool OS_Haiku::can_draw() const { + +} + +Point2 OS_Haiku::get_mouse_pos() const { + +} + +int OS_Haiku::get_mouse_button_state() const { + +} + +void OS_Haiku::set_cursor_shape(CursorShape p_shape) { + +} + +void OS_Haiku::set_window_title(const String& p_title) { + +} + +Size2 OS_Haiku::get_window_size() const { + +} + +void OS_Haiku::set_video_mode(const VideoMode& p_video_mode, int p_screen) { + +} + +OS::VideoMode OS_Haiku::get_video_mode(int p_screen) const { + +} + +void OS_Haiku::get_fullscreen_mode_list(List *p_list, int p_screen) const { + +} diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index ee1283f018..7e3cf84579 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -1,6 +1,7 @@ #ifndef OS_HAIKU_H #define OS_HAIKU_H +#include "os/os.h" #include "drivers/unix/os_unix.h" @@ -24,7 +25,7 @@ public: virtual String get_name(); - virtual MainLoop *get_main_loop() const; + virtual MainLoop* get_main_loop() const; virtual bool can_draw() const; virtual Point2 get_mouse_pos() const; -- cgit v1.2.3 From a5533270436e51c660d2c196e2a6a8f9e21d6420 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Mon, 25 May 2015 06:34:16 +0300 Subject: Haiku: some small fixes --- drivers/unix/stream_peer_tcp_posix.cpp | 5 ++--- platform/haiku/os_haiku.cpp | 4 ++++ platform/haiku/os_haiku.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index f65eb694d6..6e19647933 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -206,11 +206,10 @@ Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent, while (data_to_send) { - // TODO: haiku does not have MSG_NOSIGNAL #ifdef __HAIKU__ - int sent_amount = send(sockfd, offset, data_to_send, 0); + int sent_amount = send(sockfd, offset, data_to_send, 0); #else - int sent_amount = send(sockfd, offset, data_to_send, MSG_NOSIGNAL); + int sent_amount = send(sockfd, offset, data_to_send, MSG_NOSIGNAL); #endif //printf("Sent TCP data of %d bytes, errno %d\n", sent_amount, errno); diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 4d45bb3333..7c207f265b 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -79,3 +79,7 @@ OS::VideoMode OS_Haiku::get_video_mode(int p_screen) const { void OS_Haiku::get_fullscreen_mode_list(List *p_list, int p_screen) const { } + +String OS_Haiku::get_executable_path() const { + return OS::get_executable_path(); +} diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 7e3cf84579..8740a738cc 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -1,7 +1,6 @@ #ifndef OS_HAIKU_H #define OS_HAIKU_H -#include "os/os.h" #include "drivers/unix/os_unix.h" @@ -38,6 +37,7 @@ public: virtual void set_video_mode(const VideoMode& p_video_mode, int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list, int p_screen=0) const; + virtual String get_executable_path() const; }; #endif -- cgit v1.2.3 From 8dd674d6399b5543f589d3b770c97209e3e31c3b Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Thu, 28 May 2015 00:59:41 +0300 Subject: Haiku: enable debug support --- platform/haiku/detect.py | 12 +++++++++++- platform/haiku/platform_config.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index b443469d8d..0c4d091824 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -39,6 +39,16 @@ def configure(env): env["CC"] = "gcc-x86" env["CXX"] = "g++-x86" - env.Append(CPPFLAGS = ['-DDEBUG_METHODS_ENABLED']) + if (env["target"]=="release"): + if (env["debug_release"]=="yes"): + env.Append(CCFLAGS=['-g2','-fomit-frame-pointer']) + else: + env.Append(CCFLAGS=['-O2','-ffast-math','-fomit-frame-pointer']) + elif (env["target"]=="release_debug"): + env.Append(CCFLAGS=['-O2','-ffast-math','-DDEBUG_ENABLED']) + elif (env["target"]=="debug"): + env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) + + #env.Append(CPPFLAGS = ['-DDEBUG_METHODS_ENABLED']) env.Append(CPPFLAGS = ['-DUNIX_ENABLED']) env.Append(LIBS = ['be', 'z', 'network', 'bnetapi']) diff --git a/platform/haiku/platform_config.h b/platform/haiku/platform_config.h index dad24432a5..d37873ca8b 100644 --- a/platform/haiku/platform_config.h +++ b/platform/haiku/platform_config.h @@ -1 +1,4 @@ #include + +// for ifaddrs.h needed in drivers/unix/ip_unix.cpp +#define _BSD_SOURCE 1 -- cgit v1.2.3 From 513d509783678d1a6c9fd47d7e2e822d886f2c84 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Thu, 28 May 2015 03:42:40 +0300 Subject: Haiku: enable building with GLES --- platform/haiku/detect.py | 5 +++-- platform/haiku/os_haiku.cpp | 46 +++++++++++++++++++++++++++++++++------- platform/haiku/os_haiku.h | 7 +++++- platform/haiku/platform_config.h | 2 ++ 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index 0c4d091824..bb123c6aa0 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -49,6 +49,7 @@ def configure(env): elif (env["target"]=="debug"): env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) - #env.Append(CPPFLAGS = ['-DDEBUG_METHODS_ENABLED']) - env.Append(CPPFLAGS = ['-DUNIX_ENABLED']) + #env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) + env.Append(CPPFLAGS = ['-DOPENGL_ENABLED', '-DGLEW_ENABLED']) + env.Append(CPPFLAGS = ['-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES_OVER_GL']) env.Append(LIBS = ['be', 'z', 'network', 'bnetapi']) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 7c207f265b..103b1ac748 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -1,3 +1,5 @@ +#include "servers/visual/visual_server_raster.h" +#include "drivers/gles2/rasterizer_gles2.h" #include "os_haiku.h" OS_Haiku::OS_Haiku() { @@ -5,17 +7,13 @@ OS_Haiku::OS_Haiku() { }; void OS_Haiku::run() { - + } String OS_Haiku::get_name() { return "Haiku"; } -void OS_Haiku::delete_main_loop() { - -} - int OS_Haiku::get_video_driver_count() const { } @@ -29,19 +27,51 @@ OS::VideoMode OS_Haiku::get_default_video_mode() const { } void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_audio_driver) { - + main_loop = NULL; + +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + //context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); + //context_gl->initialize(); + + rasterizer = memnew(RasterizerGLES2); +#endif + + visual_server = memnew(VisualServerRaster(rasterizer)); + + if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { + visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); + } } void OS_Haiku::finalize() { - + if (main_loop) { + memdelete(main_loop); + } + + main_loop = NULL; + + visual_server->finish(); + memdelete(visual_server); + memdelete(rasterizer); } void OS_Haiku::set_main_loop(MainLoop* p_main_loop) { + main_loop = p_main_loop; + // TODO: enable + //input->set_main_loop(p_main_loop); } MainLoop* OS_Haiku::get_main_loop() const { - + return main_loop; +} + +void OS_Haiku::delete_main_loop() { + if (main_loop) { + memdelete(main_loop); + } + + main_loop = NULL; } bool OS_Haiku::can_draw() const { diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 8740a738cc..67faff5e96 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -2,10 +2,15 @@ #define OS_HAIKU_H #include "drivers/unix/os_unix.h" - +#include "servers/visual_server.h" +#include "servers/visual/rasterizer.h" class OS_Haiku : public OS_Unix { private: + MainLoop* main_loop; + Rasterizer* rasterizer; + VisualServer* visual_server; + virtual void delete_main_loop(); protected: diff --git a/platform/haiku/platform_config.h b/platform/haiku/platform_config.h index d37873ca8b..b63b600fc1 100644 --- a/platform/haiku/platform_config.h +++ b/platform/haiku/platform_config.h @@ -2,3 +2,5 @@ // for ifaddrs.h needed in drivers/unix/ip_unix.cpp #define _BSD_SOURCE 1 + +#define GLES2_INCLUDE_H "gl_context/glew.h" -- cgit v1.2.3 From db459fba1db908b21d6ea3e99c6e75d65c6cc6b0 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Fri, 29 May 2015 23:36:48 +0300 Subject: Haiku: fix build, link with libGL and libGLEW --- platform/haiku/detect.py | 9 +++++++-- platform/haiku/os_haiku.cpp | 1 + platform/haiku/platform_config.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index bb123c6aa0..2c15720a92 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -50,6 +50,11 @@ def configure(env): env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) #env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) - env.Append(CPPFLAGS = ['-DOPENGL_ENABLED', '-DGLEW_ENABLED']) + env.Append(CPPFLAGS = ['-DOPENGL_ENABLED']) env.Append(CPPFLAGS = ['-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES_OVER_GL']) - env.Append(LIBS = ['be', 'z', 'network', 'bnetapi']) + env.Append(LIBS = ['be', 'GL', 'GLEW', 'z', 'network', 'bnetapi']) + + import methods + env.Append(BUILDERS = {'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl')}) + env.Append(BUILDERS = {'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl')}) + env.Append(BUILDERS = {'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl')}) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 103b1ac748..dc3419b09e 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -1,4 +1,5 @@ #include "servers/visual/visual_server_raster.h" +#include "servers/visual/visual_server_wrap_mt.h" #include "drivers/gles2/rasterizer_gles2.h" #include "os_haiku.h" diff --git a/platform/haiku/platform_config.h b/platform/haiku/platform_config.h index b63b600fc1..691bdbdb9c 100644 --- a/platform/haiku/platform_config.h +++ b/platform/haiku/platform_config.h @@ -3,4 +3,4 @@ // for ifaddrs.h needed in drivers/unix/ip_unix.cpp #define _BSD_SOURCE 1 -#define GLES2_INCLUDE_H "gl_context/glew.h" +#define GLES2_INCLUDE_H -- cgit v1.2.3 From 8130707e018757d9270d8b3d94241eaecc82b896 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sat, 30 May 2015 00:57:07 +0300 Subject: Haiku: start implementing the os-dependant stuff --- platform/haiku/os_haiku.cpp | 29 ++++++++++++++++------------- platform/haiku/os_haiku.h | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index dc3419b09e..fb06413478 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -8,7 +8,7 @@ OS_Haiku::OS_Haiku() { }; void OS_Haiku::run() { - + ERR_PRINT("run() NOT IMPLEMENTED"); } String OS_Haiku::get_name() { @@ -16,19 +16,20 @@ String OS_Haiku::get_name() { } int OS_Haiku::get_video_driver_count() const { - + return 1; } const char* OS_Haiku::get_video_driver_name(int p_driver) const { - + return "GLES2"; } OS::VideoMode OS_Haiku::get_default_video_mode() const { - + return OS::VideoMode(800, 600, false); } void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_audio_driver) { main_loop = NULL; + current_video_mode = p_desired; #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) //context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); @@ -42,6 +43,8 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); } + + visual_server->init(); } void OS_Haiku::finalize() { @@ -76,39 +79,39 @@ void OS_Haiku::delete_main_loop() { } bool OS_Haiku::can_draw() const { - + ERR_PRINT("can_draw() NOT IMPLEMENTED"); } Point2 OS_Haiku::get_mouse_pos() const { - + ERR_PRINT("get_mouse_pos() NOT IMPLEMENTED"); } int OS_Haiku::get_mouse_button_state() const { - + ERR_PRINT("get_mouse_button_state() NOT IMPLEMENTED"); } void OS_Haiku::set_cursor_shape(CursorShape p_shape) { - + ERR_PRINT("set_cursor_shape() NOT IMPLEMENTED"); } void OS_Haiku::set_window_title(const String& p_title) { - + ERR_PRINT("set_window_title() NOT IMPLEMENTED"); } Size2 OS_Haiku::get_window_size() const { - + ERR_PRINT("get_window_size() NOT IMPLEMENTED"); } void OS_Haiku::set_video_mode(const VideoMode& p_video_mode, int p_screen) { - + ERR_PRINT("set_video_mode() NOT IMPLEMENTED"); } OS::VideoMode OS_Haiku::get_video_mode(int p_screen) const { - + return current_video_mode; } void OS_Haiku::get_fullscreen_mode_list(List *p_list, int p_screen) const { - + ERR_PRINT("get_fullscreen_mode_list() NOT IMPLEMENTED"); } String OS_Haiku::get_executable_path() const { diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 67faff5e96..dfe559c969 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -10,6 +10,7 @@ private: MainLoop* main_loop; Rasterizer* rasterizer; VisualServer* visual_server; + VideoMode current_video_mode; virtual void delete_main_loop(); -- cgit v1.2.3 From f99b72c04f484c39ae728bc175114544a26d7bca Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Wed, 10 Jun 2015 21:18:39 +0300 Subject: Haiku: remove an #ifdef as the platform now supports MSG_NOSIGNAL --- drivers/unix/stream_peer_tcp_posix.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index 6e19647933..5aa3915893 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -206,11 +206,7 @@ Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent, while (data_to_send) { -#ifdef __HAIKU__ - int sent_amount = send(sockfd, offset, data_to_send, 0); -#else int sent_amount = send(sockfd, offset, data_to_send, MSG_NOSIGNAL); -#endif //printf("Sent TCP data of %d bytes, errno %d\n", sent_amount, errno); if (sent_amount == -1) { -- cgit v1.2.3 From 8df3e30abd06ce8d51e6b1ad696aabf97ea9f178 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Thu, 11 Jun 2015 22:57:41 +0300 Subject: Haiku: create a GL context and initialize the audio and physics servers --- drivers/gl_context/glew.c | 2 +- platform/haiku/SCsub | 6 ++- platform/haiku/context_gl_haiku.cpp | 55 ++++++++++++++++++++ platform/haiku/context_gl_haiku.h | 31 ++++++++++++ platform/haiku/detect.py | 3 +- platform/haiku/haiku_application.cpp | 7 +++ platform/haiku/haiku_application.h | 15 ++++++ platform/haiku/haiku_direct_window.cpp | 45 ++++++++++++++++ platform/haiku/haiku_direct_window.h | 27 ++++++++++ platform/haiku/haiku_gl_view.cpp | 54 ++++++++++++++++++++ platform/haiku/haiku_gl_view.h | 27 ++++++++++ platform/haiku/os_haiku.cpp | 93 +++++++++++++++++++++++++++++++--- platform/haiku/os_haiku.h | 30 +++++++++++ 13 files changed, 386 insertions(+), 9 deletions(-) create mode 100644 platform/haiku/context_gl_haiku.cpp create mode 100644 platform/haiku/context_gl_haiku.h create mode 100644 platform/haiku/haiku_application.cpp create mode 100644 platform/haiku/haiku_application.h create mode 100644 platform/haiku/haiku_direct_window.cpp create mode 100644 platform/haiku/haiku_direct_window.h create mode 100644 platform/haiku/haiku_gl_view.cpp create mode 100644 platform/haiku/haiku_gl_view.h diff --git a/drivers/gl_context/glew.c b/drivers/gl_context/glew.c index fc0aa28a72..e38942de4f 100644 --- a/drivers/gl_context/glew.c +++ b/drivers/gl_context/glew.c @@ -1,4 +1,4 @@ -#ifdef GLEW_ENABLED +#ifndef GLEW_ENABLED /* ** The OpenGL Extension Wrangler Library ** Copyright (C) 2002-2008, Milan Ikits diff --git a/platform/haiku/SCsub b/platform/haiku/SCsub index 8ae489cf54..18fa2e2b15 100644 --- a/platform/haiku/SCsub +++ b/platform/haiku/SCsub @@ -1,7 +1,11 @@ Import('env') common_haiku = [ - 'os_haiku.cpp' + 'os_haiku.cpp', + 'context_gl_haiku.cpp', + 'haiku_application.cpp', + 'haiku_direct_window.cpp', + 'haiku_gl_view.cpp' ] env.Program( diff --git a/platform/haiku/context_gl_haiku.cpp b/platform/haiku/context_gl_haiku.cpp new file mode 100644 index 0000000000..5c82b187b3 --- /dev/null +++ b/platform/haiku/context_gl_haiku.cpp @@ -0,0 +1,55 @@ +#include "context_gl_haiku.h" + +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + +ContextGL_Haiku::ContextGL_Haiku(HaikuDirectWindow** p_window, OS::VideoMode& p_default_video_mode) { + video_mode = p_default_video_mode; + + uint32 type = BGL_RGB|BGL_DOUBLE|BGL_DEPTH; + + BRect windowRect; + windowRect.Set(50, 50, 800, 600); + + window = new HaikuDirectWindow(windowRect); + view = new HaikuGLView(window->Bounds(), type); + + *p_window = window; +} + +ContextGL_Haiku::~ContextGL_Haiku() { + delete view; +} + +Error ContextGL_Haiku::initialize() { + window->AddChild(view); + view->LockGL(); + window->SetHaikuGLView(view); + window->InitMessageRunner(); + window->Show(); + + return OK; +} + +void ContextGL_Haiku::release_current() { + ERR_PRINT("release_current() NOT IMPLEMENTED"); +} + +void ContextGL_Haiku::make_current() { + ERR_PRINT("make_current() NOT IMPLEMENTED"); +} + +void ContextGL_Haiku::swap_buffers() { + view->SwapBuffers(); +} + +int ContextGL_Haiku::get_window_width() { + // TODO: implement + return 800; +} + +int ContextGL_Haiku::get_window_height() { + // TODO: implement + return 600; +} + +#endif diff --git a/platform/haiku/context_gl_haiku.h b/platform/haiku/context_gl_haiku.h new file mode 100644 index 0000000000..16efa8f61d --- /dev/null +++ b/platform/haiku/context_gl_haiku.h @@ -0,0 +1,31 @@ +#ifndef CONTEXT_GL_HAIKU_H +#define CONTEXT_GL_HAIKU_H + +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + +#include "os/os.h" +#include "drivers/gl_context/context_gl.h" + +#include "haiku_direct_window.h" +#include "haiku_gl_view.h" + +class ContextGL_Haiku : public ContextGL { +private: + HaikuGLView* view; + HaikuDirectWindow* window; + OS::VideoMode video_mode; + +public: + ContextGL_Haiku(HaikuDirectWindow** p_window, OS::VideoMode& default_video_mode); + ~ContextGL_Haiku(); + + virtual Error initialize(); + virtual void release_current(); + virtual void make_current(); + virtual void swap_buffers(); + virtual int get_window_width(); + virtual int get_window_height(); +}; + +#endif +#endif diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index 2c15720a92..587148838f 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -50,9 +50,10 @@ def configure(env): env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) #env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) + env.Append(CPPFLAGS = ['-DGLEW_ENABLED']) env.Append(CPPFLAGS = ['-DOPENGL_ENABLED']) env.Append(CPPFLAGS = ['-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES_OVER_GL']) - env.Append(LIBS = ['be', 'GL', 'GLEW', 'z', 'network', 'bnetapi']) + env.Append(LIBS = ['be', 'game', 'GL', 'GLEW', 'z', 'network', 'bnetapi']) import methods env.Append(BUILDERS = {'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl')}) diff --git a/platform/haiku/haiku_application.cpp b/platform/haiku/haiku_application.cpp new file mode 100644 index 0000000000..56024f605d --- /dev/null +++ b/platform/haiku/haiku_application.cpp @@ -0,0 +1,7 @@ +#include "haiku_application.h" + +HaikuApplication::HaikuApplication() + : BApplication("application/x-vnd.Haiku-GLDirectMode") +{ + +} diff --git a/platform/haiku/haiku_application.h b/platform/haiku/haiku_application.h new file mode 100644 index 0000000000..995a917d62 --- /dev/null +++ b/platform/haiku/haiku_application.h @@ -0,0 +1,15 @@ +#ifndef HAIKU_APPLICATION_H +#define HAIKU_APPLICATION_H + +#include // needed for image_id +#include + +class HaikuApplication : public BApplication +{ +public: + HaikuApplication(); +//private: +// HaikuDirectWindow* window; +}; + +#endif diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp new file mode 100644 index 0000000000..e7f2718278 --- /dev/null +++ b/platform/haiku/haiku_direct_window.cpp @@ -0,0 +1,45 @@ +#include "haiku_direct_window.h" + +HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) + : BDirectWindow(p_frame, "Godot", B_TITLED_WINDOW, 0) +{ + // TODO: formatting + float minWidth = 0.0f; + float maxWidth = 0.0f; + float minHeight = 0.0f; + float maxHeight = 0.0f; + + GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); + SetSizeLimits(50.0f, maxWidth, 50.0f, maxHeight); +} + + +HaikuDirectWindow::~HaikuDirectWindow() +{ + delete update_runner; +} + +void HaikuDirectWindow::SetHaikuGLView(HaikuGLView* p_view) { + view = p_view; +} + +void HaikuDirectWindow::InitMessageRunner() { + update_runner = new BMessageRunner(BMessenger(view), + new BMessage(REDRAW_MSG), 1000000/60 /* 60 fps */); +} + + +bool HaikuDirectWindow::QuitRequested() +{ + view->EnableDirectMode(false); + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +void HaikuDirectWindow::DirectConnected(direct_buffer_info *info) +{ + view->DirectConnected(info); + view->EnableDirectMode(true); +} + diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h new file mode 100644 index 0000000000..450ea64296 --- /dev/null +++ b/platform/haiku/haiku_direct_window.h @@ -0,0 +1,27 @@ +#ifndef HAIKU_DIRECT_WINDOW_H +#define HAIKU_DIRECT_WINDOW_H + +#include // needed for image_id +#include + +#include "haiku_gl_view.h" + +#define REDRAW_MSG 'rdrw' + +class HaikuDirectWindow : public BDirectWindow +{ +public: + HaikuDirectWindow(BRect p_frame); + ~HaikuDirectWindow(); + + void SetHaikuGLView(HaikuGLView* p_view); + void InitMessageRunner(); + virtual bool QuitRequested(); + virtual void DirectConnected(direct_buffer_info *info); + +private: + HaikuGLView* view; + BMessageRunner* update_runner; +}; + +#endif diff --git a/platform/haiku/haiku_gl_view.cpp b/platform/haiku/haiku_gl_view.cpp new file mode 100644 index 0000000000..61a0120656 --- /dev/null +++ b/platform/haiku/haiku_gl_view.cpp @@ -0,0 +1,54 @@ +#include "haiku_gl_view.h" + +HaikuGLView::HaikuGLView(BRect frame, uint32 type) + : BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type), rotate(0) +{ + width = frame.right-frame.left; + height = frame.bottom-frame.top; +} + +void HaikuGLView::AttachedToWindow(void) +{ + LockGL(); + BGLView::AttachedToWindow(); + UnlockGL(); + MakeFocus(); +} + +void HaikuGLView::FrameResized(float newWidth, float newHeight) +{ +} + +void HaikuGLView::gDraw(float rotation) +{ +} + +void HaikuGLView::gReshape(int width, int height) +{ +} + +void HaikuGLView::Render(void) +{ + LockGL(); + SwapBuffers(); + UnlockGL(); +} + +void HaikuGLView::MessageReceived(BMessage * msg) +{ + switch (msg->what) { + case 'rdrw': + Render(); + /* Rotate a bit more */ + rotate++; + break; + + default: + BGLView::MessageReceived(msg); + } +} + +void HaikuGLView::KeyDown(const char *bytes, int32 numBytes) +{ + +} diff --git a/platform/haiku/haiku_gl_view.h b/platform/haiku/haiku_gl_view.h new file mode 100644 index 0000000000..44d05fa27f --- /dev/null +++ b/platform/haiku/haiku_gl_view.h @@ -0,0 +1,27 @@ +#ifndef HAIKU_GL_VIEW_H +#define HAIKU_GL_VIEW_H + +#include // needed for image_id +#include + +class HaikuGLView : public BGLView +{ +public: + HaikuGLView(BRect frame, uint32 type); + virtual void AttachedToWindow(void); + virtual void FrameResized(float newWidth, float newHeight); + virtual void MessageReceived(BMessage * msg); + virtual void KeyDown(const char* bytes, int32 numBytes); + + void Render(void); + +private: + void gDraw(float rotation = 0); + void gReshape(int width, int height); + + float width; + float height; + float rotate; +}; + +#endif diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index fb06413478..bf96cf1716 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -1,14 +1,37 @@ #include "servers/visual/visual_server_raster.h" #include "servers/visual/visual_server_wrap_mt.h" #include "drivers/gles2/rasterizer_gles2.h" +#include "servers/physics/physics_server_sw.h" +#include "main/main.h" + #include "os_haiku.h" + OS_Haiku::OS_Haiku() { - + AudioDriverManagerSW::add_driver(&driver_dummy); }; void OS_Haiku::run() { - ERR_PRINT("run() NOT IMPLEMENTED"); + if (!main_loop) { + return; + } + + main_loop->init(); + + /* + while (true) { + // TODO: process events + + if (Main::iteration() == true) { + break; + } + } + */ + + app->Run(); + delete app; + + main_loop->finish(); } String OS_Haiku::get_name() { @@ -31,20 +54,44 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ main_loop = NULL; current_video_mode = p_desired; + app = new HaikuApplication(); + #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) - //context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); - //context_gl->initialize(); + context_gl = memnew(ContextGL_Haiku(&window, current_video_mode)); + context_gl->initialize(); rasterizer = memnew(RasterizerGLES2); #endif visual_server = memnew(VisualServerRaster(rasterizer)); + ERR_FAIL_COND(!visual_server); + if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); } visual_server->init(); + + physics_server = memnew(PhysicsServerSW); + physics_server->init(); + physics_2d_server = memnew(Physics2DServerSW); + physics_2d_server->init(); + + AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + + if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) { + ERR_PRINT("Initializing audio failed."); + } + + sample_manager = memnew(SampleManagerMallocSW); + audio_server = memnew(AudioServerSW(sample_manager)); + audio_server->init(); + + spatial_sound_server = memnew(SpatialSoundServerSW); + spatial_sound_server->init(); + spatial_sound_2d_server = memnew(SpatialSound2DServerSW); + spatial_sound_2d_server->init(); } void OS_Haiku::finalize() { @@ -54,9 +101,29 @@ void OS_Haiku::finalize() { main_loop = NULL; + spatial_sound_server->finish(); + memdelete(spatial_sound_server); + + spatial_sound_2d_server->finish(); + memdelete(spatial_sound_2d_server); + + audio_server->finish(); + memdelete(audio_server); + memdelete(sample_manager); + visual_server->finish(); memdelete(visual_server); memdelete(rasterizer); + + physics_server->finish(); + memdelete(physics_server); + + physics_2d_server->finish(); + memdelete(physics_2d_server); + +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + memdelete(context_gl); +#endif } void OS_Haiku::set_main_loop(MainLoop* p_main_loop) { @@ -78,8 +145,21 @@ void OS_Haiku::delete_main_loop() { main_loop = NULL; } +void OS_Haiku::release_rendering_thread() { + ERR_PRINT("release_rendering_thread() NOT IMPLEMENTED"); +} + +void OS_Haiku::make_rendering_thread() { + ERR_PRINT("make_rendering_thread() NOT IMPLEMENTED"); +} + bool OS_Haiku::can_draw() const { - ERR_PRINT("can_draw() NOT IMPLEMENTED"); + // TODO: implement + return true; +} + +void OS_Haiku::swap_buffers() { + context_gl->swap_buffers(); } Point2 OS_Haiku::get_mouse_pos() const { @@ -95,7 +175,8 @@ void OS_Haiku::set_cursor_shape(CursorShape p_shape) { } void OS_Haiku::set_window_title(const String& p_title) { - ERR_PRINT("set_window_title() NOT IMPLEMENTED"); + //ERR_PRINT("set_window_title() NOT IMPLEMENTED"); + window->SetTitle(p_title.utf8().get_data()); } Size2 OS_Haiku::get_window_size() const { diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index dfe559c969..938983347c 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -4,13 +4,39 @@ #include "drivers/unix/os_unix.h" #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" +#include "servers/physics_server.h" +#include "servers/physics_2d/physics_2d_server_sw.h" +#include "servers/audio/audio_server_sw.h" +#include "servers/audio/sample_manager_sw.h" +#include "servers/spatial_sound/spatial_sound_server_sw.h" +#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/audio/audio_driver_dummy.h" + +#include "context_gl_haiku.h" +#include "haiku_application.h" +#include "haiku_direct_window.h" + class OS_Haiku : public OS_Unix { private: + HaikuApplication* app; + HaikuDirectWindow* window; MainLoop* main_loop; Rasterizer* rasterizer; VisualServer* visual_server; VideoMode current_video_mode; + PhysicsServer* physics_server; + Physics2DServer* physics_2d_server; + AudioServerSW* audio_server; + SampleManagerMallocSW* sample_manager; + SpatialSoundServerSW* spatial_sound_server; + SpatialSound2DServerSW* spatial_sound_2d_server; + + AudioDriverDummy driver_dummy; // TODO: use a real driver + +#if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + ContextGL_Haiku* context_gl; +#endif virtual void delete_main_loop(); @@ -31,7 +57,11 @@ public: virtual String get_name(); virtual MainLoop* get_main_loop() const; + virtual bool can_draw() const; + virtual void release_rendering_thread(); + virtual void make_rendering_thread(); + virtual void swap_buffers(); virtual Point2 get_mouse_pos() const; virtual int get_mouse_button_state() const; -- cgit v1.2.3 From 1505d65ac9ec9f44195e961f0089343aabe3de79 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Tue, 16 Jun 2015 21:52:24 +0300 Subject: Haiku: handle mouse movement and click events --- platform/haiku/context_gl_haiku.cpp | 27 ++--- platform/haiku/context_gl_haiku.h | 4 +- platform/haiku/haiku_direct_window.cpp | 177 +++++++++++++++++++++++++++++---- platform/haiku/haiku_direct_window.h | 26 +++-- platform/haiku/haiku_gl_view.cpp | 45 ++------- platform/haiku/haiku_gl_view.h | 20 +--- platform/haiku/os_haiku.cpp | 29 ++++-- platform/haiku/os_haiku.h | 2 + 8 files changed, 227 insertions(+), 103 deletions(-) diff --git a/platform/haiku/context_gl_haiku.cpp b/platform/haiku/context_gl_haiku.cpp index 5c82b187b3..8cb1adc360 100644 --- a/platform/haiku/context_gl_haiku.cpp +++ b/platform/haiku/context_gl_haiku.cpp @@ -2,18 +2,11 @@ #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) -ContextGL_Haiku::ContextGL_Haiku(HaikuDirectWindow** p_window, OS::VideoMode& p_default_video_mode) { - video_mode = p_default_video_mode; - - uint32 type = BGL_RGB|BGL_DOUBLE|BGL_DEPTH; +ContextGL_Haiku::ContextGL_Haiku(HaikuDirectWindow* p_window) { + window = p_window; - BRect windowRect; - windowRect.Set(50, 50, 800, 600); - - window = new HaikuDirectWindow(windowRect); + uint32 type = BGL_RGB | BGL_DOUBLE | BGL_DEPTH; view = new HaikuGLView(window->Bounds(), type); - - *p_window = window; } ContextGL_Haiku::~ContextGL_Haiku() { @@ -24,18 +17,18 @@ Error ContextGL_Haiku::initialize() { window->AddChild(view); view->LockGL(); window->SetHaikuGLView(view); - window->InitMessageRunner(); - window->Show(); return OK; } void ContextGL_Haiku::release_current() { - ERR_PRINT("release_current() NOT IMPLEMENTED"); + //ERR_PRINT("release_current() NOT IMPLEMENTED"); + view->UnlockGL(); } void ContextGL_Haiku::make_current() { - ERR_PRINT("make_current() NOT IMPLEMENTED"); + view->LockGL(); + //ERR_PRINT("make_current() NOT IMPLEMENTED"); } void ContextGL_Haiku::swap_buffers() { @@ -43,13 +36,11 @@ void ContextGL_Haiku::swap_buffers() { } int ContextGL_Haiku::get_window_width() { - // TODO: implement - return 800; + return window->Bounds().IntegerWidth(); } int ContextGL_Haiku::get_window_height() { - // TODO: implement - return 600; + return window->Bounds().IntegerHeight(); } #endif diff --git a/platform/haiku/context_gl_haiku.h b/platform/haiku/context_gl_haiku.h index 16efa8f61d..e37fe14970 100644 --- a/platform/haiku/context_gl_haiku.h +++ b/platform/haiku/context_gl_haiku.h @@ -3,7 +3,6 @@ #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) -#include "os/os.h" #include "drivers/gl_context/context_gl.h" #include "haiku_direct_window.h" @@ -13,10 +12,9 @@ class ContextGL_Haiku : public ContextGL { private: HaikuGLView* view; HaikuDirectWindow* window; - OS::VideoMode video_mode; public: - ContextGL_Haiku(HaikuDirectWindow** p_window, OS::VideoMode& default_video_mode); + ContextGL_Haiku(HaikuDirectWindow* p_window); ~ContextGL_Haiku(); virtual Error initialize(); diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index e7f2718278..9c0696bc42 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -1,45 +1,186 @@ +#include "main/main.h" #include "haiku_direct_window.h" HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) : BDirectWindow(p_frame, "Godot", B_TITLED_WINDOW, 0) { - // TODO: formatting - float minWidth = 0.0f; - float maxWidth = 0.0f; - float minHeight = 0.0f; - float maxHeight = 0.0f; - - GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); - SetSizeLimits(50.0f, maxWidth, 50.0f, maxHeight); + last_mouse_pos_valid = false; + last_buttons_state = 0; } -HaikuDirectWindow::~HaikuDirectWindow() -{ - delete update_runner; +HaikuDirectWindow::~HaikuDirectWindow() { + if (update_runner) { + delete update_runner; + } } void HaikuDirectWindow::SetHaikuGLView(HaikuGLView* p_view) { view = p_view; } -void HaikuDirectWindow::InitMessageRunner() { - update_runner = new BMessageRunner(BMessenger(view), +void HaikuDirectWindow::StartMessageRunner() { + update_runner = new BMessageRunner(BMessenger(this), new BMessage(REDRAW_MSG), 1000000/60 /* 60 fps */); } +void HaikuDirectWindow::StopMessageRunner() { + delete update_runner; +} -bool HaikuDirectWindow::QuitRequested() -{ +void HaikuDirectWindow::SetInput(InputDefault* p_input) { + input = p_input; +} + +bool HaikuDirectWindow::QuitRequested() { view->EnableDirectMode(false); be_app->PostMessage(B_QUIT_REQUESTED); return true; } - -void HaikuDirectWindow::DirectConnected(direct_buffer_info *info) -{ +void HaikuDirectWindow::DirectConnected(direct_buffer_info* info) { view->DirectConnected(info); view->EnableDirectMode(true); } +void HaikuDirectWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case REDRAW_MSG: + //ERR_PRINT("iteration 1"); + Main::iteration(); + + //if (NeedsUpdate()) { + // ERR_PRINT("NEEDS UPDATE"); + // Main::force_redraw(); + //} + + //ERR_PRINT("iteration 2"); + break; + + case B_INVALIDATE: + ERR_PRINT("WINDOW B_INVALIDATE"); + //Main::force_redraw(); + break; + + default: + BDirectWindow::MessageReceived(message); + } +} + +void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { + switch (message->what) { + case B_MOUSE_DOWN: + case B_MOUSE_UP: + DispatchMouseButton(message); + break; + + case B_MOUSE_MOVED: + DispatchMouseMoved(message); + break; + + default: + BDirectWindow::DispatchMessage(message, handler); + } +} + +void HaikuDirectWindow::DispatchMouseButton(BMessage* message) { + message->PrintToStream(); + + BPoint where; + if (message->FindPoint("where", &where) != B_OK) { + return; + } + + uint32 buttons = message->FindInt32("buttons"); + uint32 button = buttons ^ last_buttons_state; + last_buttons_state = buttons; + + // TODO: implement the mouse_mode checks + //if (mouse_mode == MOUSE_MODE_CAPTURED) { + // event.xbutton.x=last_mouse_pos.x; + // event.xbutton.y=last_mouse_pos.y; + //} + + InputEvent mouse_event; + mouse_event.ID = ++event_id; + mouse_event.type = InputEvent::MOUSE_BUTTON; + mouse_event.device = 0; + + // TODO: implement the modifier state getters + //mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state); + //mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state); + mouse_event.mouse_button.x = where.x; + mouse_event.mouse_button.y = where.y; + mouse_event.mouse_button.global_x = where.x; + mouse_event.mouse_button.global_y = where.y; + + switch (button) { + default: + case B_PRIMARY_MOUSE_BUTTON: + ERR_PRINT("PRIMARY"); + mouse_event.mouse_button.button_index = 1; + break; + + case B_SECONDARY_MOUSE_BUTTON: + ERR_PRINT("SECONDARY"); + mouse_event.mouse_button.button_index = 2; + break; + + case B_TERTIARY_MOUSE_BUTTON: + ERR_PRINT("MIDDLE"); + mouse_event.mouse_button.button_index = 3; + break; + } + + mouse_event.mouse_button.pressed = (message->what == B_MOUSE_DOWN); + + if (message->what == B_MOUSE_DOWN && mouse_event.mouse_button.button_index == 1) { + int32 clicks = message->FindInt32("clicks"); + + if (clicks > 1) { + mouse_event.mouse_button.doubleclick=true; + } + } + + input->parse_input_event(mouse_event); +} + +void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { + BPoint where; + if (message->FindPoint("where", &where) != B_OK) { + return; + } + + Point2i pos(where.x, where.y); + + if (!last_mouse_pos_valid) { + last_mouse_pos=pos; + last_mouse_pos_valid=true; + } + + Point2i rel = pos - last_mouse_pos; + + InputEvent motion_event; + motion_event.ID = ++event_id; + motion_event.type = InputEvent::MOUSE_MOTION; + motion_event.device = 0; + + // TODO: implement the modifier state getters + //motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state); + //motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state); + motion_event.mouse_motion.x = pos.x; + motion_event.mouse_motion.y = pos.y; + input->set_mouse_pos(pos); + motion_event.mouse_motion.global_x = pos.x; + motion_event.mouse_motion.global_y = pos.y; + motion_event.mouse_motion.speed_x = input->get_mouse_speed().x; + motion_event.mouse_motion.speed_y = input->get_mouse_speed().y; + + motion_event.mouse_motion.relative_x = rel.x; + motion_event.mouse_motion.relative_y = rel.y; + + last_mouse_pos=pos; + + input->parse_input_event(motion_event); +} diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index 450ea64296..19ea987e76 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -4,24 +4,38 @@ #include // needed for image_id #include +#include "os/input.h" #include "haiku_gl_view.h" #define REDRAW_MSG 'rdrw' class HaikuDirectWindow : public BDirectWindow { +private: + unsigned int event_id; + Point2i last_mouse_pos; + bool last_mouse_pos_valid; + uint32 last_buttons_state; + + InputDefault* input; + HaikuGLView* view; + BMessageRunner* update_runner; + + void DispatchMouseButton(BMessage* message); + void DispatchMouseMoved(BMessage* message); + public: HaikuDirectWindow(BRect p_frame); ~HaikuDirectWindow(); void SetHaikuGLView(HaikuGLView* p_view); - void InitMessageRunner(); + void StartMessageRunner(); + void StopMessageRunner(); + void SetInput(InputDefault* p_input); virtual bool QuitRequested(); - virtual void DirectConnected(direct_buffer_info *info); - -private: - HaikuGLView* view; - BMessageRunner* update_runner; + virtual void DirectConnected(direct_buffer_info* info); + virtual void MessageReceived(BMessage* message); + virtual void DispatchMessage(BMessage* message, BHandler* handler); }; #endif diff --git a/platform/haiku/haiku_gl_view.cpp b/platform/haiku/haiku_gl_view.cpp index 61a0120656..8adab96a87 100644 --- a/platform/haiku/haiku_gl_view.cpp +++ b/platform/haiku/haiku_gl_view.cpp @@ -1,54 +1,31 @@ +#include "main/main.h" #include "haiku_gl_view.h" HaikuGLView::HaikuGLView(BRect frame, uint32 type) - : BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type), rotate(0) + : BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type) { - width = frame.right-frame.left; - height = frame.bottom-frame.top; } -void HaikuGLView::AttachedToWindow(void) -{ +void HaikuGLView::AttachedToWindow(void) { LockGL(); BGLView::AttachedToWindow(); UnlockGL(); MakeFocus(); } -void HaikuGLView::FrameResized(float newWidth, float newHeight) -{ -} - -void HaikuGLView::gDraw(float rotation) -{ -} - -void HaikuGLView::gReshape(int width, int height) -{ -} - -void HaikuGLView::Render(void) -{ - LockGL(); - SwapBuffers(); - UnlockGL(); +void HaikuGLView::Draw(BRect updateRect) { + Main::force_redraw(); } -void HaikuGLView::MessageReceived(BMessage * msg) +void HaikuGLView::MessageReceived(BMessage* msg) { + // TODO: remove if not needed switch (msg->what) { - case 'rdrw': - Render(); - /* Rotate a bit more */ - rotate++; - break; - - default: - BGLView::MessageReceived(msg); + default: + BGLView::MessageReceived(msg); } } -void HaikuGLView::KeyDown(const char *bytes, int32 numBytes) -{ - +void HaikuGLView::MouseMoved (BPoint where, uint32 code, const BMessage *dragMessage) { + ERR_PRINT("MouseMoved()"); } diff --git a/platform/haiku/haiku_gl_view.h b/platform/haiku/haiku_gl_view.h index 44d05fa27f..78ebb513a8 100644 --- a/platform/haiku/haiku_gl_view.h +++ b/platform/haiku/haiku_gl_view.h @@ -7,21 +7,11 @@ class HaikuGLView : public BGLView { public: - HaikuGLView(BRect frame, uint32 type); - virtual void AttachedToWindow(void); - virtual void FrameResized(float newWidth, float newHeight); - virtual void MessageReceived(BMessage * msg); - virtual void KeyDown(const char* bytes, int32 numBytes); - - void Render(void); - -private: - void gDraw(float rotation = 0); - void gReshape(int width, int height); - - float width; - float height; - float rotate; + HaikuGLView(BRect frame, uint32 type); + virtual void AttachedToWindow(void); + virtual void MessageReceived(BMessage* msg); + virtual void MouseMoved (BPoint where, uint32 code, const BMessage *dragMessage); + virtual void Draw(BRect updateRect); }; #endif diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index bf96cf1716..193927238d 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -17,6 +17,8 @@ void OS_Haiku::run() { } main_loop->init(); + window->Show(); + window->StartMessageRunner(); /* while (true) { @@ -29,6 +31,7 @@ void OS_Haiku::run() { */ app->Run(); + window->StopMessageRunner(); delete app; main_loop->finish(); @@ -56,8 +59,13 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ app = new HaikuApplication(); + BRect frame; + frame.Set(50, 50, 50 + current_video_mode.width - 1, 50 + current_video_mode.height - 1); + + window = new HaikuDirectWindow(frame); + #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) - context_gl = memnew(ContextGL_Haiku(&window, current_video_mode)); + context_gl = memnew(ContextGL_Haiku(window)); context_gl->initialize(); rasterizer = memnew(RasterizerGLES2); @@ -67,9 +75,9 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ ERR_FAIL_COND(!visual_server); - if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { - visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); - } + //if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { + // visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); + //} visual_server->init(); @@ -92,6 +100,9 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ spatial_sound_server->init(); spatial_sound_2d_server = memnew(SpatialSound2DServerSW); spatial_sound_2d_server->init(); + + input = memnew(InputDefault); + window->SetInput(input); } void OS_Haiku::finalize() { @@ -121,6 +132,8 @@ void OS_Haiku::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); + memdelete(input); + #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) memdelete(context_gl); #endif @@ -128,9 +141,7 @@ void OS_Haiku::finalize() { void OS_Haiku::set_main_loop(MainLoop* p_main_loop) { main_loop = p_main_loop; - - // TODO: enable - //input->set_main_loop(p_main_loop); + input->set_main_loop(p_main_loop); } MainLoop* OS_Haiku::get_main_loop() const { @@ -146,11 +157,11 @@ void OS_Haiku::delete_main_loop() { } void OS_Haiku::release_rendering_thread() { - ERR_PRINT("release_rendering_thread() NOT IMPLEMENTED"); + context_gl->release_current(); } void OS_Haiku::make_rendering_thread() { - ERR_PRINT("make_rendering_thread() NOT IMPLEMENTED"); + context_gl->make_current(); } bool OS_Haiku::can_draw() const { diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 938983347c..b741ae7da0 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -1,6 +1,7 @@ #ifndef OS_HAIKU_H #define OS_HAIKU_H +#include "os/input.h" #include "drivers/unix/os_unix.h" #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" @@ -22,6 +23,7 @@ private: HaikuApplication* app; HaikuDirectWindow* window; MainLoop* main_loop; + InputDefault* input; Rasterizer* rasterizer; VisualServer* visual_server; VideoMode current_video_mode; -- cgit v1.2.3 From 2102d35e9c18a0cede87e7e45d375153702b3ea5 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Wed, 17 Jun 2015 22:27:45 +0300 Subject: Haiku: read the status of the key modifiers and mouse buttons --- platform/haiku/haiku_direct_window.cpp | 71 +++++++++++++++++++++++----------- platform/haiku/haiku_direct_window.h | 2 + 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index 9c0696bc42..6ff4369087 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -39,7 +39,7 @@ bool HaikuDirectWindow::QuitRequested() { } void HaikuDirectWindow::DirectConnected(direct_buffer_info* info) { - view->DirectConnected(info); + view->DirectConnected(info); view->EnableDirectMode(true); } @@ -49,21 +49,21 @@ void HaikuDirectWindow::MessageReceived(BMessage* message) case REDRAW_MSG: //ERR_PRINT("iteration 1"); Main::iteration(); - + //if (NeedsUpdate()) { // ERR_PRINT("NEEDS UPDATE"); // Main::force_redraw(); //} - + //ERR_PRINT("iteration 2"); break; - + case B_INVALIDATE: ERR_PRINT("WINDOW B_INVALIDATE"); //Main::force_redraw(); break; - default: + default: BDirectWindow::MessageReceived(message); } } @@ -92,6 +92,7 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) { return; } + uint32 modifiers = message->FindInt32("modifiers"); uint32 buttons = message->FindInt32("buttons"); uint32 button = buttons ^ last_buttons_state; last_buttons_state = buttons; @@ -101,15 +102,14 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) { // event.xbutton.x=last_mouse_pos.x; // event.xbutton.y=last_mouse_pos.y; //} - + InputEvent mouse_event; mouse_event.ID = ++event_id; mouse_event.type = InputEvent::MOUSE_BUTTON; mouse_event.device = 0; - // TODO: implement the modifier state getters - //mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state); - //mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state); + mouse_event.mouse_button.mod = GetKeyModifierState(modifiers); + mouse_event.mouse_button.button_mask = GetMouseButtonState(buttons); mouse_event.mouse_button.x = where.x; mouse_event.mouse_button.y = where.y; mouse_event.mouse_button.global_x = where.x; @@ -118,30 +118,27 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) { switch (button) { default: case B_PRIMARY_MOUSE_BUTTON: - ERR_PRINT("PRIMARY"); mouse_event.mouse_button.button_index = 1; break; case B_SECONDARY_MOUSE_BUTTON: - ERR_PRINT("SECONDARY"); mouse_event.mouse_button.button_index = 2; break; case B_TERTIARY_MOUSE_BUTTON: - ERR_PRINT("MIDDLE"); mouse_event.mouse_button.button_index = 3; break; } - + mouse_event.mouse_button.pressed = (message->what == B_MOUSE_DOWN); if (message->what == B_MOUSE_DOWN && mouse_event.mouse_button.button_index == 1) { int32 clicks = message->FindInt32("clicks"); - + if (clicks > 1) { mouse_event.mouse_button.doubleclick=true; } - } + } input->parse_input_event(mouse_event); } @@ -151,12 +148,14 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { if (message->FindPoint("where", &where) != B_OK) { return; } - + Point2i pos(where.x, where.y); - + uint32 modifiers = message->FindInt32("modifiers"); + uint32 buttons = message->FindInt32("buttons"); + if (!last_mouse_pos_valid) { - last_mouse_pos=pos; - last_mouse_pos_valid=true; + last_mouse_pos = pos; + last_mouse_pos_valid = true; } Point2i rel = pos - last_mouse_pos; @@ -166,9 +165,8 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { motion_event.type = InputEvent::MOUSE_MOTION; motion_event.device = 0; - // TODO: implement the modifier state getters - //motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state); - //motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state); + motion_event.mouse_motion.mod = GetKeyModifierState(modifiers); + motion_event.mouse_motion.button_mask = GetMouseButtonState(buttons); motion_event.mouse_motion.x = pos.x; motion_event.mouse_motion.y = pos.y; input->set_mouse_pos(pos); @@ -184,3 +182,32 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { input->parse_input_event(motion_event); } + +inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state) { + InputModifierState state; + + state.shift = (p_state & B_SHIFT_KEY) != 0; + state.control = (p_state & B_CONTROL_KEY) != 0; + state.alt = (p_state & B_OPTION_KEY) != 0; + state.meta = (p_state & B_COMMAND_KEY) != 0; + + return state; +} + +inline unsigned int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) { + unsigned int state = 0; + + if (p_state & B_PRIMARY_MOUSE_BUTTON) { + state |= 1 << 0; + } + + if (p_state & B_SECONDARY_MOUSE_BUTTON) { + state |= 1 << 1; + } + + if (p_state & B_TERTIARY_MOUSE_BUTTON) { + state |= 1 << 2; + } + + return state; +} diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index 19ea987e76..bb0ef43da0 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -23,6 +23,8 @@ private: void DispatchMouseButton(BMessage* message); void DispatchMouseMoved(BMessage* message); + inline InputModifierState GetKeyModifierState(uint32 p_state); + inline unsigned int GetMouseButtonState(uint32 p_state); public: HaikuDirectWindow(BRect p_frame); -- cgit v1.2.3 From f10eb8ffa1a7f6bee9b5228ea1204fd93844e4cc Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Thu, 18 Jun 2015 22:41:33 +0300 Subject: Haiku: implement get_mouse_pos() and get_mouse_button_state() --- platform/haiku/haiku_direct_window.cpp | 13 ++++++++----- platform/haiku/haiku_direct_window.h | 8 ++++++-- platform/haiku/os_haiku.cpp | 7 +++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index 6ff4369087..62231565a9 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -6,6 +6,7 @@ HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) { last_mouse_pos_valid = false; last_buttons_state = 0; + last_button_mask = 0; } @@ -154,11 +155,11 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { uint32 buttons = message->FindInt32("buttons"); if (!last_mouse_pos_valid) { - last_mouse_pos = pos; + last_mouse_position = pos; last_mouse_pos_valid = true; } - Point2i rel = pos - last_mouse_pos; + Point2i rel = pos - last_mouse_position; InputEvent motion_event; motion_event.ID = ++event_id; @@ -178,7 +179,7 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { motion_event.mouse_motion.relative_x = rel.x; motion_event.mouse_motion.relative_y = rel.y; - last_mouse_pos=pos; + last_mouse_position = pos; input->parse_input_event(motion_event); } @@ -194,8 +195,8 @@ inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state) return state; } -inline unsigned int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) { - unsigned int state = 0; +inline int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) { + int state = 0; if (p_state & B_PRIMARY_MOUSE_BUTTON) { state |= 1 << 0; @@ -209,5 +210,7 @@ inline unsigned int HaikuDirectWindow::GetMouseButtonState(uint32 p_state) { state |= 1 << 2; } + last_button_mask = state; + return state; } diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index bb0ef43da0..be4dcd9e94 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -13,9 +13,10 @@ class HaikuDirectWindow : public BDirectWindow { private: unsigned int event_id; - Point2i last_mouse_pos; + Point2i last_mouse_position; bool last_mouse_pos_valid; uint32 last_buttons_state; + int last_button_mask; InputDefault* input; HaikuGLView* view; @@ -24,7 +25,7 @@ private: void DispatchMouseButton(BMessage* message); void DispatchMouseMoved(BMessage* message); inline InputModifierState GetKeyModifierState(uint32 p_state); - inline unsigned int GetMouseButtonState(uint32 p_state); + inline int GetMouseButtonState(uint32 p_state); public: HaikuDirectWindow(BRect p_frame); @@ -38,6 +39,9 @@ public: virtual void DirectConnected(direct_buffer_info* info); virtual void MessageReceived(BMessage* message); virtual void DispatchMessage(BMessage* message, BHandler* handler); + + inline Point2i GetLastMousePosition() { return last_mouse_position; }; + inline int GetLastButtonMask() { return last_button_mask; }; }; #endif diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 193927238d..3694244e0a 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -174,19 +174,18 @@ void OS_Haiku::swap_buffers() { } Point2 OS_Haiku::get_mouse_pos() const { - ERR_PRINT("get_mouse_pos() NOT IMPLEMENTED"); + return window->GetLastMousePosition(); } int OS_Haiku::get_mouse_button_state() const { - ERR_PRINT("get_mouse_button_state() NOT IMPLEMENTED"); + return window->GetLastButtonMask(); } void OS_Haiku::set_cursor_shape(CursorShape p_shape) { - ERR_PRINT("set_cursor_shape() NOT IMPLEMENTED"); + //ERR_PRINT("set_cursor_shape() NOT IMPLEMENTED"); } void OS_Haiku::set_window_title(const String& p_title) { - //ERR_PRINT("set_window_title() NOT IMPLEMENTED"); window->SetTitle(p_title.utf8().get_data()); } -- cgit v1.2.3 From 93ac4ace0a0d84fdd7003fcaa02296d55ad5b2ad Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sat, 20 Jun 2015 01:59:32 +0300 Subject: Haiku: handle the quit request message --- platform/haiku/haiku_direct_window.cpp | 32 +++++++++++++------------------- platform/haiku/haiku_direct_window.h | 2 ++ platform/haiku/os_haiku.cpp | 3 +++ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index 62231565a9..3fccab10dd 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -2,7 +2,7 @@ #include "haiku_direct_window.h" HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) - : BDirectWindow(p_frame, "Godot", B_TITLED_WINDOW, 0) + : BDirectWindow(p_frame, "Godot", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) { last_mouse_pos_valid = false; last_buttons_state = 0; @@ -33,10 +33,13 @@ void HaikuDirectWindow::SetInput(InputDefault* p_input) { input = p_input; } +void HaikuDirectWindow::SetMainLoop(MainLoop* p_main_loop) { + main_loop = p_main_loop; +} + bool HaikuDirectWindow::QuitRequested() { - view->EnableDirectMode(false); - be_app->PostMessage(B_QUIT_REQUESTED); - return true; + main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); + return false; } void HaikuDirectWindow::DirectConnected(direct_buffer_info* info) { @@ -44,24 +47,15 @@ void HaikuDirectWindow::DirectConnected(direct_buffer_info* info) { view->EnableDirectMode(true); } -void HaikuDirectWindow::MessageReceived(BMessage* message) -{ +void HaikuDirectWindow::MessageReceived(BMessage* message) { switch (message->what) { case REDRAW_MSG: - //ERR_PRINT("iteration 1"); - Main::iteration(); - - //if (NeedsUpdate()) { - // ERR_PRINT("NEEDS UPDATE"); - // Main::force_redraw(); - //} - - //ERR_PRINT("iteration 2"); - break; + Sync(); - case B_INVALIDATE: - ERR_PRINT("WINDOW B_INVALIDATE"); - //Main::force_redraw(); + if (Main::iteration() == true) { + view->EnableDirectMode(false); + Quit(); + } break; default: diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index be4dcd9e94..c985cdc5d6 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -18,6 +18,7 @@ private: uint32 last_buttons_state; int last_button_mask; + MainLoop* main_loop; InputDefault* input; HaikuGLView* view; BMessageRunner* update_runner; @@ -35,6 +36,7 @@ public: void StartMessageRunner(); void StopMessageRunner(); void SetInput(InputDefault* p_input); + void SetMainLoop(MainLoop* p_main_loop); virtual bool QuitRequested(); virtual void DirectConnected(direct_buffer_info* info); virtual void MessageReceived(BMessage* message); diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 3694244e0a..699b0ba1ce 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -29,6 +29,7 @@ void OS_Haiku::run() { } } */ + app->Run(); window->StopMessageRunner(); @@ -142,6 +143,7 @@ void OS_Haiku::finalize() { void OS_Haiku::set_main_loop(MainLoop* p_main_loop) { main_loop = p_main_loop; input->set_main_loop(p_main_loop); + window->SetMainLoop(p_main_loop); } MainLoop* OS_Haiku::get_main_loop() const { @@ -154,6 +156,7 @@ void OS_Haiku::delete_main_loop() { } main_loop = NULL; + window->SetMainLoop(NULL); } void OS_Haiku::release_rendering_thread() { -- cgit v1.2.3 From d44dfc244099eafe40ff0d48abbcefd4271d029b Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sat, 20 Jun 2015 03:43:11 +0300 Subject: Haiku: cleanup, add TODOs --- platform/haiku/os_haiku.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 699b0ba1ce..7e4bb83177 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -2,6 +2,7 @@ #include "servers/visual/visual_server_wrap_mt.h" #include "drivers/gles2/rasterizer_gles2.h" #include "servers/physics/physics_server_sw.h" +//#include "servers/physics_2d/physics_2d_server_wrap_mt.h" #include "main/main.h" #include "os_haiku.h" @@ -19,22 +20,10 @@ void OS_Haiku::run() { main_loop->init(); window->Show(); window->StartMessageRunner(); - - /* - while (true) { - // TODO: process events - - if (Main::iteration() == true) { - break; - } - } - */ - - app->Run(); window->StopMessageRunner(); - delete app; + delete app; main_loop->finish(); } @@ -76,6 +65,7 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ ERR_FAIL_COND(!visual_server); + // TODO: enable multithreaded VS //if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { // visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); //} @@ -85,6 +75,8 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ physics_server = memnew(PhysicsServerSW); physics_server->init(); physics_2d_server = memnew(Physics2DServerSW); + // TODO: enable multithreaded PS + //physics_2d_server = Physics2DServerWrapMT::init_server(); physics_2d_server->init(); AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); -- cgit v1.2.3 From b59e95ce1c9905af8c7d44b74082ac489520e9b2 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sat, 20 Jun 2015 15:35:54 +0300 Subject: Haiku: implemet get_widow_size() get/set_window_position() --- platform/haiku/os_haiku.cpp | 13 ++++++++++++- platform/haiku/os_haiku.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 7e4bb83177..1dc16f7e1c 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -185,7 +185,18 @@ void OS_Haiku::set_window_title(const String& p_title) { } Size2 OS_Haiku::get_window_size() const { - ERR_PRINT("get_window_size() NOT IMPLEMENTED"); + BSize size = window->Size(); + return Size2i(size.IntegerWidth(), size.IntegerHeight()); +} + +Point2 OS_Haiku::get_window_position() const { + BPoint point(0, 0); + window->ConvertToScreen(&point); + return Point2i(point.x, point.y); +} + +void OS_Haiku::set_window_position(const Point2& p_position) { + window->MoveTo(p_position.x, p_position.y); } void OS_Haiku::set_video_mode(const VideoMode& p_video_mode, int p_screen) { diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index b741ae7da0..59f47fa11f 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -71,6 +71,8 @@ public: virtual void set_window_title(const String& p_title); virtual Size2 get_window_size() const; + virtual Point2 get_window_position() const; + virtual void set_window_position(const Point2& p_position); virtual void set_video_mode(const VideoMode& p_video_mode, int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; -- cgit v1.2.3 From 6f48ddc61db9a06e0751356e712fc87ded9ae3c3 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sun, 21 Jun 2015 02:08:31 +0300 Subject: Haiku: add some screen and window-related methods --- platform/haiku/os_haiku.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++- platform/haiku/os_haiku.h | 8 ++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 1dc16f7e1c..230340f325 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -1,3 +1,5 @@ +#include + #include "servers/visual/visual_server_raster.h" #include "servers/visual/visual_server_wrap_mt.h" #include "drivers/gles2/rasterizer_gles2.h" @@ -180,13 +182,48 @@ void OS_Haiku::set_cursor_shape(CursorShape p_shape) { //ERR_PRINT("set_cursor_shape() NOT IMPLEMENTED"); } +int OS_Haiku::get_screen_count() const { + // TODO: implement get_screen_count() + return 1; +} + +int OS_Haiku::get_current_screen() const { + // TODO: implement get_current_screen() + return 0; +} + +void OS_Haiku::set_current_screen(int p_screen) { + // TODO: implement set_current_screen() +} + +Point2 OS_Haiku::get_screen_position(int p_screen) const { + // TODO: make this work with the p_screen parameter + BScreen* screen = new BScreen(window); + BRect frame = screen->Frame(); + delete screen; + return Point2i(frame.left, frame.top); +} + +Size2 OS_Haiku::get_screen_size(int p_screen) const { + // TODO: make this work with the p_screen parameter + BScreen* screen = new BScreen(window); + BRect frame = screen->Frame(); + delete screen; + return Size2i(frame.IntegerWidth() + 1, frame.IntegerHeight() + 1); +} + void OS_Haiku::set_window_title(const String& p_title) { window->SetTitle(p_title.utf8().get_data()); } Size2 OS_Haiku::get_window_size() const { BSize size = window->Size(); - return Size2i(size.IntegerWidth(), size.IntegerHeight()); + return Size2i(size.IntegerWidth() + 1, size.IntegerHeight() + 1); +} + +void OS_Haiku::set_window_size(const Size2 p_size) { + // TODO: why does it stop redrawing after this is called? + window->ResizeTo(p_size.x, p_size.y); } Point2 OS_Haiku::get_window_position() const { @@ -199,6 +236,16 @@ void OS_Haiku::set_window_position(const Point2& p_position) { window->MoveTo(p_position.x, p_position.y); } +void OS_Haiku::set_window_fullscreen(bool p_enabled) { + window->SetFullScreen(p_enabled); + current_video_mode.fullscreen = p_enabled; + visual_server->init(); +} + +bool OS_Haiku::is_window_fullscreen() const { + return current_video_mode.fullscreen; +} + void OS_Haiku::set_video_mode(const VideoMode& p_video_mode, int p_screen) { ERR_PRINT("set_video_mode() NOT IMPLEMENTED"); } diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 59f47fa11f..983fbc33a9 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -69,10 +69,18 @@ public: virtual int get_mouse_button_state() const; virtual void set_cursor_shape(CursorShape p_shape); + virtual int get_screen_count() const; + virtual int get_current_screen() const; + virtual void set_current_screen(int p_screen); + virtual Point2 get_screen_position(int p_screen=0) const; + virtual Size2 get_screen_size(int p_screen=0) const; virtual void set_window_title(const String& p_title); virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2 p_size); virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); + virtual void set_window_fullscreen(bool p_enabled); + virtual bool is_window_fullscreen() const; virtual void set_video_mode(const VideoMode& p_video_mode, int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; -- cgit v1.2.3 From 174df9a276b26eb6594e3387f71e3fe8c1706253 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sun, 21 Jun 2015 22:18:27 +0300 Subject: Haiku: add support for mouse wheel --- platform/haiku/haiku_direct_window.cpp | 33 +++++++++++++++++++++++++++++++++ platform/haiku/haiku_direct_window.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index 3fccab10dd..8c8069af49 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -7,6 +7,7 @@ HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) last_mouse_pos_valid = false; last_buttons_state = 0; last_button_mask = 0; + last_key_modifier_state = 0; } @@ -74,6 +75,10 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { DispatchMouseMoved(message); break; + case B_MOUSE_WHEEL_CHANGED: + DispatchMouseWheelChanged(message); + break; + default: BDirectWindow::DispatchMessage(message, handler); } @@ -178,7 +183,35 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { input->parse_input_event(motion_event); } +void HaikuDirectWindow::DispatchMouseWheelChanged(BMessage* message) { + float wheel_delta_y = 0; + if (message->FindFloat("be:wheel_delta_y", &wheel_delta_y) != B_OK) { + return; + } + + InputEvent mouse_event; + mouse_event.ID = ++event_id; + mouse_event.type = InputEvent::MOUSE_BUTTON; + mouse_event.device = 0; + + mouse_event.mouse_button.button_index = wheel_delta_y < 0 ? 4 : 5; + mouse_event.mouse_button.mod = GetKeyModifierState(last_key_modifier_state); + mouse_event.mouse_button.button_mask = last_button_mask; + mouse_event.mouse_button.x = last_mouse_position.x; + mouse_event.mouse_button.y = last_mouse_position.y; + mouse_event.mouse_button.global_x = last_mouse_position.x; + mouse_event.mouse_button.global_y = last_mouse_position.y; + + mouse_event.mouse_button.pressed = true; + input->parse_input_event(mouse_event); + + mouse_event.ID = ++event_id; + mouse_event.mouse_button.pressed = false; + input->parse_input_event(mouse_event); +} + inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state) { + last_key_modifier_state = p_state; InputModifierState state; state.shift = (p_state & B_SHIFT_KEY) != 0; diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index c985cdc5d6..5355ab4dd4 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -16,6 +16,7 @@ private: Point2i last_mouse_position; bool last_mouse_pos_valid; uint32 last_buttons_state; + uint32 last_key_modifier_state; int last_button_mask; MainLoop* main_loop; @@ -25,6 +26,7 @@ private: void DispatchMouseButton(BMessage* message); void DispatchMouseMoved(BMessage* message); + void DispatchMouseWheelChanged(BMessage* message); inline InputModifierState GetKeyModifierState(uint32 p_state); inline int GetMouseButtonState(uint32 p_state); -- cgit v1.2.3 From 7ad89c7e8383144292609f857803a4c57f852259 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Tue, 23 Jun 2015 21:22:12 +0300 Subject: Haiku: implement some more window-related methods --- platform/haiku/os_haiku.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- platform/haiku/os_haiku.h | 6 ++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 230340f325..b4b7877038 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -20,7 +20,6 @@ void OS_Haiku::run() { } main_loop->init(); - window->Show(); window->StartMessageRunner(); app->Run(); window->StopMessageRunner(); @@ -56,6 +55,16 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ window = new HaikuDirectWindow(frame); + if (current_video_mode.fullscreen) { + window->SetFullScreen(true); + } + + if (!current_video_mode.resizable) { + uint32 flags = window->Flags(); + flags |= B_NOT_RESIZABLE; + window->SetFlags(flags); + } + #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) context_gl = memnew(ContextGL_Haiku(window)); context_gl->initialize(); @@ -98,6 +107,7 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ input = memnew(InputDefault); window->SetInput(input); + window->Show(); } void OS_Haiku::finalize() { @@ -246,6 +256,38 @@ bool OS_Haiku::is_window_fullscreen() const { return current_video_mode.fullscreen; } +void OS_Haiku::set_window_resizable(bool p_enabled) { + uint32 flags = window->Flags(); + + if (p_enabled) { + flags &= ~(B_NOT_RESIZABLE); + } else { + flags |= B_NOT_RESIZABLE; + } + + window->SetFlags(flags); +} + +bool OS_Haiku::is_window_resizable() const { + return !(window->Flags() & B_NOT_RESIZABLE); +} + +void OS_Haiku::set_window_minimized(bool p_enabled) { + window->Minimize(p_enabled); +} + +bool OS_Haiku::is_window_minimized() const { + return window->IsMinimized(); +} + +void OS_Haiku::set_window_maximized(bool p_enabled) { + window->Minimize(!p_enabled); +} + +bool OS_Haiku::is_window_maximized() const { + return !window->IsMinimized(); +} + void OS_Haiku::set_video_mode(const VideoMode& p_video_mode, int p_screen) { ERR_PRINT("set_video_mode() NOT IMPLEMENTED"); } diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 983fbc33a9..a7a8bee522 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -81,6 +81,12 @@ public: virtual void set_window_position(const Point2& p_position); virtual void set_window_fullscreen(bool p_enabled); virtual bool is_window_fullscreen() const; + virtual void set_window_resizable(bool p_enabled); + virtual bool is_window_resizable() const; + virtual void set_window_minimized(bool p_enabled); + virtual bool is_window_minimized() const; + virtual void set_window_maximized(bool p_enabled); + virtual bool is_window_maximized() const; virtual void set_video_mode(const VideoMode& p_video_mode, int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; -- cgit v1.2.3 From f61eb5fd8e13642c82364f8ee66a0f6c791a4511 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Fri, 26 Jun 2015 21:32:57 +0300 Subject: Haiku: fix the glew.c hack --- drivers/gl_context/glew.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gl_context/glew.c b/drivers/gl_context/glew.c index e38942de4f..962e82b657 100644 --- a/drivers/gl_context/glew.c +++ b/drivers/gl_context/glew.c @@ -1,4 +1,8 @@ -#ifndef GLEW_ENABLED +#ifdef __HAIKU__ + #undef GLEW_ENABLED +#endif + +#ifdef GLEW_ENABLED /* ** The OpenGL Extension Wrangler Library ** Copyright (C) 2002-2008, Milan Ikits -- cgit v1.2.3 From 77e78cdb200b08a079b9d4047ea99227874ff3e1 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Thu, 2 Jul 2015 18:41:32 +0300 Subject: Haiku: gl context locking --- platform/haiku/context_gl_haiku.cpp | 3 --- platform/haiku/haiku_direct_window.cpp | 42 ++++++++++++++++++++++++++++------ platform/haiku/haiku_direct_window.h | 12 +++++++--- platform/haiku/os_haiku.cpp | 23 +++++++++++++++---- 4 files changed, 62 insertions(+), 18 deletions(-) diff --git a/platform/haiku/context_gl_haiku.cpp b/platform/haiku/context_gl_haiku.cpp index 8cb1adc360..21107a52a4 100644 --- a/platform/haiku/context_gl_haiku.cpp +++ b/platform/haiku/context_gl_haiku.cpp @@ -15,20 +15,17 @@ ContextGL_Haiku::~ContextGL_Haiku() { Error ContextGL_Haiku::initialize() { window->AddChild(view); - view->LockGL(); window->SetHaikuGLView(view); return OK; } void ContextGL_Haiku::release_current() { - //ERR_PRINT("release_current() NOT IMPLEMENTED"); view->UnlockGL(); } void ContextGL_Haiku::make_current() { view->LockGL(); - //ERR_PRINT("make_current() NOT IMPLEMENTED"); } void ContextGL_Haiku::swap_buffers() { diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index 8c8069af49..e400d70108 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -23,7 +23,7 @@ void HaikuDirectWindow::SetHaikuGLView(HaikuGLView* p_view) { void HaikuDirectWindow::StartMessageRunner() { update_runner = new BMessageRunner(BMessenger(this), - new BMessage(REDRAW_MSG), 1000000/60 /* 60 fps */); + new BMessage(REDRAW_MSG), 1000000/30 /* 30 fps */); } void HaikuDirectWindow::StopMessageRunner() { @@ -68,15 +68,31 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { switch (message->what) { case B_MOUSE_DOWN: case B_MOUSE_UP: - DispatchMouseButton(message); + HandleMouseButton(message); break; case B_MOUSE_MOVED: - DispatchMouseMoved(message); + HandleMouseMoved(message); break; case B_MOUSE_WHEEL_CHANGED: - DispatchMouseWheelChanged(message); + HandleMouseWheelChanged(message); + break; + + case B_WINDOW_RESIZED: + HandleWindowResized(message); + //view->UnlockGL(); + //BDirectWindow::DispatchMessage(message, handler); + //view->LockGL(); + break; + + case LOCKGL_MSG: + ERR_PRINT("LOCKGL"); + view->LockGL(); + break; + + case UNLOCKGL_MSG: + view->UnlockGL(); break; default: @@ -84,7 +100,7 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { } } -void HaikuDirectWindow::DispatchMouseButton(BMessage* message) { +void HaikuDirectWindow::HandleMouseButton(BMessage* message) { message->PrintToStream(); BPoint where; @@ -143,7 +159,7 @@ void HaikuDirectWindow::DispatchMouseButton(BMessage* message) { input->parse_input_event(mouse_event); } -void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { +void HaikuDirectWindow::HandleMouseMoved(BMessage* message) { BPoint where; if (message->FindPoint("where", &where) != B_OK) { return; @@ -183,7 +199,7 @@ void HaikuDirectWindow::DispatchMouseMoved(BMessage* message) { input->parse_input_event(motion_event); } -void HaikuDirectWindow::DispatchMouseWheelChanged(BMessage* message) { +void HaikuDirectWindow::HandleMouseWheelChanged(BMessage* message) { float wheel_delta_y = 0; if (message->FindFloat("be:wheel_delta_y", &wheel_delta_y) != B_OK) { return; @@ -210,6 +226,18 @@ void HaikuDirectWindow::DispatchMouseWheelChanged(BMessage* message) { input->parse_input_event(mouse_event); } +void HaikuDirectWindow::HandleWindowResized(BMessage* message) { + int32 width = 0; + int32 height = 0; + + if ((message->FindInt32("width", &width) != B_OK) || (message->FindInt32("height", &height) != B_OK)) { + return; + } + + current_video_mode->width = width; + current_video_mode->height = height; +} + inline InputModifierState HaikuDirectWindow::GetKeyModifierState(uint32 p_state) { last_key_modifier_state = p_state; InputModifierState state; diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index 5355ab4dd4..3667eb24d1 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -5,9 +5,12 @@ #include #include "os/input.h" +#include "core/os/os.h" #include "haiku_gl_view.h" #define REDRAW_MSG 'rdrw' +#define LOCKGL_MSG 'glck' +#define UNLOCKGL_MSG 'ulck' class HaikuDirectWindow : public BDirectWindow { @@ -18,15 +21,17 @@ private: uint32 last_buttons_state; uint32 last_key_modifier_state; int last_button_mask; + OS::VideoMode* current_video_mode; MainLoop* main_loop; InputDefault* input; HaikuGLView* view; BMessageRunner* update_runner; - void DispatchMouseButton(BMessage* message); - void DispatchMouseMoved(BMessage* message); - void DispatchMouseWheelChanged(BMessage* message); + void HandleMouseButton(BMessage* message); + void HandleMouseMoved(BMessage* message); + void HandleMouseWheelChanged(BMessage* message); + void HandleWindowResized(BMessage* message); inline InputModifierState GetKeyModifierState(uint32 p_state); inline int GetMouseButtonState(uint32 p_state); @@ -39,6 +44,7 @@ public: void StopMessageRunner(); void SetInput(InputDefault* p_input); void SetMainLoop(MainLoop* p_main_loop); + inline void SetVideoMode(OS::VideoMode* video_mode) { current_video_mode = video_mode; }; virtual bool QuitRequested(); virtual void DirectConnected(direct_buffer_info* info); virtual void MessageReceived(BMessage* message); diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index b4b7877038..2c29260281 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -20,11 +20,21 @@ void OS_Haiku::run() { } main_loop->init(); + context_gl->release_current(); + + // TODO: clean up + BMessenger* bms = new BMessenger(window); + BMessage* msg = new BMessage(); + bms->SendMessage(LOCKGL_MSG, msg); + window->StartMessageRunner(); app->Run(); window->StopMessageRunner(); delete app; + + delete bms; + delete msg; main_loop->finish(); } @@ -54,6 +64,7 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ frame.Set(50, 50, 50 + current_video_mode.width - 1, 50 + current_video_mode.height - 1); window = new HaikuDirectWindow(frame); + window->SetVideoMode(¤t_video_mode); if (current_video_mode.fullscreen) { window->SetFullScreen(true); @@ -68,6 +79,7 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) context_gl = memnew(ContextGL_Haiku(window)); context_gl->initialize(); + context_gl->make_current(); rasterizer = memnew(RasterizerGLES2); #endif @@ -81,6 +93,10 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ // visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD)); //} + input = memnew(InputDefault); + window->SetInput(input); + + window->Show(); visual_server->init(); physics_server = memnew(PhysicsServerSW); @@ -104,10 +120,6 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ spatial_sound_server->init(); spatial_sound_2d_server = memnew(SpatialSound2DServerSW); spatial_sound_2d_server->init(); - - input = memnew(InputDefault); - window->SetInput(input); - window->Show(); } void OS_Haiku::finalize() { @@ -266,10 +278,11 @@ void OS_Haiku::set_window_resizable(bool p_enabled) { } window->SetFlags(flags); + current_video_mode.resizable = p_enabled; } bool OS_Haiku::is_window_resizable() const { - return !(window->Flags() & B_NOT_RESIZABLE); + return current_video_mode.resizable; } void OS_Haiku::set_window_minimized(bool p_enabled) { -- cgit v1.2.3 From 07e76a3f2ce85c996ddddce8e4e5180c7b948490 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sun, 12 Jul 2015 00:52:47 +0300 Subject: Haiku: add keyboard support --- platform/haiku/SCsub | 3 +- platform/haiku/haiku_direct_window.cpp | 84 ++++++++++++++ platform/haiku/haiku_direct_window.h | 2 + platform/haiku/key_mapping_haiku.cpp | 193 +++++++++++++++++++++++++++++++++ platform/haiku/key_mapping_haiku.h | 13 +++ 5 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 platform/haiku/key_mapping_haiku.cpp create mode 100644 platform/haiku/key_mapping_haiku.h diff --git a/platform/haiku/SCsub b/platform/haiku/SCsub index 18fa2e2b15..88c9b8b464 100644 --- a/platform/haiku/SCsub +++ b/platform/haiku/SCsub @@ -5,7 +5,8 @@ common_haiku = [ 'context_gl_haiku.cpp', 'haiku_application.cpp', 'haiku_direct_window.cpp', - 'haiku_gl_view.cpp' + 'haiku_gl_view.cpp', + 'key_mapping_haiku.cpp' ] env.Program( diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index e400d70108..e7577602ca 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -1,5 +1,9 @@ +#include + #include "main/main.h" +#include "os/keyboard.h" #include "haiku_direct_window.h" +#include "key_mapping_haiku.h" HaikuDirectWindow::HaikuDirectWindow(BRect p_frame) : BDirectWindow(p_frame, "Godot", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) @@ -79,6 +83,15 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { HandleMouseWheelChanged(message); break; + case B_KEY_DOWN: + case B_KEY_UP: + HandleKeyboardEvent(message); + break; + + case B_MODIFIERS_CHANGED: + HandleKeyboardModifierEvent(message); + break; + case B_WINDOW_RESIZED: HandleWindowResized(message); //view->UnlockGL(); @@ -226,6 +239,77 @@ void HaikuDirectWindow::HandleMouseWheelChanged(BMessage* message) { input->parse_input_event(mouse_event); } +void HaikuDirectWindow::HandleKeyboardEvent(BMessage* message) { + message->PrintToStream(); + int32 raw_char = 0; + int32 key = 0; + int32 modifiers = 0; + + if (message->FindInt32("raw_char", &raw_char) != B_OK) { + return; + } + + if (message->FindInt32("key", &key) != B_OK) { + return; + } + + if (message->FindInt32("modifiers", &modifiers) != B_OK) { + return; + } + + InputEvent event; + event.ID = ++event_id; + event.type = InputEvent::KEY; + event.device = 0; + event.key.mod = GetKeyModifierState(modifiers); + event.key.pressed = (message->what == B_KEY_DOWN); + event.key.scancode = KeyMappingHaiku::get_keysym(raw_char, key); + event.key.echo = message->HasInt32("be:key_repeat"); + event.key.unicode = 0; + + const char* bytes = NULL; + if (message->FindString("bytes", &bytes) == B_OK) { + event.key.unicode = BUnicodeChar::FromUTF8(&bytes); + } + + //make it consistent accross platforms. + if (event.key.scancode==KEY_BACKTAB) { + event.key.scancode=KEY_TAB; + event.key.mod.shift=true; + } + + input->parse_input_event(event); +} + +void HaikuDirectWindow::HandleKeyboardModifierEvent(BMessage* message) { + message->PrintToStream(); + + int32 old_modifiers = 0; + int32 modifiers = 0; + + if (message->FindInt32("be:old_modifiers", &old_modifiers) != B_OK) { + return; + } + + if (message->FindInt32("modifiers", &modifiers) != B_OK) { + return; + } + + int32 key = old_modifiers ^ modifiers; + + InputEvent event; + event.ID = ++event_id; + event.type = InputEvent::KEY; + event.device = 0; + event.key.mod = GetKeyModifierState(modifiers); + event.key.pressed = ((modifiers & key) != 0); + event.key.scancode = KeyMappingHaiku::get_modifier_keysym(key); + event.key.echo = false; + event.key.unicode = 0; + + input->parse_input_event(event); +} + void HaikuDirectWindow::HandleWindowResized(BMessage* message) { int32 width = 0; int32 height = 0; diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index 3667eb24d1..7b1fd851fa 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -32,6 +32,8 @@ private: void HandleMouseMoved(BMessage* message); void HandleMouseWheelChanged(BMessage* message); void HandleWindowResized(BMessage* message); + void HandleKeyboardEvent(BMessage* message); + void HandleKeyboardModifierEvent(BMessage* message); inline InputModifierState GetKeyModifierState(uint32 p_state); inline int GetMouseButtonState(uint32 p_state); diff --git a/platform/haiku/key_mapping_haiku.cpp b/platform/haiku/key_mapping_haiku.cpp new file mode 100644 index 0000000000..d7bde9a727 --- /dev/null +++ b/platform/haiku/key_mapping_haiku.cpp @@ -0,0 +1,193 @@ +#include + +#include "key_mapping_haiku.h" +#include "os/keyboard.h" + +struct _HaikuTranslatePair { + unsigned int keysym; + int32 keycode; +}; + +static _HaikuTranslatePair _mod_to_keycode[] = { + { KEY_SHIFT, B_SHIFT_KEY }, + { KEY_ALT, B_COMMAND_KEY }, + { KEY_CONTROL, B_CONTROL_KEY }, + { KEY_CAPSLOCK, B_CAPS_LOCK }, + { KEY_SCROLLLOCK, B_SCROLL_LOCK }, + { KEY_NUMLOCK, B_NUM_LOCK }, + { KEY_SUPER_L, B_OPTION_KEY }, + { KEY_MENU, B_MENU_KEY }, + { KEY_SHIFT, B_LEFT_SHIFT_KEY }, + { KEY_SHIFT, B_RIGHT_SHIFT_KEY }, + { KEY_ALT, B_LEFT_COMMAND_KEY }, + { KEY_ALT, B_RIGHT_COMMAND_KEY }, + { KEY_CONTROL, B_LEFT_CONTROL_KEY }, + { KEY_CONTROL, B_RIGHT_CONTROL_KEY }, + { KEY_SUPER_L, B_LEFT_OPTION_KEY }, + { KEY_SUPER_R, B_RIGHT_OPTION_KEY }, + { KEY_UNKNOWN, 0 } +}; + +static _HaikuTranslatePair _fn_to_keycode[] = { + { KEY_F1, B_F1_KEY }, + { KEY_F2, B_F2_KEY }, + { KEY_F3, B_F3_KEY }, + { KEY_F4, B_F4_KEY }, + { KEY_F5, B_F5_KEY }, + { KEY_F6, B_F6_KEY }, + { KEY_F7, B_F7_KEY }, + { KEY_F8, B_F8_KEY }, + { KEY_F9, B_F9_KEY }, + { KEY_F10, B_F10_KEY }, + { KEY_F11, B_F11_KEY }, + { KEY_F12, B_F12_KEY }, + //{ KEY_F13, ? }, + //{ KEY_F14, ? }, + //{ KEY_F15, ? }, + //{ KEY_F16, ? }, + { KEY_PRINT, B_PRINT_KEY }, + { KEY_SCROLLLOCK, B_SCROLL_KEY }, + { KEY_PAUSE, B_PAUSE_KEY }, + { KEY_UNKNOWN, 0 } +}; + +static _HaikuTranslatePair _hb_to_keycode[] = { + { KEY_BACKSPACE, B_BACKSPACE }, + { KEY_TAB, B_TAB }, + { KEY_RETURN, B_RETURN }, + { KEY_CAPSLOCK, B_CAPS_LOCK }, + { KEY_ESCAPE, B_ESCAPE }, + { KEY_SPACE, B_SPACE }, + { KEY_PAGEUP, B_PAGE_UP }, + { KEY_PAGEDOWN, B_PAGE_DOWN }, + { KEY_END, B_END }, + { KEY_HOME, B_HOME }, + { KEY_LEFT, B_LEFT_ARROW }, + { KEY_UP, B_UP_ARROW }, + { KEY_RIGHT, B_RIGHT_ARROW }, + { KEY_DOWN, B_DOWN_ARROW }, + { KEY_PRINT, B_PRINT_KEY }, + { KEY_INSERT, B_INSERT }, + { KEY_DELETE, B_DELETE }, + // { KEY_HELP, ??? }, + + { KEY_0, (0x30) }, + { KEY_1, (0x31) }, + { KEY_2, (0x32) }, + { KEY_3, (0x33) }, + { KEY_4, (0x34) }, + { KEY_5, (0x35) }, + { KEY_6, (0x36) }, + { KEY_7, (0x37) }, + { KEY_8, (0x38) }, + { KEY_9, (0x39) }, + { KEY_A, (0x61) }, + { KEY_B, (0x62) }, + { KEY_C, (0x63) }, + { KEY_D, (0x64) }, + { KEY_E, (0x65) }, + { KEY_F, (0x66) }, + { KEY_G, (0x67) }, + { KEY_H, (0x68) }, + { KEY_I, (0x69) }, + { KEY_J, (0x6A) }, + { KEY_K, (0x6B) }, + { KEY_L, (0x6C) }, + { KEY_M, (0x6D) }, + { KEY_N, (0x6E) }, + { KEY_O, (0x6F) }, + { KEY_P, (0x70) }, + { KEY_Q, (0x71) }, + { KEY_R, (0x72) }, + { KEY_S, (0x73) }, + { KEY_T, (0x74) }, + { KEY_U, (0x75) }, + { KEY_V, (0x76) }, + { KEY_W, (0x77) }, + { KEY_X, (0x78) }, + { KEY_Y, (0x79) }, + { KEY_Z, (0x7A) }, + +/* +{ KEY_PLAY, VK_PLAY},// (0xFA) +{ KEY_STANDBY,VK_SLEEP },//(0x5F) +{ KEY_BACK,VK_BROWSER_BACK},// (0xA6) +{ KEY_FORWARD,VK_BROWSER_FORWARD},// (0xA7) +{ KEY_REFRESH,VK_BROWSER_REFRESH},// (0xA8) +{ KEY_STOP,VK_BROWSER_STOP},// (0xA9) +{ KEY_SEARCH,VK_BROWSER_SEARCH},// (0xAA) +{ KEY_FAVORITES, VK_BROWSER_FAVORITES},// (0xAB) +{ KEY_HOMEPAGE,VK_BROWSER_HOME},// (0xAC) +{ KEY_VOLUMEMUTE,VK_VOLUME_MUTE},// (0xAD) +{ KEY_VOLUMEDOWN,VK_VOLUME_DOWN},// (0xAE) +{ KEY_VOLUMEUP,VK_VOLUME_UP},// (0xAF) +{ KEY_MEDIANEXT,VK_MEDIA_NEXT_TRACK},// (0xB0) +{ KEY_MEDIAPREVIOUS,VK_MEDIA_PREV_TRACK},// (0xB1) +{ KEY_MEDIASTOP,VK_MEDIA_STOP},// (0xB2) +{ KEY_LAUNCHMAIL, VK_LAUNCH_MAIL},// (0xB4) +{ KEY_LAUNCHMEDIA,VK_LAUNCH_MEDIA_SELECT},// (0xB5) +{ KEY_LAUNCH0,VK_LAUNCH_APP1},// (0xB6) +{ KEY_LAUNCH1,VK_LAUNCH_APP2},// (0xB7) +*/ + + { KEY_SEMICOLON, 0x3B }, + { KEY_EQUAL, 0x3D }, + { KEY_COLON, 0x2C }, + { KEY_MINUS, 0x2D }, + { KEY_PERIOD, 0x2E }, + { KEY_SLASH, 0x2F }, + { KEY_KP_MULTIPLY, 0x2A }, + { KEY_KP_ADD, 0x2B }, + + { KEY_QUOTELEFT, 0x60 }, + { KEY_BRACKETLEFT, 0x5B }, + { KEY_BACKSLASH, 0x5C }, + { KEY_BRACKETRIGHT, 0x5D }, + { KEY_APOSTROPHE, 0x27 }, + + { KEY_UNKNOWN, 0 } +}; + +unsigned int KeyMappingHaiku::get_keysym(int32 raw_char, int32 key) { + if (raw_char == B_INSERT && key == 0x64) { return KEY_KP_0; } + if (raw_char == B_END && key == 0x58) { return KEY_KP_1; } + if (raw_char == B_DOWN_ARROW && key == 0x59) { return KEY_KP_2; } + if (raw_char == B_PAGE_DOWN && key == 0x5A) { return KEY_KP_3; } + if (raw_char == B_LEFT_ARROW && key == 0x48) { return KEY_KP_4; } + if (raw_char == 0x35 && key == 0x49) { return KEY_KP_5; } + if (raw_char == B_RIGHT_ARROW && key == 0x4A) { return KEY_KP_6; } + if (raw_char == B_HOME && key == 0x37) { return KEY_KP_7; } + if (raw_char == B_UP_ARROW && key == 0x38) { return KEY_KP_8; } + if (raw_char == B_PAGE_UP && key == 0x39) { return KEY_KP_9; } + if (raw_char == 0x2F && key == 0x23) { return KEY_KP_DIVIDE; } + if (raw_char == 0x2D && key == 0x25) { return KEY_KP_SUBSTRACT; } + if (raw_char == B_DELETE && key == 0x65) { return KEY_KP_PERIOD; } + + if (raw_char == 0x10) { + for(int i = 0; _fn_to_keycode[i].keysym != KEY_UNKNOWN; i++) { + if (_fn_to_keycode[i].keycode == key) { + return _fn_to_keycode[i].keysym; + } + } + + return KEY_UNKNOWN; + } + + for(int i = 0; _hb_to_keycode[i].keysym != KEY_UNKNOWN; i++) { + if (_hb_to_keycode[i].keycode == raw_char) { + return _hb_to_keycode[i].keysym; + } + } + + return KEY_UNKNOWN; +} + +unsigned int KeyMappingHaiku::get_modifier_keysym(int32 key) { + for(int i = 0; _mod_to_keycode[i].keysym != KEY_UNKNOWN; i++) { + if ((_mod_to_keycode[i].keycode & key) != 0) { + return _mod_to_keycode[i].keysym; + } + } + + return KEY_UNKNOWN; +} diff --git a/platform/haiku/key_mapping_haiku.h b/platform/haiku/key_mapping_haiku.h new file mode 100644 index 0000000000..e2864678a8 --- /dev/null +++ b/platform/haiku/key_mapping_haiku.h @@ -0,0 +1,13 @@ +#ifndef KEY_MAPPING_HAIKU_H +#define KEY_MAPPING_HAIKU_H + +class KeyMappingHaiku +{ + KeyMappingHaiku() {}; + +public: + static unsigned int get_keysym(int32 raw_char, int32 key); + static unsigned int get_modifier_keysym(int32 key); +}; + +#endif -- cgit v1.2.3 From f8db8b72155ef904b9399295d3c40737e265e2ad Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Mon, 20 Jul 2015 22:45:22 +0300 Subject: Haiku: update detect.py --- platform/haiku/detect.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index 587148838f..d219850bb4 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -17,7 +17,9 @@ def can_build(): return True def get_opts(): - return [] + return [ + ('debug_release', 'Add debug symbols to release version','no') + ] def get_flags(): return [ @@ -41,9 +43,9 @@ def configure(env): if (env["target"]=="release"): if (env["debug_release"]=="yes"): - env.Append(CCFLAGS=['-g2','-fomit-frame-pointer']) + env.Append(CCFLAGS=['-g2']) else: - env.Append(CCFLAGS=['-O2','-ffast-math','-fomit-frame-pointer']) + env.Append(CCFLAGS=['-O3','-ffast-math']) elif (env["target"]=="release_debug"): env.Append(CCFLAGS=['-O2','-ffast-math','-DDEBUG_ENABLED']) elif (env["target"]=="debug"): -- cgit v1.2.3 From f5bfd497aab7e24a6f4dc0315e9e9333504067a0 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sun, 26 Jul 2015 02:18:32 +0300 Subject: Haiku: add sound support --- drivers/SCsub | 1 + drivers/media_kit/SCsub | 5 + drivers/media_kit/audio_driver_media_kit.cpp | 143 +++++++++++++++++++++++++++ drivers/media_kit/audio_driver_media_kit.h | 72 ++++++++++++++ platform/haiku/detect.py | 5 +- platform/haiku/os_haiku.cpp | 4 +- platform/haiku/os_haiku.h | 6 +- 7 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 drivers/media_kit/SCsub create mode 100644 drivers/media_kit/audio_driver_media_kit.cpp create mode 100644 drivers/media_kit/audio_driver_media_kit.h diff --git a/drivers/SCsub b/drivers/SCsub index 6ab0973625..2bb2d4966c 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -12,6 +12,7 @@ SConscript('windows/SCsub'); SConscript('gles2/SCsub'); SConscript('gl_context/SCsub'); SConscript('openssl/SCsub'); +SConscript('media_kit/SCsub'); if (env["png"]=="yes"): SConscript("png/SCsub"); diff --git a/drivers/media_kit/SCsub b/drivers/media_kit/SCsub new file mode 100644 index 0000000000..9fbb467baa --- /dev/null +++ b/drivers/media_kit/SCsub @@ -0,0 +1,5 @@ +Import('env') + +env.add_source_files(env.drivers_sources,"*.cpp") + +Export('env') diff --git a/drivers/media_kit/audio_driver_media_kit.cpp b/drivers/media_kit/audio_driver_media_kit.cpp new file mode 100644 index 0000000000..3fabe4f96f --- /dev/null +++ b/drivers/media_kit/audio_driver_media_kit.cpp @@ -0,0 +1,143 @@ +/*************************************************************************/ +/* audio_driver_media_kit.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "audio_driver_media_kit.h" + +#ifdef MEDIA_KIT_ENABLED + +#include "globals.h" + +int32_t* AudioDriverMediaKit::samples_in = NULL; + +Error AudioDriverMediaKit::init() { + active = false; + + mix_rate = 44100; + output_format = OUTPUT_STEREO; + channels = 2; + + int latency = GLOBAL_DEF("audio/output_latency", 25); + buffer_size = nearest_power_of_2(latency * mix_rate / 1000); + samples_in = memnew_arr(int32_t, buffer_size * channels); + + media_raw_audio_format format; + format = media_raw_audio_format::wildcard; + format.frame_rate = mix_rate; + format.channel_count = channels; + format.format = media_raw_audio_format::B_AUDIO_INT; + format.byte_order = B_MEDIA_LITTLE_ENDIAN; + format.buffer_size = buffer_size * sizeof(int32_t) * channels; + + player = new BSoundPlayer( + &format, + "godot_sound_server", + AudioDriverMediaKit::PlayBuffer, + NULL, + this + ); + + if (player->InitCheck() != B_OK) { + fprintf(stderr, "MediaKit ERR: can not create a BSoundPlayer instance\n"); + ERR_FAIL_COND_V(player == NULL, ERR_CANT_OPEN); + } + + mutex = Mutex::create(); + player->Start(); + + return OK; +} + +void AudioDriverMediaKit::PlayBuffer(void* cookie, void* buffer, size_t size, const media_raw_audio_format& format) { + AudioDriverMediaKit* ad = (AudioDriverMediaKit*) cookie; + int32_t* buf = (int32_t*) buffer; + + if (!ad->active) { + for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { + AudioDriverMediaKit::samples_in[i] = 0; + } + } else { + ad->lock(); + ad->audio_server_process(ad->buffer_size, AudioDriverMediaKit::samples_in); + ad->unlock(); + } + + for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { + buf[i] = AudioDriverMediaKit::samples_in[i]; + } +} + +void AudioDriverMediaKit::start() { + active = true; +} + +int AudioDriverMediaKit::get_mix_rate() const { + return mix_rate; +} + +AudioDriverSW::OutputFormat AudioDriverMediaKit::get_output_format() const { + return output_format; +} + +void AudioDriverMediaKit::lock() { + if (!mutex) + return; + + mutex->lock(); +} + +void AudioDriverMediaKit::unlock() { + if (!mutex) + return; + + mutex->unlock(); +} + +void AudioDriverMediaKit::finish() { + if (player) + delete player; + + if (samples_in) { + memdelete_arr(samples_in); + }; + + if (mutex) { + memdelete(mutex); + mutex = NULL; + } +} + +AudioDriverMediaKit::AudioDriverMediaKit() { + mutex = NULL; + player = NULL; +} + +AudioDriverMediaKit::~AudioDriverMediaKit() { + +} + +#endif diff --git a/drivers/media_kit/audio_driver_media_kit.h b/drivers/media_kit/audio_driver_media_kit.h new file mode 100644 index 0000000000..a23ec447f1 --- /dev/null +++ b/drivers/media_kit/audio_driver_media_kit.h @@ -0,0 +1,72 @@ +/*************************************************************************/ +/* audio_driver_media_kit.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "servers/audio/audio_server_sw.h" + +#ifdef MEDIA_KIT_ENABLED + +#include "core/os/thread.h" +#include "core/os/mutex.h" + +#include // needed for image_id +#include + +class AudioDriverMediaKit : public AudioDriverSW { + Mutex* mutex; + + BSoundPlayer* player; + static int32_t* samples_in; + + static void PlayBuffer(void* cookie, void* buffer, size_t size, const media_raw_audio_format& format); + + unsigned int mix_rate; + OutputFormat output_format; + unsigned int buffer_size; + int channels; + + bool active; + +public: + + const char* get_name() const { + return "MediaKit"; + }; + + virtual Error init(); + virtual void start(); + virtual int get_mix_rate() const; + virtual OutputFormat get_output_format() const; + virtual void lock(); + virtual void unlock(); + virtual void finish(); + + AudioDriverMediaKit(); + ~AudioDriverMediaKit(); +}; + +#endif diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index d219850bb4..f4198e50cd 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -52,10 +52,9 @@ def configure(env): env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) #env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) - env.Append(CPPFLAGS = ['-DGLEW_ENABLED']) - env.Append(CPPFLAGS = ['-DOPENGL_ENABLED']) + env.Append(CPPFLAGS = ['-DGLEW_ENABLED', '-DOPENGL_ENABLED', '-DMEDIA_KIT_ENABLED']) env.Append(CPPFLAGS = ['-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES_OVER_GL']) - env.Append(LIBS = ['be', 'game', 'GL', 'GLEW', 'z', 'network', 'bnetapi']) + env.Append(LIBS = ['be', 'game', 'media', 'network', 'bnetapi', 'z', 'GL', 'GLEW']) import methods env.Append(BUILDERS = {'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl')}) diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 2c29260281..1edb23d504 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -11,7 +11,9 @@ OS_Haiku::OS_Haiku() { - AudioDriverManagerSW::add_driver(&driver_dummy); +#ifdef MEDIA_KIT_ENABLED + AudioDriverManagerSW::add_driver(&driver_media_kit); +#endif }; void OS_Haiku::run() { diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index a7a8bee522..f88b8182f8 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -11,7 +11,7 @@ #include "servers/audio/sample_manager_sw.h" #include "servers/spatial_sound/spatial_sound_server_sw.h" #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" -#include "servers/audio/audio_driver_dummy.h" +#include "drivers/media_kit/audio_driver_media_kit.h" #include "context_gl_haiku.h" #include "haiku_application.h" @@ -34,7 +34,9 @@ private: SpatialSoundServerSW* spatial_sound_server; SpatialSound2DServerSW* spatial_sound_2d_server; - AudioDriverDummy driver_dummy; // TODO: use a real driver +#ifdef MEDIA_KIT_ENABLED + AudioDriverMediaKit driver_media_kit; +#endif #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) ContextGL_Haiku* context_gl; -- cgit v1.2.3 From f48ce8901ab4fb74dd1a2de15b75895d0cb08fd8 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Wed, 12 Aug 2015 21:40:45 +0300 Subject: Haiku: remove unneeded code --- platform/haiku/haiku_direct_window.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index e7577602ca..2097ace497 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -94,13 +94,9 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { case B_WINDOW_RESIZED: HandleWindowResized(message); - //view->UnlockGL(); - //BDirectWindow::DispatchMessage(message, handler); - //view->LockGL(); break; case LOCKGL_MSG: - ERR_PRINT("LOCKGL"); view->LockGL(); break; -- cgit v1.2.3 From ced44b45d3590e6c2149fd83792dbf702321aff5 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Wed, 12 Aug 2015 22:14:40 +0300 Subject: Haiku: remove unneeded code --- platform/haiku/detect.py | 2 +- platform/haiku/haiku_application.cpp | 2 +- platform/haiku/haiku_application.h | 2 -- platform/haiku/haiku_direct_window.cpp | 7 ------- platform/haiku/haiku_gl_view.cpp | 15 +-------------- platform/haiku/haiku_gl_view.h | 2 -- 6 files changed, 3 insertions(+), 27 deletions(-) diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index f4198e50cd..19fe2f79fb 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -27,7 +27,7 @@ def get_flags(): ] def configure(env): - is64=sys.maxsize > 2**32 + is64 = sys.maxsize > 2**32 if (env["bits"]=="default"): if (is64): diff --git a/platform/haiku/haiku_application.cpp b/platform/haiku/haiku_application.cpp index 56024f605d..ea20d73729 100644 --- a/platform/haiku/haiku_application.cpp +++ b/platform/haiku/haiku_application.cpp @@ -1,7 +1,7 @@ #include "haiku_application.h" HaikuApplication::HaikuApplication() - : BApplication("application/x-vnd.Haiku-GLDirectMode") + : BApplication("application/x-vnd.Godot") { } diff --git a/platform/haiku/haiku_application.h b/platform/haiku/haiku_application.h index 995a917d62..a64b01c94d 100644 --- a/platform/haiku/haiku_application.h +++ b/platform/haiku/haiku_application.h @@ -8,8 +8,6 @@ class HaikuApplication : public BApplication { public: HaikuApplication(); -//private: -// HaikuDirectWindow* window; }; #endif diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index 2097ace497..3914ee272a 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -55,8 +55,6 @@ void HaikuDirectWindow::DirectConnected(direct_buffer_info* info) { void HaikuDirectWindow::MessageReceived(BMessage* message) { switch (message->what) { case REDRAW_MSG: - Sync(); - if (Main::iteration() == true) { view->EnableDirectMode(false); Quit(); @@ -110,8 +108,6 @@ void HaikuDirectWindow::DispatchMessage(BMessage* message, BHandler* handler) { } void HaikuDirectWindow::HandleMouseButton(BMessage* message) { - message->PrintToStream(); - BPoint where; if (message->FindPoint("where", &where) != B_OK) { return; @@ -236,7 +232,6 @@ void HaikuDirectWindow::HandleMouseWheelChanged(BMessage* message) { } void HaikuDirectWindow::HandleKeyboardEvent(BMessage* message) { - message->PrintToStream(); int32 raw_char = 0; int32 key = 0; int32 modifiers = 0; @@ -278,8 +273,6 @@ void HaikuDirectWindow::HandleKeyboardEvent(BMessage* message) { } void HaikuDirectWindow::HandleKeyboardModifierEvent(BMessage* message) { - message->PrintToStream(); - int32 old_modifiers = 0; int32 modifiers = 0; diff --git a/platform/haiku/haiku_gl_view.cpp b/platform/haiku/haiku_gl_view.cpp index 8adab96a87..481d6098a7 100644 --- a/platform/haiku/haiku_gl_view.cpp +++ b/platform/haiku/haiku_gl_view.cpp @@ -2,7 +2,7 @@ #include "haiku_gl_view.h" HaikuGLView::HaikuGLView(BRect frame, uint32 type) - : BGLView(frame, "SampleGLView", B_FOLLOW_ALL_SIDES, 0, type) + : BGLView(frame, "GodotGLView", B_FOLLOW_ALL_SIDES, 0, type) { } @@ -16,16 +16,3 @@ void HaikuGLView::AttachedToWindow(void) { void HaikuGLView::Draw(BRect updateRect) { Main::force_redraw(); } - -void HaikuGLView::MessageReceived(BMessage* msg) -{ - // TODO: remove if not needed - switch (msg->what) { - default: - BGLView::MessageReceived(msg); - } -} - -void HaikuGLView::MouseMoved (BPoint where, uint32 code, const BMessage *dragMessage) { - ERR_PRINT("MouseMoved()"); -} diff --git a/platform/haiku/haiku_gl_view.h b/platform/haiku/haiku_gl_view.h index 78ebb513a8..f44b6d4325 100644 --- a/platform/haiku/haiku_gl_view.h +++ b/platform/haiku/haiku_gl_view.h @@ -9,8 +9,6 @@ class HaikuGLView : public BGLView public: HaikuGLView(BRect frame, uint32 type); virtual void AttachedToWindow(void); - virtual void MessageReceived(BMessage* msg); - virtual void MouseMoved (BPoint where, uint32 code, const BMessage *dragMessage); virtual void Draw(BRect updateRect); }; -- cgit v1.2.3 From b038a2c3c21b7be4cc1db0aca6c84ddaf57132cf Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Thu, 13 Aug 2015 22:36:43 +0300 Subject: Haiku: update logo.png --- platform/haiku/logo.png | Bin 2055 -> 1361 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/platform/haiku/logo.png b/platform/haiku/logo.png index c40214d6de..42d7728da8 100644 Binary files a/platform/haiku/logo.png and b/platform/haiku/logo.png differ -- cgit v1.2.3 From 2a757a6ad4ef4e7767b7d3ef7e177ec6613ef6d1 Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Fri, 14 Aug 2015 22:52:28 +0300 Subject: Haiku: move the audio driver to platform/haiku --- drivers/SCsub | 1 - drivers/media_kit/SCsub | 5 - drivers/media_kit/audio_driver_media_kit.cpp | 143 --------------------------- drivers/media_kit/audio_driver_media_kit.h | 72 -------------- platform/haiku/SCsub | 3 +- platform/haiku/audio_driver_media_kit.cpp | 143 +++++++++++++++++++++++++++ platform/haiku/audio_driver_media_kit.h | 72 ++++++++++++++ platform/haiku/os_haiku.h | 2 +- 8 files changed, 218 insertions(+), 223 deletions(-) delete mode 100644 drivers/media_kit/SCsub delete mode 100644 drivers/media_kit/audio_driver_media_kit.cpp delete mode 100644 drivers/media_kit/audio_driver_media_kit.h create mode 100644 platform/haiku/audio_driver_media_kit.cpp create mode 100644 platform/haiku/audio_driver_media_kit.h diff --git a/drivers/SCsub b/drivers/SCsub index bed1f22a64..3028139f50 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -12,7 +12,6 @@ SConscript('windows/SCsub'); SConscript('gles2/SCsub'); SConscript('gl_context/SCsub'); SConscript('openssl/SCsub'); -SConscript('media_kit/SCsub'); if (env["png"]=="yes"): SConscript("png/SCsub"); diff --git a/drivers/media_kit/SCsub b/drivers/media_kit/SCsub deleted file mode 100644 index 9fbb467baa..0000000000 --- a/drivers/media_kit/SCsub +++ /dev/null @@ -1,5 +0,0 @@ -Import('env') - -env.add_source_files(env.drivers_sources,"*.cpp") - -Export('env') diff --git a/drivers/media_kit/audio_driver_media_kit.cpp b/drivers/media_kit/audio_driver_media_kit.cpp deleted file mode 100644 index 3fabe4f96f..0000000000 --- a/drivers/media_kit/audio_driver_media_kit.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/*************************************************************************/ -/* audio_driver_media_kit.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "audio_driver_media_kit.h" - -#ifdef MEDIA_KIT_ENABLED - -#include "globals.h" - -int32_t* AudioDriverMediaKit::samples_in = NULL; - -Error AudioDriverMediaKit::init() { - active = false; - - mix_rate = 44100; - output_format = OUTPUT_STEREO; - channels = 2; - - int latency = GLOBAL_DEF("audio/output_latency", 25); - buffer_size = nearest_power_of_2(latency * mix_rate / 1000); - samples_in = memnew_arr(int32_t, buffer_size * channels); - - media_raw_audio_format format; - format = media_raw_audio_format::wildcard; - format.frame_rate = mix_rate; - format.channel_count = channels; - format.format = media_raw_audio_format::B_AUDIO_INT; - format.byte_order = B_MEDIA_LITTLE_ENDIAN; - format.buffer_size = buffer_size * sizeof(int32_t) * channels; - - player = new BSoundPlayer( - &format, - "godot_sound_server", - AudioDriverMediaKit::PlayBuffer, - NULL, - this - ); - - if (player->InitCheck() != B_OK) { - fprintf(stderr, "MediaKit ERR: can not create a BSoundPlayer instance\n"); - ERR_FAIL_COND_V(player == NULL, ERR_CANT_OPEN); - } - - mutex = Mutex::create(); - player->Start(); - - return OK; -} - -void AudioDriverMediaKit::PlayBuffer(void* cookie, void* buffer, size_t size, const media_raw_audio_format& format) { - AudioDriverMediaKit* ad = (AudioDriverMediaKit*) cookie; - int32_t* buf = (int32_t*) buffer; - - if (!ad->active) { - for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { - AudioDriverMediaKit::samples_in[i] = 0; - } - } else { - ad->lock(); - ad->audio_server_process(ad->buffer_size, AudioDriverMediaKit::samples_in); - ad->unlock(); - } - - for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { - buf[i] = AudioDriverMediaKit::samples_in[i]; - } -} - -void AudioDriverMediaKit::start() { - active = true; -} - -int AudioDriverMediaKit::get_mix_rate() const { - return mix_rate; -} - -AudioDriverSW::OutputFormat AudioDriverMediaKit::get_output_format() const { - return output_format; -} - -void AudioDriverMediaKit::lock() { - if (!mutex) - return; - - mutex->lock(); -} - -void AudioDriverMediaKit::unlock() { - if (!mutex) - return; - - mutex->unlock(); -} - -void AudioDriverMediaKit::finish() { - if (player) - delete player; - - if (samples_in) { - memdelete_arr(samples_in); - }; - - if (mutex) { - memdelete(mutex); - mutex = NULL; - } -} - -AudioDriverMediaKit::AudioDriverMediaKit() { - mutex = NULL; - player = NULL; -} - -AudioDriverMediaKit::~AudioDriverMediaKit() { - -} - -#endif diff --git a/drivers/media_kit/audio_driver_media_kit.h b/drivers/media_kit/audio_driver_media_kit.h deleted file mode 100644 index a23ec447f1..0000000000 --- a/drivers/media_kit/audio_driver_media_kit.h +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************/ -/* audio_driver_media_kit.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "servers/audio/audio_server_sw.h" - -#ifdef MEDIA_KIT_ENABLED - -#include "core/os/thread.h" -#include "core/os/mutex.h" - -#include // needed for image_id -#include - -class AudioDriverMediaKit : public AudioDriverSW { - Mutex* mutex; - - BSoundPlayer* player; - static int32_t* samples_in; - - static void PlayBuffer(void* cookie, void* buffer, size_t size, const media_raw_audio_format& format); - - unsigned int mix_rate; - OutputFormat output_format; - unsigned int buffer_size; - int channels; - - bool active; - -public: - - const char* get_name() const { - return "MediaKit"; - }; - - virtual Error init(); - virtual void start(); - virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; - virtual void lock(); - virtual void unlock(); - virtual void finish(); - - AudioDriverMediaKit(); - ~AudioDriverMediaKit(); -}; - -#endif diff --git a/platform/haiku/SCsub b/platform/haiku/SCsub index 88c9b8b464..859095fa5a 100644 --- a/platform/haiku/SCsub +++ b/platform/haiku/SCsub @@ -6,7 +6,8 @@ common_haiku = [ 'haiku_application.cpp', 'haiku_direct_window.cpp', 'haiku_gl_view.cpp', - 'key_mapping_haiku.cpp' + 'key_mapping_haiku.cpp', + 'audio_driver_media_kit.cpp' ] env.Program( diff --git a/platform/haiku/audio_driver_media_kit.cpp b/platform/haiku/audio_driver_media_kit.cpp new file mode 100644 index 0000000000..3fabe4f96f --- /dev/null +++ b/platform/haiku/audio_driver_media_kit.cpp @@ -0,0 +1,143 @@ +/*************************************************************************/ +/* audio_driver_media_kit.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "audio_driver_media_kit.h" + +#ifdef MEDIA_KIT_ENABLED + +#include "globals.h" + +int32_t* AudioDriverMediaKit::samples_in = NULL; + +Error AudioDriverMediaKit::init() { + active = false; + + mix_rate = 44100; + output_format = OUTPUT_STEREO; + channels = 2; + + int latency = GLOBAL_DEF("audio/output_latency", 25); + buffer_size = nearest_power_of_2(latency * mix_rate / 1000); + samples_in = memnew_arr(int32_t, buffer_size * channels); + + media_raw_audio_format format; + format = media_raw_audio_format::wildcard; + format.frame_rate = mix_rate; + format.channel_count = channels; + format.format = media_raw_audio_format::B_AUDIO_INT; + format.byte_order = B_MEDIA_LITTLE_ENDIAN; + format.buffer_size = buffer_size * sizeof(int32_t) * channels; + + player = new BSoundPlayer( + &format, + "godot_sound_server", + AudioDriverMediaKit::PlayBuffer, + NULL, + this + ); + + if (player->InitCheck() != B_OK) { + fprintf(stderr, "MediaKit ERR: can not create a BSoundPlayer instance\n"); + ERR_FAIL_COND_V(player == NULL, ERR_CANT_OPEN); + } + + mutex = Mutex::create(); + player->Start(); + + return OK; +} + +void AudioDriverMediaKit::PlayBuffer(void* cookie, void* buffer, size_t size, const media_raw_audio_format& format) { + AudioDriverMediaKit* ad = (AudioDriverMediaKit*) cookie; + int32_t* buf = (int32_t*) buffer; + + if (!ad->active) { + for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { + AudioDriverMediaKit::samples_in[i] = 0; + } + } else { + ad->lock(); + ad->audio_server_process(ad->buffer_size, AudioDriverMediaKit::samples_in); + ad->unlock(); + } + + for (unsigned int i = 0; i < ad->buffer_size * ad->channels; i++) { + buf[i] = AudioDriverMediaKit::samples_in[i]; + } +} + +void AudioDriverMediaKit::start() { + active = true; +} + +int AudioDriverMediaKit::get_mix_rate() const { + return mix_rate; +} + +AudioDriverSW::OutputFormat AudioDriverMediaKit::get_output_format() const { + return output_format; +} + +void AudioDriverMediaKit::lock() { + if (!mutex) + return; + + mutex->lock(); +} + +void AudioDriverMediaKit::unlock() { + if (!mutex) + return; + + mutex->unlock(); +} + +void AudioDriverMediaKit::finish() { + if (player) + delete player; + + if (samples_in) { + memdelete_arr(samples_in); + }; + + if (mutex) { + memdelete(mutex); + mutex = NULL; + } +} + +AudioDriverMediaKit::AudioDriverMediaKit() { + mutex = NULL; + player = NULL; +} + +AudioDriverMediaKit::~AudioDriverMediaKit() { + +} + +#endif diff --git a/platform/haiku/audio_driver_media_kit.h b/platform/haiku/audio_driver_media_kit.h new file mode 100644 index 0000000000..a23ec447f1 --- /dev/null +++ b/platform/haiku/audio_driver_media_kit.h @@ -0,0 +1,72 @@ +/*************************************************************************/ +/* audio_driver_media_kit.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "servers/audio/audio_server_sw.h" + +#ifdef MEDIA_KIT_ENABLED + +#include "core/os/thread.h" +#include "core/os/mutex.h" + +#include // needed for image_id +#include + +class AudioDriverMediaKit : public AudioDriverSW { + Mutex* mutex; + + BSoundPlayer* player; + static int32_t* samples_in; + + static void PlayBuffer(void* cookie, void* buffer, size_t size, const media_raw_audio_format& format); + + unsigned int mix_rate; + OutputFormat output_format; + unsigned int buffer_size; + int channels; + + bool active; + +public: + + const char* get_name() const { + return "MediaKit"; + }; + + virtual Error init(); + virtual void start(); + virtual int get_mix_rate() const; + virtual OutputFormat get_output_format() const; + virtual void lock(); + virtual void unlock(); + virtual void finish(); + + AudioDriverMediaKit(); + ~AudioDriverMediaKit(); +}; + +#endif diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index f88b8182f8..57b72df3cf 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -11,8 +11,8 @@ #include "servers/audio/sample_manager_sw.h" #include "servers/spatial_sound/spatial_sound_server_sw.h" #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" -#include "drivers/media_kit/audio_driver_media_kit.h" +#include "audio_driver_media_kit.h" #include "context_gl_haiku.h" #include "haiku_application.h" #include "haiku_direct_window.h" -- cgit v1.2.3 From c925fbce2da5925009d5f78183e017f9252af35f Mon Sep 17 00:00:00 2001 From: Kostadin Damyanov Date: Sat, 17 Oct 2015 15:41:01 +0300 Subject: Haiku: fix build --- platform/haiku/detect.py | 19 +++++++++---------- platform/haiku/haiku_direct_window.h | 5 +++-- platform/haiku/os_haiku.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/platform/haiku/detect.py b/platform/haiku/detect.py index 19fe2f79fb..b5fd550442 100644 --- a/platform/haiku/detect.py +++ b/platform/haiku/detect.py @@ -10,10 +10,10 @@ def get_name(): def can_build(): if (os.name != "posix"): return False - + if (sys.platform == "darwin"): return False - + return True def get_opts(): @@ -34,13 +34,12 @@ def configure(env): env["bits"]="64" else: env["bits"]="32" - + env.Append(CPPPATH = ['#platform/haiku']) - - # TODO: add clang and try gcc2 too - env["CC"] = "gcc-x86" - env["CXX"] = "g++-x86" - + + env["CC"] = "gcc" + env["CXX"] = "g++" + if (env["target"]=="release"): if (env["debug_release"]=="yes"): env.Append(CCFLAGS=['-g2']) @@ -50,12 +49,12 @@ def configure(env): env.Append(CCFLAGS=['-O2','-ffast-math','-DDEBUG_ENABLED']) elif (env["target"]=="debug"): env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) - + #env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) env.Append(CPPFLAGS = ['-DGLEW_ENABLED', '-DOPENGL_ENABLED', '-DMEDIA_KIT_ENABLED']) env.Append(CPPFLAGS = ['-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DGLES_OVER_GL']) env.Append(LIBS = ['be', 'game', 'media', 'network', 'bnetapi', 'z', 'GL', 'GLEW']) - + import methods env.Append(BUILDERS = {'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl')}) env.Append(BUILDERS = {'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl')}) diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index 7b1fd851fa..f0398df505 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -4,15 +4,16 @@ #include // needed for image_id #include -#include "os/input.h" #include "core/os/os.h" +#include "main/input_default.h" + #include "haiku_gl_view.h" #define REDRAW_MSG 'rdrw' #define LOCKGL_MSG 'glck' #define UNLOCKGL_MSG 'ulck' -class HaikuDirectWindow : public BDirectWindow +class HaikuDirectWindow : public BDirectWindow { private: unsigned int event_id; diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 57b72df3cf..e1b0b86cf4 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -1,7 +1,6 @@ #ifndef OS_HAIKU_H #define OS_HAIKU_H -#include "os/input.h" #include "drivers/unix/os_unix.h" #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" @@ -11,6 +10,7 @@ #include "servers/audio/sample_manager_sw.h" #include "servers/spatial_sound/spatial_sound_server_sw.h" #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "main/input_default.h" #include "audio_driver_media_kit.h" #include "context_gl_haiku.h" @@ -46,7 +46,7 @@ private: protected: virtual int get_video_driver_count() const; - virtual const char* get_video_driver_name(int p_driver) const; + virtual const char* get_video_driver_name(int p_driver) const; virtual VideoMode get_default_video_mode() const; virtual void initialize(const VideoMode& p_desired, int p_video_driver, int p_audio_driver); -- cgit v1.2.3