From 73b99b6d78ee97781af3734d96bb7a24c9e85d8e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 8 Jun 2019 17:42:12 +0000 Subject: [PATCH 1/4] Makefile cleanup, and improve cross-compilation support bin2h should run on the host system, not the target --- Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f03e0e10..aeced61b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +NATIVECC = cc +NATIVECXX = c++ + ifeq ($(RELEASE), 1) CXXFLAGS = -O3 -flto LDFLAGS = -s @@ -179,7 +182,7 @@ RESOURCES = \ ORG/White.org \ ORG/XXXX.org \ ORG/Zonbie.org \ - WAVE/Wave.dat \ + WAVE/Wave.dat ifeq ($(JAPANESE), 1) RESOURCES += BITMAP/pixel_jp.bmp @@ -204,12 +207,12 @@ ifeq ($(WINDOWS), 1) endif all: $(BUILD_DIR)/$(FILENAME) + @echo Finished $(BUILD_DIR)/$(FILENAME): $(OBJECTS) @mkdir -p $(@D) - @echo Linking + @echo Linking $@ @$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) - @echo Finished compiling: $@ obj/$(BUILD_DIR)/$(FILENAME)/%.o: src/%.cpp @mkdir -p $(@D) @@ -229,7 +232,7 @@ src/Resource/%.h: res/% obj/bin2h obj/bin2h: bin2h/bin2h.c @mkdir -p $(@D) @echo Compiling $^ - @$(CC) -O3 -s -std=c90 -Wall -Wextra -pedantic $^ -o $@ + @$(NATIVECC) -O3 -s -std=c90 -Wall -Wextra -pedantic $^ -o $@ include $(wildcard $(DEPENDENCIES)) From 082ffeb04dc375130b341853fac82bf37f120b4e Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 8 Jun 2019 17:43:21 +0000 Subject: [PATCH 2/4] Make CMake bin2h installable Working towards making CMake CSE2 cross-compilation-friendly --- bin2h/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin2h/CMakeLists.txt b/bin2h/CMakeLists.txt index f2b1ce9d..79713c55 100644 --- a/bin2h/CMakeLists.txt +++ b/bin2h/CMakeLists.txt @@ -29,3 +29,5 @@ if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") endif() endif() endif() + +install(TARGETS bin2h RUNTIME) From 75f585a72736822c24b1ef63f2920844c0d4d07c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 8 Jun 2019 18:27:57 +0000 Subject: [PATCH 3/4] Made CMakeLists.txt cross-compile-friendly bin2h is built natively --- CMakeLists.txt | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fb63af5..1800114c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,8 +262,26 @@ elseif(NOT WIN32) list(APPEND RESOURCES "FONT/cour.ttf") endif() -# Magic to convert resources to header files -add_subdirectory("bin2h") +# Build bin2h externally, so it isn't cross-compiled when CSE2 is (Emscripten) +include(ExternalProject) + +ExternalProject_Add(bin2h + SOURCE_DIR "${CMAKE_SOURCE_DIR}/bin2h" + DOWNLOAD_COMMAND "" + UPDATE_COMMAND "" + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_CONFIGURATION_TYPES=Release +) + +ExternalProject_Get_Property(bin2h INSTALL_DIR) + +add_executable(bin2h_tool IMPORTED) +add_dependencies(bin2h_tool bin2h) +set_target_properties(bin2h_tool PROPERTIES IMPORTED_LOCATION "${INSTALL_DIR}/bin/bin2h") + +# Convert resources to header files foreach(FILENAME IN LISTS RESOURCES) set(IN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res") set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/Resource") @@ -271,8 +289,8 @@ foreach(FILENAME IN LISTS RESOURCES) add_custom_command( OUTPUT "${OUT_DIR}/${FILENAME}.h" COMMAND ${CMAKE_COMMAND} -E make_directory "${OUT_DIR}/${DIRECTORY}" - COMMAND bin2h "${IN_DIR}/${FILENAME}" "${OUT_DIR}/${FILENAME}.h" - DEPENDS bin2h "${IN_DIR}/${FILENAME}" + COMMAND bin2h_tool "${IN_DIR}/${FILENAME}" "${OUT_DIR}/${FILENAME}.h" + DEPENDS bin2h_tool "${IN_DIR}/${FILENAME}" ) target_sources(CSE2 PRIVATE "${OUT_DIR}/${FILENAME}.h") endforeach() From 078da6ccf77e4153b526603432d57a994c1a0ed6 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 14 Jun 2019 17:06:42 +0100 Subject: [PATCH 4/4] Correct fmod usage --- src/Sound.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sound.cpp b/src/Sound.cpp index 2be03cb0..e8a04510 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -169,7 +169,7 @@ void SOUNDBUFFER::Mix(float *buffer, size_t frames) const float sample2 = ((looping || (((size_t)samplePosition) + 1) < size) ? data[(((size_t)samplePosition) + 1) % size] : 128.0f); //Interpolate sample - const float subPos = (float)std::fmod(samplePosition, 1.0); + const float subPos = (float)fmod(samplePosition, 1.0); const float sampleA = sample1 + (sample2 - sample1) * subPos; //Convert sample to float32 @@ -186,7 +186,7 @@ void SOUNDBUFFER::Mix(float *buffer, size_t frames) { if (looping) { - samplePosition = std::fmod(samplePosition, size); + samplePosition = fmod(samplePosition, size); looped = true; } else