Also support space in game process command line arguments on unix/android/iOS platform backends

This commit is contained in:
UnknownShadow200 2022-02-26 09:58:37 +11:00
parent 60a017b951
commit 9d4e8d1e2c
4 changed files with 39 additions and 32 deletions

View file

@ -27,11 +27,15 @@ void Platform_Log(const char* msg, int len) {
/*########################################################################################################################*
*-----------------------------------------------------Process/Module------------------------------------------------------*
*#########################################################################################################################*/
static char gameArgsBuffer[512];
static cc_string gameArgs = String_FromArray(gameArgsBuffer);
static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE];
static int gameNumArgs;
cc_result Process_StartGame(const cc_string* args) {
String_Copy(&gameArgs, args);
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
for (int i = 0; i < numArgs; i++) {
String_CopyToRawArray(gameArgs[i], &args[i]);
}
gameNumArgs = numArgs;
return 0;
}
@ -94,13 +98,14 @@ void Platform_ShareScreenshot(const cc_string* filename) {
*-----------------------------------------------------Configuration-------------------------------------------------------*
*#########################################################################################################################*/
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
int count = 0;
if (gameArgs.length) {
count = String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
/* clear arguments so after game is closed, launcher is started */
gameArgs.length = 0;
int count = gameNumArgs;
for (int i = 0; i < count; i++) {
args[i] = String_FromRawArray(gameArgs[i]);
}
return count;
// clear arguments so after game is closed, launcher is started
gameNumArgs = 0;
return count;
}
cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {

View file

@ -622,25 +622,20 @@ static cc_result Process_RawStart(const char* path, char** argv) {
static cc_result Process_RawGetExePath(char* path, int* len);
cc_result Process_StartGame(const cc_string* args) {
char path[NATIVE_STR_LEN], raw[NATIVE_STR_LEN];
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
char raw[GAME_MAX_CMDARGS][NATIVE_STR_LEN];
char path[NATIVE_STR_LEN];
int i, j, len = 0;
char* argv[15];
cc_result res = Process_RawGetExePath(path, &len);
if (res) return res;
path[len] = '\0';
argv[0] = path;
Platform_EncodeUtf8(raw, args);
argv[0] = path; argv[1] = raw;
/* need to null-terminate multiple arguments */
for (i = 0, j = 2; raw[i] && i < Array_Elems(raw); i++) {
if (raw[i] != ' ') continue;
/* null terminate previous argument */
raw[i] = '\0';
argv[j++] = &raw[i + 1];
for (i = 0, j = 1; i < numArgs; i++, j++) {
Platform_EncodeUtf8(raw[i], &args[i]);
argv[j] = raw[i];
}
if (defaultDirectory) { argv[j++] = defaultDirectory; }

View file

@ -85,7 +85,7 @@ static void LimitFPS(void) {
float cooldown = gfx_targetTime - gfx_actualTime;
Thread_Sleep((int)(cooldown + 0.5f));
/* also accumulate Thread_Sleep duration, as actual sleep
/* also accumulate Thread_Sleep duration, as actual sleep */
/* duration can significantly deviate from requested time */
/* (e.g. requested 4ms, but actually slept for 8ms) */
cc_uint64 sleepEnd = Stopwatch_Measure();

View file

@ -406,6 +406,9 @@ cc_result Updater_SetNewBuildTime(cc_uint64 t) { return ERR_NOT_SUPPORTED; }
/*########################################################################################################################*
*--------------------------------------------------------Platform--------------------------------------------------------*
*#########################################################################################################################*/
static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE];
static int gameNumArgs;
cc_result Process_StartOpen(const cc_string* args) {
char raw[NATIVE_STR_LEN];
NSURL* url;
@ -418,19 +421,23 @@ cc_result Process_StartOpen(const cc_string* args) {
return 0;
}
static char gameArgsBuffer[512];
static cc_string gameArgs = String_FromArray(gameArgsBuffer);
cc_result Process_StartGame(const cc_string* args) {
String_Copy(&gameArgs, args);
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
for (int i = 0; i < numArgs; i++) {
String_CopyToRawArray(gameArgs[i], &args[i]);
}
gameNumArgs = numArgs;
return 0;
}
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
if (!gameArgs.length) return 0;
int count = String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
// clear arguments so after game is closed, launcher is started again
gameArgs.length = 0;
int count = gameNumArgs;
for (int i = 0; i < count; i++) {
args[i] = String_FromRawArray(gameArgs[i]);
}
// clear arguments so after game is closed, launcher is started
gameNumArgs = 0;
return count;
}