Use documents directory as game data folder

This commit is contained in:
Alexander Batalov 2022-10-14 10:07:26 +03:00
parent 954b0b1ac3
commit acaf8769ad
4 changed files with 51 additions and 0 deletions

View File

@ -271,6 +271,13 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/sfall_config.h"
)
if(IOS)
target_sources(${EXECUTABLE_NAME} PUBLIC
"src/platform/ios/paths.h"
"src/platform/ios/paths.mm"
)
endif()
if(WIN32)
target_compile_definitions(${EXECUTABLE_NAME} PUBLIC
_CRT_SECURE_NO_WARNINGS

6
src/platform/ios/paths.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef FALLOUT_PLATFORM_IOS_PATHS_H_
#define FALLOUT_PLATFORM_IOS_PATHS_H_
const char* iOSGetDocumentsPath();
#endif /* FALLOUT_PLATFORM_IOS_PATHS_H_ */

33
src/platform/ios/paths.mm Normal file
View File

@ -0,0 +1,33 @@
#include "paths.h"
#include <Foundation/Foundation.h>
#include <SDL.h>
// Modelled after SDL_AndroidGetExternalStoragePath.
const char* iOSGetDocumentsPath()
{
static char* s_iOSDocumentsPath = NULL;
if (s_iOSDocumentsPath == NULL) {
@autoreleasepool {
NSArray* array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([array count] > 0) {
NSString* str = [array objectAtIndex:0];
const char* base = [str fileSystemRepresentation];
if (base) {
const size_t len = SDL_strlen(base) + 2;
s_iOSDocumentsPath = (char*)SDL_malloc(len);
if (s_iOSDocumentsPath == NULL) {
SDL_OutOfMemory();
} else {
SDL_snprintf(s_iOSDocumentsPath, len, "%s/", base);
}
}
}
}
}
return s_iOSDocumentsPath;
}

View File

@ -8,6 +8,10 @@
#include "svga.h"
#include "window_manager.h"
#if __APPLE__ && TARGET_OS_IOS
#include "platform/ios/paths.h"
#endif
namespace fallout {
#ifdef _WIN32
@ -39,6 +43,7 @@ int main(int argc, char* argv[])
#if __APPLE__ && TARGET_OS_IOS
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
chdir(iOSGetDocumentsPath());
#endif
#if __APPLE__ && TARGET_OS_OSX