mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
cmake: rework asset compression pipeline a bit
This commit is contained in:
parent
ddfe7cc50a
commit
c480289123
5 changed files with 151 additions and 94 deletions
|
@ -2,7 +2,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
|||
include(AssetCache)
|
||||
|
||||
find_program(OPUSENC NAMES opusenc NO_CMAKE_FIND_ROOT_PATH)
|
||||
if(OPUSENC)
|
||||
if(OPUSENC AND DATADIR)
|
||||
file(GLOB_RECURSE FLAC_FILES RELATIVE ${DATADIR} ${DATADIR}/*.flac)
|
||||
message(STATUS "FlacToOpus engaging... (using ${OPUSENC})")
|
||||
foreach(file IN LISTS FLAC_FILES)
|
||||
|
@ -23,6 +23,10 @@ if(OPUSENC)
|
|||
endif()
|
||||
endif()
|
||||
endforeach(file)
|
||||
else(OPUSENC)
|
||||
else(OPUSENC AND DATADIR)
|
||||
if(NOT OPUSENC)
|
||||
message(WARNING "FlacToOpus: can't find opusenc!")
|
||||
endif(OPUSENC)
|
||||
else()
|
||||
message(WARNING "FlacToOpus: no DATADIR specified!")
|
||||
endif()
|
||||
endif(OPUSENC AND DATADIR)
|
||||
|
|
|
@ -2,9 +2,9 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
|||
include(AssetCache)
|
||||
|
||||
find_program(OGGENC NAMES oggenc NO_CMAKE_FIND_ROOT_PATH)
|
||||
if(OGGENC)
|
||||
if(OGGENC AND DATADIR)
|
||||
file(GLOB_RECURSE FLAC_FILES RELATIVE ${DATADIR} ${DATADIR}/*.flac)
|
||||
message(STATUS "FlacToOgg engaging... (using ${OGGENC})")
|
||||
message(STATUS "FlacToVorbis engaging... (using ${OGGENC})")
|
||||
foreach(file IN LISTS FLAC_FILES)
|
||||
message(STATUS ${file})
|
||||
string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" filename ${file})
|
||||
|
@ -23,6 +23,10 @@ if(OGGENC)
|
|||
endif()
|
||||
endif()
|
||||
endforeach(file)
|
||||
else(OGGENC)
|
||||
message(WARNING "FlacToOgg: can't find oggenc!")
|
||||
endif(OGGENC)
|
||||
else(OGGENC AND DATADIR)
|
||||
if(NOT OGGENC)
|
||||
message(WARNING "FlacToVorbis: can't find oggenc!")
|
||||
else()
|
||||
message(WARNING "FlacToVorbis: no DATADIR specified!")
|
||||
endif()
|
||||
endif(OGGENC AND DATADIR)
|
|
@ -2,7 +2,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
|||
include(AssetCache)
|
||||
|
||||
find_program(CONVERT NAMES convert NO_CMAKE_FIND_ROOT_PATH)
|
||||
if(CONVERT)
|
||||
if(CONVERT AND DATADIR)
|
||||
file(GLOB_RECURSE IMAGE_FILES RELATIVE ${DATADIR} ${DATADIR}/*.png ${DATADIR}/*.jpg ${DATADIR}/*.JPG ${DATADIR}/*.webp)
|
||||
message(STATUS "ImgToWebp engaging... (using ${CONVERT})")
|
||||
foreach(file IN LISTS IMAGE_FILES)
|
||||
|
@ -37,6 +37,10 @@ if(CONVERT)
|
|||
endif()
|
||||
endif()
|
||||
endforeach(file)
|
||||
else(CONVERT)
|
||||
else(CONVERT AND DATADIR)
|
||||
if(NOT CONVERT)
|
||||
message(WARNING "ImgToWebp: can't find convert!")
|
||||
endif(CONVERT)
|
||||
else()
|
||||
message(WARNING "ImgToWebp: no DATADIR specified!")
|
||||
endif()
|
||||
endif(CONVERT AND DATADIR)
|
||||
|
|
|
@ -323,7 +323,6 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
set(LIBSUPERDERPY_APPID "net.dosowisko.${LIBSUPERDERPY_GAMENAME}")
|
||||
endif(NOT DEFINED LIBSUPERDERPY_APPID)
|
||||
|
||||
if (ANDROID OR EMSCRIPTEN)
|
||||
if (ANDROID)
|
||||
set(ASSET_PIPELINE_DATADIR "${CMAKE_BINARY_DIR}/android/app/src/main/assets/data")
|
||||
set(ASSET_PIPELINE_DEPEND "")
|
||||
|
@ -332,13 +331,47 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
set(ASSET_PIPELINE_DEPEND ${LIBSUPERDERPY_GAMENAME}_install)
|
||||
endif()
|
||||
|
||||
set(FLACTOOPUS_BITRATE "192" CACHE STRING "Bitrate of resulting Opus files (kbps)")
|
||||
set(FLACTOLOSSY_DEFAULT OFF)
|
||||
set(FLACTOLOSSY_FORMAT_DEFAULT "Opus")
|
||||
set(IMGTOWEBP_DEFAULT OFF)
|
||||
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_flac_to_opus
|
||||
if (ANDROID OR EMSCRIPTEN)
|
||||
set(FLACTOLOSSY_DEFAULT ON)
|
||||
set(IMGTOWEBP_DEFAULT ON)
|
||||
endif()
|
||||
|
||||
if (MAEMO5)
|
||||
set(FLACTOLOSSY_DEFAULT ON)
|
||||
set(FLACTOLOSSY_FORMAT_DEFAULT "Vorbis")
|
||||
endif()
|
||||
|
||||
if (ANDROID OR EMSCRIPTEN)
|
||||
# restrict to Android or Emscripten for now, because only those platforms have ASSET_PIPELINE_DATADIR at this moment
|
||||
|
||||
option(FLACTOLOSSY "Compress FLAC audio assets to lossy format" ${FLACTOLOSSY_DEFAULT})
|
||||
set(FLACTOLOSSY_BITRATE "192" CACHE STRING "Bitrate of resulting Vorbis/Opus files (kbps)")
|
||||
set(FLACTOLOSSY_SAMPLERATE "48000" CACHE STRING "Sample rate of resulting Vorbis files (does not apply to Opus) (Hz)")
|
||||
set(FLACTOLOSSY_FORMAT ${FLACTOLOSSY_FORMAT_DEFAULT} CACHE STRING "Lossy codec to use when encoding audio files")
|
||||
set_property(CACHE FLACTOLOSSY_FORMAT PROPERTY STRINGS "Opus;Vorbis")
|
||||
|
||||
if (FLACTOLOSSY)
|
||||
if (${FLACTOLOSSY_FORMAT} STREQUAL "Vorbis")
|
||||
add_definitions(-DLIBSUPERDERPY_FLACTOLOSSY_EXT="ogg")
|
||||
else()
|
||||
add_definitions(-DLIBSUPERDERPY_FLACTOLOSSY_EXT="opus")
|
||||
endif()
|
||||
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_flac_to_lossy
|
||||
DEPENDS ${ASSET_PIPELINE_DEPEND}
|
||||
COMMAND ${CMAKE_COMMAND} -DDATADIR=${ASSET_PIPELINE_DATADIR} -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DBITRATE=${FLACTOOPUS_BITRATE} -P ${LIBSUPERDERPY_DIR}/cmake/FlacToOpus.cmake
|
||||
COMMAND ${CMAKE_COMMAND} -DDATADIR=${ASSET_PIPELINE_DATADIR} -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DBITRATE=${FLACTOLOSSY_BITRATE} -DSAMPLERATE=${FLACTOLOSSY_SAMPLERATE} -P ${LIBSUPERDERPY_DIR}/cmake/FlacTo${FLACTOLOSSY_FORMAT}.cmake
|
||||
USES_TERMINAL)
|
||||
|
||||
else(FLACTOLOSSY)
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_flac_to_lossy
|
||||
DEPENDS ${ASSET_PIPELINE_DEPEND})
|
||||
endif(FLACTOLOSSY)
|
||||
|
||||
option(IMGTOWEBP "Compress image assets to WebP format" ${IMGTOWEBP_DEFAULT})
|
||||
option(IMGTOWEBP_LOSSLESS "Use lossless WebP compression" OFF)
|
||||
if(IMGTOWEBP_LOSSLESS)
|
||||
set(IMGTOWEBP_QUALITY "100" CACHE STRING "Quality of resulting WebP files")
|
||||
|
@ -348,10 +381,16 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
set(IMGTOWEBP_RESIZE "" CACHE STRING "Value passed as -resize to ImageMagick (no resizing when empty)")
|
||||
set(IMGTOWEBP_PARAMS "" CACHE STRING "Additional ImageMagick parameters")
|
||||
|
||||
if(IMGTOWEBP)
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_img_to_webp
|
||||
DEPENDS ${ASSET_PIPELINE_DEPEND}
|
||||
COMMAND ${CMAKE_COMMAND} -DQUALITY="${IMGTOWEBP_QUALITY}" -DRESIZE="${IMGTOWEBP_RESIZE}" -DPARAMS="${IMGTOWEBP_PARAMS}" -DCACHE="${CMAKE_SOURCE_DIR}/.assetcache" -DLOSSLESS="${IMGTOWEBP_LOSSLESS}" -DDATADIR=${ASSET_PIPELINE_DATADIR} -P ${LIBSUPERDERPY_DIR}/cmake/ImgToWebp.cmake
|
||||
USES_TERMINAL)
|
||||
add_definitions(-DLIBSUPERDERPY_IMGTOWEBP)
|
||||
else(IMGTOWEBP)
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_img_to_webp
|
||||
DEPENDS ${ASSET_PIPELINE_DEPEND})
|
||||
endif(IMGTOWEBP)
|
||||
|
||||
endif (ANDROID OR EMSCRIPTEN)
|
||||
|
||||
|
@ -363,7 +402,7 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
set(APK_PATH ${CMAKE_BINARY_DIR}/android/bin/${LIBSUPERDERPY_GAMENAME}-debug.apk)
|
||||
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_apk ALL
|
||||
DEPENDS ${EXECUTABLE} ${LIBSUPERDERPY_GAMENAME}_flac_to_opus ${LIBSUPERDERPY_GAMENAME}_img_to_webp
|
||||
DEPENDS ${EXECUTABLE} ${LIBSUPERDERPY_GAMENAME}_flac_to_lossy ${LIBSUPERDERPY_GAMENAME}_img_to_webp
|
||||
BYPRODUCTS ${APK_PATH}
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/android"
|
||||
COMMAND ./gradlew assembleDebug
|
||||
|
@ -406,7 +445,7 @@ if (NOT LIBSUPERDERPY_CONFIG_INCLUDED)
|
|||
endif()
|
||||
|
||||
add_custom_target(${LIBSUPERDERPY_GAMENAME}_js
|
||||
DEPENDS ${LIBSUPERDERPY_GAMENAME}_install ${LIBSUPERDERPY_GAMENAME}_flac_to_opus ${LIBSUPERDERPY_GAMENAME}_img_to_webp ${CMAKE_BINARY_DIR}/emscripten-imports.json
|
||||
DEPENDS ${LIBSUPERDERPY_GAMENAME}_install ${LIBSUPERDERPY_GAMENAME}_flac_to_lossy ${LIBSUPERDERPY_GAMENAME}_img_to_webp ${CMAKE_BINARY_DIR}/emscripten-imports.json
|
||||
WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}/${LIBSUPERDERPY_GAMENAME}"
|
||||
COMMAND "${CMAKE_C_COMPILER}" ${CFLAGS_LIST} ../bin/${LIBSUPERDERPY_GAMENAME}${CMAKE_EXECUTABLE_SUFFIX} ../lib/libsuperderpy${CMAKE_SHARED_LIBRARY_SUFFIX} ../lib/lib${LIBSUPERDERPY_GAMENAME}${CMAKE_SHARED_LIBRARY_SUFFIX} ${ALLEGRO5_LIBS} ${EMSCRIPTEN_FLAGS} -o ${LIBSUPERDERPY_GAMENAME}.html --pre-js ${LIBSUPERDERPY_DIR}/src/emscripten-pre-js.js --preload-file ../share/${LIBSUPERDERPY_GAMENAME}/data --preload-file gamestates@/
|
||||
USES_TERMINAL
|
||||
|
|
20
src/utils.c
20
src/utils.c
|
@ -404,23 +404,29 @@ SYMBOL_EXPORT const char* FindDataFilePath(struct Game* game, const char* filena
|
|||
}
|
||||
#endif
|
||||
|
||||
#if (defined __EMSCRIPTEN__) || (defined ALLEGRO_ANDROID)
|
||||
#ifdef LIBSUPERDERPY_FLACTOLOSSY_EXT
|
||||
{
|
||||
char* file = AddGarbage(game, strdup(filename));
|
||||
char* sub = strstr(file, ".flac");
|
||||
if (sub) {
|
||||
sub[0] = '.';
|
||||
sub[1] = 'o';
|
||||
sub[2] = 'p';
|
||||
sub[3] = 'u';
|
||||
sub[4] = 's';
|
||||
sub[1] = LIBSUPERDERPY_FLACTOLOSSY_EXT[0];
|
||||
sub[2] = LIBSUPERDERPY_FLACTOLOSSY_EXT[1];
|
||||
sub[3] = LIBSUPERDERPY_FLACTOLOSSY_EXT[2];
|
||||
sub[4] = LIBSUPERDERPY_FLACTOLOSSY_EXT[3];
|
||||
sub[5] = 0;
|
||||
}
|
||||
result = TestDataFilePath(game, file);
|
||||
if (result) {
|
||||
return AddGarbage(game, result);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
sub = strstr(file, ".png");
|
||||
#ifdef LIBSUPERDERPY_IMGTOWEBP
|
||||
{
|
||||
char* file = AddGarbage(game, strdup(filename));
|
||||
char* sub = strstr(file, ".png");
|
||||
if (sub) {
|
||||
sub[0] = '.';
|
||||
sub[1] = 'w';
|
||||
|
@ -471,7 +477,7 @@ SYMBOL_EXPORT const char* FindDataFilePath(struct Game* game, const char* filena
|
|||
if (result) {
|
||||
return AddGarbage(game, result);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
result = TestDataFilePath(game, filename);
|
||||
|
|
Loading…
Reference in a new issue