Fix wasm build
This commit is contained in:
parent
b6ee1be6c2
commit
e00e23682c
4 changed files with 25 additions and 26 deletions
|
@ -973,8 +973,7 @@ impl GameInterface for RaylibGame {
|
||||||
let path_str = path
|
let path_str = path
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or_else(|| format!("Failed to convert \"{path:?}\" to str!"))?;
|
.ok_or_else(|| format!("Failed to convert \"{path:?}\" to str!"))?;
|
||||||
let path_buf: Vec<u8> = path_str.as_bytes().into();
|
let cstring: CString = CString::from_vec_unchecked(path_str.as_bytes().into());
|
||||||
let cstring: CString = CString::from_vec_unchecked(path_buf);
|
|
||||||
let sound = ffi::LoadSound(cstring.as_ptr());
|
let sound = ffi::LoadSound(cstring.as_ptr());
|
||||||
let raylib_sound_handler = RaylibSoundHandler {
|
let raylib_sound_handler = RaylibSoundHandler {
|
||||||
sound: Rc::new(RaylibSound { sound }),
|
sound: Rc::new(RaylibSound { sound }),
|
||||||
|
|
|
@ -8,8 +8,8 @@ use faux_quicksilver::Window;
|
||||||
use original_impl::GameState;
|
use original_impl::GameState;
|
||||||
|
|
||||||
pub struct WasmState {
|
pub struct WasmState {
|
||||||
pub window: Window,
|
pub window: Box<Window>,
|
||||||
pub game_state: GameState,
|
pub game_state: Box<GameState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WasmState {
|
impl WasmState {
|
||||||
|
@ -25,8 +25,8 @@ impl WasmState {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn ld45_initialize() -> *mut ::std::os::raw::c_void {
|
pub extern "C" fn ld45_initialize() -> *mut ::std::os::raw::c_void {
|
||||||
let game_interface = RaylibGame::new_boxed(800, 600);
|
let game_interface = RaylibGame::new_boxed(800, 600);
|
||||||
let mut window = Window::new(game_interface);
|
let mut window = Box::new(Window::new(game_interface));
|
||||||
let game_state = GameState::new(&mut window).unwrap();
|
let game_state = Box::new(GameState::new(&mut window).unwrap());
|
||||||
|
|
||||||
Box::into_raw(Box::new(WasmState { window, game_state })) as *mut ::std::os::raw::c_void
|
Box::into_raw(Box::new(WasmState { window, game_state })) as *mut ::std::os::raw::c_void
|
||||||
}
|
}
|
||||||
|
|
|
@ -1238,11 +1238,11 @@ impl GameState {
|
||||||
s_get.clone(),
|
s_get.clone(),
|
||||||
)?;
|
)?;
|
||||||
let s_power_up = String::from("power_up.mp3");
|
let s_power_up = String::from("power_up.mp3");
|
||||||
window.load_sound(
|
//window.load_sound(
|
||||||
&PathBuf::from_str("static/power_up.mp3")
|
// &PathBuf::from_str("static/power_up.mp3")
|
||||||
.map_err(|_| String::from("Failed to load \"static/power_up.mp3\""))?,
|
// .map_err(|_| String::from("Failed to load \"static/power_up.mp3\""))?,
|
||||||
s_power_up.clone(),
|
// s_power_up.clone(),
|
||||||
)?;
|
//)?;
|
||||||
let s_tap = String::from("tap.mp3");
|
let s_tap = String::from("tap.mp3");
|
||||||
window.load_sound(
|
window.load_sound(
|
||||||
&PathBuf::from_str("static/tap.mp3")
|
&PathBuf::from_str("static/tap.mp3")
|
||||||
|
@ -1250,17 +1250,17 @@ impl GameState {
|
||||||
s_tap.clone(),
|
s_tap.clone(),
|
||||||
)?;
|
)?;
|
||||||
let s_speak_m = String::from("speak_m.mp3");
|
let s_speak_m = String::from("speak_m.mp3");
|
||||||
window.load_sound(
|
//window.load_sound(
|
||||||
&PathBuf::from_str("static/speak_m.mp3")
|
// &PathBuf::from_str("static/speak_m.mp3")
|
||||||
.map_err(|_| String::from("Failed to load \"static/speak_m.mp3\""))?,
|
// .map_err(|_| String::from("Failed to load \"static/speak_m.mp3\""))?,
|
||||||
s_speak_m.clone(),
|
// s_speak_m.clone(),
|
||||||
)?;
|
//)?;
|
||||||
let s_speak_f = String::from("speak_f.mp3");
|
let s_speak_f = String::from("speak_f.mp3");
|
||||||
window.load_sound(
|
//window.load_sound(
|
||||||
&PathBuf::from_str("static/speak_f.mp3")
|
// &PathBuf::from_str("static/speak_f.mp3")
|
||||||
.map_err(|_| String::from("Failed to load \"static/speak_f.mp3\""))?,
|
// .map_err(|_| String::from("Failed to load \"static/speak_f.mp3\""))?,
|
||||||
s_speak_f.clone(),
|
// s_speak_f.clone(),
|
||||||
)?;
|
//)?;
|
||||||
|
|
||||||
let font = String::from("ClearSans-Regular.ttf");
|
let font = String::from("ClearSans-Regular.ttf");
|
||||||
window.load_font(
|
window.load_font(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
CC = source "${HOME}/git/emsdk/emsdk_env.sh" && emcc
|
EM_ENV = "${HOME}/git/emsdk/emsdk_env.sh"
|
||||||
|
CC = source ${EM_ENV} && emcc
|
||||||
|
|
||||||
all: ld45.html
|
all: ld45.html
|
||||||
|
|
||||||
|
@ -6,10 +7,8 @@ ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a
|
||||||
${CC} -o ld45.html -s USE_GLFW=3 -Iinclude \
|
${CC} -o ld45.html -s USE_GLFW=3 -Iinclude \
|
||||||
-Llib -lraylib \
|
-Llib -lraylib \
|
||||||
-L../target/wasm32-unknown-emscripten/release -lld45_lib \
|
-L../target/wasm32-unknown-emscripten/release -lld45_lib \
|
||||||
-sTOTAL_MEMORY=1024MB \
|
-sALLOW_MEMORY_GROWTH \
|
||||||
-sALLOW_MEMORY_GROWTH=1 \
|
|
||||||
-O2 \
|
-O2 \
|
||||||
-fsanitize=address \
|
|
||||||
-sEXPORTED_FUNCTIONS="['_malloc', '_main']" \
|
-sEXPORTED_FUNCTIONS="['_malloc', '_main']" \
|
||||||
-sEXPORTED_RUNTIME_METHODS=ccall,cwrap \
|
-sEXPORTED_RUNTIME_METHODS=ccall,cwrap \
|
||||||
--preload-file ../static src/main.c
|
--preload-file ../static src/main.c
|
||||||
|
@ -19,7 +18,8 @@ ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a
|
||||||
#-sWARN_UNALIGNED=1 \
|
#-sWARN_UNALIGNED=1 \
|
||||||
|
|
||||||
../target/wasm32-unknown-emscripten/release/libld45_lib.a: ../src/lib.rs
|
../target/wasm32-unknown-emscripten/release/libld45_lib.a: ../src/lib.rs
|
||||||
cd ..; source "${HOME}/git/emsdk/emsdk_env.sh"; cargo build --lib --release --target wasm32-unknown-emscripten
|
cd .. && source ${EM_ENV} && cargo build --lib --release --target wasm32-unknown-emscripten
|
||||||
|
# cd .. && source ${EM_ENV} && cargo rustc --lib --release --target wasm32-unknown-emscripten -- -C link-args=-Wl,-zstack-size=8388608
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue