From e507454912f69b202c0a49d772696eabcccaa024 Mon Sep 17 00:00:00 2001 From: realtradam Date: Sat, 4 Mar 2023 19:53:46 -0500 Subject: add emscripten --- CMakeLists.txt | 46 +++++++++++++++++- build | 3 +- configure | 3 +- external/RodeoEngine | 2 +- run | 2 +- serve | 3 ++ src/main.c | 135 +++++++++++++++++++++++++++------------------------ 7 files changed, 124 insertions(+), 70 deletions(-) create mode 100755 serve diff --git a/CMakeLists.txt b/CMakeLists.txt index c885377..5a81e2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,28 @@ cmake_minimum_required(VERSION 3.25.1) -set(CMAKE_BUILD_TYPE Debug) - project(space_squad) +if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") + set(CMAKE_EXECUTABLE_SUFFIX ".html") +endif() + +set(CMAKE_BUILD_TYPE Debug) + file(GLOB SOURCES "src/main.c" ) add_executable(${PROJECT_NAME} ${SOURCES}) +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") +target_compile_options(${PROJECT_NAME} PRIVATE +-Wall +-Wextra +-Wpedantic +#-Werror +) +endif() + find_package(Git QUIET) if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") # Update submodules as needed @@ -27,6 +40,8 @@ endif() add_subdirectory(external/RodeoEngine) +add_dependencies(${PROJECT_NAME} RodeoEngine) + target_include_directories(${PROJECT_NAME} PUBLIC external/RodeoEngine/include ) @@ -34,3 +49,30 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} RodeoEngine ) + +add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD + DEPENDS RodeoEngine + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/external/RodeoEngine/build_dir/shaders $/shaders + ) + +if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") + set_target_properties(space_squad PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_SDL_IMAGE=2 -s ALLOW_MEMORY_GROWTH") + + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \ + -s MAX_WEBGL_VERSION=2 \ + -s WASM=1 \ + -s NO_EXIT_RUNTIME=1 \ + -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 \ + -s OFFSCREENCANVAS_SUPPORT=1 \ + -s ALLOW_MEMORY_GROWTH=1\ + --preload-file shaders") + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -fno-exceptions \ + -fno-rtti \ + -s USE_SDL=2") + #-s USE_SDL_IMAGE=2 \ + +endif () + diff --git a/build b/build index 45cd35b..2e2e93e 100755 --- a/build +++ b/build @@ -1,2 +1,3 @@ #! /bin/sh -cd build_dir ; make +cd build_dir/tux ; make +#cd build_dir/web ; emmake make diff --git a/configure b/configure index 352dcd6..6a85de8 100755 --- a/configure +++ b/configure @@ -1,3 +1,4 @@ #! /bin/sh -cmake -S . -B build_dir +cmake -S . -B build_dir/tux +#emcmake cmake -S . -B build_dir/web diff --git a/external/RodeoEngine b/external/RodeoEngine index b172c2a..4bd628f 160000 --- a/external/RodeoEngine +++ b/external/RodeoEngine @@ -1 +1 @@ -Subproject commit b172c2a6b22796dc16c059979d2ec6108b0402e4 +Subproject commit 4bd628fc4a9a8244c70fc241f9e6576e4af2d35e diff --git a/run b/run index c6fe24f..3d6af5c 100755 --- a/run +++ b/run @@ -1,4 +1,4 @@ #! /bin/sh #gdb ./build_dir/space_squad -./build_dir/space_squad +(cd ./build_dir/tux/ ; ./space_squad) diff --git a/serve b/serve new file mode 100755 index 0000000..267cdfa --- /dev/null +++ b/serve @@ -0,0 +1,3 @@ +#! /bin/sh + +ruby -run -ehttpd ./build_dir/web -p8000 diff --git a/src/main.c b/src/main.c index f578bfd..5d37985 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,3 @@ -#include -#include #include "rodeo.h" @@ -47,75 +45,84 @@ const Rodeo__color_rgba_t pink_clear = 0.5f }; -int -main() +void +main_loop(void) { - Rodeo__init_window(&state, 480, 640, "Rodeo Window"); + Rodeo__begin(state); - while(!Rodeo__should_quit(state)) - { - Rodeo__begin(state); + //printf("%s\n", Rodeo__get_renderer_name_as_string()); - Rodeo__draw_rectangle( - state, - 100, 100, - 50, 50, - red - ); - Rodeo__draw_rectangle( - state, - 100, 160, - 50, 50, - green - ); - Rodeo__draw_rectangle( - state, - 160, 100, - 50, 50, - blue - ); - Rodeo__draw_rectangle( - state, - 160, 160, - 50, 50, - pink - ); + Rodeo__draw_rectangle( + state, + 100, 100, + 50, 50, + red + ); + Rodeo__draw_rectangle( + state, + 100, 160, + 50, 50, + green + ); + Rodeo__draw_rectangle( + state, + 160, 100, + 50, 50, + blue + ); + Rodeo__draw_rectangle( + state, + 160, 160, + 50, 50, + pink + ); - Rodeo__draw_rectangle( - state, - 300, 300, - 50, 50, - red_clear - ); - Rodeo__draw_rectangle( - state, - 310, 310, - 50, 50, - green_clear - ); - Rodeo__draw_rectangle( - state, - 320, 320, - 50, 50, - blue_clear - ); - Rodeo__draw_rectangle( - state, - 330, 330, - 50, 50, - pink_clear - ); + Rodeo__draw_rectangle( + state, + 300, 300, + 50, 50, + red_clear + ); + Rodeo__draw_rectangle( + state, + 310, 310, + 50, 50, + green_clear + ); + Rodeo__draw_rectangle( + state, + 320, 320, + 50, 50, + blue_clear + ); + Rodeo__draw_rectangle( + state, + 330, 330, + 50, 50, + pink_clear + ); + Rodeo__draw_debug_text( + 1, + 1, + " using %s renderer ", + Rodeo__get_renderer_name_as_string() + ); + + Rodeo__end(state); +} - Rodeo__draw_debug_text( - 1, - 1, - " using %s renderer ", - Rodeo__get_renderer_name_as_string() - ); +int +main() +{ + printf("Init window...\n"); + Rodeo__init_window(&state, 480, 640, "Rodeo Window"); + printf("done creating window\n"); - Rodeo__end(state); - } + Rodeo__execute_main_loop( + state, + main_loop + ); Rodeo__deinit_window(state); Rodeo__quit(); -- cgit v1.2.3