mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
Add option to pretend save failed a random pct of time. Point it to
test fix for problem on Android, but right now turning this on breaks networking.
This commit is contained in:
parent
ad4231289f
commit
75474e1891
2 changed files with 30 additions and 12 deletions
|
@ -175,8 +175,6 @@ writeToFile( XWStreamCtxt* stream, void* closure )
|
||||||
}
|
}
|
||||||
|
|
||||||
free( buf );
|
free( buf );
|
||||||
|
|
||||||
game_saveSucceeded( &cGlobals->game, cGlobals->curSaveToken );
|
|
||||||
} /* writeToFile */
|
} /* writeToFile */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -239,6 +237,15 @@ void
|
||||||
saveGame( CommonGlobals* cGlobals )
|
saveGame( CommonGlobals* cGlobals )
|
||||||
{
|
{
|
||||||
if ( !!cGlobals->params->fileName ) {
|
if ( !!cGlobals->params->fileName ) {
|
||||||
|
XP_Bool doSave = XP_TRUE;
|
||||||
|
if ( 0 < cGlobals->params->saveFailPct
|
||||||
|
/* don't fail to save first time! */
|
||||||
|
&& file_exists( cGlobals->params->fileName ) ) {
|
||||||
|
XP_U16 pct = XP_RANDOM() % 100;
|
||||||
|
doSave = pct >= cGlobals->params->saveFailPct;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( doSave ) {
|
||||||
XWStreamCtxt* outStream;
|
XWStreamCtxt* outStream;
|
||||||
|
|
||||||
outStream = mem_stream_make( cGlobals->params->util->mpool,
|
outStream = mem_stream_make( cGlobals->params->util->mpool,
|
||||||
|
@ -253,6 +260,10 @@ saveGame( CommonGlobals* cGlobals )
|
||||||
stream_destroy( outStream );
|
stream_destroy( outStream );
|
||||||
|
|
||||||
game_saveSucceeded( &cGlobals->game, cGlobals->curSaveToken );
|
game_saveSucceeded( &cGlobals->game, cGlobals->curSaveToken );
|
||||||
|
XP_LOGF( "%s: saved", __func__ );
|
||||||
|
} else {
|
||||||
|
XP_LOGF( "%s: simulating save failure", __func__ );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,6 +492,7 @@ typedef enum {
|
||||||
,CMD_SEED
|
,CMD_SEED
|
||||||
,CMD_GAMESEED
|
,CMD_GAMESEED
|
||||||
,CMD_GAMEFILE
|
,CMD_GAMEFILE
|
||||||
|
,CMD_SAVEFAIL_PCT
|
||||||
#ifdef USE_SQLITE
|
#ifdef USE_SQLITE
|
||||||
,CMD_GAMEDB_FILE
|
,CMD_GAMEDB_FILE
|
||||||
,CMD_GAMEDB_ID
|
,CMD_GAMEDB_ID
|
||||||
|
@ -572,6 +584,7 @@ static CmdInfoRec CmdInfoRecs[] = {
|
||||||
,{ CMD_SEED, true, "seed", "random seed" }
|
,{ CMD_SEED, true, "seed", "random seed" }
|
||||||
,{ CMD_GAMESEED, true, "game-seed", "game seed (for relay play)" }
|
,{ CMD_GAMESEED, true, "game-seed", "game seed (for relay play)" }
|
||||||
,{ CMD_GAMEFILE, true, "file", "file to save to/read from" }
|
,{ CMD_GAMEFILE, true, "file", "file to save to/read from" }
|
||||||
|
,{ CMD_SAVEFAIL_PCT, true, "savefail-pct", "How often, at random, does save fail?" }
|
||||||
#ifdef USE_SQLITE
|
#ifdef USE_SQLITE
|
||||||
,{ CMD_GAMEDB_FILE, true, "game-db-file",
|
,{ CMD_GAMEDB_FILE, true, "game-db-file",
|
||||||
"sqlite3 file, android format, holding game" }
|
"sqlite3 file, android format, holding game" }
|
||||||
|
@ -1538,6 +1551,10 @@ main( int argc, char** argv )
|
||||||
case CMD_GAMEFILE:
|
case CMD_GAMEFILE:
|
||||||
mainParams.fileName = optarg;
|
mainParams.fileName = optarg;
|
||||||
break;
|
break;
|
||||||
|
case CMD_SAVEFAIL_PCT:
|
||||||
|
mainParams.saveFailPct = atoi( optarg );
|
||||||
|
break;
|
||||||
|
|
||||||
#ifdef USE_SQLITE
|
#ifdef USE_SQLITE
|
||||||
case CMD_GAMEDB_FILE:
|
case CMD_GAMEDB_FILE:
|
||||||
/* Android isn't using XWFEATURE_SEARCHLIMIT, and it writes to
|
/* Android isn't using XWFEATURE_SEARCHLIMIT, and it writes to
|
||||||
|
|
|
@ -49,6 +49,7 @@ typedef struct LaunchParams {
|
||||||
CurGameInfo gi;
|
CurGameInfo gi;
|
||||||
PlayerDicts dicts;
|
PlayerDicts dicts;
|
||||||
char* fileName;
|
char* fileName;
|
||||||
|
XP_U16 saveFailPct;
|
||||||
const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS];
|
const XP_UCHAR* playerDictNames[MAX_NUM_PLAYERS];
|
||||||
#ifdef USE_SQLITE
|
#ifdef USE_SQLITE
|
||||||
char* dbFileName;
|
char* dbFileName;
|
||||||
|
|
Loading…
Reference in a new issue