fix curses build for 64bit compile and to use common layout (meaning

tray is now under the board unstead of to the right).  Works on 64-bit
system at least for non-networked games.
This commit is contained in:
Eric House 2014-01-05 13:04:59 -08:00
parent 3f67afaefb
commit b43855a313
8 changed files with 100 additions and 73 deletions

View file

@ -439,6 +439,9 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
// Scrolling's required if we use cell width sufficient to // Scrolling's required if we use cell width sufficient to
// fill the screen. But perhaps we don't need to. // fill the screen. But perhaps we don't need to.
int cellWidth = 2 * (bHeight / ( 4 + 3 + (2*nCells))); int cellWidth = 2 * (bHeight / ( 4 + 3 + (2*nCells)));
if ( cellWidth < fontWidth ) {
cellWidth = fontWidth;
}
if ( firstPass && cellWidth >= fontHt ) { if ( firstPass && cellWidth >= fontHt ) {
firstPass = XP_FALSE; firstPass = XP_FALSE;
ldims.boardWidth = nCells * cellWidth; ldims.boardWidth = nCells * cellWidth;

View file

@ -31,9 +31,9 @@
/* Figure out how many lines there are and how wide the widest is. /* Figure out how many lines there are and how wide the widest is.
*/ */
short int
cursesask( CursesAppGlobals* globals, const char* question, short numButtons, cursesask( CursesAppGlobals* globals, const char* question, short numButtons,
const char* button1, ... ) const char** buttons )
{ {
WINDOW* confWin; WINDOW* confWin;
int x, y, rows, row, nLines; int x, y, rows, row, nLines;
@ -79,7 +79,7 @@ cursesask( CursesAppGlobals* globals, const char* question, short numButtons,
if ( newSelButton != curSelButton ) { if ( newSelButton != curSelButton ) {
drawButtons( confWin, rows+1, spacePerButton, numButtons, drawButtons( confWin, rows+1, spacePerButton, numButtons,
curSelButton=newSelButton, &button1 ); curSelButton=newSelButton, buttons );
} }
ch = wgetch( confWin ); ch = wgetch( confWin );

View file

@ -22,8 +22,8 @@
#include "cursesmain.h" #include "cursesmain.h"
short cursesask( CursesAppGlobals* globals, const char* question, int cursesask( CursesAppGlobals* globals, const char* question,
short numButtons, const char* button1, ... ); short numButtons, const char** buttons );
#endif #endif

View file

@ -122,12 +122,12 @@ curses_draw_drawRemText( DrawCtx* p_dctx, XP_S16 nTilesLeft,
} }
#else #else
static void static void
formatRemText( char* buf, int bufLen, XP_S16 nTilesLeft, int width ) formatRemText( char* buf, int bufLen, XP_S16 nTilesLeft, int XP_UNUSED(width) )
{ {
snprintf( buf, bufLen, "Tiles left in pool: %.3d", nTilesLeft ); /* int len = snprintf( buf, bufLen, "Tiles left in pool: %.3d", nTilesLeft ); */
if ( strlen(buf)+1 >= width ) { /* if ( len > bufLen || strlen(buf)+1 >= width ) { */
snprintf( buf, bufLen, "Rem: %.3d", nTilesLeft ); snprintf( buf, bufLen, "Rem: %.3d", nTilesLeft );
} /* } */
} /* formatRemText */ } /* formatRemText */
static XP_Bool static XP_Bool
@ -136,11 +136,11 @@ curses_draw_measureRemText( DrawCtx* XP_UNUSED(dctx),
XP_S16 nTilesLeft, XP_S16 nTilesLeft,
XP_U16* width, XP_U16* height ) XP_U16* width, XP_U16* height )
{ {
char buf[32]; char buf[64];
formatRemText( buf, sizeof(buf), nTilesLeft, r->width ); formatRemText( buf, sizeof(buf), nTilesLeft, r->width );
*width = strlen(buf); *width = strlen(buf);
*height = 1; *height = r->height;
return XP_TRUE; return XP_TRUE;
} /* curses_draw_measureRemText */ } /* curses_draw_measureRemText */
@ -162,6 +162,7 @@ curses_draw_drawRemText( DrawCtx* p_dctx, const XP_Rect* rInner,
#ifdef XWFEATURE_SCOREONEPASS #ifdef XWFEATURE_SCOREONEPASS
#else #else
#if 0
static int static int
fitIn( char* buf, int len, int* rem, const char* str ) fitIn( char* buf, int len, int* rem, const char* str )
{ {
@ -177,41 +178,35 @@ fitIn( char* buf, int len, int* rem, const char* str )
memcpy( buf, str, slen ); memcpy( buf, str, slen );
return len; return len;
} /* fitIn */ } /* fitIn */
#endif
static void static void
formatScoreText( XP_UCHAR* out, int outLen, const DrawScoreInfo* dsi, formatScoreText( XP_UCHAR* out, const DrawScoreInfo* dsi, const XP_Rect* rect,
int width ) char** lines )
{ {
/* Long and short formats. We'll try long first. If it fits, cool. if ( 2 <= rect->height ) {
Otherwise we use short. Either way, we fill the whole rect so it can sprintf( out, "%s", dsi->name );
overwrite anything that was there before.*/ *lines++ = out;
char tmp[width+1]; out += 1 + strlen(out);
char buf[width+1];
int scoreWidth = 4;
XP_ASSERT( width < outLen );
XP_MEMSET( buf, ' ', width );
buf[width] = '\0';
/* Status/role chars at start */
if ( dsi->isTurn ) {
buf[0] = 'T';
}
if ( dsi->selected ) {
buf[1] = 'S';
}
if ( dsi->isRobot) {
buf[2] = 'r';
} }
/* Score always goes at end. Will overwrite status if width is really small */ /* Status/role chars at start/top, if there's room */
snprintf( tmp, scoreWidth, "%.3d", dsi->totalScore ); if ( 3 <= rect->height ) {
memcpy( &buf[width-scoreWidth+1], tmp, scoreWidth-1 ); out[0] = dsi->isTurn ? 'T': ' ';
out[1] = dsi->selected ? 'S' : ' ';
out[2] = dsi->isRobot ? 'r' : ' ';
out[3] = '\0';
*lines++ = out;
out += 4;
}
sprintf( out, "%.3d", dsi->totalScore );
*lines++ = out;
out += 1 + strlen(out);
#if 0
/* Now we want to fit name, rem tiles, last score, and last move, if /* Now we want to fit name, rem tiles, last score, and last move, if
there's space. Allocate to each so they're in columns. */ there's space. Allocate to each so they're in columns. */
width -= 8; /* status chars plus space; score plus space */ width -= 8; /* status chars plus space; score plus space */
if ( width > 0 ) { if ( width > 0 ) {
int pos = 4; int pos = 4;
@ -243,20 +238,28 @@ formatScoreText( XP_UCHAR* out, int outLen, const DrawScoreInfo* dsi,
} }
snprintf( out, outLen, "%s", buf ); snprintf( out, outLen, "%s", buf );
#endif
} /* formatScoreText */ } /* formatScoreText */
static void static void
curses_draw_measureScoreText( DrawCtx* XP_UNUSED(p_dctx), curses_draw_measureScoreText( DrawCtx* XP_UNUSED(p_dctx),
const XP_Rect* r, const XP_Rect* rect,
const DrawScoreInfo* dsi, const DrawScoreInfo* dsi,
XP_U16* width, XP_U16* height ) XP_U16* width, XP_U16* height )
{ {
XP_UCHAR buf[100]; XP_UCHAR buf[100];
formatScoreText( buf, sizeof(buf), dsi, r->width ); char* lines[3] = {0};
formatScoreText( buf, dsi, rect, lines );
*width = strlen( buf ); int ii;
XP_ASSERT( *width <= r->width ); int max = 0;
*height = 1; /* one line per player */ for ( ii = 0; ii < VSIZE(lines) && !!lines[ii]; ++ii ) {
max = XP_MAX( max, strlen( lines[ii] ) );
}
XP_ASSERT( ii <= rect->height );
*height = ii;
*width = max;
XP_ASSERT( *width <= rect->width );
} /* curses_draw_measureScoreText */ } /* curses_draw_measureScoreText */
static void static void
@ -271,8 +274,12 @@ curses_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
curses_draw_clearRect( p_dctx, rOuter ); curses_draw_clearRect( p_dctx, rOuter );
/* print the name and turn/remoteness indicator */ /* print the name and turn/remoteness indicator */
formatScoreText( buf, sizeof(buf), dsi, rInner->width ); char* lines[3] = {0};
mvwprintw( dctx->boardWin, y, rOuter->left, buf ); formatScoreText( buf, dsi, rInner, lines );
int ii;
for ( ii = 0; ii < VSIZE(lines) && !!lines[ii]; ++ii ) {
mvwprintw( dctx->boardWin, ii + y, rOuter->left, lines[ii] );
}
if ( (dsi->flags&CELL_ISCURSOR) != 0 ) { if ( (dsi->flags&CELL_ISCURSOR) != 0 ) {
cursesHiliteRect( dctx->boardWin, rOuter ); cursesHiliteRect( dctx->boardWin, rOuter );
@ -329,6 +336,10 @@ curses_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect,
XP_MEMCPY( loc, letter, strlen(letter) ); XP_MEMCPY( loc, letter, strlen(letter) );
} }
if ( highlight ) {
wstandout( dctx->boardWin );
}
/* in case it's not 1x1 */ /* in case it's not 1x1 */
eraseRect( dctx, rect ); eraseRect( dctx, rect );
@ -347,12 +358,7 @@ curses_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect,
} /* switch */ } /* switch */
} }
if ( highlight ) { mvwaddnstr( dctx->boardWin, rect->top, rect->left, loc, rect->width );
wstandout( dctx->boardWin );
}
mvwaddnstr( dctx->boardWin, rect->top, rect->left,
loc, rect->width );
if ( highlight ) { if ( highlight ) {
wstandend( dctx->boardWin ); wstandend( dctx->boardWin );
@ -457,12 +463,16 @@ curses_draw_drawTileBack( DrawCtx* p_dctx, const XP_Rect* rect,
static void static void
curses_draw_drawTrayDivider( DrawCtx* p_dctx, const XP_Rect* rect, curses_draw_drawTrayDivider( DrawCtx* p_dctx, const XP_Rect* rect,
CellFlags XP_UNUSED(flags) ) CellFlags flags )
{ {
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx; CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
wmove( dctx->boardWin, rect->top, rect->left ); eraseRect( dctx, rect );
wvline( dctx->boardWin, '#', rect->height );
wmove( dctx->boardWin, rect->top, rect->left + (rect->width/2));
wvline( dctx->boardWin, '#', rect->height );
if ( 0 != (flags & CELL_ISCURSOR) ) {
cursesHiliteRect( dctx->boardWin, rect );
}
} /* curses_draw_drawTrayDivider */ } /* curses_draw_drawTrayDivider */
static void static void

View file

@ -228,7 +228,8 @@ cursesUserError( CursesAppGlobals* globals, const char* format, ... )
vsprintf( buf, format, ap ); vsprintf( buf, format, ap );
(void)cursesask( globals, buf, 1, "OK" ); const char* buttons[] = {"OK"};
(void)cursesask( globals, buf, VSIZE(buttons), buttons );
va_end(ap); va_end(ap);
} /* cursesUserError */ } /* cursesUserError */
@ -287,7 +288,7 @@ curses_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
{ {
CursesAppGlobals* globals; CursesAppGlobals* globals;
char* question; char* question;
char* answers[3] = {NULL}; const char* answers[3] = {NULL};
short numAnswers = 0; short numAnswers = 0;
XP_Bool freeMe = XP_FALSE; XP_Bool freeMe = XP_FALSE;
XP_Bool result; XP_Bool result;
@ -312,8 +313,7 @@ curses_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
return 0; return 0;
} }
globals = (CursesAppGlobals*)uc->closure; globals = (CursesAppGlobals*)uc->closure;
result = cursesask( globals, question, numAnswers, result = okIndex == cursesask( globals, question, numAnswers, answers );
answers[0], answers[1], answers[2] ) == okIndex;
if ( freeMe ) { if ( freeMe ) {
free( question ); free( question );
@ -329,7 +329,8 @@ curses_util_confirmTrade( XW_UtilCtxt* uc, const XP_UCHAR** tiles,
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure; CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
char question[256]; char question[256];
formatConfirmTrade( tiles, nTiles, question, sizeof(question) ); formatConfirmTrade( tiles, nTiles, question, sizeof(question) );
return 1 == cursesask( globals, question, 2, "Cancel", "Ok" ); const char* buttons[] = { "Cancel", "Ok" };
return 1 == cursesask( globals, question, VSIZE(buttons), buttons );
} }
static void static void
@ -353,7 +354,8 @@ cursesShowFinalScores( CursesAppGlobals* globals )
text = strFromStream( stream ); text = strFromStream( stream );
(void)cursesask( globals, text, 1, "Ok" ); const char* buttons[] = { "Ok" };
(void)cursesask( globals, text, VSIZE(buttons), buttons );
free( text ); free( text );
stream_destroy( stream ); stream_destroy( stream );
@ -365,7 +367,8 @@ curses_util_informMove( XW_UtilCtxt* uc, XWStreamCtxt* expl,
{ {
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure; CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
char* question = strFromStream( expl ); char* question = strFromStream( expl );
(void)cursesask( globals, question, 1, "Ok" ); const char* buttons[] = { "Ok" };
(void)cursesask( globals, question, VSIZE(buttons), buttons );
free( question ); free( question );
} }
@ -1524,7 +1527,8 @@ curses_util_remSelected( XW_UtilCtxt* uc )
text = strFromStream( stream ); text = strFromStream( stream );
(void)cursesask( globals, text, 1, "Ok" ); const char* buttons[] = { "Ok" };
(void)cursesask( globals, text, VSIZE(buttons), buttons );
free( text ); free( text );
} }
@ -1636,10 +1640,18 @@ passKeyToBoard( CursesAppGlobals* globals, char ch )
static void static void
positionSizeStuff( CursesAppGlobals* globals, int width, int height ) positionSizeStuff( CursesAppGlobals* globals, int width, int height )
{ {
BoardCtxt* board = globals->cGlobals.game.board; CommonGlobals* cGlobals = &globals->cGlobals;
BoardCtxt* board = cGlobals->game.board;
#ifdef COMMON_LAYOUT #ifdef COMMON_LAYOUT
XP_USE( width );
XP_USE( height ); BoardDims dims;
board_figureLayout( board, cGlobals->gi,
0, 0, width, height,
150, 200, /* percents */
width*100/75, 2, 1,
XP_FALSE, &dims );
board_applyLayout( board, &dims );
#else #else
XP_U16 cellWidth, cellHt, scoreLeft, scoreWidth; XP_U16 cellWidth, cellHt, scoreLeft, scoreWidth;
int remWidth = width; int remWidth = width;
@ -1852,7 +1864,8 @@ cursesErrorMsgRcvd( void* closure, const XP_UCHAR* msg )
} else { } else {
g_free( globals->lastErr ); g_free( globals->lastErr );
globals->lastErr = g_strdup( msg ); globals->lastErr = g_strdup( msg );
(void)cursesask( globals, msg, 1, "Ok" ); const char* buttons[] = { "Ok" };
(void)cursesask( globals, msg, VSIZE(buttons), buttons );
} }
} }

View file

@ -903,7 +903,7 @@ CookieRef::send_stored_messages( HostID dest, const AddrInfo* addr )
break; break;
} }
if ( !UDPAckTrack::setOnAck( onMsgAcked, packetID, if ( !UDPAckTrack::setOnAck( onMsgAcked, packetID,
(void*)msg.msgID() ) ) { (void*)(uintptr_t)msg.msgID() ) ) {
sentIDs.push_back( msg.msgID() ); sentIDs.push_back( msg.msgID() );
} }
} }

View file

@ -547,7 +547,7 @@ cmd_print( int socket, const char* cmd, int argc, gchar** argv )
static void static void
onAckProc( bool acked, DevIDRelay devid, uint32_t packetID, void* data ) onAckProc( bool acked, DevIDRelay devid, uint32_t packetID, void* data )
{ {
int socket = (int)data; int socket = (int)(uintptr_t)data;
if ( acked ) { if ( acked ) {
print_to_sock( socket, true, "got ack for packet %d from dev %d", print_to_sock( socket, true, "got ack for packet %d from dev %d",
packetID, devid ); packetID, devid );
@ -660,7 +660,7 @@ cmd_devs( int socket, const char* cmd, int argc, gchar** argv )
DevIDRelay devid = *iter; DevIDRelay devid = *iter;
if ( 0 != devid ) { if ( 0 != devid ) {
if ( post_message( devid, unesc, onAckProc, if ( post_message( devid, unesc, onAckProc,
(void*)socket ) ) { (void*)(uintptr_t)socket ) ) {
result.catf( "posted message: %s\n", unesc ); result.catf( "posted message: %s\n", unesc );
} else { } else {
result.catf( "unable to post; does dev %d exist\n", result.catf( "unable to post; does dev %d exist\n",
@ -744,7 +744,7 @@ static void*
ctrl_thread_main( void* arg ) ctrl_thread_main( void* arg )
{ {
blockSignals(); blockSignals();
int sock = (int)arg; int sock = (int)(uintptr_t)arg;
{ {
MutexLock ml( &g_ctrlSocksMutex ); MutexLock ml( &g_ctrlSocksMutex );
@ -819,7 +819,7 @@ run_ctrl_thread( int ctrl_sock )
pthread_t thread; pthread_t thread;
int result = pthread_create( &thread, NULL, int result = pthread_create( &thread, NULL,
ctrl_thread_main, (void*)newSock ); ctrl_thread_main, (void*)(uintptr_t)newSock );
pthread_detach( thread ); pthread_detach( thread );
assert( result == 0 ); assert( result == 0 );

View file

@ -1550,7 +1550,7 @@ onMsgAcked( bool acked, uint32_t packetID, void* data )
logf( XW_LOGINFO, "%s(packetID=%d, acked=%s)", __func__, packetID, logf( XW_LOGINFO, "%s(packetID=%d, acked=%s)", __func__, packetID,
acked?"true":"false" ); acked?"true":"false" );
if ( acked ) { if ( acked ) {
int msgID = (int)data; int msgID = (int)(uintptr_t)data;
DBMgr::Get()->RemoveStoredMessage( msgID ); DBMgr::Get()->RemoveStoredMessage( msgID );
} }
} }
@ -1587,7 +1587,8 @@ retrieveMessages( DevID& devID, const AddrInfo* addr )
__func__, devID.asRelayID() ); __func__, devID.asRelayID() );
break; break;
} }
UDPAckTrack::setOnAck( onMsgAcked, packetID, (void*)msg.msgID() ); UDPAckTrack::setOnAck( onMsgAcked, packetID,
(void*)(uintptr_t)msg.msgID() );
} }
} }