refactor: struct ptr replaces a bunch of params

This commit is contained in:
Eric House 2020-04-19 10:44:57 -07:00
parent f0444c5c1e
commit ddb01d8930
6 changed files with 45 additions and 75 deletions

View file

@ -1040,19 +1040,13 @@ typedef struct _BadWordList {
} BadWordList; } BadWordList;
static void static void
saveBadWords( const XP_UCHAR* word, XP_Bool isLegal, saveBadWords( const WNParams* wnp )
const DictionaryCtxt* XP_UNUSED(dict),
#ifdef XWFEATURE_BOARDWORDS
const MoveInfo* XP_UNUSED(movei),
XP_U16 XP_UNUSED(start), XP_U16 XP_UNUSED(end),
#endif
void* closure )
{ {
if ( !isLegal ) { if ( !wnp->isLegal ) {
BadWordList* bwlp = (BadWordList*)closure; BadWordList* bwlp = (BadWordList*)wnp->closure;
bwlp->bwi.words[bwlp->bwi.nWords] = &bwlp->buf[bwlp->index]; bwlp->bwi.words[bwlp->bwi.nWords] = &bwlp->buf[bwlp->index];
XP_STRCAT( &bwlp->buf[bwlp->index], word ); XP_STRCAT( &bwlp->buf[bwlp->index], wnp->word );
bwlp->index += XP_STRLEN(word) + 1; bwlp->index += XP_STRLEN(wnp->word) + 1;
++bwlp->bwi.nWords; ++bwlp->bwi.nWords;
} }
} /* saveBadWords */ } /* saveBadWords */

View file

@ -1104,16 +1104,10 @@ considerMove( EngineCtxt* engine, Tile* tiles, XP_S16 tileLength,
} /* considerMove */ } /* considerMove */
static void static void
countWords( const XP_UCHAR* XP_UNUSED(word), XP_Bool isLegal, countWords( const WNParams* wnp )
const DictionaryCtxt* XP_UNUSED(dict),
#ifdef XWFEATURE_BOARDWORDS
const MoveInfo* XP_UNUSED(movei), XP_U16 XP_UNUSED(start),
XP_U16 XP_UNUSED(end),
#endif
void* closure )
{ {
XP_U16* wcp = (XP_U16*)closure; XP_U16* wcp = (XP_U16*)wnp->closure;
if ( isLegal ) { if ( wnp->isLegal ) {
++*wcp; ++*wcp;
} }
} }

View file

@ -77,13 +77,7 @@ static void loadPlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
static void writePlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream, static void writePlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
const PlayerCtxt* pc ); const PlayerCtxt* pc );
static XP_U16 model_getRecentPassCount( ModelCtxt* model ); static XP_U16 model_getRecentPassCount( ModelCtxt* model );
static void recordWord( const XP_UCHAR* word, XP_Bool isLegal, static void recordWord( const WNParams* wnp );
const DictionaryCtxt* dict,
#ifdef XWFEATURE_BOARDWORDS
const MoveInfo* movei, XP_U16 start, XP_U16 end,
#endif
void* clsur );
#ifdef DEBUG #ifdef DEBUG
typedef struct _DiffTurnState { typedef struct _DiffTurnState {
XP_S16 lastPlayerNum; XP_S16 lastPlayerNum;
@ -2465,17 +2459,11 @@ typedef struct _FirstWordData {
} FirstWordData; } FirstWordData;
static void static void
getFirstWord( const XP_UCHAR* word, XP_Bool XP_UNUSED(isLegal), getFirstWord( const WNParams* wnp )
const DictionaryCtxt* XP_UNUSED(dict),
#ifdef XWFEATURE_BOARDWORDS
const MoveInfo* XP_UNUSED(movei), XP_U16 XP_UNUSED(start),
XP_U16 XP_UNUSED(end),
#endif
void* closure )
{ {
FirstWordData* data = (FirstWordData*)closure; FirstWordData* data = (FirstWordData*)wnp->closure;
if ( '\0' == data->word[0] && '\0' != word[0] ) { if ( '\0' == data->word[0] && '\0' != wnp->word[0] ) {
XP_STRCAT( data->word, word ); XP_STRCAT( data->word, wnp->word );
} }
} }
@ -2560,17 +2548,10 @@ appendWithCR( XWStreamCtxt* stream, const XP_UCHAR* word, XP_U16* counter )
} }
static void static void
recordWord( const XP_UCHAR* word, XP_Bool XP_UNUSED(isLegal), recordWord( const WNParams* wnp )
const DictionaryCtxt* XP_UNUSED(dict),
#ifdef XWFEATURE_BOARDWORDS
const MoveInfo* XP_UNUSED(movei), XP_U16 XP_UNUSED(start),
XP_U16 XP_UNUSED(end),
#endif
void* closure )
{ {
RecordWordsInfo* info = (RecordWordsInfo*)closure; RecordWordsInfo* info = (RecordWordsInfo*)wnp->closure;
appendWithCR( info->stream, word, &info->nWords ); appendWithCR( info->stream, wnp->word, &info->nWords );
} }
WordNotifierInfo* WordNotifierInfo*
@ -2591,22 +2572,20 @@ typedef struct _ListWordsThroughInfo {
} ListWordsThroughInfo; } ListWordsThroughInfo;
static void static void
listWordsThrough( const XP_UCHAR* word, XP_Bool XP_UNUSED(isLegal), listWordsThrough( const WNParams* wnp )
const DictionaryCtxt* XP_UNUSED(dict),
const MoveInfo* movei, XP_U16 start, XP_U16 end,
void* closure )
{ {
ListWordsThroughInfo* info = (ListWordsThroughInfo*)closure; ListWordsThroughInfo* info = (ListWordsThroughInfo*)wnp->closure;
const MoveInfo* movei = wnp->movei;
XP_Bool contained = XP_FALSE; XP_Bool contained = XP_FALSE;
if ( movei->isHorizontal && movei->commonCoord == info->row ) { if ( movei->isHorizontal && movei->commonCoord == info->row ) {
contained = start <= info->col && end >= info->col; contained = wnp->start <= info->col && wnp->end >= info->col;
} else if ( !movei->isHorizontal && movei->commonCoord == info->col ) { } else if ( !movei->isHorizontal && movei->commonCoord == info->col ) {
contained = start <= info->row && end >= info->row; contained = wnp->start <= info->row && wnp->end >= info->row;
} }
if ( contained ) { if ( contained ) {
appendWithCR( info->stream, word, &info->nWords ); appendWithCR( info->stream, wnp->word, &info->nWords );
} }
} }

View file

@ -282,13 +282,19 @@ void model_countAllTrayTiles( ModelCtxt* model, XP_U16* counts,
/********************* scoring ********************/ /********************* scoring ********************/
typedef void (*WordNotifierProc)( const XP_UCHAR* word, XP_Bool isLegal, typedef struct _WNParams {
const DictionaryCtxt* dict, const XP_UCHAR* word;
XP_Bool isLegal;
const DictionaryCtxt* dict;
#ifdef XWFEATURE_BOARDWORDS #ifdef XWFEATURE_BOARDWORDS
const MoveInfo* movei, XP_U16 start, const MoveInfo* movei;
XP_U16 end, XP_U16 start;
XP_U16 end;
#endif #endif
void* closure ); void* closure;
} WNParams;
typedef void (*WordNotifierProc)( const WNParams* wnp );
typedef struct WordNotifierInfo { typedef struct WordNotifierInfo {
WordNotifierProc proc; WordNotifierProc proc;
void* closure; void* closure;

View file

@ -695,11 +695,14 @@ scoreWord( const ModelCtxt* model, XP_U16 turn,
XP_UCHAR buf[(MAX_ROWS*2)+1]; XP_UCHAR buf[(MAX_ROWS*2)+1];
dict_tilesToString( dict, checkWordBuf, len, buf, dict_tilesToString( dict, checkWordBuf, len, buf,
sizeof(buf) ); sizeof(buf) );
(void)(*notifyInfo->proc)( buf, legal, dict,
WNParams wnp = { .word = buf, .isLegal =legal, .dict = dict,
#ifdef XWFEATURE_BOARDWORDS #ifdef XWFEATURE_BOARDWORDS
movei, start, end, .movei = movei, .start = start, .end = end,
#endif #endif
notifyInfo->closure ); .closure = notifyInfo->closure,
};
(void)(*notifyInfo->proc)( &wnp );
} }
if ( !!stream ) { if ( !!stream ) {

View file

@ -2613,24 +2613,18 @@ server_setGameOverListener( ServerCtxt* server, GameOverListener gol,
} /* server_setGameOverListener */ } /* server_setGameOverListener */
static void static void
storeBadWords( const XP_UCHAR* word, XP_Bool isLegal, storeBadWords( const WNParams* wnp )
const DictionaryCtxt* dict,
#ifdef XWFEATURE_BOARDWORDS
const MoveInfo* XP_UNUSED(movei), XP_U16 XP_UNUSED(start),
XP_U16 XP_UNUSED(end),
#endif
void* closure )
{ {
if ( !isLegal ) { if ( !wnp->isLegal ) {
ServerCtxt* server = (ServerCtxt*)closure; ServerCtxt* server = (ServerCtxt*)wnp->closure;
const XP_UCHAR* name = dict_getShortName( dict ); const XP_UCHAR* name = dict_getShortName( wnp->dict );
XP_LOGF( "storeBadWords called with \"%s\" (name=%s)", word, name ); XP_LOGF( "storeBadWords called with \"%s\" (name=%s)", wnp->word, name );
if ( NULL == server->illegalWordInfo.dictName ) { if ( NULL == server->illegalWordInfo.dictName ) {
server->illegalWordInfo.dictName = copyString( server->mpool, name ); server->illegalWordInfo.dictName = copyString( server->mpool, name );
} }
server->illegalWordInfo.words[server->illegalWordInfo.nWords++] server->illegalWordInfo.words[server->illegalWordInfo.nWords++]
= copyString( server->mpool, word ); = copyString( server->mpool, wnp->word );
} }
} /* storeBadWords */ } /* storeBadWords */