From 870533037ab71559e4db59f5f9e23d0707a3a178 Mon Sep 17 00:00:00 2001 From: pmp-p Date: Fri, 21 Oct 2022 13:14:26 +0200 Subject: [PATCH 1/2] emsdk 3.1.25 / emscripten-sdl2 target --- harfang/engine/audio.cpp | 8 +++++--- harfang/platform/posix/thread.cpp | 4 ++++ harfang/platform/sdl/platform_sdl.cpp | 20 ++++++++++++++++---- harfang/platform/sdl/window_system.cpp | 16 ++++++++++++++-- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/harfang/engine/audio.cpp b/harfang/engine/audio.cpp index a755887..3e8508b 100644 --- a/harfang/engine/audio.cpp +++ b/harfang/engine/audio.cpp @@ -10,9 +10,12 @@ #include "engine/ogg_audio_stream.h" #include "engine/wav_audio_stream.h" -#ifndef EMSCRIPTEN #include -#include +#if !defined(__EMSCRIPTEN__) + #include +#else + #include +#endif #include @@ -625,4 +628,3 @@ void StopAllSources() { } } // namespace hg -#endif \ No newline at end of file diff --git a/harfang/platform/posix/thread.cpp b/harfang/platform/posix/thread.cpp index 9dc82ef..527651f 100644 --- a/harfang/platform/posix/thread.cpp +++ b/harfang/platform/posix/thread.cpp @@ -12,6 +12,9 @@ void set_thread_name(const std::string &name) {} std::string get_thread_name(std::thread::id id) { return "Unsupported"; } bool set_thread_priority(std::thread::native_handle_type handle, unsigned int priority) { +#if defined(__EMSCRIPTEN__) + return true; +#else if (!handle) return false; @@ -20,6 +23,7 @@ bool set_thread_priority(std::thread::native_handle_type handle, unsigned int pr param.sched_priority = priority; return pthread_setschedparam(handle, SCHED_OTHER, ¶m) == 0; +#endif } bool set_thread_affinity(std::thread::native_handle_type handle, unsigned int mask) { return false; } diff --git a/harfang/platform/sdl/platform_sdl.cpp b/harfang/platform/sdl/platform_sdl.cpp index b43fca3..15e2f72 100644 --- a/harfang/platform/sdl/platform_sdl.cpp +++ b/harfang/platform/sdl/platform_sdl.cpp @@ -1,5 +1,5 @@ // HARFANG(R) Copyright (C) 2019 Emmanuel Julien, Movida Production. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. - +#include "../platform.h" #include "foundation/assert.h" #include "foundation/format.h" #include "foundation/log.h" @@ -13,19 +13,31 @@ bool InitPlatform() { return true; } +enum class Action : int { + FileOpen = 0, + FileSave, + SelectFolder, + Count +}; + std::string GetPlatformLocale() { - return "fr"; + return "C"; } +#pragma message "SDL2 dialogs not implemented for WASM" + bool OpenFolderDialog(const std::string &title, std::string &OUTPUT, const std::string &initial_dir) { + puts(__FILE__ ":OpenFolderDialog"); return false; } -bool OpenFileDialog(const std::string &title, const std::string &filter, std::string &OUTPUT, const std::string &initial_dir) { +bool OpenFileDialog(const std::string &title, const std::vector &filters, std::string &output, const std::string &initial_dir) { + puts(__FILE__ ":OpenFileDialog"); return false; } -bool SaveFileDialog(const std::string &title, const std::string &filter, std::string &OUTPUT, const std::string &initial_dir) { +bool SaveFileDialog(const std::string &title, const std::vector &filters, std::string &output, const std::string &initial_dir) { + puts(__FILE__ ":SaveFileDialog"); return false; } diff --git a/harfang/platform/sdl/window_system.cpp b/harfang/platform/sdl/window_system.cpp index 3304c96..5530919 100644 --- a/harfang/platform/sdl/window_system.cpp +++ b/harfang/platform/sdl/window_system.cpp @@ -100,7 +100,13 @@ Window *NewWindowFrom(void *handle) { } // TODO Create a new fullscreen window on a specified monitor. -Window *NewFullscreenWindow(const Monitor *monitor, int mode_index, MonitorRotation rotation) { return NewWindow(512, 512, 32, WV_Windowed); } +Window *NewFullscreenWindow(const Monitor *monitor, int mode_index, MonitorRotation rotation) { + return NewWindow(512, 512, 32, WV_Windowed); +} +Window * NewFullscreenWindow(const char *title, const Monitor *monitor, int mode_index, MonitorRotation rotation) { + return NewWindow(512, 512, 32, WV_Windowed); +} + void *GetDisplay() { return nullptr; } @@ -161,7 +167,7 @@ bool SetWindowTitle(Window *w, const std::string &title) { return true; } bool WindowHasFocus(const Window *w) { return true; } -bool SetWindowPos(const Window *w, const hg::iVec2 &v) { +bool SetWindowPos(Window *w, const hg::iVec2 &v) { SDL_SetWindowPosition(w->w, v.x, v.y); UpdateWindow(w); // process messages on the spot return true; @@ -176,7 +182,13 @@ hg::iVec2 GetWindowPos(const Window *w) { return pos; } +hg::Vec2 GetWindowContentScale(const Window *window) { + puts(__FILE__ "GetWindowContentScale"); + return { 1, 1 }; +} + void ShowCursor() { SDL_ShowCursor(SDL_ENABLE); } void HideCursor() { SDL_ShowCursor(SDL_DISABLE); } +void WindowSystemShutdown() { } } // namespace hg From 570f65517b33f87267789530f07a5d00504a8ba6 Mon Sep 17 00:00:00 2001 From: "Paul m. p. Peny" Date: Fri, 21 Oct 2022 19:05:09 +0200 Subject: [PATCH 2/2] fix canvas selector no more "canvas" only "#canvas" works with recent emsdk --- harfang/platform/sdl/window_system.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harfang/platform/sdl/window_system.cpp b/harfang/platform/sdl/window_system.cpp index 5530919..c233c1b 100644 --- a/harfang/platform/sdl/window_system.cpp +++ b/harfang/platform/sdl/window_system.cpp @@ -110,7 +110,7 @@ Window * NewFullscreenWindow(const char *title, const Monitor *monitor, int mode void *GetDisplay() { return nullptr; } -static const char *canvas_name = "canvas"; +static const char *canvas_name = "#canvas"; void *GetWindowHandle(const Window *w) { return (void *)canvas_name; // return reinterpret_cast(w->w);