mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-26 09:58:20 +01:00
fix bugs around new variable-length tiles array changes, and otherwise
improve storage of col/row data so that test runs succeed with MAX_COLS of 16 or 32. Still to do: test mid-game upgrade.
This commit is contained in:
parent
42d1d2f7bd
commit
adb9b3853d
6 changed files with 146 additions and 118 deletions
|
@ -207,6 +207,12 @@ board_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
|
|||
BoardCtxt* board;
|
||||
XP_U16 ii;
|
||||
XP_U16 version = stream_getVersion( stream );
|
||||
XP_U16 nColsNBits;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
nColsNBits = 16 > model_numCols(model) ? NUMCOLS_NBITS_4 : NUMCOLS_NBITS_5;
|
||||
#else
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
board = board_make( MPPARM(mpool) model, server, draw, util );
|
||||
|
||||
|
@ -238,8 +244,8 @@ board_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
|
|||
for ( ii = 0; ii < nPlayers; ++ii ) {
|
||||
PerTurnInfo* pti = &board->pti[ii];
|
||||
BoardArrow* arrow = &pti->boardArrow;
|
||||
arrow->col = (XP_U8)stream_getBits( stream, NUMCOLS_NBITS );
|
||||
arrow->row = (XP_U8)stream_getBits( stream, NUMCOLS_NBITS );
|
||||
arrow->col = (XP_U8)stream_getBits( stream, nColsNBits );
|
||||
arrow->row = (XP_U8)stream_getBits( stream, nColsNBits );
|
||||
arrow->vert = (XP_Bool)stream_getBits( stream, 1 );
|
||||
arrow->visible = (XP_Bool)stream_getBits( stream, 1 );
|
||||
|
||||
|
@ -284,7 +290,15 @@ board_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model,
|
|||
void
|
||||
board_writeToStream( BoardCtxt* board, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_U16 nPlayers, i;
|
||||
XP_U16 nPlayers, ii;
|
||||
XP_U16 nColsNBits;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
nColsNBits = 16 > model_numCols(board->model) ? NUMCOLS_NBITS_4
|
||||
: NUMCOLS_NBITS_5;
|
||||
#else
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
|
||||
stream_putBits( stream, 4, board->sd[SCROLL_H].offset );
|
||||
stream_putBits( stream, 4, board->zoomCount );
|
||||
|
@ -304,11 +318,11 @@ board_writeToStream( BoardCtxt* board, XWStreamCtxt* stream )
|
|||
XP_ASSERT( !!board->server );
|
||||
nPlayers = board->gi->nPlayers;
|
||||
|
||||
for ( i = 0; i < nPlayers; ++i ) {
|
||||
PerTurnInfo* pti = &board->pti[i];
|
||||
for ( ii = 0; ii < nPlayers; ++ii ) {
|
||||
PerTurnInfo* pti = &board->pti[ii];
|
||||
BoardArrow* arrow = &pti->boardArrow;
|
||||
stream_putBits( stream, NUMCOLS_NBITS, arrow->col );
|
||||
stream_putBits( stream, NUMCOLS_NBITS, arrow->row );
|
||||
stream_putBits( stream, nColsNBits, arrow->col );
|
||||
stream_putBits( stream, nColsNBits, arrow->row );
|
||||
stream_putBits( stream, 1, arrow->vert );
|
||||
stream_putBits( stream, 1, arrow->visible );
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE"; -*- */
|
||||
/* -*- compile-command: "cd ../linux && make -j3 MEMDEBUG=TRUE"; -*- */
|
||||
/*
|
||||
* Copyright 2001-2009 by Eric House (xwords@eehouse.org). All rights
|
||||
* Copyright 2001-2011 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -90,7 +90,7 @@ game_makeNewGame( MPFORMAL XWGame* game, CurGameInfo* gi,
|
|||
gi->gameID = gameID;
|
||||
|
||||
game->model = model_make( MPPARM(mpool) (DictionaryCtxt*)NULL, NULL, util,
|
||||
gi->boardSize, gi->boardSize );
|
||||
gi->boardSize );
|
||||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
if ( gi->serverRole != SERVER_STANDALONE ) {
|
||||
|
@ -162,7 +162,7 @@ game_reset( MPFORMAL XWGame* game, CurGameInfo* gi,
|
|||
# endif
|
||||
#endif
|
||||
|
||||
model_init( game->model, gi->boardSize, gi->boardSize );
|
||||
model_setSize( game->model, gi->boardSize );
|
||||
server_reset( game->server,
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
game->comms
|
||||
|
@ -259,6 +259,7 @@ game_saveToStream( const XWGame* game, const CurGameInfo* gi,
|
|||
XWStreamCtxt* stream )
|
||||
{
|
||||
stream_putU8( stream, CUR_STREAM_VERS );
|
||||
stream_setVersion( stream, CUR_STREAM_VERS );
|
||||
|
||||
gi_writeToStream( stream, gi );
|
||||
|
||||
|
@ -426,10 +427,13 @@ gi_readFromStream( MPFORMAL XWStreamCtxt* stream, CurGameInfo* gi )
|
|||
XP_U16 ii;
|
||||
XP_UCHAR* str;
|
||||
XP_U16 strVersion = stream_getVersion( stream );
|
||||
XP_U16 nColsNBits;
|
||||
XP_ASSERT( 0 < strVersion );
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
XP_U16 nColsNBits = STREAM_VERS_BIGBOARD > strVersion ? 4 : NUMCOLS_NBITS;
|
||||
nColsNBits = STREAM_VERS_BIGBOARD > strVersion ? NUMCOLS_NBITS_4
|
||||
: NUMCOLS_NBITS_5;
|
||||
#else
|
||||
XP_U16 nColsNBits = NUMCOLS_NBITS;
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
str = stringFromStream( mpool, stream );
|
||||
|
@ -495,16 +499,16 @@ gi_writeToStream( XWStreamCtxt* stream, const CurGameInfo* gi )
|
|||
{
|
||||
const LocalPlayer* pl;
|
||||
XP_U16 ii;
|
||||
|
||||
XP_U16 nColsNBits;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
XP_U16 strVersion = stream_getVersion( stream );
|
||||
XP_ASSERT( STREAM_SAVE_PREVWORDS <= strVersion );
|
||||
XP_U16 nColsNBits = STREAM_VERS_BIGBOARD > strVersion ? 4 : NUMCOLS_NBITS;
|
||||
nColsNBits = STREAM_VERS_BIGBOARD > strVersion ? NUMCOLS_NBITS_4
|
||||
: NUMCOLS_NBITS_5;
|
||||
#else
|
||||
XP_U16 nColsNBits = NUMCOLS_NBITS;
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
|
||||
stringToStream( stream, gi->dictName );
|
||||
|
||||
stream_putBits( stream, NPLAYERS_NBITS, gi->nPlayers );
|
||||
|
|
|
@ -71,9 +71,10 @@ static void buildModelFromStack( ModelCtxt* model, StackCtxt* stack,
|
|||
MovePrintFuncPre mpfpr,
|
||||
MovePrintFuncPost mpfpo, void* closure );
|
||||
static void setPendingCounts( ModelCtxt* model, XP_S16 turn );
|
||||
static void loadPlayerCtxt( XWStreamCtxt* stream, XP_U16 version,
|
||||
PlayerCtxt* pc );
|
||||
static void writePlayerCtxt( XWStreamCtxt* stream, PlayerCtxt* pc );
|
||||
static void loadPlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
|
||||
XP_U16 version, PlayerCtxt* pc );
|
||||
static void writePlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
|
||||
PlayerCtxt* pc );
|
||||
static XP_U16 model_getRecentPassCount( ModelCtxt* model );
|
||||
static XP_Bool recordWord( const XP_UCHAR* word, XP_Bool isLegal,
|
||||
#ifdef XWFEATURE_BOARDWORDS
|
||||
|
@ -85,13 +86,10 @@ static XP_Bool recordWord( const XP_UCHAR* word, XP_Bool isLegal,
|
|||
*
|
||||
****************************************************************************/
|
||||
ModelCtxt*
|
||||
model_make( MPFORMAL DictionaryCtxt* dict,
|
||||
const PlayerDicts* dicts, XW_UtilCtxt* util, XP_U16 nCols,
|
||||
XP_U16 nRows )
|
||||
model_make( MPFORMAL DictionaryCtxt* dict, const PlayerDicts* dicts,
|
||||
XW_UtilCtxt* util, XP_U16 nCols )
|
||||
{
|
||||
ModelCtxt* result;
|
||||
XP_U16 size = sizeof(*result) + TILES_SIZE(result, nCols);
|
||||
result = (ModelCtxt*)XP_MALLOC( mpool, size );
|
||||
ModelCtxt* result = (ModelCtxt*)XP_MALLOC( mpool, sizeof( *result ) );
|
||||
if ( result != NULL ) {
|
||||
XP_MEMSET( result, 0, sizeof(*result) );
|
||||
MPASSIGN(result->vol.mpool, mpool);
|
||||
|
@ -100,7 +98,7 @@ model_make( MPFORMAL DictionaryCtxt* dict,
|
|||
result->vol.wni.proc = recordWord;
|
||||
result->vol.wni.closure = &result->vol.rwi;
|
||||
|
||||
model_init( result, nCols, nRows );
|
||||
model_setSize( result, nCols );
|
||||
|
||||
XP_ASSERT( !!util->gameInfo );
|
||||
result->vol.gi = util->gameInfo;
|
||||
|
@ -121,18 +119,21 @@ model_makeFromStream( MPFORMAL XWStreamCtxt* stream, DictionaryCtxt* dict,
|
|||
XP_U16 ii;
|
||||
XP_Bool hasDict;
|
||||
XP_U16 nPlayers;
|
||||
XP_U16 nColsNBits;
|
||||
XP_U16 version = stream_getVersion( stream );
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
nColsNBits = STREAM_VERS_BIGBOARD > version ? 4 : NUMCOLS_NBITS;
|
||||
#else
|
||||
nColsNBits = NUMCOLS_NBITS;
|
||||
#endif
|
||||
|
||||
XP_ASSERT( !!dict || !!dicts );
|
||||
|
||||
nCols = (XP_U16)stream_getBits( stream, nColsNBits );
|
||||
nRows = (XP_U16)stream_getBits( stream, nColsNBits );
|
||||
if ( 0 ) {
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
} else if ( STREAM_VERS_BIGBOARD <= version ) {
|
||||
nCols = (XP_U16)stream_getBits( stream, NUMCOLS_NBITS_5 );
|
||||
nRows = nCols;
|
||||
#endif
|
||||
} else {
|
||||
nCols = (XP_U16)stream_getBits( stream, NUMCOLS_NBITS_4 );
|
||||
nRows = (XP_U16)stream_getBits( stream, NUMCOLS_NBITS_4 );
|
||||
}
|
||||
XP_ASSERT( MAX_COLS >= nCols );
|
||||
|
||||
hasDict = (version >= STREAM_VERS_MODEL_NO_DICT)
|
||||
? XP_FALSE : stream_getBits( stream, 1 );
|
||||
|
@ -144,18 +145,18 @@ model_makeFromStream( MPFORMAL XWStreamCtxt* stream, DictionaryCtxt* dict,
|
|||
dict_destroy( savedDict );
|
||||
}
|
||||
|
||||
model = model_make( MPPARM(mpool) dict, dicts, util, nCols, nRows );
|
||||
model = model_make( MPPARM(mpool) dict, dicts, util, nCols );
|
||||
model->nPlayers = nPlayers;
|
||||
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
if ( STREAM_VERS_BIGBOARD <= version ) {
|
||||
model->nBonuses = stream_getBits( stream, 7 );
|
||||
if ( 0 < model->nBonuses ) {
|
||||
model->bonuses =
|
||||
model->vol.nBonuses = stream_getBits( stream, 7 );
|
||||
if ( 0 < model->vol.nBonuses ) {
|
||||
model->vol.bonuses =
|
||||
XP_MALLOC( model->vol.mpool,
|
||||
model->nBonuses * sizeof( model->bonuses[0] ) );
|
||||
for ( ii = 0; ii < model->nBonuses; ++ii ) {
|
||||
model->bonuses[ii] = stream_getBits( stream, 4 );
|
||||
model->vol.nBonuses * sizeof( model->vol.bonuses[0] ) );
|
||||
for ( ii = 0; ii < model->vol.nBonuses; ++ii ) {
|
||||
model->vol.bonuses[ii] = stream_getBits( stream, 4 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +170,7 @@ model_makeFromStream( MPFORMAL XWStreamCtxt* stream, DictionaryCtxt* dict,
|
|||
NULL );
|
||||
|
||||
for ( ii = 0; ii < model->nPlayers; ++ii ) {
|
||||
loadPlayerCtxt( stream, version, &model->players[ii] );
|
||||
loadPlayerCtxt( model, stream, version, &model->players[ii] );
|
||||
setPendingCounts( model, ii );
|
||||
invalidateScore( model, ii );
|
||||
}
|
||||
|
@ -181,24 +182,28 @@ void
|
|||
model_writeToStream( ModelCtxt* model, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_U16 ii;
|
||||
|
||||
stream_putBits( stream, NUMCOLS_NBITS, model->nCols );
|
||||
stream_putBits( stream, NUMCOLS_NBITS, model->nRows );
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
XP_ASSERT( STREAM_VERS_BIGBOARD <= stream_getVersion( stream ) );
|
||||
stream_putBits( stream, NUMCOLS_NBITS_5, model->nCols );
|
||||
#else
|
||||
stream_putBits( stream, NUMCOLS_NBITS_4, model->nCols );
|
||||
stream_putBits( stream, NUMCOLS_NBITS_4, model->nRows );
|
||||
#endif
|
||||
|
||||
/* we have two bits for nPlayers, so range must be 0..3, not 1..4 */
|
||||
stream_putBits( stream, NPLAYERS_NBITS, model->nPlayers );
|
||||
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
stream_putBits( stream, 7, model->nBonuses );
|
||||
for ( ii = 0; ii < model->nBonuses; ++ii ) {
|
||||
stream_putBits( stream, 4, model->bonuses[ii] );
|
||||
stream_putBits( stream, 7, model->vol.nBonuses );
|
||||
for ( ii = 0; ii < model->vol.nBonuses; ++ii ) {
|
||||
stream_putBits( stream, 4, model->vol.bonuses[ii] );
|
||||
}
|
||||
#endif
|
||||
|
||||
stack_writeToStream( model->vol.stack, stream );
|
||||
|
||||
for ( ii = 0; ii < model->nPlayers; ++ii ) {
|
||||
writePlayerCtxt( stream, &model->players[ii] );
|
||||
writePlayerCtxt( model, stream, &model->players[ii] );
|
||||
}
|
||||
} /* model_writeToStream */
|
||||
|
||||
|
@ -244,35 +249,44 @@ model_writeToTextStream( const ModelCtxt* model, XWStreamCtxt* stream )
|
|||
#endif
|
||||
|
||||
void
|
||||
model_init( ModelCtxt* model, XP_U16 nCols, XP_U16 nRows )
|
||||
model_setSize( ModelCtxt* model, XP_U16 nCols )
|
||||
{
|
||||
ModelVolatiles vol = model->vol; /* save vol so we don't wipe it out */
|
||||
XP_U16 oldSize = model->nCols; /* zero when called from model_make() */
|
||||
|
||||
XP_ASSERT( MAX_COLS >= nCols );
|
||||
XP_ASSERT( model != NULL );
|
||||
XP_MEMSET( model, 0, sizeof( *model ) );
|
||||
XP_MEMSET( &model->tiles, TILE_EMPTY_BIT, TILES_SIZE(model, nCols) );
|
||||
|
||||
model->nCols = nCols;
|
||||
model->nRows = nRows;
|
||||
|
||||
model->nRows = nCols;
|
||||
model->vol = vol;
|
||||
|
||||
if ( oldSize != nCols ) {
|
||||
if ( !!model->vol.tiles ) {
|
||||
XP_FREE( model->vol.mpool, model->vol.tiles );
|
||||
}
|
||||
model->vol.tiles = XP_MALLOC( model->vol.mpool, TILES_SIZE(model, nCols) );
|
||||
}
|
||||
XP_MEMSET( model->vol.tiles, TILE_EMPTY_BIT, TILES_SIZE(model, nCols) );
|
||||
|
||||
if ( !!model->vol.stack ) {
|
||||
stack_init( model->vol.stack );
|
||||
} else {
|
||||
model->vol.stack = stack_make( MPPARM(model->vol.mpool)
|
||||
util_getVTManager(model->vol.util));
|
||||
}
|
||||
} /* model_init */
|
||||
} /* model_setSize */
|
||||
|
||||
void
|
||||
model_destroy( ModelCtxt* model )
|
||||
{
|
||||
stack_destroy( model->vol.stack );
|
||||
/* is this it!? */
|
||||
if ( !!model->bonuses ) {
|
||||
XP_FREE( model->vol.mpool, model->bonuses );
|
||||
if ( !!model->vol.bonuses ) {
|
||||
XP_FREE( model->vol.mpool, model->vol.bonuses );
|
||||
}
|
||||
XP_FREE( model->vol.mpool, model->vol.tiles );
|
||||
XP_FREE( model->vol.mpool, model );
|
||||
} /* model_destroy */
|
||||
|
||||
|
@ -290,42 +304,28 @@ model_setSquareBonuses( ModelCtxt* model, XWBonusType* bonuses, XP_U16 nBonuses
|
|||
XP_ASSERT( wantLen == nBonuses );
|
||||
#endif
|
||||
|
||||
if ( !!model->bonuses ) {
|
||||
XP_FREE( model->vol.mpool, model->bonuses );
|
||||
if ( !!model->vol.bonuses ) {
|
||||
XP_FREE( model->vol.mpool, model->vol.bonuses );
|
||||
}
|
||||
model->bonuses = XP_MALLOC( model->vol.mpool,
|
||||
nBonuses * sizeof(model->bonuses[0]) );
|
||||
XP_MEMCPY( model->bonuses, bonuses, nBonuses * sizeof(model->bonuses[0]) );
|
||||
model->nBonuses = nBonuses;
|
||||
model->vol.bonuses = XP_MALLOC( model->vol.mpool,
|
||||
nBonuses * sizeof(model->vol.bonuses[0]) );
|
||||
XP_MEMCPY( model->vol.bonuses, bonuses,
|
||||
nBonuses * sizeof(model->vol.bonuses[0]) );
|
||||
model->vol.nBonuses = nBonuses;
|
||||
}
|
||||
|
||||
static void
|
||||
borrowSquareBonuses( ModelCtxt* dest, const ModelCtxt* src )
|
||||
{
|
||||
XP_ASSERT( !dest->bonuses );
|
||||
dest->bonuses = src->bonuses;
|
||||
dest->nBonuses = src->nBonuses;
|
||||
}
|
||||
|
||||
static void
|
||||
returnSquareBonuses( ModelCtxt* dest )
|
||||
{
|
||||
dest->bonuses = NULL;
|
||||
dest->nBonuses = 0;
|
||||
}
|
||||
#else
|
||||
# define borrowSquareBonuses(d,s)
|
||||
# define returnSquareBonuses(d)
|
||||
#endif
|
||||
|
||||
XWBonusType
|
||||
model_getSquareBonus( const ModelCtxt* model, XP_U16 col, XP_U16 row )
|
||||
{
|
||||
XWBonusType result = BONUS_NONE;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
const ModelCtxt* bonusOwner = model->loaner? model->loaner : model;
|
||||
#endif
|
||||
|
||||
if ( 0 ) {
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
} else if ( !!model->bonuses ) {
|
||||
} else if ( !!bonusOwner->vol.bonuses ) {
|
||||
XP_U16 nCols = model_numCols( model );
|
||||
XP_U16 ii;
|
||||
if ( col > (nCols/2) ) {
|
||||
|
@ -343,8 +343,8 @@ model_getSquareBonus( const ModelCtxt* model, XP_U16 col, XP_U16 row )
|
|||
col += ii;
|
||||
}
|
||||
|
||||
if ( col < model->nBonuses ) {
|
||||
result = model->bonuses[col];
|
||||
if ( col < bonusOwner->vol.nBonuses ) {
|
||||
result = bonusOwner->vol.bonuses[col];
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
|
@ -694,7 +694,7 @@ setModelTileRaw( ModelCtxt* model, XP_U16 col, XP_U16 row, CellTile tile )
|
|||
{
|
||||
XP_ASSERT( col < model->nCols );
|
||||
XP_ASSERT( row < model->nRows );
|
||||
model->tiles[(row*model->nCols) + col] = tile;
|
||||
model->vol.tiles[(row*model->nCols) + col] = tile;
|
||||
} /* model_setTile */
|
||||
|
||||
static CellTile
|
||||
|
@ -704,7 +704,7 @@ getModelTileRaw( const ModelCtxt* model, XP_U16 col, XP_U16 row )
|
|||
XP_U16 nCols = model->nCols;
|
||||
XP_ASSERT( model->nRows == nCols );
|
||||
if ( col < nCols && row < nCols ) {
|
||||
tile = model->tiles[(row*nCols) + col];
|
||||
tile = model->vol.tiles[(row*nCols) + col];
|
||||
} else {
|
||||
tile = TILE_EMPTY_BIT;
|
||||
}
|
||||
|
@ -932,11 +932,12 @@ model_currentMoveToStream( ModelCtxt* model, XP_S16 turn,
|
|||
{
|
||||
PlayerCtxt* player;
|
||||
XP_S16 numTiles;
|
||||
XP_U16 nColsNBits;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
XP_U16 version = stream_getVersion( stream );
|
||||
XP_U16 nColsNBits = STREAM_VERS_BIGBOARD > version ? 4 : NUMCOLS_NBITS;
|
||||
nColsNBits = 16 <= model_numCols( model ) ? NUMCOLS_NBITS_5
|
||||
: NUMCOLS_NBITS_4;
|
||||
#else
|
||||
XP_U16 nColsNBits = NUMCOLS_NBITS;
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
XP_ASSERT( turn >= 0 );
|
||||
|
@ -972,14 +973,14 @@ model_makeTurnFromStream( ModelCtxt* model, XP_U16 playerNum,
|
|||
{
|
||||
XP_U16 numTiles, ii;
|
||||
Tile blank = dict_getBlankTile( model_getDictionary(model) );
|
||||
XP_U16 nColsNBits;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
XP_U16 version = stream_getVersion( stream );
|
||||
XP_U16 nColsNBits = STREAM_VERS_BIGBOARD > version ? 4 : NUMCOLS_NBITS;
|
||||
nColsNBits = 16 <= model_numCols( model ) ? NUMCOLS_NBITS_5
|
||||
: NUMCOLS_NBITS_4;
|
||||
#else
|
||||
XP_U16 nColsNBits = NUMCOLS_NBITS;
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
|
||||
model_resetCurrentTurn( model, playerNum );
|
||||
|
||||
numTiles = (XP_U16)stream_getBits( stream, NTILES_NBITS );
|
||||
|
@ -2058,10 +2059,9 @@ makeTmpModel( ModelCtxt* model, XWStreamCtxt* stream,
|
|||
{
|
||||
ModelCtxt* tmpModel = model_make( MPPARM(model->vol.mpool)
|
||||
model_getDictionary(model), NULL,
|
||||
model->vol.util, model_numCols(model),
|
||||
model_numRows(model));
|
||||
model->vol.util, model_numCols(model) );
|
||||
tmpModel->loaner = model;
|
||||
model_setNPlayers( tmpModel, model->nPlayers );
|
||||
borrowSquareBonuses( tmpModel, model );
|
||||
|
||||
buildModelFromStack( tmpModel, model->vol.stack, XP_FALSE, 0, stream,
|
||||
(WordNotifierInfo*)NULL, mpf_pre, mpf_post, closure );
|
||||
|
@ -2083,7 +2083,6 @@ model_writeGameHistory( ModelCtxt* model, XWStreamCtxt* stream,
|
|||
|
||||
tmpModel = makeTmpModel( model, stream, printMovePre, printMovePost,
|
||||
&closure );
|
||||
returnSquareBonuses( tmpModel );
|
||||
model_destroy( tmpModel );
|
||||
|
||||
if ( gameOver ) {
|
||||
|
@ -2343,14 +2342,18 @@ model_getPlayersLastScore( ModelCtxt* model, XP_S16 player,
|
|||
} /* model_getPlayersLastScore */
|
||||
|
||||
static void
|
||||
loadPlayerCtxt( XWStreamCtxt* stream, XP_U16 version, PlayerCtxt* pc )
|
||||
loadPlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream, XP_U16 version,
|
||||
PlayerCtxt* pc )
|
||||
{
|
||||
PendingTile* pt;
|
||||
XP_U16 nTiles;
|
||||
XP_U16 nColsNBits;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
XP_U16 nColsNBits = STREAM_VERS_BIGBOARD > version ? 4 : NUMCOLS_NBITS;
|
||||
nColsNBits = 16 <= model_numCols( model ) ? NUMCOLS_NBITS_5
|
||||
: NUMCOLS_NBITS_4;
|
||||
#else
|
||||
XP_U16 nColsNBits = NUMCOLS_NBITS;
|
||||
XP_USE(model);
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
pc->curMoveValid = stream_getBits( stream, 1 );
|
||||
|
@ -2377,10 +2380,18 @@ loadPlayerCtxt( XWStreamCtxt* stream, XP_U16 version, PlayerCtxt* pc )
|
|||
} /* loadPlayerCtxt */
|
||||
|
||||
static void
|
||||
writePlayerCtxt( XWStreamCtxt* stream, PlayerCtxt* pc )
|
||||
writePlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream, PlayerCtxt* pc )
|
||||
{
|
||||
XP_U16 nTiles;
|
||||
PendingTile* pt;
|
||||
XP_U16 nColsNBits;
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
nColsNBits = 16 <= model_numCols( model ) ? NUMCOLS_NBITS_5
|
||||
: NUMCOLS_NBITS_4;
|
||||
#else
|
||||
XP_USE(model);
|
||||
nColsNBits = NUMCOLS_NBITS_4;
|
||||
#endif
|
||||
|
||||
stream_putBits( stream, 1, pc->curMoveValid );
|
||||
|
||||
|
@ -2391,8 +2402,8 @@ writePlayerCtxt( XWStreamCtxt* stream, PlayerCtxt* pc )
|
|||
|
||||
nTiles = pc->nPending + pc->nUndone;
|
||||
for ( pt = pc->pendingTiles; nTiles-- > 0; ++pt ) {
|
||||
stream_putBits( stream, NUMCOLS_NBITS, pt->col );
|
||||
stream_putBits( stream, NUMCOLS_NBITS, pt->row );
|
||||
stream_putBits( stream, nColsNBits, pt->col );
|
||||
stream_putBits( stream, nColsNBits, pt->row );
|
||||
stream_putBits( stream, 7, pt->tile );
|
||||
}
|
||||
} /* writePlayerCtxt */
|
||||
|
|
|
@ -29,10 +29,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if MAX_COLS <= 16
|
||||
# define NUMCOLS_NBITS 4
|
||||
#elif MAX_COLS <= 32
|
||||
# define NUMCOLS_NBITS 5
|
||||
#define NUMCOLS_NBITS_4 4
|
||||
#if 16 < MAX_COLS && MAX_COLS <= 32
|
||||
# define NUMCOLS_NBITS_5 5
|
||||
#endif
|
||||
|
||||
#ifdef EIGHT_TILES
|
||||
|
@ -101,7 +100,7 @@ typedef XP_U8 TileBit; /* bits indicating selection of tiles in tray */
|
|||
|
||||
|
||||
ModelCtxt* model_make( MPFORMAL DictionaryCtxt* dict, const PlayerDicts* dicts,
|
||||
XW_UtilCtxt* util, XP_U16 nCols, XP_U16 nRows );
|
||||
XW_UtilCtxt* util, XP_U16 nCols );
|
||||
|
||||
ModelCtxt* model_makeFromStream( MPFORMAL XWStreamCtxt* stream,
|
||||
DictionaryCtxt* dict, const PlayerDicts* dicts,
|
||||
|
@ -113,7 +112,7 @@ void model_writeToStream( ModelCtxt* model, XWStreamCtxt* stream );
|
|||
void model_writeToTextStream( const ModelCtxt* model, XWStreamCtxt* stream );
|
||||
#endif
|
||||
|
||||
void model_init( ModelCtxt* model, XP_U16 nCols, XP_U16 nRows );
|
||||
void model_setSize( ModelCtxt* model, XP_U16 boardSize );
|
||||
void model_destroy( ModelCtxt* model );
|
||||
void model_setNPlayers( ModelCtxt* model, XP_U16 numPlayers );
|
||||
XP_U16 model_getNPlayers( const ModelCtxt* model );
|
||||
|
|
|
@ -64,6 +64,11 @@ typedef struct ModelVolatiles {
|
|||
RecordWordsInfo rwi;
|
||||
WordNotifierInfo wni;
|
||||
XP_U16 nTilesOnBoard;
|
||||
CellTile* tiles;
|
||||
|
||||
XP_U16 nBonuses;
|
||||
XWBonusType* bonuses;
|
||||
|
||||
MPSLOT
|
||||
} ModelVolatiles;
|
||||
|
||||
|
@ -75,13 +80,11 @@ struct ModelCtxt {
|
|||
XP_U16 nPlayers;
|
||||
XP_U16 nCols;
|
||||
XP_U16 nRows;
|
||||
XP_U16 nBonuses;
|
||||
XWBonusType* bonuses;
|
||||
|
||||
CellTile tiles[];
|
||||
const ModelCtxt* loaner; /* allows sharing bonuses */
|
||||
};
|
||||
|
||||
#define TILES_SIZE(m,nc) ((nc) * (nc) * sizeof((m)->tiles[0]))
|
||||
#define TILES_SIZE(m,nc) ((nc) * (nc) * sizeof((m)->vol.tiles[0]))
|
||||
|
||||
void invalidateScore( ModelCtxt* model, XP_S16 player );
|
||||
XP_Bool tilesInLine( ModelCtxt* model, XP_S16 turn, XP_Bool* isHorizontal );
|
||||
|
|
|
@ -1199,8 +1199,7 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
XP_ASSERT( channelNo != 0 );
|
||||
server->nv.addresses[0].channelNo = channelNo;
|
||||
|
||||
/* PENDING init's a bit harsh for setting the size */
|
||||
model_init( model, nCols, nCols );
|
||||
model_setSize( model, nCols );
|
||||
|
||||
nPlayers = localGI.nPlayers;
|
||||
XP_STATUSF( "reading in %d players", localGI.nPlayers );
|
||||
|
@ -1418,9 +1417,6 @@ messageStreamWithHeader( ServerCtxt* server, XP_U16 devIndex, XW_Proto code )
|
|||
printCode("making", code);
|
||||
|
||||
stream = util_makeStreamFromAddr( server->vol.util, channelNo );
|
||||
#ifdef STREAM_VERS_BIGBOARD
|
||||
stream_setVersion( stream, server->nv.streamVersion );
|
||||
#endif
|
||||
stream_open( stream );
|
||||
writeProto( server, stream, code );
|
||||
|
||||
|
@ -2528,6 +2524,7 @@ writeProto( const ServerCtxt* server, XWStreamCtxt* stream, XW_Proto proto )
|
|||
stream_putBits( stream, XWPROTO_NBITS, XWPROTO_NEW_PROTO );
|
||||
stream_putBits( stream, 8, CUR_STREAM_VERS );
|
||||
}
|
||||
stream_setVersion( stream, server->nv.streamVersion );
|
||||
#else
|
||||
XP_USE(server);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue