From 08450f4bc90c77738f0fa35848d35e23ca8c5d63 Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Tue, 19 Mar 2024 12:11:21 -0600 Subject: Got working on the web --- CMakeLists.txt | 10 ++++++++++ src/gameCommon.h | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b206b49..790ad24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,11 +8,21 @@ set(C_STANDARD 99) set(C_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +if (EMSCRIPTEN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s GL_ENABLE_GET_PROC_ADDRESS=1 -s ALLOW_MEMORY_GROWTH=1 -s STACK_SIZE=16777216") + set(CMAKE_EXECUTABLE_SUFFIX ".html") # This line is used to set your executable to build with the emscripten html template so taht you can directly open it. +endif () + # Add source files. file(GLOB SRC_FILES src/*.c) add_executable(${PROJECT_NAME} ${SRC_FILES}) +# Link the assets +if (${PLATFORM} MATCHES "Web") + set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "--preload-file assets") +endif() + target_include_directories(${PROJECT_NAME} PUBLIC include src) target_link_libraries(${PROJECT_NAME} raylib m) diff --git a/src/gameCommon.h b/src/gameCommon.h index eb5ccf7..1592092 100644 --- a/src/gameCommon.h +++ b/src/gameCommon.h @@ -15,8 +15,8 @@ #define YP_MALLOC(size) malloc(size) #define YP_CALLOC(nmemb, size) calloc(nmemb, size) #define YP_REALLOC(ptr, size) realloc(ptr, size) -#define YP_REALLOCARRAY(ptr, nmemb, size) reallocarray(ptr, nmemb, size) -//#define YP_REALLOCARRAY(ptr, nmemb, size) realloc(ptr, nmemb * size) +//#define YP_REALLOCARRAY(ptr, nmemb, size) reallocarray(ptr, nmemb, size) +#define YP_REALLOCARRAY(ptr, nmemb, size) realloc(ptr, nmemb * size) #define YP_FREE(ptr) free(ptr) #define ALLOCATION_ERROR TraceLog(LOG_ERROR, "Allocation error in %s:%d", __FILE__, __LINE__) -- cgit v1.2.3