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:
ehouse 2008-09-10 12:18:30 +00:00
parent 1825939981
commit 720160e7de
4 changed files with 71 additions and 7 deletions

View file

@ -72,9 +72,10 @@ typedef struct _PenColorPair {
typedef struct _FontCacheEntry {
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 actualHt;
} FontCacheEntry;
struct CEDrawCtx {
@ -590,7 +591,8 @@ ceBestFitFont( CEDrawCtx* dctx, XP_U16 soughtHeight, RFIndex index,
if ( thisHeight <= soughtHeight ) { /* got it!!! */
fce->setFont = testFont;
fce->setFontHt = soughtHeight;
fce->boundingHt = soughtHeight;
fce->nominalHt = testSize;
fce->offset = top;
fce->actualHt = thisHeight;
XP_LOGF( "Looking for %d; PICKED %d",
@ -612,7 +614,7 @@ ceGetSizedFont( CEDrawCtx* dctx, XP_U16 height, RFIndex index )
{
FontCacheEntry* fce = &dctx->fcEntry[index];
if ( (0 != height) /* 0 means use what we have */
&& fce->setFontHt != height ) {
&& fce->boundingHt != height ) {
ceBestFitFont( dctx, height, index, fce );
}
@ -1723,3 +1725,50 @@ ce_drawctxt_make( MPFORMAL HWND mainWin, CEAppGlobals* globals )
return dctx;
} /* 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]) );
}
}
}

View file

@ -28,5 +28,7 @@ CEDrawCtx* ce_drawctxt_make( MPFORMAL HWND mainWin, CEAppGlobals* globals );
void ce_draw_update( CEDrawCtx* dctx );
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

View file

@ -1011,9 +1011,10 @@ ceLoadSavedGame( CEAppGlobals* globals )
success = stream != NULL;
if ( success ) {
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 ) {
#ifdef STUBBED_DICT
XP_ASSERT(0); /* just don't do this!!!! */
@ -1027,6 +1028,10 @@ ceLoadSavedGame( CEAppGlobals* globals )
dict = NULL;
}
if ( flags >= CE_GAMEFILE_VERSION ) {
ce_draw_fromStream( globals->draw, stream );
}
if ( success ) {
XP_DEBUGF( "calling game_makeFromStream" );
game_makeFromStream( MEMPOOL stream, &globals->game,
@ -1666,6 +1671,7 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
DictionaryCtxt* dict;
FileWriteState fwState;
const char* dictName;
XP_U8 flags;
fwState.path = globals->curGameName;
fwState.globals = globals;
@ -1682,11 +1688,16 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
#else
dictName = !!dict? dict_getName( dict ) : NULL;
#endif
stream_putU8( memStream, (XP_U8)!!dictName );
flags = !!dictName? 0x01 : 0x00;
flags |= CE_GAMEFILE_VERSION << 1;
stream_putU8( memStream, flags );
if ( !!dictName ) {
stringToStream( memStream, dictName );
}
ce_draw_toStream( globals->draw, memStream );
game_saveToStream( &globals->game, &globals->gameInfo, memStream );
stream_destroy( memStream );

View file

@ -29,6 +29,8 @@
#include "mempool.h"
#include "cesockwr.h"
#define CE_GAMEFILE_VERSION 0x01 /* means draw gets to save/restore */
#ifdef _WIN32_WCE
typedef enum {
WINCE_UNKNOWN