void PreloadScene::update(float dt)
{
    if(!m_dataStartLoading)
        PreloadData();

    if(m_dataFinishLoading)
    {
        auto director = Director::getInstance();
        auto menu = MenuScene::createScene();
        director->replaceScene(menu);
    }
}
Beispiel #2
0
bool CXZip::Load( FILE* handle, int nOffset, int nSize, bool bPreload )	// Load a pack file into this instance.  Returns true on success.
{
    Unload();

    m_bByteSwapped = false;

    m_hZip = handle;
    m_nOffset = nOffset;
    m_nSize = nSize;

    // Hacky, clean up:
    if( m_hZip && !m_pRead )
    {
        InstallAlternateIO( defaultRead, (int)m_hZip );
    }

    if( m_hZip == NULL && m_pRead == NULL )
    {
        return false;
    }

    // Read the header:
    m_pRead( &m_Header, 0, -1, sizeof(m_Header), m_hUser );

    // Validate the Magic number and at the same time determine if I am reading a regular or swappped xZip file:
    switch( m_Swap.SourceIsNativeEndian<int>( m_Header.Magic, xZipHeader_t::MAGIC ) )
    {
    // Does the magic match exactly?
    case 1:
        m_Swap.ActivateByteSwapping( false );
        m_bByteSwapped = false;
        break;

    // Does the magic match, but is swapped?
    case 0:
        m_bByteSwapped = true;
        m_Swap.ActivateByteSwapping( true );	// We must be reading the opposite endianness.
        m_Swap.SwapFieldsToTargetEndian<xZipHeader_t>( &m_Header );
        break;

    default:
        assert( 0 );
    // Fail gently in release:

    // The magic doesn't match in any respect:
    case -1:
    {
        printf("Invalid xZip file\n");

        if( m_hZip )
        {
            fclose( m_hZip );
            m_hZip = NULL;
        }
        return false;
    }
    }

    // Validate the archive version:
    if( m_Header.Version != xZipHeader_t::VERSION )
    {
        // Backward compatable support for version 1
        Msg("Incorrect xZip version found %u - expected %u\n", m_Header.Version, xZipHeader_t::VERSION );
        if( m_hZip )
        {
            fclose( m_hZip );
            m_hZip = NULL;
        }

        m_Header.Magic = xZipHeader_t::FREE;
        return false;
    }

    // Read the directory:
    {
        MEM_ALLOC_CREDIT();

        m_pDirectory = (xZipDirectoryEntry_t*)malloc( sizeof(xZipDirectoryEntry_t) * m_Header.DirectoryEntries );
        m_pRead( m_pDirectory, m_Header.HeaderLength, -1, sizeof( xZipDirectoryEntry_t ) * m_Header.DirectoryEntries, m_hUser );

        // Swap the directory entries if nessecary
        if( m_bByteSwapped )
        {
            for( unsigned nDirectoryEntry = 0; nDirectoryEntry < m_Header.DirectoryEntries; nDirectoryEntry++ )
            {
                m_Swap.SwapFieldsToTargetEndian<xZipDirectoryEntry_t>(  &( m_pDirectory[nDirectoryEntry] ) );
            }
        }


        m_nPreloadStart = m_Header.HeaderLength + ( sizeof( xZipDirectoryEntry_t ) * m_Header.DirectoryEntries );
    }

    // Preload the preload chunk if desired:
    if( bPreload )
    {
        PreloadData();
    }

    return true;
}