Skip to content

Commit

Permalink
add resource pack path and update resource handling
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Mar 1, 2024
1 parent 201ae35 commit 8d6005f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
set(DOXYGEN_FOUND OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)

set(RESOURCE_PACK ${CMAKE_SOURCE_DIR}/tools/resource.pack)

if(ANDROID)
# change project name to main for libmain
Expand All @@ -39,10 +40,6 @@ if(ANDROID)
elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL "arm64-v8a")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfix-cortex-a53-835769")
endif()

elseif(UNIX)
# change resource output path
set(RESOURCE_FILE ${CMAKE_SOURCE_DIR}/out/resource.pack)
endif()

option(W_BUILD_MINSIZE "Build a smaller executable (Wispy)" OFF)
Expand All @@ -67,7 +64,14 @@ endif()
# add sources
file(GLOB_RECURSE SOURCES "src/*.c")
if(MSVC)
list(APPEND SOURCES "src/ressource.rc")
list(APPEND SOURCES "src/resource.rc")
elseif(UNIX)
add_custom_target(link_resource
COMMAND objcopy --input binary --output elf32-i386 --binary-architecture i386 ${RESOURCE_PACK} ${CMAKE_SOURCE_DIR}/src/resource.o
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_dependencies(${PROJECT_NAME} link_resource)
list(APPEND SOURCES "src/resource.o")
endif()

# add definitions
Expand Down Expand Up @@ -107,10 +111,10 @@ if(W_BUILD_MINSIZE)
endif()

# copy resource.pack to output directory
if(UNIX OR ANDROID)
if(EXISTS ${CMAKE_SOURCE_DIR}/tools/resource.pack)
if(ANDROID)
if(EXISTS ${RESOURCE_PACK})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tools/resource.pack ${RESOURCE_FILE}
COMMAND ${CMAKE_COMMAND} -E copy ${RESOURCE_PACK} ${RESOURCE_FILE}
)
else()
message(WARNING "resource.pack file not found. Skipping copying.")
Expand Down
22 changes: 7 additions & 15 deletions src/resource.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
//{{NO_DEPENDENCIES}}
// fichier Include Microsoft Visual C++.
// Utilisé par ressource.rc
//
#define IDR_ASSETS_PACK1 101
#define IDR_ASSETS_PACK1 101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
#if defined(APSTUDIO_INVOKED) && !defined(APSTUDIO_READONLY_SYMBOLS)
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif // APSTUDIO_INVOKED
3 changes: 3 additions & 0 deletions src/resource.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "resource.h"

IDR_ASSETS_PACK1 RCDATA "..\\tools\\resource.pack"
Binary file removed src/ressource.aps
Binary file not shown.
Binary file removed src/ressource.rc
Binary file not shown.
3 changes: 3 additions & 0 deletions src/unpack/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ w_asset *unpack_assets(size_t *size)
if (hInstance == NULL)
return NULL;
char *in_buffer = load_resource(hInstance, &in_size);
#elif __linux__
char *in_buffer = &_binary_resource_pack_start;
in_size = &_binary_resource_pack_end - &_binary_resource_pack_start;
#else
char *in_buffer = (char *)LoadFileData(RESOURCE_NAME, &in_size);
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/unpack/unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#define MAX_UNCOMPRESSE_TRY 4
#ifdef _WIN32
#define RESOURCE_NAME "ASSETS_PACK"
#elif __linux__
extern char _binary_resource_pack_start;
extern char _binary_resource_pack_end;
#else
#define RESOURCE_NAME "resource.pack"
#endif
Expand Down

0 comments on commit 8d6005f

Please sign in to comment.