transparent-cube

Minimal cross-platform native/wasm graphics example.
git clone git://git.amin.space/transparent-cube.git
Log | Files | Refs | README | LICENSE

commit 5453e87b2da65f115eb7d2222051d116c8c407a3
parent d658ac6284717ce4742174f4431a5059ec5ce876
Author: amin <dev@aminmesbah.com>
Date:   Tue, 25 Jun 2019 05:30:40 +0000

Export functions via linker arguments

FossilOrigin-Name: 8009ff9cc62b63527042fc29829df4fe1657b4a6ce0d18650dcd7ac7e338c8f0
Diffstat:
Mbuild_wasm.sh | 5+++--
Msrc/platform_wasm.c | 12+++---------
Msrc/platform_wasm.h | 4++++
3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/build_wasm.sh b/build_wasm.sh @@ -33,9 +33,10 @@ wasm-ld \ --no-entry $wasm_dir/wasm.o \ -o $wasm_dir/binary.wasm \ -allow-undefined-file src/platform_wasm_js_symbols.txt \ - --export-all \ + --export=init \ + --export=render \ + --export=window_resize \ --import-memory rm $wasm_dir/*.o rm $wasm_dir/*.bc -rm src/*.bc diff --git a/src/platform_wasm.c b/src/platform_wasm.c @@ -2,11 +2,6 @@ #include "platform.h" #include "platform_wasm.h" -#define export __attribute__( ( visibility( "default" ) ) ) - -char *js_read_entire_file(i32 file_path, i32 name_len, char *file_data); -int js_print(i32 string, i32 len); - struct GameState g_game_state = {0}; i32 g_width = PLATFORM_SCR_WIDTH; i32 g_height = PLATFORM_SCR_HEIGHT; @@ -14,8 +9,7 @@ char g_mem_buffer[1000] = {0}; i32 g_mem_buffer_i = 0; u32 time = 0; - -export bool init(void) +bool init(void) { g_game_state.platform.platform_read_entire_file = &wasm_read_entire_file; g_game_state.platform.platform_print = &wasm_print; @@ -24,13 +18,13 @@ export bool init(void) return true; } -export void render(void) +void render(void) { time += 16; game_update_and_render(&g_game_state, time/1000.0f, g_width, g_height); } -export void window_resize(int w, int h) +void window_resize(int w, int h) { g_width = w; g_height = h; diff --git a/src/platform_wasm.h b/src/platform_wasm.h @@ -4,3 +4,7 @@ PLATFORM_READ_ENTIRE_FILE(wasm_read_entire_file); PLATFORM_PRINT(wasm_print); PLATFORM_MEMORY_FREE(wasm_memory_free); + +// Functions implemented in the JS loader +char *js_read_entire_file(i32 file_path, i32 name_len, char *file_data); +int js_print(i32 string, i32 len);