Skip to content

Commit 53c222c

Browse files
committed
emsc
1 parent fac3a34 commit 53c222c

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

build/emscripten/conan.profile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[settings]
2+
os=Emscripten
3+
arch=wasm
4+
compiler=clang
5+
compiler.version=15
6+
compiler.libcxx=libc++
7+
build_type=Release
8+
9+
[tool_requires]
10+
emsdk/[>=3.1.72]

build/emscripten/conanfile.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[requires]
2+
ruis/[>=0.5.278]@cppfw/main
3+
ruis-render-opengles/[>=0.0.0]@cppfw/main

config/emsc.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ this_static_lib_only := true
1212
# Suppress version-check warning due to https://github.com/conan-io/conan-center-index/pull/26247
1313
this_cxxflags += -Wno-version-check
1414

15+
this_cxxflags += -D RUISAPP_RENDER_OPENGLES
16+
1517
this_cxxflags += -fwasm-exceptions
1618
this_cxxflags += -sSUPPORT_LONGJMP=wasm
1719
this_ldflags += -fwasm-exceptions
1820
this_ldflags += -sSUPPORT_LONGJMP=wasm
21+
this_ldflags += -sALLOW_MEMORY_GROWTH
22+
this_ldflags += -sMEMORY_GROWTH_GEOMETRIC_STEP=1.0
1923

2024
this_cxxflags += -pthread
2125
this_ldflags += -pthread

src/ruisapp/glue/sdl/glue.cxx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2626

2727
#include "../../application.hpp"
2828

29+
#if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
30+
# include <emscripten.h>
31+
#endif
32+
2933
#if CFG_COMPILER == CFG_COMPILER_MSVC
3034
# include <SDL.h>
3135
#else
@@ -632,10 +636,12 @@ void main_loop_iteration(void* user_data)
632636
// clamp to_wait_ms to max of int as SDL_WaitEventTimeout() accepts int type
633637
to_wait_ms = std::min(to_wait_ms, uint32_t(std::numeric_limits<int32_t>::max()));
634638

639+
#if CFG_OS_NAME != CFG_OS_NAME_EMSCRIPTEN
635640
if (SDL_WaitEventTimeout(nullptr, int(to_wait_ms)) == 0) {
636641
// No events or error. In case of error not much we can do, just ignore it.
637642
return;
638643
}
644+
#endif
639645

640646
ruis::vector2 new_win_dims(-1, -1);
641647

@@ -750,6 +756,13 @@ void main_loop_iteration(void* user_data)
750756
if (new_win_dims.is_positive_or_zero()) {
751757
update_window_rect(*app, ruis::rect(0, new_win_dims));
752758
}
759+
760+
#if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
761+
if(ww.quit_flag.load()){
762+
std::unique_ptr<ruisapp::application> p(app);
763+
emscripten_cancel_main_loop();
764+
}
765+
#endif
753766
}
754767
} // namespace
755768

@@ -765,10 +778,11 @@ int main(int argc, const char** argv)
765778
#if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
766779
emscripten_set_main_loop_arg(
767780
&main_loop_iteration,
768-
app.get(),
781+
app.release(),
769782
0,
770783
false
771784
);
785+
return 0;
772786
#else
773787
while (!get_impl(*app).quit_flag.load()) {
774788
main_loop_iteration(app.get());

0 commit comments

Comments
 (0)