Skip to content

Commit b91b2bf

Browse files
committed
Trying to get multi-threading working with wasm.
This is the first trial to get threads working after the issue with wasm-ld was solved: emscripten-core/emscripten#15891
1 parent 63f1dd1 commit b91b2bf

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

.cargo/config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ rustflags = [
77

88
[target.wasm32-unknown-emscripten]
99
rustflags = [
10-
"-C", "link-args=src/gxx_personality_v0_stub.o -sUSE_SDL=2 -sUSE_SDL_TTF=2 -s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1, --embed-file assets",
11-
#"-C", "link-args=src/gxx_personality_v0_stub.o -pthread -s PROXY_TO_PTHREAD -sUSE_SDL=2 -sUSE_SDL_TTF=2 -s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1, --embed-file assets -Wl,--shared-memory",
10+
"-C", "target-feature=+atomics,+bulk-memory",
11+
"-C", "link-args=src/gxx_personality_v0_stub.o -pthread -sUSE_SDL=2 -sUSE_SDL_TTF=2 -s PROXY_TO_PTHREAD -s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=8 -s OFFSCREEN_FRAMEBUFFER=1, --embed-file assets",
12+
#"-C", "link-args=src/gxx_personality_v0_stub.o -pthread -sUSE_SDL=2 -sUSE_SDL_TTF=2 -s PROXY_TO_PTHREAD -s ASYNCIFY -s ALLOW_MEMORY_GROWTH=1, --embed-file assets",
1213
]

index-wasm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
</script>
249249
<script
250250
type="text/javascript"
251-
src="target/wasm32-unknown-emscripten/release/orbits.js"
251+
src="target/wasm32-unknown-emscripten/release/deps/orbits.js"
252252
></script>
253253
</body>
254254
</html>

src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use std::convert::TryInto;
33
use std::time::{Instant};
44
use num::Complex;
55

6-
#[cfg(not(target_os = "emscripten"))]
6+
//#[cfg(not(target_os = "emscripten"))]
77
use rayon::prelude::*;
88

99
use sdl2;
1010
use sdl2::event::Event;
1111
use sdl2::event::WindowEvent;
1212
use sdl2::keyboard::Keycode;
1313
use sdl2::mouse::MouseButton;
14+
use sdl2::mouse::MouseState;
1415
use sdl2::pixels::{Color, PixelFormatEnum};
1516
use sdl2::rect::Point;
1617
use sdl2::rect::Rect;
@@ -299,7 +300,9 @@ fn main() -> Result<(), String> {
299300
}
300301
},
301302
Event::MouseMotion {x, y, which, .. } if which != SDL_TOUCH_MOUSEID => {
302-
if pump.mouse_state().is_mouse_button_pressed(MouseButton::Left) {
303+
//if pump.mouse_state().is_mouse_button_pressed(MouseButton::Left) {
304+
//if MouseState::new(pump).left() {
305+
if pump.mouse_state().left() {
303306
//panning
304307
//TODO: Problem with emscripten thinking that left mouse button is pressed after return from full screen mode
305308
println!("left pressed...");
@@ -517,10 +520,10 @@ fn update_bg(bg_texture: &mut sdl2::render::Texture, view:&ComplexBBox, iter:u32
517520

518521
//change to .into_par_iter() for parallelism
519522
//emscripten target don't yet support multi-threading
520-
#[cfg(not(target_os = "emscripten"))]
523+
//#[cfg(not(target_os = "emscripten"))]
521524
let row_iter = rows.into_par_iter();
522-
#[cfg(target_os = "emscripten")]
523-
let row_iter = rows.into_iter();
525+
//#[cfg(target_os = "emscripten")]
526+
//let row_iter = rows.into_iter();
524527
row_iter.for_each(|(y, buffer)| {
525528
for x in 0 .. w {
526529
let c = view.screen_to_complex(x.try_into().unwrap(),y.try_into().unwrap(),

0 commit comments

Comments
 (0)