mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Merge branch 'bin2c' into options-menu
This commit is contained in:
commit
4c36fbcb86
7 changed files with 155 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ cmake_minimum_required (VERSION 3.20)
|
||||||
|
|
||||||
include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
|
||||||
set(SWA_THIRDPARTY_ROOT ${CMAKE_SOURCE_DIR}/thirdparty)
|
set(SWA_THIRDPARTY_ROOT ${CMAKE_SOURCE_DIR}/thirdparty)
|
||||||
|
set(SWA_TOOLS_ROOT ${CMAKE_SOURCE_DIR}/tools)
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
|
|
||||||
|
|
@ -14,11 +15,10 @@ endif()
|
||||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||||
|
|
||||||
add_subdirectory(${SWA_THIRDPARTY_ROOT})
|
add_subdirectory(${SWA_THIRDPARTY_ROOT})
|
||||||
|
add_subdirectory(${SWA_TOOLS_ROOT})
|
||||||
|
|
||||||
project("UnleashedRecomp-ALL")
|
project("UnleashedRecomp-ALL")
|
||||||
|
|
||||||
include("thirdparty/PowerRecomp/cmake/bin2h.cmake")
|
|
||||||
|
|
||||||
# Include sub-projects.
|
# Include sub-projects.
|
||||||
add_subdirectory("UnleashedRecompResources")
|
|
||||||
add_subdirectory("UnleashedRecompLib")
|
add_subdirectory("UnleashedRecompLib")
|
||||||
add_subdirectory("UnleashedRecomp")
|
add_subdirectory("UnleashedRecomp")
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,32 @@ set(TARGET_NAME "SWA")
|
||||||
|
|
||||||
option(SWA_XAUDIO2 "Use XAudio2 for audio playback" OFF)
|
option(SWA_XAUDIO2 "Use XAudio2 for audio playback" OFF)
|
||||||
|
|
||||||
|
function(BIN2C)
|
||||||
|
cmake_parse_arguments(BIN2C_ARGS "" "TARGET_OBJ;SOURCE_FILE;DEST_FILE;ARRAY_TYPE;ARRAY_NAME" "" ${ARGN})
|
||||||
|
|
||||||
|
if(NOT BIN2C_ARGS_TARGET_OBJ)
|
||||||
|
message(FATAL_ERROR "TARGET_OBJ not specified.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT BIN2C_ARGS_SOURCE_FILE)
|
||||||
|
message(FATAL_ERROR "SOURCE_FILE not specified.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT BIN2C_ARGS_DEST_FILE)
|
||||||
|
set(BIN2C_ARGS_DEST_FILE "${BIN2C_ARGS_SOURCE_FILE}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT "${BIN2C_ARGS_DEST_FILE}.c"
|
||||||
|
COMMAND file_to_c "${BIN2C_ARGS_SOURCE_FILE}" "${BIN2C_ARGS_ARRAY_NAME}" "${BIN2C_ARGS_ARRAY_TYPE}" "${BIN2C_ARGS_DEST_FILE}.c" "${BIN2C_ARGS_DEST_FILE}.h"
|
||||||
|
DEPENDS "${BIN2C_ARGS_SOURCE_FILE}" file_to_c
|
||||||
|
BYPRODUCTS "${BIN2C_ARGS_DEST_FILE}.h"
|
||||||
|
COMMENT "Generating binary header for ${BIN2C_ARGS_SOURCE_FILE}..."
|
||||||
|
)
|
||||||
|
|
||||||
|
set_source_files_properties(${BIN2C_ARGS_DEST_FILE}.c PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
||||||
|
target_sources(${BIN2C_ARGS_TARGET_OBJ} PRIVATE ${BIN2C_ARGS_DEST_FILE}.c)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
/fp:strict
|
/fp:strict
|
||||||
-march=sandybridge
|
-march=sandybridge
|
||||||
|
|
@ -283,3 +309,10 @@ generate_aggregate_header(
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/api"
|
"${CMAKE_CURRENT_SOURCE_DIR}/api"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/api/SWA.h"
|
"${CMAKE_CURRENT_SOURCE_DIR}/api/SWA.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(RESOURCES_SOURCE_PATH "${PROJECT_SOURCE_DIR}/../UnleashedRecompResources")
|
||||||
|
set(RESOURCES_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/res")
|
||||||
|
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/achievements_menu/trophy.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/achievements_menu/trophy.dds" ARRAY_TYPE "unsigned char" ARRAY_NAME "g_trophy")
|
||||||
|
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/game_icon.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/game_icon.bmp" ARRAY_TYPE "unsigned char" ARRAY_NAME "g_game_icon")
|
||||||
|
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/game_icon_night.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/game_icon_night.bmp" ARRAY_TYPE "unsigned char" ARRAY_NAME "g_game_icon_night")
|
||||||
|
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/pause.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/pause.dds" ARRAY_TYPE "unsigned char" ARRAY_NAME "g_pause")
|
||||||
|
|
|
||||||
1
UnleashedRecomp/res/.gitignore
vendored
1
UnleashedRecomp/res/.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
![Ww][Ii][Nn]32/
|
![Ww][Ii][Nn]32/
|
||||||
|
*.c
|
||||||
*.h
|
*.h
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../UnleashedRecompResources/images/game_icon.h"
|
#include <res/images/game_icon.bmp.h>
|
||||||
#include "../UnleashedRecompResources/images/game_icon_night.h"
|
#include <res/images/game_icon_night.bmp.h>
|
||||||
#include <ui/window_events.h>
|
#include <ui/window_events.h>
|
||||||
#include <user/config.h>
|
#include <user/config.h>
|
||||||
|
|
||||||
|
|
@ -46,11 +46,11 @@ public:
|
||||||
{
|
{
|
||||||
if (isNight)
|
if (isNight)
|
||||||
{
|
{
|
||||||
SetIcon((void*)g_res_game_icon_night, g_res_game_icon_night_size);
|
SetIcon(g_game_icon_night, sizeof(g_game_icon_night));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetIcon((void*)g_res_game_icon, g_res_game_icon_size);
|
SetIcon(g_game_icon, sizeof(g_game_icon));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
1
tools/CMakeLists.txt
Normal file
1
tools/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
add_subdirectory(${SWA_TOOLS_ROOT}/file_to_c)
|
||||||
8
tools/file_to_c/CMakeLists.txt
Normal file
8
tools/file_to_c/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
|
include(CMakeParseArguments)
|
||||||
|
|
||||||
|
project("file_to_c")
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
add_executable(file_to_c "file_to_c.cpp")
|
||||||
105
tools/file_to_c/file_to_c.cpp
Normal file
105
tools/file_to_c/file_to_c.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 RT64 Contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
std::vector<char> read_file(const char* path) {
|
||||||
|
std::ifstream input_file{path, std::ios::binary};
|
||||||
|
std::vector<char> ret{};
|
||||||
|
|
||||||
|
if (!input_file.good()) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the length of the file
|
||||||
|
input_file.seekg(0, std::ios::end);
|
||||||
|
ret.resize(input_file.tellg());
|
||||||
|
|
||||||
|
// Read the file contents into the vector
|
||||||
|
input_file.seekg(0, std::ios::beg);
|
||||||
|
input_file.read(ret.data(), ret.size());
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_parent_if_needed(const char* path) {
|
||||||
|
std::filesystem::path parent_path = std::filesystem::path{path}.parent_path();
|
||||||
|
if (!parent_path.empty()) {
|
||||||
|
std::filesystem::create_directories(parent_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char** argv) {
|
||||||
|
if (argc != 6) {
|
||||||
|
printf("Usage: %s [input file] [array name] [array type] [output C file] [output C header]\n", argv[0]);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* input_path = argv[1];
|
||||||
|
const char* array_name = argv[2];
|
||||||
|
const char* array_type = argv[3];
|
||||||
|
const char* output_c_path = argv[4];
|
||||||
|
const char* output_h_path = argv[5];
|
||||||
|
|
||||||
|
// Read the input file's contents
|
||||||
|
std::vector<char> contents = read_file(input_path);
|
||||||
|
|
||||||
|
if (contents.empty()) {
|
||||||
|
fprintf(stderr, "Failed to open file %s! (Or it's empty)\n", input_path);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the output directories if they don't exist
|
||||||
|
create_parent_if_needed(output_c_path);
|
||||||
|
create_parent_if_needed(output_h_path);
|
||||||
|
|
||||||
|
// Write the C file with the array
|
||||||
|
{
|
||||||
|
std::ofstream output_c_file{output_c_path};
|
||||||
|
output_c_file << "extern " << array_type << " " << array_name << "[" << contents.size() << "];\n";
|
||||||
|
output_c_file << array_type << " " << array_name << "[" << contents.size() << "] = {";
|
||||||
|
|
||||||
|
for (char x : contents) {
|
||||||
|
output_c_file << (int)x << ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
output_c_file << "};\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the header file with the extern array
|
||||||
|
{
|
||||||
|
std::ofstream output_h_file{output_h_path};
|
||||||
|
output_h_file <<
|
||||||
|
"#ifdef __cplusplus\n"
|
||||||
|
" extern \"C\" {\n"
|
||||||
|
"#endif\n"
|
||||||
|
"extern " << array_type << " " << array_name << "[" << contents.size() << "];\n"
|
||||||
|
"#ifdef __cplusplus\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue