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;
static void
saveBadWords( const XP_UCHAR* word, XP_Bool isLegal,
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 )
saveBadWords( const WNParams* wnp )
{
if ( !isLegal ) {
BadWordList* bwlp = (BadWordList*)closure;
if ( !wnp->isLegal ) {
BadWordList* bwlp = (BadWordList*)wnp->closure;
bwlp->bwi.words[bwlp->bwi.nWords] = &bwlp->buf[bwlp->index];
XP_STRCAT( &bwlp->buf[bwlp->index], word );
bwlp->index += XP_STRLEN(word) + 1;
XP_STRCAT( &bwlp->buf[bwlp->index], wnp->word );
bwlp->index += XP_STRLEN(wnp->word) + 1;
++bwlp->bwi.nWords;
}
} /* saveBadWords */

View file

@ -1104,16 +1104,10 @@ considerMove( EngineCtxt* engine, Tile* tiles, XP_S16 tileLength,
} /* considerMove */
static void
countWords( const XP_UCHAR* XP_UNUSED(word), XP_Bool isLegal,
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 )
countWords( const WNParams* wnp )
{
XP_U16* wcp = (XP_U16*)closure;
if ( isLegal ) {
XP_U16* wcp = (XP_U16*)wnp->closure;
if ( wnp->isLegal ) {
++*wcp;
}
}

View file

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

View file

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

View file

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