Fix two-device game by fixing dict<-->stream transitions.

This commit is contained in:
ehouse 2009-03-29 16:47:03 +00:00
parent 8f08667f5d
commit ee0b6ef0ef

View file

@ -80,14 +80,13 @@ dict_getTileValue( const DictionaryCtxt* dict, Tile tile )
return dict->countsAndValues[tile+1]; return dict->countsAndValues[tile+1];
} /* dict_getTileValue */ } /* dict_getTileValue */
static const XP_UCHAR* const XP_UCHAR*
dict_getTileChar( const DictionaryCtxt* dict, Tile tile ) dict_getTileString( const DictionaryCtxt* ctxt, Tile tile )
{ {
XP_ASSERT( tile < dict->nFaces ); XP_ASSERT( tile < ctxt->nFaces );
/* XP_ASSERT( (dict->faces[tile] & 0xFF00) == 0 ); /\* no unicode yet *\/ */ XP_U16 index = ctxt->faceIndices[tile];
XP_U16 index = dict->faceIndices[tile]; return &ctxt->faces[index];
return &dict->faces[index]; }
} /* dict_getTileValue */
XP_U16 XP_U16
dict_numTiles( const DictionaryCtxt* dict, Tile tile ) dict_numTiles( const DictionaryCtxt* dict, Tile tile )
@ -112,7 +111,7 @@ dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles,
while ( nTiles-- ) { while ( nTiles-- ) {
Tile tile = *tiles++; Tile tile = *tiles++;
const XP_UCHAR* facep = dict_getTileChar( ctxt, tile ); const XP_UCHAR* facep = dict_getTileString( ctxt, tile );
if ( IS_SPECIAL(*facep) ) { if ( IS_SPECIAL(*facep) ) {
XP_UCHAR* chars = ctxt->chars[(XP_U16)*facep]; XP_UCHAR* chars = ctxt->chars[(XP_U16)*facep];
@ -142,12 +141,6 @@ dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles,
return result; return result;
} /* dict_tilesToString */ } /* dict_tilesToString */
const XP_UCHAR*
dict_getTileString( const DictionaryCtxt* ctxt, Tile tile )
{
return dict_getTileChar( ctxt, tile );
}
Tile Tile
dict_tileForString( const DictionaryCtxt* dict, const XP_UCHAR* key ) dict_tileForString( const DictionaryCtxt* dict, const XP_UCHAR* key )
{ {
@ -156,7 +149,7 @@ dict_tileForString( const DictionaryCtxt* dict, const XP_UCHAR* key )
XP_Bool keyNotSpecial = XP_STRLEN(key) == 1; XP_Bool keyNotSpecial = XP_STRLEN(key) == 1;
for ( tile = 0; tile < nFaces; ++tile ) { for ( tile = 0; tile < nFaces; ++tile ) {
const XP_UCHAR* facep = dict_getTileChar( dict, tile ); const XP_UCHAR* facep = dict_getTileString( dict, tile );
if ( IS_SPECIAL(*facep) ) { if ( IS_SPECIAL(*facep) ) {
XP_UCHAR* chars = dict->chars[(XP_U16)*facep]; XP_UCHAR* chars = dict->chars[(XP_U16)*facep];
if ( 0 == XP_STRNCMP( chars, key, XP_STRLEN(chars) ) ) { if ( 0 == XP_STRNCMP( chars, key, XP_STRLEN(chars) ) ) {
@ -174,47 +167,47 @@ dict_tilesAreSame( const DictionaryCtxt* dict1, const DictionaryCtxt* dict2 )
{ {
XP_Bool result = XP_FALSE; XP_Bool result = XP_FALSE;
Tile i; Tile ii;
XP_U16 nTileFaces = dict_numTileFaces( dict1 ); XP_U16 nTileFaces = dict_numTileFaces( dict1 );
if ( nTileFaces == dict_numTileFaces( dict2 ) ) { if ( nTileFaces == dict_numTileFaces( dict2 ) ) {
for ( i = 0; i < nTileFaces; ++i ) { for ( ii = 0; ii < nTileFaces; ++ii ) {
const XP_UCHAR* face1; const XP_UCHAR* face1;
const XP_UCHAR* face2; const XP_UCHAR* face2;
if ( dict_getTileValue( dict1, i ) if ( dict_getTileValue( dict1, ii )
!= dict_getTileValue( dict2, i ) ){ != dict_getTileValue( dict2, ii ) ){
break; break;
} }
#if 1 #if 0
face1 = dict_getTileChar( dict1, i ); face1 = dict_getTileString( dict1, ii );
face2 = dict_getTileChar( dict2, i ); face2 = dict_getTileString( dict2, ii );
if ( face1 != face2 ) { if ( 0 != XP_STRCMP( face1, face2 ) ) {
break; break;
} }
#else #else
face1 = dict_getTileChar( dict1, i ); face1 = dict_getTileString( dict1, ii );
face2 = dict_getTileChar( dict2, i ); face2 = dict_getTileString( dict2, ii );
if ( IS_SPECIAL(face1) != IS_SPECIAL(face2) ) { if ( IS_SPECIAL(*face1) != IS_SPECIAL(*face2) ) {
break; break;
} }
if ( IS_SPECIAL(face1) ) { if ( IS_SPECIAL(*face1) ) {
XP_UCHAR* chars1 = dict1->chars[face1]; XP_UCHAR* chars1 = dict1->chars[(int)*face1];
XP_UCHAR* chars2 = dict2->chars[face2]; XP_UCHAR* chars2 = dict2->chars[(int)*face2];
XP_U16 len = XP_STRLEN(chars1); XP_U16 len = XP_STRLEN(chars1);
if ( 0 != XP_STRNCMP( chars1, chars2, len ) ) { if ( 0 != XP_STRNCMP( chars1, chars2, len ) ) {
break; break;
} }
} else if ( face1 != face2 ) { } else if ( 0 != XP_STRCMP( face1, face2 ) ) {
break; break;
} }
#endif #endif
if ( dict_numTiles( dict1, i ) != dict_numTiles( dict2, i ) ) { if ( dict_numTiles( dict1, ii ) != dict_numTiles( dict2, ii ) ) {
break; break;
} }
} }
result = i == nTileFaces; /* did we get that far */ result = ii == nTileFaces; /* did we get that far */
} }
return result; return result;
} /* dict_tilesAreSame */ } /* dict_tilesAreSame */
@ -226,10 +219,15 @@ ucharsToNarrow( const DictionaryCtxt* dict, XP_UCHAR* buf, XP_U16* bufsizep )
XP_U16 nUsed = 0; XP_U16 nUsed = 0;
XP_U16 bufsize = *bufsizep; XP_U16 bufsize = *bufsizep;
for ( ii = 0; ii < dict->nFaces; ++ii ) { for ( ii = 0; ii < dict->nFaces; ++ii ) {
const XP_UCHAR* face = dict_getTileChar( dict, ii ); const XP_UCHAR* facep = dict_getTileString( dict, ii );
nUsed += XP_SNPRINTF( &buf[nUsed], bufsize - nUsed, "%s", face ); if ( IS_SPECIAL(*facep) ) {
buf[nUsed++] = *facep;
} else {
nUsed += XP_SNPRINTF( &buf[nUsed], bufsize - nUsed, "%s", facep );
}
XP_ASSERT( nUsed < bufsize ); XP_ASSERT( nUsed < bufsize );
} }
buf[nUsed] = 0;
*bufsizep = nUsed; *bufsizep = nUsed;
} }
@ -275,7 +273,7 @@ dict_writeToStream( const DictionaryCtxt* dict, XWStreamCtxt* stream )
stream_putBytes( stream, buf, nBytes ); stream_putBytes( stream, buf, nBytes );
for ( nSpecials = i = 0; i < dict->nFaces; ++i ) { for ( nSpecials = i = 0; i < dict->nFaces; ++i ) {
const XP_UCHAR* facep = dict_getTileChar( dict, (Tile)i ); const XP_UCHAR* facep = dict_getTileString( dict, (Tile)i );
if ( IS_SPECIAL( *facep ) ) { if ( IS_SPECIAL( *facep ) ) {
stringToStream( stream, dict->chars[nSpecials++] ); stringToStream( stream, dict->chars[nSpecials++] );
} }
@ -289,7 +287,7 @@ freeSpecials( DictionaryCtxt* dict )
XP_U16 nSpecials; XP_U16 nSpecials;
for ( nSpecials = t = 0; t < dict->nFaces; ++t ) { for ( nSpecials = t = 0; t < dict->nFaces; ++t ) {
const XP_UCHAR* facep = dict_getTileChar( dict, t ); const XP_UCHAR* facep = dict_getTileString( dict, t );
if ( IS_SPECIAL( *facep ) ) { if ( IS_SPECIAL( *facep ) ) {
XP_ASSERT( !!dict->chars[nSpecials] ); XP_ASSERT( !!dict->chars[nSpecials] );
@ -321,13 +319,11 @@ common_destructor( DictionaryCtxt* dict )
XP_FREE( dict->mpool, dict->faceIndices ); XP_FREE( dict->mpool, dict->faceIndices );
XP_FREE( dict->mpool, dict ); XP_FREE( dict->mpool, dict );
} /* dict */ } /* common_destructor */
void void
dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream ) dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
{ {
XP_ASSERT(0);
XP_U8 nFaces, nFaceBytes; XP_U8 nFaces, nFaceBytes;
XP_U16 maxCountBits, maxValueBits; XP_U16 maxCountBits, maxValueBits;
XP_U16 i, nSpecials; XP_U16 i, nSpecials;
@ -357,10 +353,11 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
nFaceBytes = (XP_U8)stream_getU8( stream ); nFaceBytes = (XP_U8)stream_getU8( stream );
XP_U8 utf8[nFaceBytes]; XP_U8 utf8[nFaceBytes];
stream_getBytes( stream, utf8, nFaceBytes ); stream_getBytes( stream, utf8, nFaceBytes );
dict->isUTF8 = XP_TRUE; /* need to communicate this in stream */
dict_splitFaces( dict, utf8, nFaceBytes, nFaces ); dict_splitFaces( dict, utf8, nFaceBytes, nFaces );
for ( nSpecials = i = 0; i < nFaces; ++i ) { for ( nSpecials = i = 0; i < nFaces; ++i ) {
const XP_UCHAR* facep = dict_getTileChar( dict, (Tile)i ); const XP_UCHAR* facep = dict_getTileString( dict, (Tile)i );
if ( IS_SPECIAL( *facep ) ) { if ( IS_SPECIAL( *facep ) ) {
XP_UCHAR* txt = stringFromStream( dict->mpool, stream ); XP_UCHAR* txt = stringFromStream( dict->mpool, stream );
XP_ASSERT( !!txt ); XP_ASSERT( !!txt );
@ -393,7 +390,7 @@ dict_getName( const DictionaryCtxt* dict )
XP_Bool XP_Bool
dict_faceIsBitmap( const DictionaryCtxt* dict, Tile tile ) dict_faceIsBitmap( const DictionaryCtxt* dict, Tile tile )
{ {
const XP_UCHAR* facep = dict_getTileChar( dict, tile ); const XP_UCHAR* facep = dict_getTileString( dict, tile );
return IS_SPECIAL(*facep); return IS_SPECIAL(*facep);
} /* dict_faceIsBitmap */ } /* dict_faceIsBitmap */
@ -401,7 +398,7 @@ void
dict_getFaceBitmaps( const DictionaryCtxt* dict, Tile tile, XP_Bitmaps* bmps ) dict_getFaceBitmaps( const DictionaryCtxt* dict, Tile tile, XP_Bitmaps* bmps )
{ {
SpecialBitmaps* bitmaps; SpecialBitmaps* bitmaps;
const XP_UCHAR* facep = dict_getTileChar( dict, tile ); const XP_UCHAR* facep = dict_getTileString( dict, tile );
XP_ASSERT( dict_faceIsBitmap( dict, tile ) ); XP_ASSERT( dict_faceIsBitmap( dict, tile ) );
XP_ASSERT( !!dict->bitmaps ); XP_ASSERT( !!dict->bitmaps );