mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Merge branch 'android_branch' into android_bt
This commit is contained in:
commit
64199c4e64
4 changed files with 85 additions and 38 deletions
|
@ -72,6 +72,7 @@ static void buildModelFromStack( ModelCtxt* model, StackCtxt* stack,
|
||||||
MovePrintFuncPost mpfpo, void* closure );
|
MovePrintFuncPost mpfpo, void* closure );
|
||||||
static void setPendingCounts( ModelCtxt* model, XP_S16 turn );
|
static void setPendingCounts( ModelCtxt* model, XP_S16 turn );
|
||||||
static XP_S16 setContains( const TrayTileSet* tiles, Tile tile );
|
static XP_S16 setContains( const TrayTileSet* tiles, Tile tile );
|
||||||
|
static void sortTiles( TrayTileSet* dest, const TrayTileSet* src );
|
||||||
static void removeTile( TrayTileSet* tiles, XP_U16 index );
|
static void removeTile( TrayTileSet* tiles, XP_U16 index );
|
||||||
static void loadPlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
|
static void loadPlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
|
||||||
XP_U16 version, PlayerCtxt* pc );
|
XP_U16 version, PlayerCtxt* pc );
|
||||||
|
@ -1765,7 +1766,9 @@ model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
|
||||||
const TrayTileSet* tiles )
|
const TrayTileSet* tiles )
|
||||||
{
|
{
|
||||||
XP_ASSERT( turn >= 0 );
|
XP_ASSERT( turn >= 0 );
|
||||||
stack_addAssign( model->vol.stack, turn, tiles );
|
TrayTileSet sorted;
|
||||||
|
sortTiles( &sorted, tiles );
|
||||||
|
stack_addAssign( model->vol.stack, turn, &sorted );
|
||||||
|
|
||||||
assignPlayerTiles( model, turn, tiles );
|
assignPlayerTiles( model, turn, tiles );
|
||||||
} /* model_assignPlayerTiles */
|
} /* model_assignPlayerTiles */
|
||||||
|
@ -1773,30 +1776,17 @@ model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
|
||||||
void
|
void
|
||||||
model_sortTiles( ModelCtxt* model, XP_S16 turn )
|
model_sortTiles( ModelCtxt* model, XP_S16 turn )
|
||||||
{
|
{
|
||||||
PlayerCtxt* player;
|
|
||||||
XP_S16 ii;
|
|
||||||
TrayTileSet tiles = { .nTiles = 0 };
|
|
||||||
XP_S16 nTiles;
|
XP_S16 nTiles;
|
||||||
|
|
||||||
XP_ASSERT( turn >= 0 );
|
TrayTileSet sorted;
|
||||||
player = &model->players[turn];
|
sortTiles( &sorted, model_getPlayerTiles( model, turn ) );
|
||||||
|
|
||||||
for ( nTiles = model_getNumTilesInTray( model, turn ) - 1;
|
nTiles = sorted.nTiles;
|
||||||
nTiles >= 0; --nTiles ) {
|
while ( nTiles > 0 ) {
|
||||||
Tile min = 0xFF;
|
removePlayerTile( model, turn, --nTiles );
|
||||||
XP_U16 minIndex = 0;
|
|
||||||
for ( ii = 0; ii <= nTiles; ++ii ) {
|
|
||||||
Tile tile = player->trayTiles.tiles[ii];
|
|
||||||
if ( tile < min ) {
|
|
||||||
min = tile;
|
|
||||||
minIndex = ii;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tiles.tiles[tiles.nTiles++] =
|
|
||||||
removePlayerTile( model, turn, minIndex );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assignPlayerTiles( model, turn, &tiles );
|
assignPlayerTiles( model, turn, &sorted );
|
||||||
} /* model_sortTiles */
|
} /* model_sortTiles */
|
||||||
|
|
||||||
XP_U16
|
XP_U16
|
||||||
|
@ -2449,6 +2439,23 @@ setContains( const TrayTileSet* tiles, Tile tile )
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sortTiles( TrayTileSet* dest, const TrayTileSet* src )
|
||||||
|
{
|
||||||
|
TrayTileSet tmp = *src;
|
||||||
|
dest->nTiles = 0;
|
||||||
|
while ( 0 < tmp.nTiles ) {
|
||||||
|
XP_U16 ii, smallest;
|
||||||
|
for ( smallest = ii = 0; ii < tmp.nTiles; ++ii ) {
|
||||||
|
if ( tmp.tiles[ii] < tmp.tiles[smallest] ) {
|
||||||
|
smallest = ii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dest->tiles[dest->nTiles++] = tmp.tiles[smallest];
|
||||||
|
removeTile( &tmp, smallest );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CPLUS
|
#ifdef CPLUS
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,6 +26,15 @@
|
||||||
#include "memstream.h"
|
#include "memstream.h"
|
||||||
#include "strutils.h"
|
#include "strutils.h"
|
||||||
|
|
||||||
|
/* HASH_STREAM: It should be possible to hash the move stack by simply hashing
|
||||||
|
the stream from the beginning to the top of the undo stack (excluding
|
||||||
|
what's in the redo area), avoiding iterating over it and doing a ton of
|
||||||
|
bitwise operations to read it into entries. But I don't currently seem to
|
||||||
|
have a XWStreamPos that corresponds to the undo-top and so I can't figure
|
||||||
|
out the length. Hashing that includes the redo part of the stack doesn't
|
||||||
|
work once there's been undo activity. (Not sure why...) */
|
||||||
|
// #define HASH_STREAM
|
||||||
|
|
||||||
#ifdef CPLUS
|
#ifdef CPLUS
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,8 +67,22 @@ stack_init( StackCtxt* stack )
|
||||||
} /* stack_init */
|
} /* stack_init */
|
||||||
|
|
||||||
#ifdef STREAM_VERS_BIGBOARD
|
#ifdef STREAM_VERS_BIGBOARD
|
||||||
|
#ifdef HASH_STREAM
|
||||||
|
static XP_U16
|
||||||
|
figureStackSize( const StackCtxt* stack )
|
||||||
|
{
|
||||||
|
XWStreamCtxt* data = stack->data;
|
||||||
|
XWStreamPos oldReadPos = stream_setPos( data, POS_READ, START_OF_STREAM );
|
||||||
|
XWStreamPos oldWritePos = stream_setPos( data, POS_WRITE, stack->cachedPos );
|
||||||
|
XP_U16 len = stream_getSize( data );
|
||||||
|
(void)stream_setPos( data, POS_READ, oldReadPos );
|
||||||
|
(void)stream_setPos( data, POS_WRITE, oldWritePos );
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static XP_U32
|
static XP_U32
|
||||||
augmentHash( XP_U32 hash, XP_U8* ptr, XP_U16 len )
|
augmentHash( XP_U32 hash, const XP_U8* ptr, XP_U16 len )
|
||||||
{
|
{
|
||||||
XP_ASSERT( 0 < len );
|
XP_ASSERT( 0 < len );
|
||||||
// see http://en.wikipedia.org/wiki/Jenkins_hash_function
|
// see http://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||||
|
@ -72,9 +95,11 @@ augmentHash( XP_U32 hash, XP_U8* ptr, XP_U16 len )
|
||||||
hash += (hash << 3);
|
hash += (hash << 3);
|
||||||
hash ^= (hash >> 11);
|
hash ^= (hash >> 11);
|
||||||
hash += (hash << 15);
|
hash += (hash << 15);
|
||||||
|
// XP_LOGF( "%s: hashed %d bytes -> %X", __func__, len, (unsigned int)hash );
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HASH_STREAM
|
||||||
static XP_U32
|
static XP_U32
|
||||||
augmentFor( XP_U32 hash, const StackEntry* entry )
|
augmentFor( XP_U32 hash, const StackEntry* entry )
|
||||||
{
|
{
|
||||||
|
@ -98,12 +123,20 @@ augmentFor( XP_U32 hash, const StackEntry* entry )
|
||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XP_U32
|
XP_U32
|
||||||
stack_getHash( StackCtxt* stack )
|
stack_getHash( StackCtxt* stack )
|
||||||
{
|
{
|
||||||
XP_U32 hash = 0L;
|
XP_U32 hash;
|
||||||
|
#ifdef HASH_STREAM
|
||||||
|
XP_U16 len = figureStackSize( stack );
|
||||||
|
const XP_U8* ptr = stream_getPtr( stack->data );
|
||||||
|
LOG_HEX( ptr, len, __func__ );
|
||||||
|
hash = augmentHash( 0L, ptr, len );
|
||||||
|
#else
|
||||||
XP_U16 nn, nEntries = stack->nEntries;
|
XP_U16 nn, nEntries = stack->nEntries;
|
||||||
|
hash = 0L;
|
||||||
for ( nn = 0; nn < nEntries; ++nn ) {
|
for ( nn = 0; nn < nEntries; ++nn ) {
|
||||||
StackEntry entry;
|
StackEntry entry;
|
||||||
XP_MEMSET( &entry, 0, sizeof(entry) );
|
XP_MEMSET( &entry, 0, sizeof(entry) );
|
||||||
|
@ -115,6 +148,7 @@ stack_getHash( StackCtxt* stack )
|
||||||
}
|
}
|
||||||
XP_ASSERT( 0 != hash );
|
XP_ASSERT( 0 != hash );
|
||||||
// LOG_RETURNF( "%.8X", (unsigned int)hash );
|
// LOG_RETURNF( "%.8X", (unsigned int)hash );
|
||||||
|
#endif
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -214,7 +248,7 @@ stack_copy( const StackCtxt* stack )
|
||||||
static void
|
static void
|
||||||
pushEntry( StackCtxt* stack, const StackEntry* entry )
|
pushEntry( StackCtxt* stack, const StackEntry* entry )
|
||||||
{
|
{
|
||||||
XP_U16 i, bitsPerTile;
|
XP_U16 ii, bitsPerTile;
|
||||||
XWStreamPos oldLoc;
|
XWStreamPos oldLoc;
|
||||||
XP_U16 nTiles = entry->u.move.moveInfo.nTiles;
|
XP_U16 nTiles = entry->u.move.moveInfo.nTiles;
|
||||||
XWStreamCtxt* stream = stack->data;
|
XWStreamCtxt* stream = stack->data;
|
||||||
|
@ -239,12 +273,12 @@ pushEntry( StackCtxt* stack, const StackEntry* entry )
|
||||||
stream_putBits( stream, 1, entry->u.move.moveInfo.isHorizontal );
|
stream_putBits( stream, 1, entry->u.move.moveInfo.isHorizontal );
|
||||||
bitsPerTile = stack->bitsPerTile;
|
bitsPerTile = stack->bitsPerTile;
|
||||||
XP_ASSERT( bitsPerTile == 5 || bitsPerTile == 6 );
|
XP_ASSERT( bitsPerTile == 5 || bitsPerTile == 6 );
|
||||||
for ( i = 0; i < nTiles; ++i ) {
|
for ( ii = 0; ii < nTiles; ++ii ) {
|
||||||
Tile tile;
|
Tile tile;
|
||||||
stream_putBits( stream, 5,
|
stream_putBits( stream, 5,
|
||||||
entry->u.move.moveInfo.tiles[i].varCoord );
|
entry->u.move.moveInfo.tiles[ii].varCoord );
|
||||||
|
|
||||||
tile = entry->u.move.moveInfo.tiles[i].tile;
|
tile = entry->u.move.moveInfo.tiles[ii].tile;
|
||||||
stream_putBits( stream, bitsPerTile, tile & TILE_VALUE_MASK );
|
stream_putBits( stream, bitsPerTile, tile & TILE_VALUE_MASK );
|
||||||
stream_putBits( stream, 1, (tile & TILE_BLANK_BIT) != 0 );
|
stream_putBits( stream, 1, (tile & TILE_BLANK_BIT) != 0 );
|
||||||
}
|
}
|
||||||
|
@ -270,6 +304,7 @@ pushEntry( StackCtxt* stack, const StackEntry* entry )
|
||||||
++stack->nEntries;
|
++stack->nEntries;
|
||||||
stack->highWaterMark = stack->nEntries;
|
stack->highWaterMark = stack->nEntries;
|
||||||
stack->top = stream_setPos( stream, POS_WRITE, oldLoc );
|
stack->top = stream_setPos( stream, POS_WRITE, oldLoc );
|
||||||
|
// XP_LOGF( "after %s size now %d", __func__, figureStackSize( stack ) );
|
||||||
} /* pushEntry */
|
} /* pushEntry */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -380,18 +415,18 @@ stack_addAssign( StackCtxt* stack, XP_U16 turn, const TrayTileSet* tiles )
|
||||||
} /* stack_addAssign */
|
} /* stack_addAssign */
|
||||||
|
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
setCacheReadyFor( StackCtxt* stack, XP_U16 n )
|
setCacheReadyFor( StackCtxt* stack, XP_U16 nn )
|
||||||
{
|
{
|
||||||
StackEntry dummy;
|
XP_U16 ii;
|
||||||
XP_U16 i;
|
|
||||||
|
|
||||||
stream_setPos( stack->data, POS_READ, START_OF_STREAM );
|
stream_setPos( stack->data, POS_READ, START_OF_STREAM );
|
||||||
for ( i = 0; i < n; ++i ) {
|
for ( ii = 0; ii < nn; ++ii ) {
|
||||||
|
StackEntry dummy;
|
||||||
readEntry( stack, &dummy );
|
readEntry( stack, &dummy );
|
||||||
}
|
}
|
||||||
|
|
||||||
stack->cacheNext = n;
|
stack->cacheNext = nn;
|
||||||
stack->cachedPos = stream_getPos( stack->data, XP_FALSE );
|
stack->cachedPos = stream_getPos( stack->data, POS_READ );
|
||||||
|
|
||||||
return XP_TRUE;
|
return XP_TRUE;
|
||||||
} /* setCacheReadyFor */
|
} /* setCacheReadyFor */
|
||||||
|
@ -434,14 +469,15 @@ stack_getNthEntry( StackCtxt* stack, XP_U16 nn, StackEntry* entry )
|
||||||
XP_Bool
|
XP_Bool
|
||||||
stack_popEntry( StackCtxt* stack, StackEntry* entry )
|
stack_popEntry( StackCtxt* stack, StackEntry* entry )
|
||||||
{
|
{
|
||||||
XP_U16 n = stack->nEntries - 1;
|
XP_U16 nn = stack->nEntries - 1;
|
||||||
XP_Bool found = stack_getNthEntry( stack, n, entry );
|
XP_Bool found = stack_getNthEntry( stack, nn, entry );
|
||||||
if ( found ) {
|
if ( found ) {
|
||||||
stack->nEntries = n;
|
stack->nEntries = nn;
|
||||||
|
|
||||||
setCacheReadyFor( stack, n ); /* set cachedPos by side-effect */
|
setCacheReadyFor( stack, nn ); /* set cachedPos by side-effect */
|
||||||
stack->top = stack->cachedPos;
|
stack->top = stack->cachedPos;
|
||||||
}
|
}
|
||||||
|
//XP_LOGF( "after %s size now %d", __func__, figureStackSize( stack ) );
|
||||||
return found;
|
return found;
|
||||||
} /* stack_popEntry */
|
} /* stack_popEntry */
|
||||||
|
|
||||||
|
|
|
@ -1706,6 +1706,10 @@ cursesmain( XP_Bool isServer, LaunchParams* params )
|
||||||
g_globals.cGlobals.cp.showBoardArrow = XP_TRUE;
|
g_globals.cGlobals.cp.showBoardArrow = XP_TRUE;
|
||||||
g_globals.cGlobals.cp.showRobotScores = params->showRobotScores;
|
g_globals.cGlobals.cp.showRobotScores = params->showRobotScores;
|
||||||
g_globals.cGlobals.cp.hideTileValues = params->hideValues;
|
g_globals.cGlobals.cp.hideTileValues = params->hideValues;
|
||||||
|
g_globals.cGlobals.cp.skipCommitConfirm = params->skipCommitConfirm;
|
||||||
|
g_globals.cGlobals.cp.sortNewTiles = params->sortNewTiles;
|
||||||
|
g_globals.cGlobals.cp.showColors = params->showColors;
|
||||||
|
g_globals.cGlobals.cp.allowPeek = params->allowPeek;
|
||||||
#ifdef XWFEATURE_SLOW_ROBOT
|
#ifdef XWFEATURE_SLOW_ROBOT
|
||||||
g_globals.cGlobals.cp.robotThinkMin = params->robotThinkMin;
|
g_globals.cGlobals.cp.robotThinkMin = params->robotThinkMin;
|
||||||
g_globals.cGlobals.cp.robotThinkMax = params->robotThinkMax;
|
g_globals.cGlobals.cp.robotThinkMax = params->robotThinkMax;
|
||||||
|
|
|
@ -159,7 +159,7 @@ build_cmds() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PARAMS="$(player_params $NLOCALS $NPLAYERS $DEV)"
|
PARAMS="$(player_params $NLOCALS $NPLAYERS $DEV)"
|
||||||
PARAMS="$PARAMS $BOARD_SIZE --room $ROOM --trade-pct 20"
|
PARAMS="$PARAMS $BOARD_SIZE --room $ROOM --trade-pct 20 --sort-tiles "
|
||||||
PARAMS="$PARAMS --game-dict $DICT --port $PORT --host $HOST "
|
PARAMS="$PARAMS --game-dict $DICT --port $PORT --host $HOST "
|
||||||
PARAMS="$PARAMS --file $FILE --slow-robot 1:3 --skip-confirm"
|
PARAMS="$PARAMS --file $FILE --slow-robot 1:3 --skip-confirm"
|
||||||
PARAMS="$PARAMS --drop-nth-packet $DROP_N $PLAT_PARMS"
|
PARAMS="$PARAMS --drop-nth-packet $DROP_N $PLAT_PARMS"
|
||||||
|
@ -481,7 +481,7 @@ while [ "$#" -gt 0 ]; do
|
||||||
APP_NEW=$(getArg $*)
|
APP_NEW=$(getArg $*)
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--dict)
|
--game-dict)
|
||||||
DICTS[${#DICTS[@]}]=$(getArg $*)
|
DICTS[${#DICTS[@]}]=$(getArg $*)
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue