From 316128b7afc33b3e5dd6e82985151f4fa16c6538 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 2 Mar 2020 01:59:31 -0500 Subject: [PATCH] Use bintoc_compress; reduce URDE/HECL binary sizes --- CMakeLists.txt | 9 +++++++-- DataSpec/AssetNameMap.cpp | 25 +++++++++++++++++++++---- DataSpec/AssetNameMapNull.cpp | 9 +++++++++ DataSpec/CMakeLists.txt | 13 ++++++++----- Runtime/CMakeLists.txt | 2 +- hecl | 2 +- 6 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 DataSpec/AssetNameMapNull.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b747473f4..113db8d11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,11 @@ else() if (HAS_NO_PLT) add_compile_options(-fno-plt) endif() + check_cxx_compiler_flag(-fno-asynchronous-unwind-tables HAS_NO_ASYNC_UNWIND_TABLES) + if (HAS_NO_ASYNC_UNWIND_TABLES) + # Binary size reduction + add_compile_options(-fno-asynchronous-unwind-tables) + endif() if(URDE_MSAN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") @@ -180,7 +185,7 @@ endif() if(USE_LD_LLD) execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) if("${LD_VERSION}" MATCHES "LLD") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -Wl,--build-id=uuid") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld") if(USE_LTO) add_compile_options(-flto=thin) @@ -228,7 +233,7 @@ add_subdirectory(nod) set(HECL_DLPACKAGE ${URDE_DLPACKAGE}) -set(DATA_SPEC_LIBS RetroDataSpec) +set(DATA_SPEC_LIBS RetroDataSpec AssetNameMap) set(HECL_DATASPEC_DECLS "/* RetroCommon specs */ namespace DataSpec diff --git a/DataSpec/AssetNameMap.cpp b/DataSpec/AssetNameMap.cpp index ace70701c..da6828b94 100644 --- a/DataSpec/AssetNameMap.cpp +++ b/DataSpec/AssetNameMap.cpp @@ -1,10 +1,13 @@ #include "AssetNameMap.hpp" +#include "athena/Compression.hpp" #include "athena/MemoryReader.hpp" extern "C" const uint8_t ASSET_NAME_MP32[]; extern "C" const size_t ASSET_NAME_MP32_SZ; +extern "C" const size_t ASSET_NAME_MP32_DECOMPRESSED_SZ; extern "C" const uint8_t ASSET_NAME_MP64[]; extern "C" const size_t ASSET_NAME_MP64_SZ; +extern "C" const size_t ASSET_NAME_MP64_DECOMPRESSED_SZ; namespace DataSpec::AssetNameMap { logvisor::Module Log("AssetNameMap"); @@ -53,14 +56,28 @@ void InitAssetNameMap() { Log.report(logvisor::Info, fmt("Initializing asset name database...")); /* First load the 32bit map for MP1/2 */ - { - athena::io::MemoryReader ar(ASSET_NAME_MP32, ASSET_NAME_MP32_SZ); + if (ASSET_NAME_MP32_DECOMPRESSED_SZ) { + auto decompressed = new uint8_t[ASSET_NAME_MP32_DECOMPRESSED_SZ]; + athena::io::Compression::decompressZlib(ASSET_NAME_MP32, ASSET_NAME_MP32_SZ, decompressed, + ASSET_NAME_MP32_DECOMPRESSED_SZ); + athena::io::MemoryReader ar(decompressed, ASSET_NAME_MP32_DECOMPRESSED_SZ); LoadAssetMap(ar); + delete[](decompressed); + } else { + Log.report(logvisor::Warning, + fmt(_SYS_STR("AssetNameMap32 unavailable; Assets will not have proper filenames for most files."))); } /* Now load the 64bit map for MP3 */ - { - athena::io::MemoryReader ar(ASSET_NAME_MP64, ASSET_NAME_MP64_SZ); + if (ASSET_NAME_MP64_DECOMPRESSED_SZ) { + auto decompressed = new uint8_t[ASSET_NAME_MP64_DECOMPRESSED_SZ]; + athena::io::Compression::decompressZlib(ASSET_NAME_MP64, ASSET_NAME_MP64_SZ, decompressed, + ASSET_NAME_MP64_DECOMPRESSED_SZ); + athena::io::MemoryReader ar(decompressed, ASSET_NAME_MP64_DECOMPRESSED_SZ); LoadAssetMap(ar); + delete[](decompressed); + } else { + Log.report(logvisor::Warning, + fmt(_SYS_STR("AssetNameMap64 unavailable; Assets will not have proper filenames for most files."))); } g_AssetNameMapInit = true; } diff --git a/DataSpec/AssetNameMapNull.cpp b/DataSpec/AssetNameMapNull.cpp new file mode 100644 index 000000000..7922ca0e1 --- /dev/null +++ b/DataSpec/AssetNameMapNull.cpp @@ -0,0 +1,9 @@ +#include +#include + +extern "C" const uint8_t ASSET_NAME_MP32[] = {}; +extern "C" const size_t ASSET_NAME_MP32_SZ = 0; +extern "C" const size_t ASSET_NAME_MP32_DECOMPRESSED_SZ = 0; +extern "C" const uint8_t ASSET_NAME_MP64[] = {}; +extern "C" const size_t ASSET_NAME_MP64_SZ = 0; +extern "C" const size_t ASSET_NAME_MP64_DECOMPRESSED_SZ = 0; diff --git a/DataSpec/CMakeLists.txt b/DataSpec/CMakeLists.txt index a07ccb557..f5d8d8633 100644 --- a/DataSpec/CMakeLists.txt +++ b/DataSpec/CMakeLists.txt @@ -42,11 +42,11 @@ bintoc(RetroMasterShader.cpp Blender/RetroMasterShader.py RETRO_MASTER_SHADER) # Download asset name databases add_custom_command(OUTPUT AssetNameMap32.bin COMMAND ${CMAKE_COMMAND} ARGS -P ${CMAKE_CURRENT_SOURCE_DIR}/AssetMap32Download.cmake) -bintoc(AssetNameMap32.cpp ${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap32.bin ASSET_NAME_MP32) +bintoc_compress(AssetNameMap32.cpp ${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap32.bin ASSET_NAME_MP32) add_custom_command(OUTPUT AssetNameMap64.bin COMMAND ${CMAKE_COMMAND} ARGS -P ${CMAKE_CURRENT_SOURCE_DIR}/AssetMap64Download.cmake) -bintoc(AssetNameMap64.cpp ${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap64.bin ASSET_NAME_MP64) +bintoc_compress(AssetNameMap64.cpp ${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap64.bin ASSET_NAME_MP64) # Each game's DataSpec implementation add_library(RetroDataSpec @@ -65,9 +65,12 @@ add_library(RetroDataSpec Blender/RetroMasterShader.py AssetNameMap.hpp AssetNameMap.cpp - AssetNameMap32.bin AssetNameMap32.cpp - AssetNameMap64.bin AssetNameMap64.cpp RetroMasterShader.cpp) +add_library(AssetNameMap + AssetNameMap32.bin AssetNameMap32.cpp + AssetNameMap64.bin AssetNameMap64.cpp) +add_library(AssetNameMapNull + AssetNameMapNull.cpp) get_target_property(HECL_INCLUDES hecl-full INCLUDE_DIRECTORIES) target_include_directories(RetroDataSpec PUBLIC ${LIBPNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} @@ -86,4 +89,4 @@ foreach(i RANGE ${count}) target_atdna(RetroDataSpec ${src} ${header}) endforeach() -add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$") \ No newline at end of file +add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$") diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 5ce5f49ad..b777e1be4 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -132,7 +132,7 @@ endif() endfunction() set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -set(RUNTIME_LIBRARIES ${HECL_APPLICATION_REPS_TARGETS_LIST} RetroDataSpec NESEmulator +set(RUNTIME_LIBRARIES ${HECL_APPLICATION_REPS_TARGETS_LIST} RetroDataSpec AssetNameMapNull NESEmulator libjpeg-turbo jbus kabufuda discord-rpc logvisor) if(MSVC) diff --git a/hecl b/hecl index 57bfd8cb3..7bd95f9ab 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 57bfd8cb3fefb3e57caddef46b636d762ec642a1 +Subproject commit 7bd95f9abe8b315a4aeba03d88b83f7b0a5e0ef1