mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
Pass streams to cedraw on save and restore, adding version flag for
backward compatibility. Within cedraw, save cached font info to remove the visible delay on startup.
This commit is contained in:
parent
1825939981
commit
720160e7de
4 changed files with 71 additions and 7 deletions
|
@ -72,9 +72,10 @@ typedef struct _PenColorPair {
|
||||||
|
|
||||||
typedef struct _FontCacheEntry {
|
typedef struct _FontCacheEntry {
|
||||||
HFONT setFont;
|
HFONT setFont;
|
||||||
XP_U16 setFontHt;
|
XP_U16 boundingHt; /* what we fit within */
|
||||||
|
XP_U16 nominalHt; /* the "size" of the font we choose */
|
||||||
|
XP_U16 actualHt; /* the height of the tallest glyph we use */
|
||||||
XP_U16 offset;
|
XP_U16 offset;
|
||||||
XP_U16 actualHt;
|
|
||||||
} FontCacheEntry;
|
} FontCacheEntry;
|
||||||
|
|
||||||
struct CEDrawCtx {
|
struct CEDrawCtx {
|
||||||
|
@ -590,7 +591,8 @@ ceBestFitFont( CEDrawCtx* dctx, XP_U16 soughtHeight, RFIndex index,
|
||||||
|
|
||||||
if ( thisHeight <= soughtHeight ) { /* got it!!! */
|
if ( thisHeight <= soughtHeight ) { /* got it!!! */
|
||||||
fce->setFont = testFont;
|
fce->setFont = testFont;
|
||||||
fce->setFontHt = soughtHeight;
|
fce->boundingHt = soughtHeight;
|
||||||
|
fce->nominalHt = testSize;
|
||||||
fce->offset = top;
|
fce->offset = top;
|
||||||
fce->actualHt = thisHeight;
|
fce->actualHt = thisHeight;
|
||||||
XP_LOGF( "Looking for %d; PICKED %d",
|
XP_LOGF( "Looking for %d; PICKED %d",
|
||||||
|
@ -612,7 +614,7 @@ ceGetSizedFont( CEDrawCtx* dctx, XP_U16 height, RFIndex index )
|
||||||
{
|
{
|
||||||
FontCacheEntry* fce = &dctx->fcEntry[index];
|
FontCacheEntry* fce = &dctx->fcEntry[index];
|
||||||
if ( (0 != height) /* 0 means use what we have */
|
if ( (0 != height) /* 0 means use what we have */
|
||||||
&& fce->setFontHt != height ) {
|
&& fce->boundingHt != height ) {
|
||||||
ceBestFitFont( dctx, height, index, fce );
|
ceBestFitFont( dctx, height, index, fce );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1723,3 +1725,50 @@ ce_drawctxt_make( MPFORMAL HWND mainWin, CEAppGlobals* globals )
|
||||||
|
|
||||||
return dctx;
|
return dctx;
|
||||||
} /* ce_drawctxt_make */
|
} /* ce_drawctxt_make */
|
||||||
|
|
||||||
|
void
|
||||||
|
ce_draw_toStream( const CEDrawCtx* dctx, XWStreamCtxt* stream )
|
||||||
|
{
|
||||||
|
XP_U16 ii;
|
||||||
|
|
||||||
|
stream_putU8( stream, N_RESIZE_FONTS );
|
||||||
|
for ( ii = 0; ii < N_RESIZE_FONTS; ++ii ) {
|
||||||
|
const FontCacheEntry* fce = &dctx->fcEntry[ii];
|
||||||
|
stream_putU8( stream, fce->boundingHt );
|
||||||
|
stream_putU8( stream, fce->nominalHt );
|
||||||
|
stream_putU8( stream, fce->offset );
|
||||||
|
stream_putU8( stream, fce->actualHt );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ce_draw_fromStream( CEDrawCtx* dctx, XWStreamCtxt* stream )
|
||||||
|
{
|
||||||
|
XP_U16 ii;
|
||||||
|
XP_U16 nEntries;
|
||||||
|
|
||||||
|
ceClearFontCache( dctx ); /* no leaking! */
|
||||||
|
|
||||||
|
nEntries = (XP_U16)stream_getU8( stream );
|
||||||
|
|
||||||
|
for ( ii = 0; ii < nEntries; ++ii ) {
|
||||||
|
FontCacheEntry fce;
|
||||||
|
|
||||||
|
fce.boundingHt = (XP_U16)stream_getU8( stream );
|
||||||
|
fce.nominalHt = (XP_U16)stream_getU8( stream );
|
||||||
|
fce.offset = (XP_U16)stream_getU8( stream );
|
||||||
|
fce.actualHt = (XP_U16)stream_getU8( stream );
|
||||||
|
|
||||||
|
/* We need to read from the file no matter how many entries, but only
|
||||||
|
populate what we have room for */
|
||||||
|
if ( ii < N_RESIZE_FONTS ) {
|
||||||
|
LOGFONT fontInfo;
|
||||||
|
XP_MEMSET( &fontInfo, 0, sizeof(fontInfo) );
|
||||||
|
fontInfo.lfHeight = fce.nominalHt;
|
||||||
|
fce.setFont = CreateFontIndirect( &fontInfo );
|
||||||
|
XP_ASSERT( !!fce.setFont );
|
||||||
|
|
||||||
|
XP_MEMCPY( &dctx->fcEntry[ii], &fce, sizeof(dctx->fcEntry[ii]) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -28,5 +28,7 @@ CEDrawCtx* ce_drawctxt_make( MPFORMAL HWND mainWin, CEAppGlobals* globals );
|
||||||
void ce_draw_update( CEDrawCtx* dctx );
|
void ce_draw_update( CEDrawCtx* dctx );
|
||||||
void ce_draw_erase( CEDrawCtx* dctx, const RECT* invalR );
|
void ce_draw_erase( CEDrawCtx* dctx, const RECT* invalR );
|
||||||
|
|
||||||
|
void ce_draw_toStream( const CEDrawCtx* dctx, XWStreamCtxt* stream );
|
||||||
|
void ce_draw_fromStream( CEDrawCtx* dctx, XWStreamCtxt* stream );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1011,9 +1011,10 @@ ceLoadSavedGame( CEAppGlobals* globals )
|
||||||
success = stream != NULL;
|
success = stream != NULL;
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
DictionaryCtxt* dict;
|
DictionaryCtxt* dict;
|
||||||
XP_Bool hasDict;
|
XP_U8 flags = stream_getU8( stream );
|
||||||
|
XP_Bool hasDict = (flags & 0x01) != 0;
|
||||||
|
flags >>= 1;
|
||||||
|
|
||||||
hasDict = stream_getU8( stream );
|
|
||||||
if ( hasDict ) {
|
if ( hasDict ) {
|
||||||
#ifdef STUBBED_DICT
|
#ifdef STUBBED_DICT
|
||||||
XP_ASSERT(0); /* just don't do this!!!! */
|
XP_ASSERT(0); /* just don't do this!!!! */
|
||||||
|
@ -1027,6 +1028,10 @@ ceLoadSavedGame( CEAppGlobals* globals )
|
||||||
dict = NULL;
|
dict = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( flags >= CE_GAMEFILE_VERSION ) {
|
||||||
|
ce_draw_fromStream( globals->draw, stream );
|
||||||
|
}
|
||||||
|
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
XP_DEBUGF( "calling game_makeFromStream" );
|
XP_DEBUGF( "calling game_makeFromStream" );
|
||||||
game_makeFromStream( MEMPOOL stream, &globals->game,
|
game_makeFromStream( MEMPOOL stream, &globals->game,
|
||||||
|
@ -1666,6 +1671,7 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
|
||||||
DictionaryCtxt* dict;
|
DictionaryCtxt* dict;
|
||||||
FileWriteState fwState;
|
FileWriteState fwState;
|
||||||
const char* dictName;
|
const char* dictName;
|
||||||
|
XP_U8 flags;
|
||||||
|
|
||||||
fwState.path = globals->curGameName;
|
fwState.path = globals->curGameName;
|
||||||
fwState.globals = globals;
|
fwState.globals = globals;
|
||||||
|
@ -1682,11 +1688,16 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
|
||||||
#else
|
#else
|
||||||
dictName = !!dict? dict_getName( dict ) : NULL;
|
dictName = !!dict? dict_getName( dict ) : NULL;
|
||||||
#endif
|
#endif
|
||||||
stream_putU8( memStream, (XP_U8)!!dictName );
|
flags = !!dictName? 0x01 : 0x00;
|
||||||
|
flags |= CE_GAMEFILE_VERSION << 1;
|
||||||
|
stream_putU8( memStream, flags );
|
||||||
|
|
||||||
if ( !!dictName ) {
|
if ( !!dictName ) {
|
||||||
stringToStream( memStream, dictName );
|
stringToStream( memStream, dictName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ce_draw_toStream( globals->draw, memStream );
|
||||||
|
|
||||||
game_saveToStream( &globals->game, &globals->gameInfo, memStream );
|
game_saveToStream( &globals->game, &globals->gameInfo, memStream );
|
||||||
|
|
||||||
stream_destroy( memStream );
|
stream_destroy( memStream );
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "cesockwr.h"
|
#include "cesockwr.h"
|
||||||
|
|
||||||
|
#define CE_GAMEFILE_VERSION 0x01 /* means draw gets to save/restore */
|
||||||
|
|
||||||
#ifdef _WIN32_WCE
|
#ifdef _WIN32_WCE
|
||||||
typedef enum {
|
typedef enum {
|
||||||
WINCE_UNKNOWN
|
WINCE_UNKNOWN
|
||||||
|
|
Loading…
Reference in a new issue