Commit ff6f2282 authored by Florian Oetke's avatar Florian Oetke
Browse files

integrated all core_assets into the binary and fixed ZIP loading/embedding [fixes #37]

parent 0b5a3e4e
core_assets
demo_assets demo_assets
extensions/* extensions/*
cfg:input_mapping = settings/input_mapping.json
cfg:graphics = graphics-cfg.json
cfg:renderer = renderer-cfg.json
cfg:sounds = sounds-cfg.json
cfg:language = language-cfg.json
cfg:languages_info = settings/languages.json
cfg:gui = settings/gui.json
loc: = loc/
pl_cache: = pipeline_caches
font: = fonts/
font:test_font = fonts/droid_sans.ttf
{
"fonts": [
{"aid":"font:test_font", "size":12, "default_font":true}
]
}
{
"default_language": "en",
"supported_languages": ["en"]
}
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
function(mirrage_copy_recursive src dst) function(mirrage_copy_recursive src dst)
foreach(path ${src}) foreach(path ${src})
get_filename_component(file ${path} NAME) get_filename_component(file ${path} NAME)
if(IS_DIRECTORY ${path}) if(IS_DIRECTORY ${path})
set(files "")
file(GLOB files ${path}/*) file(GLOB files ${path}/*)
mirrage_copy_recursive("${files}" "${dst}/${file}") mirrage_copy_recursive("${files}" "${dst}/${file}")
set(local_copied_files ${local_copied_files} ${copied_files}) set(local_copied_files ${local_copied_files} ${copied_files})
...@@ -18,10 +21,10 @@ function(mirrage_copy_recursive src dst) ...@@ -18,10 +21,10 @@ function(mirrage_copy_recursive src dst)
set(copied_files "${local_copied_files}" PARENT_SCOPE) set(copied_files "${local_copied_files}" PARENT_SCOPE)
endfunction() endfunction()
mirrage_copy_recursive("${SRC_FILES}" "${DST_DIR}/embed")
mirrage_copy_recursive(${SRC_FILES} "${DST_DIR}/embed") execute_process(COMMAND #zip -r "${DST_DIR}/embedded_assets.zip" ${copied_files}
${CMAKE_COMMAND} -E tar "cfv" "${DST_DIR}/embedded_assets.zip" --format=zip ${copied_files}
execute_process(COMMAND ${CMAKE_COMMAND} -E tar "cfv" "${DST_DIR}/embedded_assets.zip" --format=zip ${copied_files}
WORKING_DIRECTORY "${DST_DIR}/embed" WORKING_DIRECTORY "${DST_DIR}/embed"
OUTPUT_QUIET
) )
Subproject commit 7c693a1ce4d2b82ebcb62674365863224543f5bd Subproject commit 1302da8fd08d1e52ebab896a23e2dba15aa4498f
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
#optional: generated files to depend on #optional: generated files to depend on
macro(mirrage_embed_asset target src_files) macro(mirrage_embed_asset target src_files)
string (REPLACE ";" "$<SEMICOLON>" src_files_str "${src_files}")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.zip" "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.s" add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.zip" "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.s"
COMMAND ${CMAKE_COMMAND} -DSRC_FILES=${src_files} -DDST_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${MIRRAGE_ROOT_DIR}/copy_recursive.cmake COMMAND ${CMAKE_COMMAND} -DSRC_FILES=${src_files_str} -DDST_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${MIRRAGE_ROOT_DIR}/copy_recursive.cmake
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.s" COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.s"
DEPENDS ${ARGN} DEPENDS ${ARGN}
VERBATIM VERBATIM
...@@ -40,3 +44,4 @@ void ref_embedded_assets_${target}() { ...@@ -40,3 +44,4 @@ void ref_embedded_assets_${target}() {
add_custom_target(mirrage_embedded_assets_${target} DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.zip" "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.s") add_custom_target(mirrage_embedded_assets_${target} DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.zip" "${CMAKE_CURRENT_BINARY_DIR}/embedded_assets.s")
add_dependencies(${target} mirrage_embedded_assets_${target}) add_dependencies(${target} mirrage_embedded_assets_${target})
endmacro() endmacro()
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
......
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(mirrage LANGUAGES CXX) project(mirrage)
add_subdirectory(utils) add_subdirectory(utils)
add_subdirectory(error) add_subdirectory(error)
......
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(mirrage_asset LANGUAGES CXX) project(mirrage_asset)
# need to be specified with the sources for correct syntax highlighting in some IDEs # need to be specified with the sources for correct syntax highlighting in some IDEs
file(GLOB_RECURSE HEADER_FILES file(GLOB_RECURSE HEADER_FILES
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <mirrage/asset/error.hpp> #include <mirrage/asset/error.hpp>
#include <mirrage/utils/log.hpp> #include <mirrage/utils/log.hpp>
#include <mirrage/utils/md5.hpp>
#include <mirrage/utils/template_utils.hpp> #include <mirrage/utils/template_utils.hpp>
#include <physfs.h> #include <physfs.h>
...@@ -206,13 +207,16 @@ namespace mirrage::asset { ...@@ -206,13 +207,16 @@ namespace mirrage::asset {
for(auto ea : Embedded_asset::instances()) { for(auto ea : Embedded_asset::instances()) {
LOG(plog::info) << "Include embedded asset \"" << ea->name() << "\": " << ea->data().size() LOG(plog::info) << "Include embedded asset \"" << ea->name() << "\": " << ea->data().size()
<< " bytes"; << " bytes MD5: "
<< util::md5(std::string(reinterpret_cast<const char*>(ea->data().data()),
std::size_t(ea->data().size_bytes())));
auto name = "embedded_" + ea->name() + ".zip";
if(!PHYSFS_mountMemory(ea->data().data(), if(!PHYSFS_mountMemory(ea->data().data(),
static_cast<PHYSFS_uint64>(ea->data().size_bytes()), static_cast<PHYSFS_uint64>(ea->data().size_bytes()),
nullptr, nullptr,
"embedded.zip", name.c_str(),
nullptr, nullptr,
0)) { 1)) {
throw std::system_error(static_cast<Asset_error>(PHYSFS_getLastErrorCode()), throw std::system_error(static_cast<Asset_error>(PHYSFS_getLastErrorCode()),
"Unable to add embedded archive: "s + ea->name()); "Unable to add embedded archive: "s + ea->name());
} }
...@@ -263,6 +267,13 @@ namespace mirrage::asset { ...@@ -263,6 +267,13 @@ namespace mirrage::asset {
} }
} }
// unmount default search-path
PHYSFS_unmount(PHYSFS_getBaseDir());
PHYSFS_unmount(append_file(PHYSFS_getBaseDir(), "..").c_str());
PHYSFS_unmount(mirrage::asset::pwd().c_str());
print_dir_recursiv("/", 0, [](auto&& path) { LOG(plog::fatal) << path; });
_reload_dispatchers(); _reload_dispatchers();
} }
......
cmake_minimum_required(VERSION 3.2 FATAL_ERROR) cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(mirrage LANGUAGES CXX) project(mirrage)
include(version_info.cmake) include(version_info.cmake)
...@@ -24,6 +24,19 @@ add_library(mirrage STATIC ...@@ -24,6 +24,19 @@ add_library(mirrage STATIC
${HEADER_FILES} ${HEADER_FILES}
) )
add_library(mirrage::mirrage ALIAS mirrage) add_library(mirrage::mirrage ALIAS mirrage)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/assets_mirrage_core.map" CONTENT
"cfg:input_mapping = settings/input_mapping.json
cfg:graphics = graphics-cfg.json
cfg:renderer = renderer-cfg.json
cfg:sounds = sounds-cfg.json
cfg:language = language-cfg.json
cfg:languages_info = settings/languages.json
cfg:gui = settings/gui.json
loc: = loc/
pl_cache: = pipeline_caches
")
mirrage_embed_asset(mirrage "${CMAKE_CURRENT_BINARY_DIR}/assets_mirrage_core.map")
set(MIRRAGE_DEFAULT_COMPILER_ARGS ${MIRRAGE_DEFAULT_COMPILER_ARGS}) set(MIRRAGE_DEFAULT_COMPILER_ARGS ${MIRRAGE_DEFAULT_COMPILER_ARGS})
target_compile_options(mirrage PRIVATE ${MIRRAGE_DEFAULT_COMPILER_ARGS}) target_compile_options(mirrage PRIVATE ${MIRRAGE_DEFAULT_COMPILER_ARGS})
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <signal.h> #include <signal.h>
#endif #endif
extern void ref_embedded_assets_mirrage();
namespace mirrage { namespace mirrage {
namespace { namespace {
...@@ -113,6 +114,7 @@ namespace mirrage { ...@@ -113,6 +114,7 @@ namespace mirrage {
, _current_time(SDL_GetTicks() / 1000.0) , _current_time(SDL_GetTicks() / 1000.0)
, _headless(headless) , _headless(headless)
{ {
ref_embedded_assets_mirrage();
_graphics_main_window.process([&](auto& window) { _graphics_main_window.process([&](auto& window) {
_input_manager->viewport({0, 0, window.width(), window.height()}); _input_manager->viewport({0, 0, window.width(), window.height()});
......
...@@ -76,18 +76,22 @@ namespace mirrage { ...@@ -76,18 +76,22 @@ namespace mirrage {
auto Translator::supported_languages() const -> std::vector<Language_id> auto Translator::supported_languages() const -> std::vector<Language_id>
{ {
return _assets.load<Language_info>("cfg:language_info"_aid)->supported_languages; return _assets.load_maybe<Language_info>("cfg:language_info"_aid)
.process(std::vector<Language_id>{},
[&](auto& lang_info) { return lang_info->supported_languages; });
} }
void Translator::_reload() void Translator::_reload()
{ {
_print_missing(); _print_missing();
auto info = _assets.load<Language_info>("cfg:languages_info"_aid); auto info = _assets.load_maybe<Language_info>("cfg:languages_info"_aid);
if(info.is_nothing())
return;
if(!contains(info->supported_languages, _language)) { if(!contains(info.get_or_throw()->supported_languages, _language)) {
LOG(plog::info) << "Unsupported language: " << _language; LOG(plog::info) << "Unsupported language: " << _language;
_language = Language_id{info->default_language}; _language = Language_id{info.get_or_throw()->default_language};
} }
LOG(plog::info) << "Using text language: " << _language; LOG(plog::info) << "Using text language: " << _language;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment