From 86d5778ec37fb90e3b7480f8745aea6f92decb3d Mon Sep 17 00:00:00 2001 From: Andy2 Date: Mon, 14 Nov 2011 18:21:41 -0800 Subject: [PATCH] remove 16x16 limitation on board size, replacing with 32x32. Change is enabled by a compile-time flag so Android needn't follow yet. --- xwords4/common/board.c | 4 ++-- xwords4/common/boarddrw.c | 6 +++--- xwords4/common/boardp.h | 2 +- xwords4/common/comtypes.h | 12 +++++++++++- xwords4/common/game.c | 7 +++++-- xwords4/common/game.h | 7 ++++++- xwords4/common/model.c | 21 +++++++++++++++------ xwords4/common/model.h | 6 +++++- xwords4/linux/Makefile | 1 + xwords4/linux/linuxutl.c | 5 +++-- 10 files changed, 52 insertions(+), 19 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index f877b0a03..1615beb3d 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -1198,7 +1198,7 @@ invalPerimeter( BoardCtxt* board ) ScrollData* hsd = &board->sd[SCROLL_H]; XP_U16 firstCol = hsd->offset; XP_U16 lastCol = hsd->lastVisible; - XP_U16 firstAndLast = (1 << lastCol) | (1 << firstCol); + RowFlags firstAndLast = (1 << lastCol) | (1 << firstCol); ScrollData* vsd = &board->sd[SCROLL_V]; XP_U16 firstRow = vsd->offset; XP_U16 lastRow = vsd->lastVisible; @@ -1588,7 +1588,7 @@ invalReflection( BoardCtxt* board ) while ( nRows-- ) { XP_U16 nCols; - XP_U16 redrawFlag = board->redrawFlags[nRows]; + RowFlags redrawFlag = board->redrawFlags[nRows]; if ( !redrawFlag ) { continue; /* nothing set this row */ } diff --git a/xwords4/common/boarddrw.c b/xwords4/common/boarddrw.c index 8b29038fe..123c5616b 100644 --- a/xwords4/common/boarddrw.c +++ b/xwords4/common/boarddrw.c @@ -299,11 +299,11 @@ drawBoard( BoardCtxt* board ) nVisCols = model_numCols( model ) - board->zoomCount; for ( row = vsd->offset; row <= vsd->lastVisible; ++row ) { - XP_U16 rowFlags = board->redrawFlags[row]; + RowFlags rowFlags = board->redrawFlags[row]; if ( rowFlags != 0 ) { - XP_U16 failedBits = 0; + RowFlags failedBits = 0; for ( col = 0; col < nVisCols; ++col ) { - XP_U16 colMask = 1 << (col + hsd->offset); + RowFlags colMask = 1 << (col + hsd->offset); if ( 0 != (rowFlags & colMask) ) { if ( !drawCell( board, col + hsd->offset, row, XP_TRUE )) { diff --git a/xwords4/common/boardp.h b/xwords4/common/boardp.h index d9a50015b..10b4a9f0f 100644 --- a/xwords4/common/boardp.h +++ b/xwords4/common/boardp.h @@ -157,7 +157,7 @@ struct BoardCtxt { XP_S16 timerStoppedTurn; #endif - XP_U16 redrawFlags[MAX_ROWS]; + RowFlags redrawFlags[MAX_ROWS]; XP_Rect boardBounds; XP_U16 heightAsSet; diff --git a/xwords4/common/comtypes.h b/xwords4/common/comtypes.h index 10e38a518..c95cecdba 100644 --- a/xwords4/common/comtypes.h +++ b/xwords4/common/comtypes.h @@ -115,7 +115,9 @@ typedef enum { } XWTimerReason; #define MAX_NUM_PLAYERS 4 -#define MAX_ROWS 16 +#ifndef MAX_ROWS +# define MAX_ROWS 16 +#endif #define MAX_COLS MAX_ROWS #ifdef EIGHT_TILES # define MAX_TRAY_TILES 8 @@ -127,6 +129,14 @@ typedef enum { #define NPLAYERS_NBITS 3 #define EMPTIED_TRAY_BONUS 50 +#if MAX_ROWS <= 16 +typedef XP_U16 RowFlags; +#elif MAX_ROWS <= 32 +typedef XP_U32 RowFlags; +#else + error +#endif + /* I need a way to communiate prefs to common/ code. For now, though, I'll * leave storage of these values up to the platforms. First, because I don't * want to deal with versioning in the common code. Second, becuase they diff --git a/xwords4/common/game.c b/xwords4/common/game.c index b02d58ee0..1e0473727 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -432,7 +432,10 @@ gi_readFromStream( MPFORMAL XWStreamCtxt* stream, CurGameInfo* gi ) XP_FREEP( mpool, &str ); gi->nPlayers = (XP_U8)stream_getBits( stream, NPLAYERS_NBITS ); - gi->boardSize = (XP_U8)stream_getBits( stream, 4 ); + gi->boardSize = + (XP_U8)stream_getBits( stream, + strVersion < STREAM_VERS_BIGBOARD? 4 : + NUMCOLS_NBITS ); gi->serverRole = (DeviceRole)stream_getBits( stream, 2 ); gi->hintsNotAllowed = stream_getBits( stream, 1 ); if ( strVersion < STREAM_VERS_ROBOTIQ ) { @@ -494,7 +497,7 @@ gi_writeToStream( XWStreamCtxt* stream, const CurGameInfo* gi ) stringToStream( stream, gi->dictName ); stream_putBits( stream, NPLAYERS_NBITS, gi->nPlayers ); - stream_putBits( stream, 4, gi->boardSize ); + stream_putBits( stream, NUMCOLS_NBITS, gi->boardSize ); stream_putBits( stream, 2, gi->serverRole ); stream_putBits( stream, 1, gi->hintsNotAllowed ); stream_putBits( stream, 2, gi->phoniesAction ); diff --git a/xwords4/common/game.h b/xwords4/common/game.h index 139ac8878..61f4de9f3 100644 --- a/xwords4/common/game.h +++ b/xwords4/common/game.h @@ -31,6 +31,11 @@ extern "C" { #endif +#if MAX_COLS > 16 +# define STREAM_VERS_BIGBOARD 0x12 +#else +# define STREAM_VERS_BIGBOARD 0x11 +#endif #define STREAM_SAVE_PREVWORDS 0x11 #define STREAM_VERS_SERVER_SAVES_TOSHOW 0x10 #define STREAM_VERS_PLAYERDICTS 0x0F @@ -53,7 +58,7 @@ extern "C" { #define STREAM_VERS_41B4 0x02 #define STREAM_VERS_405 0x01 -#define CUR_STREAM_VERS STREAM_SAVE_PREVWORDS +#define CUR_STREAM_VERS STREAM_VERS_BIGBOARD typedef struct LocalPlayer { XP_UCHAR* name; diff --git a/xwords4/common/model.c b/xwords4/common/model.c index c40976c8c..70dd08f25 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -119,11 +119,14 @@ model_makeFromStream( MPFORMAL XWStreamCtxt* stream, DictionaryCtxt* dict, XP_Bool hasDict; XP_U16 nPlayers; XP_U16 version = stream_getVersion( stream ); + XP_U16 nColsNBits = + STREAM_VERS_BIGBOARD > version ? 4 : + NUMCOLS_NBITS; XP_ASSERT( !!dict || !!dicts ); - nCols = (XP_U16)stream_getBits( stream, NUMCOLS_NBITS ); - nRows = (XP_U16)stream_getBits( stream, NUMCOLS_NBITS ); + nCols = (XP_U16)stream_getBits( stream, nColsNBits ); + nRows = (XP_U16)stream_getBits( stream, nColsNBits ); hasDict = (version >= STREAM_VERS_MODEL_NO_DICT) ? XP_FALSE : stream_getBits( stream, 1 ); @@ -849,6 +852,9 @@ model_makeTurnFromStream( ModelCtxt* model, XP_U16 playerNum, { XP_U16 numTiles; Tile blank = dict_getBlankTile( model_getDictionary(model) ); + XP_U16 nColsNBits = + STREAM_VERS_BIGBOARD > stream_getVersion( stream ) ? 4 : + NUMCOLS_NBITS; model_resetCurrentTurn( model, playerNum ); @@ -860,8 +866,8 @@ model_makeTurnFromStream( ModelCtxt* model, XP_U16 playerNum, XP_S16 foundAt; Tile moveTile; Tile tileFace = (Tile)stream_getBits( stream, TILE_NBITS ); - XP_U16 col = (XP_U16)stream_getBits( stream, NUMCOLS_NBITS ); - XP_U16 row = (XP_U16)stream_getBits( stream, NUMCOLS_NBITS ); + XP_U16 col = (XP_U16)stream_getBits( stream, nColsNBits ); + XP_U16 row = (XP_U16)stream_getBits( stream, nColsNBits ); XP_Bool isBlank = stream_getBits( stream, 1 ); /* This code gets called both for the server, which has all the @@ -2215,6 +2221,9 @@ loadPlayerCtxt( XWStreamCtxt* stream, XP_U16 version, PlayerCtxt* pc ) { PendingTile* pt; XP_U16 nTiles; + XP_U16 nColsNBits = + STREAM_VERS_BIGBOARD > stream_getVersion( stream ) ? 4 : + NUMCOLS_NBITS; pc->curMoveValid = stream_getBits( stream, 1 ); @@ -2230,8 +2239,8 @@ loadPlayerCtxt( XWStreamCtxt* stream, XP_U16 version, PlayerCtxt* pc ) nTiles = pc->nPending + pc->nUndone; for ( pt = pc->pendingTiles; nTiles-- > 0; ++pt ) { XP_U16 nBits; - pt->col = (XP_U8)stream_getBits( stream, NUMCOLS_NBITS ); - pt->row = (XP_U8)stream_getBits( stream, NUMCOLS_NBITS ); + pt->col = (XP_U8)stream_getBits( stream, nColsNBits ); + pt->row = (XP_U8)stream_getBits( stream, nColsNBits ); nBits = (version <= STREAM_VERS_RELAY) ? 6 : 7; pt->tile = (Tile)stream_getBits( stream, nBits ); diff --git a/xwords4/common/model.h b/xwords4/common/model.h index 614829a0a..5bcf20685 100644 --- a/xwords4/common/model.h +++ b/xwords4/common/model.h @@ -29,7 +29,11 @@ extern "C" { #endif -#define NUMCOLS_NBITS 4 +#if MAX_COLS <= 16 +# define NUMCOLS_NBITS 4 +#elif MAX_COLS <= 32 +# define NUMCOLS_NBITS 5 +#endif #ifdef EIGHT_TILES # define NTILES_NBITS 4 diff --git a/xwords4/linux/Makefile b/xwords4/linux/Makefile index f7e34d4d1..861a1a3eb 100644 --- a/xwords4/linux/Makefile +++ b/xwords4/linux/Makefile @@ -93,6 +93,7 @@ DEFINES += -DSET_GAMESEED DEFINES += -DTEXT_MODEL DEFINES += -DXWFEATURE_WALKDICT DEFINES += -DXWFEATURE_DICTSANITY +#DEFINES += -DMAX_ROWS=32 ifdef CURSES_CELL_HT DEFINES += -DCURSES_CELL_HT=$(CURSES_CELL_HT) diff --git a/xwords4/linux/linuxutl.c b/xwords4/linux/linuxutl.c index 40a435489..b1df9cd12 100644 --- a/xwords4/linux/linuxutl.c +++ b/xwords4/linux/linuxutl.c @@ -179,8 +179,9 @@ linux_util_getSquareBonus( XW_UtilCtxt* uc, const ModelCtxt* model, TW,EM,EM,DL,EM,EM,EM,DW, }; /* scrabbleBoard */ - if ( col > 7 ) col = 14 - col; - if ( row > 7 ) row = 14 - row; + XP_U16 nCols = model_numCols( model ); + if ( col > (nCols/2) ) col = nCols - 1 - col; + if ( row > (nCols/2) ) row = nCols - 1 - row; if ( col > row ) { XP_U16 tmp = col; col = row;