mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
Also support space in game process command line arguments on unix/android/iOS platform backends
This commit is contained in:
parent
60a017b951
commit
9d4e8d1e2c
@ -27,11 +27,15 @@ void Platform_Log(const char* msg, int len) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------Process/Module------------------------------------------------------*
|
*-----------------------------------------------------Process/Module------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static char gameArgsBuffer[512];
|
static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE];
|
||||||
static cc_string gameArgs = String_FromArray(gameArgsBuffer);
|
static int gameNumArgs;
|
||||||
|
|
||||||
cc_result Process_StartGame(const cc_string* args) {
|
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
|
||||||
String_Copy(&gameArgs, args);
|
for (int i = 0; i < numArgs; i++) {
|
||||||
|
String_CopyToRawArray(gameArgs[i], &args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
gameNumArgs = numArgs;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,12 +98,13 @@ void Platform_ShareScreenshot(const cc_string* filename) {
|
|||||||
*-----------------------------------------------------Configuration-------------------------------------------------------*
|
*-----------------------------------------------------Configuration-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
||||||
int count = 0;
|
int count = gameNumArgs;
|
||||||
if (gameArgs.length) {
|
for (int i = 0; i < count; i++) {
|
||||||
count = String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
|
args[i] = String_FromRawArray(gameArgs[i]);
|
||||||
/* clear arguments so after game is closed, launcher is started */
|
|
||||||
gameArgs.length = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear arguments so after game is closed, launcher is started
|
||||||
|
gameNumArgs = 0;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,25 +622,20 @@ static cc_result Process_RawStart(const char* path, char** argv) {
|
|||||||
|
|
||||||
static cc_result Process_RawGetExePath(char* path, int* len);
|
static cc_result Process_RawGetExePath(char* path, int* len);
|
||||||
|
|
||||||
cc_result Process_StartGame(const cc_string* args) {
|
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
|
||||||
char path[NATIVE_STR_LEN], raw[NATIVE_STR_LEN];
|
char raw[GAME_MAX_CMDARGS][NATIVE_STR_LEN];
|
||||||
|
char path[NATIVE_STR_LEN];
|
||||||
int i, j, len = 0;
|
int i, j, len = 0;
|
||||||
char* argv[15];
|
char* argv[15];
|
||||||
|
|
||||||
cc_result res = Process_RawGetExePath(path, &len);
|
cc_result res = Process_RawGetExePath(path, &len);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
path[len] = '\0';
|
path[len] = '\0';
|
||||||
|
argv[0] = path;
|
||||||
|
|
||||||
Platform_EncodeUtf8(raw, args);
|
for (i = 0, j = 1; i < numArgs; i++, j++) {
|
||||||
argv[0] = path; argv[1] = raw;
|
Platform_EncodeUtf8(raw[i], &args[i]);
|
||||||
|
argv[j] = raw[i];
|
||||||
/* 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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultDirectory) { argv[j++] = defaultDirectory; }
|
if (defaultDirectory) { argv[j++] = defaultDirectory; }
|
||||||
|
@ -85,7 +85,7 @@ static void LimitFPS(void) {
|
|||||||
float cooldown = gfx_targetTime - gfx_actualTime;
|
float cooldown = gfx_targetTime - gfx_actualTime;
|
||||||
Thread_Sleep((int)(cooldown + 0.5f));
|
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 */
|
/* duration can significantly deviate from requested time */
|
||||||
/* (e.g. requested 4ms, but actually slept for 8ms) */
|
/* (e.g. requested 4ms, but actually slept for 8ms) */
|
||||||
cc_uint64 sleepEnd = Stopwatch_Measure();
|
cc_uint64 sleepEnd = Stopwatch_Measure();
|
||||||
|
@ -406,6 +406,9 @@ cc_result Updater_SetNewBuildTime(cc_uint64 t) { return ERR_NOT_SUPPORTED; }
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*--------------------------------------------------------Platform--------------------------------------------------------*
|
*--------------------------------------------------------Platform--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE];
|
||||||
|
static int gameNumArgs;
|
||||||
|
|
||||||
cc_result Process_StartOpen(const cc_string* args) {
|
cc_result Process_StartOpen(const cc_string* args) {
|
||||||
char raw[NATIVE_STR_LEN];
|
char raw[NATIVE_STR_LEN];
|
||||||
NSURL* url;
|
NSURL* url;
|
||||||
@ -418,19 +421,23 @@ cc_result Process_StartOpen(const cc_string* args) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char gameArgsBuffer[512];
|
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
|
||||||
static cc_string gameArgs = String_FromArray(gameArgsBuffer);
|
for (int i = 0; i < numArgs; i++) {
|
||||||
cc_result Process_StartGame(const cc_string* args) {
|
String_CopyToRawArray(gameArgs[i], &args[i]);
|
||||||
String_Copy(&gameArgs, args);
|
}
|
||||||
|
|
||||||
|
gameNumArgs = numArgs;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) {
|
||||||
if (!gameArgs.length) return 0;
|
int count = gameNumArgs;
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
args[i] = String_FromRawArray(gameArgs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
int count = String_UNSAFE_Split(&gameArgs, ' ', args, GAME_MAX_CMDARGS);
|
// clear arguments so after game is closed, launcher is started
|
||||||
// clear arguments so after game is closed, launcher is started again
|
gameNumArgs = 0;
|
||||||
gameArgs.length = 0;
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user