name = "ld45_one_and_all"
version = "0.1.1"
authors = ["Stephen Seo <seo.disparate@gmail.com>"]
-edition = "2018"
+edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
-no_link_libs = []
+no_link_libs = []
+
+[lib]
+name = "ld45_lib"
+crate-type = ["staticlib"]
+required-features = ["no_link_libs"]
+
+[[bin]]
+name = "ld45_bin"
+path = "src/main.rs"
let bindings = bindgen::Builder::default()
.header("raylib/raylib.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
+ .clang_arg("-fvisibility=default")
.generate()
.expect("Unable to generate bindings");
Self::native_setup();
unsafe {
- ffi::InitAudioDevice();
+ while !ffi::IsAudioDeviceReady() {
+ ffi::InitAudioDevice();
+ }
}
let mut self_unboxed = Self {
--- /dev/null
+use agnostic_interface::raylib_impl::RaylibGame;
+use faux_quicksilver::Window;
+use original_impl::GameState;
+
+mod agnostic_interface;
+mod faux_quicksilver;
+mod original_impl;
+mod shaders;
+
+struct WasmState {
+ pub window: Window,
+ pub game_state: GameState,
+}
+
+#[no_mangle]
+pub extern "C" fn ld45_initialize() -> *mut ::std::os::raw::c_void {
+ let game_interface = RaylibGame::new_boxed(800, 600);
+ let mut window = Window::new(game_interface);
+ let game_state = GameState::new(&mut window).unwrap();
+
+ Box::into_raw(Box::new(WasmState { window, game_state })) as *mut ::std::os::raw::c_void
+}
+
+#[no_mangle]
+pub extern "C" fn ld45_iterate(context: *mut ::std::os::raw::c_void) {
+ let state_ptr = context as *mut WasmState;
+ unsafe {
+ (*state_ptr).window.update_music().unwrap();
+ (*state_ptr)
+ .game_state
+ .update(&mut (*state_ptr).window)
+ .unwrap();
+ (*state_ptr)
+ .game_state
+ .draw(&mut (*state_ptr).window)
+ .unwrap();
+ }
+}
--- /dev/null
+/ld45.html
+/ld45.js
+/ld45.data
+/ld45.wasm
+/index.html
--- /dev/null
+CC = source "${HOME}/git/emsdk/emsdk_env.sh" && emcc
+
+all: ld45.html
+
+ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a
+ ${CC} -o ld45.html -s USE_GLFW=3 -Iinclude \
+ -Llib -lraylib \
+ -L../target/wasm32-unknown-emscripten/debug -lld45_lib \
+ -sSAFE_HEAP=1 \
+ -sEXPORTED_RUNTIME_METHODS=ccall,cwrap \
+ --preload-file ../static src/main.c
+ ln -sf ld45.html index.html
+
+../target/wasm32-unknown-emscripten/debug/libld45_lib.a: ../src/lib.rs
+ cd ..; source "${HOME}/git/emsdk/emsdk_env.sh"; cargo build --lib --target wasm32-unknown-emscripten
+
+.PHONY: clean
+
+clean:
+ rm -f ld45.html
+ rm -f ld45.js
+ rm -f ld45.wasm
+ rm -f ld45.data
+ rm -f index.html
--- /dev/null
+#ifndef LD45_ONE_AND_ALL_LIB_H_
+#define LD45_ONE_AND_ALL_LIB_H_
+
+extern void *ld45_initialize();
+
+extern void ld45_iterate(void *context);
+
+#endif
--- /dev/null
+../raylib/raylib.h
\ No newline at end of file
--- /dev/null
+#include <emscripten.h>
+#include <emscripten/html5.h>
+
+#include <ld45_lib.h>
+
+void main_loop(void *ud) {
+ ld45_iterate(ud);
+}
+
+int main(void) {
+ void *ld45_context = ld45_initialize();
+
+ emscripten_set_main_loop_arg(main_loop, ld45_context, 0, 1);
+
+ return 0;
+}