diff --git a/.ci_scripts/run_cmake.sh b/.ci_scripts/run_cmake.sh index dd6fd3bb12..fdb0c3a8f4 100755 --- a/.ci_scripts/run_cmake.sh +++ b/.ci_scripts/run_cmake.sh @@ -2,7 +2,7 @@ case "$BUILD_TARGET" in "vita") - docker exec vitasdk /bin/bash -c "mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTARGET_PLATFORM=vita .." + docker exec vitasdk /bin/bash -c "git config --global --add safe.directory /build/git && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTARGET_PLATFORM=vita .." ;; "switch") docker exec switchdev /bin/bash -c "git config --global --add safe.directory /build/git && /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -DCMAKE_BUILD_TYPE=Release -DTARGET_PLATFORM=switch -B build -S ." diff --git a/.ci_scripts/setup_environment.sh b/.ci_scripts/setup_environment.sh index 24dab93664..092a1f7555 100755 --- a/.ci_scripts/setup_environment.sh +++ b/.ci_scripts/setup_environment.sh @@ -5,7 +5,7 @@ case "$BUILD_TARGET" in # Note: Using a tagged version of the container to make sure that it's not updated unexpectedly # You can update the tag by obtaining a recent one from here: https://hub.docker.com/r/gnuton/vitasdk-docker/tags # Make sure that it compiles correctly and runs on a Vita prior to pushing the change - docker run -d --name vitasdk --workdir /build/git -v "${PWD}:/build/git" gnuton/vitasdk-docker:20210217 tail -f /dev/null + docker run -d --name vitasdk --workdir /build/git -v "${PWD}:/build/git" gnuton/vitasdk-docker:20240412 tail -f /dev/null ;; "switch") # You can obtain a recent devkitA64 image from https://hub.docker.com/repository/docker/devkitpro/devkita64/general diff --git a/CMakeLists.txt b/CMakeLists.txt index c22cceb7cb..f45fc86f36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -769,12 +769,18 @@ if (${TARGET_PLATFORM} STREQUAL "vita") vorbisfile vorbis mikmod + xmp + modplug mpg123 FLAC ogg + opusfile + opus + stdc++ m SceAppUtil_stub SceAudio_stub + SceAudioIn_stub SceCommonDialog_stub SceCtrl_stub SceDisplay_stub diff --git a/src/platform/file_manager.c b/src/platform/file_manager.c index 3460a8bc50..958df3926a 100644 --- a/src/platform/file_manager.c +++ b/src/platform/file_manager.c @@ -28,7 +28,8 @@ #define fs_dir_open _wopendir #define fs_dir_close _wclosedir #define fs_dir_read _wreaddir -#define dir_entry_name(d) wchar_to_utf8(d->d_name) +#define fs_chdir _wchdir +#define dir_entry_name(d) wchar_to_utf8((d)->d_name) typedef const wchar_t *dir_name; static const char *wchar_to_utf8(const wchar_t *str) @@ -54,12 +55,15 @@ static wchar_t *utf8_to_wchar(const char *str) } #else // not _WIN32 +#ifndef USE_FILE_CACHE #define fs_dir_type DIR #define fs_dir_entry struct dirent #define fs_dir_open opendir #define fs_dir_close closedir #define fs_dir_read readdir #define dir_entry_name(d) ((d)->d_name) +#endif +#define fs_chdir chdir typedef const char *dir_name; #endif @@ -71,11 +75,7 @@ typedef const char *dir_name; #define S_ISSOCK(m) 0 #endif -#ifdef __vita__ -#define CURRENT_DIR VITA_PATH_PREFIX -#define set_dir_name(n) vita_prepend_path(n) -#define free_dir_name(n) -#elif defined(_WIN32) +#if defined(_WIN32) #define CURRENT_DIR L"." #define set_dir_name(n) utf8_to_wchar(n) #define free_dir_name(n) @@ -87,7 +87,7 @@ typedef const char *dir_name; #ifdef _WIN32 #include -#elif !defined(__vita__) +#else #include #endif @@ -211,36 +211,21 @@ int platform_file_manager_set_base_path(const char *path) } #ifdef __ANDROID__ return android_set_base_path(path); -#elif defined(_WIN32) - wchar_t *wpath = utf8_to_wchar(path); - int result = _wchdir(wpath); - free(wpath); - return result == 0; #else - return chdir(path) == 0; + dir_name set_path = set_dir_name(path); + int result = fs_chdir(set_path); + free_dir_name(set_path); + if (result == 0) { +#ifdef USE_FILE_CACHE + platform_file_manager_cache_invalidate(); #endif -} - -#ifdef __vita__ -FILE *platform_file_manager_open_file(const char *filename, const char *mode) -{ - if (strchr(mode, 'w')) { - char temp_filename[FILE_NAME_MAX]; - strncpy(temp_filename, filename, FILE_NAME_MAX - 1); - if (!file_exists(temp_filename, NOT_LOCALIZED)) { - platform_file_manager_cache_add_file_info(filename); - } + return 1; } - return fopen(vita_prepend_path(filename), mode); -} - -int platform_file_manager_remove_file(const char *filename) -{ - platform_file_manager_cache_delete_file_info(filename); - return remove(vita_prepend_path(filename)) == 0; + return 0; +#endif } -#elif defined(_WIN32) +#if defined(_WIN32) FILE *platform_file_manager_open_file(const char *filename, const char *mode) { diff --git a/src/platform/file_manager_cache.c b/src/platform/file_manager_cache.c index e456deb2a5..3aeb510cc5 100644 --- a/src/platform/file_manager_cache.c +++ b/src/platform/file_manager_cache.c @@ -97,10 +97,6 @@ const dir_info *platform_file_manager_cache_get_dir_info(const char *dir) // This is effectively a hack, and definitely not full-proof, but the performance gains are well worth it if (!*file_item->extension) { static char full_name[FILE_NAME_MAX]; - if (!dir_name_offset) { - strncpy(full_name, info->name, FILE_NAME_MAX); - dir_name_offset = strlen(info->name); - } strncpy(full_name + dir_name_offset, name, FILE_NAME_MAX - 1 - dir_name_offset); DIR *file_d = opendir(full_name); if (file_d) { @@ -165,4 +161,21 @@ int platform_file_manager_cache_file_has_extension(const file_info *f, const cha return platform_file_manager_compare_filename(f->extension, extension) == 0; } +void platform_file_manager_cache_invalidate(void) +{ + dir_info *info = base_dir_info; + while (info) { + file_info *file_item = info->first_file; + while (file_item) { + file_info *old_file_item = file_item; + file_item = file_item->next; + free(old_file_item); + } + dir_info *old_info = info; + info = info->next; + free(old_info); + } + base_dir_info = 0; +} + #endif // USE_FILE_CACHE diff --git a/src/platform/file_manager_cache.h b/src/platform/file_manager_cache.h index 116a4b78d3..05ac166014 100644 --- a/src/platform/file_manager_cache.h +++ b/src/platform/file_manager_cache.h @@ -23,6 +23,7 @@ const dir_info *platform_file_manager_cache_get_dir_info(const char *dir); int platform_file_manager_cache_file_has_extension(const file_info *f, const char *extension); void platform_file_manager_cache_add_file_info(const char *filename); void platform_file_manager_cache_delete_file_info(const char *filename); +void platform_file_manager_cache_invalidate(void); #endif diff --git a/src/platform/julius.c b/src/platform/julius.c index d49d9c74bb..01892de2a3 100644 --- a/src/platform/julius.c +++ b/src/platform/julius.c @@ -14,6 +14,7 @@ #include "input/touch.h" #include "platform/arguments.h" #include "platform/file_manager.h" +#include "platform/file_manager_cache.h" #include "platform/joystick.h" #include "platform/keyboard_input.h" #include "platform/platform.h" @@ -32,7 +33,7 @@ #include "platform/switch/switch.h" #include "platform/vita/vita.h" -#if defined(_WIN32) +#if defined(_WIN32) || defined(__vita__) || defined(__SWITCH__) || defined(__ANDROID__) #include #endif @@ -59,7 +60,7 @@ enum { static struct { int active; int quit; -} data = {1, 0}; +} data = { 1, 0 }; static void exit_with_status(int status) { @@ -245,6 +246,9 @@ static void handle_window_event(SDL_WindowEvent *event, int *window_active) case SDL_WINDOWEVENT_SHOWN: SDL_Log("Window %u shown", (unsigned int) event->windowID); +#ifdef USE_FILE_CACHE + platform_file_manager_cache_invalidate(); +#endif *window_active = 1; break; case SDL_WINDOWEVENT_HIDDEN: @@ -456,6 +460,11 @@ static int pre_init(const char *custom_data_dir) SDL_Log("Loading game from %s", custom_data_dir); if (!platform_file_manager_set_base_path(custom_data_dir)) { SDL_Log("%s: directory not found", custom_data_dir); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, + "Error", + "Julius requires the original files from Caesar 3.\n\n" + "Please enter the proper directory or copy the files to the selected directory.", + NULL); return 0; } return game_pre_init(); @@ -503,13 +512,6 @@ static int pre_init(const char *custom_data_dir) } user_dir = ask_for_data_dir(1); } -#elif defined(__vita__) - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Error", - "Julius requires the original files from Caesar 3.\n\n" - "Please add the files to:\n\n" - VITA_PATH_PREFIX, - NULL); #else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Julius requires the original files from Caesar 3 to run.", @@ -533,7 +535,13 @@ static void setup(const julius_args *args) exit_with_status(-1); } - if (!pre_init(args->data_directory)) { +#ifdef __vita__ + const char *base_dir = VITA_PATH_PREFIX; +#else + const char *base_dir = args->data_directory; +#endif + + if (!pre_init(base_dir)) { SDL_Log("Exiting: game pre-init failed"); exit_with_status(1); } diff --git a/src/platform/sound_device.c b/src/platform/sound_device.c index 67e78f49ec..80b427f299 100644 --- a/src/platform/sound_device.c +++ b/src/platform/sound_device.c @@ -191,7 +191,7 @@ static void load_music_for_vita(const char *filename) vita_music_data.buffer = 0; } strncpy(vita_music_data.filename, filename, FILE_NAME_MAX - 1); - SceUID fd = sceIoOpen(vita_prepend_path(filename), SCE_O_RDONLY, 0777); + SceUID fd = sceIoOpen(filename, SCE_O_RDONLY, 0777); if (fd < 0) { return; } @@ -379,7 +379,7 @@ static int put_custom_audio_stream(const Uint8 *audio_data, int len) #endif // Convert audio to SDL format - custom_music.cvt.buf = (Uint8 *)malloc((size_t)(len * custom_music.cvt.len_mult)); + custom_music.cvt.buf = (Uint8 *) malloc((size_t) (len * custom_music.cvt.len_mult)); if (!custom_music.cvt.buf) { return 0; } diff --git a/src/platform/vita/vita.c b/src/platform/vita/vita.c index 5f1cf1cc0a..ca150b5a7b 100644 --- a/src/platform/vita/vita.c +++ b/src/platform/vita/vita.c @@ -13,10 +13,6 @@ #include #include "SDL.h" -#define PREPEND_PATH_OFFSET 17 - -static char prepended_path[2 * FILE_NAME_MAX * sizeof(char)]; - // max heap size is approx. 330 MB with -d ATTRIBUTE2=12, otherwise max is 192 int _newlib_heap_size_user = 330 * 1024 * 1024; @@ -36,20 +32,6 @@ void platform_init_callback(void) center_mouse_cursor(); } -int chdir(const char *path) -{ - return 0; -} - -const char *vita_prepend_path(const char *path) -{ - if (!prepended_path[0]) { - memcpy(prepended_path, VITA_PATH_PREFIX, strlen(VITA_PATH_PREFIX)); - } - strncpy(prepended_path + PREPEND_PATH_OFFSET, path, 2 * FILE_NAME_MAX * sizeof(char) - PREPEND_PATH_OFFSET - 1); - return prepended_path; -} - static void vita_start_text_input(void) { if (!keyboard_is_capturing()) { diff --git a/src/platform/vita/vita.h b/src/platform/vita/vita.h index 5a3ae3c2a3..5f133445be 100644 --- a/src/platform/vita/vita.h +++ b/src/platform/vita/vita.h @@ -21,9 +21,5 @@ void platform_hide_virtual_keyboard(void); #define PLATFORM_USE_SOFTWARE_CURSOR -int chdir(const char *path); - -const char *vita_prepend_path(const char *path); - #endif // __vita__ #endif // PLATFORM_VITA_H