Added version tag to cache data

This commit is contained in:
Cirilo Bernardo 2016-01-20 09:07:09 +11:00
parent 3a80de107d
commit ab2fff46f1
3 changed files with 38 additions and 7 deletions

View File

@ -307,11 +307,8 @@ SCENEGRAPH* S3D_CACHE::checkCache( const wxString& aFileName, S3D_CACHE_ENTRY**
wxString bname = ep->GetCacheBaseName();
wxString cachename = m_CacheDir + bname + wxT( ".3dc" );
if( wxFileName::FileExists( cachename ) )
{
loadCacheData( ep );
if( wxFileName::FileExists( cachename ) && loadCacheData( ep ) )
return ep->sceneData;
}
ep->sceneData = m_Plugins->Load3DModel( aFileName );
@ -476,9 +473,6 @@ bool S3D_CACHE::saveCacheData( S3D_CACHE_ENTRY* aCacheItem )
return false;
}
// the file already exists on disk; just exit
return true;
}
return S3D::WriteCache( fname, true, (SGNODE*)aCacheItem->sceneData );

View File

@ -574,6 +574,8 @@ bool S3D_FILENAME_RESOLVER::readPathList( void )
istr.str( cfgLine.substr( 2 ) );
istr >> vnum;
}
continue;
}
idx = 0;

View File

@ -32,6 +32,10 @@
#include "3d_cache/sg/sg_shape.h"
#include "3d_cache/sg/sg_helpers.h"
// version format of the cache file
#define SG_VERSION_TAG "VERSION:1"
SCENEGRAPH::SCENEGRAPH( SGNODE* aParent ) : SGNODE( aParent )
{
m_SGtype = S3D::SGTYPE_TRANSFORM;
@ -366,6 +370,7 @@ bool SCENEGRAPH::WriteCache( std::ofstream& aFile, SGNODE* parentNode )
// ensure unique node names
ResetNodeIndex();
ReNameNodes();
aFile << "[" << SG_VERSION_TAG << "]";
}
if( aFile.fail() )
@ -462,6 +467,36 @@ bool SCENEGRAPH::ReadCache( std::ifstream& aFile, SGNODE* parentNode )
if( NULL == parentNode )
{
// read the tag; if it's not the expected tag then we fail to read the cache file
do
{
char schar;
aFile.get( schar );
if( '[' != schar )
{
#ifdef DEBUG
std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
std::cerr << " * [INFO] corrupt data; missing left bracket at position ";
std::cerr << aFile.tellg() << "\n";
#endif
return false;
}
aFile.get( schar );
while( ']' != schar && aFile.good() )
{
name.push_back( schar );
aFile.get( schar );
}
if( name.compare( SG_VERSION_TAG ) )
return false;
} while( 0 );
// we need to read the tag and verify its type
if( S3D::SGTYPE_TRANSFORM != S3D::ReadTag( aFile, name ) )
{