Ejemplo n.º 1
0
/////////////////////////////////////////////////////////////////////////////
// Helper function to convert a file ref to an appropriate string 
// representation.
// 
tstring Editor::PathToLabel( const Helium::Path& path, const FilePathOption filePathOption )
{
    tstring filePath = path.Get();

    // Determine whether to show full path or not...
    if ( !filePath.empty() )
    {
        switch ( filePathOption )
        {
        case FilePathOptions::Basename:
            filePath = path.Basename();
            break;

        case FilePathOptions::Filename:
            filePath = path.Filename();
            break;

        case FilePathOptions::PartialPath:
            //FileSystem::StripPrefix( Finder::ProjectAssets(), filePath );
#pragma TODO( "Make this aware of the project root somehow, maybe the application/program options" )
            break;

        case FilePathOptions::FullPath:
            // Do nothing, it's already good to go
            break;
        }
    }

    return filePath;
}
Ejemplo n.º 2
0
void* ThumbnailLoader::LoadThread::Entry()
{
#ifdef HELIUM_ASSERT_ENABLED
    bool emptyQueuePollingCheck = false;
#endif

    while ( true )
    {
        m_Loader.m_Signal.Decrement();

        if ( m_Loader.m_Quit )
        {
            break;
        }

        // the device is gone, our glorious benefactor is probably cleaning up
        IDirect3DDevice9* device = m_Loader.m_DeviceManager->GetD3DDevice();
        if ( !device )
        {
            // You should stop this thread before letting go of the window that
            // owns the device.
            HELIUM_BREAK();
            break;
        }

        // while the device is lost, just wait for it to come back
        while ( device->TestCooperativeLevel() != D3D_OK )
        {
            if ( m_Loader.m_Quit )
            {
                break;
            }

            wxThread::Sleep( 100 );
            continue;
        }

        if ( m_Loader.m_Quit )
        {
            break;
        }

        Helium::Path path;

        {
            Helium::Locker< Helium::OrderedSet< Helium::Path > >::Handle queue( m_Loader.m_FileQueue );
            if ( !queue->Empty() )
            {
#ifdef HELIUM_ASSERT_ENABLED
                emptyQueuePollingCheck = false;
#endif
                path = queue->Front();
            }
            else
            {
                // if you hit this then the bookkeeping of the counting semaphore is broken
                HELIUM_ASSERT( !emptyQueuePollingCheck );

#ifdef HELIUM_ASSERT_ENABLED
                emptyQueuePollingCheck = true;
#endif
                continue;
            }

            queue->Remove( path );
        }

        ResultArgs args;
        args.m_Path = path;
        args.m_Cancelled = false;

        if ( SceneGraph::IsSupportedTexture( path.Get() ) )
        {
            IDirect3DTexture9* texture = NULL;
            if ( texture = LoadTexture( device, path.Get() ) )
            {
                ThumbnailPtr thumbnail = new Thumbnail( m_Loader.m_DeviceManager, texture );
                args.m_Textures.push_back( thumbnail );
            }
        }
        else
        {
#pragma TODO( "When we store the thumbnail in the asset file, fix this." )

            if ( path.Extension() == TXT( "HeliumEntity" ) )
            {
                Path thumbnailPath( path.Directory() + path.Basename() + TXT( "_thumbnail.png" ) );

                if ( thumbnailPath.Exists() )
                {
                    IDirect3DTexture9* texture = NULL;
                    if ( texture = LoadTexture( device, thumbnailPath.Get() ) )
                    {
                        ThumbnailPtr thumbnail = new Thumbnail( m_Loader.m_DeviceManager, texture );
                        args.m_Textures.push_back( thumbnail );
                    }
                }
            }
            // Include the color map of a shader as a possible thumbnail image
            else if ( path.Extension() == TXT( "HeliumShader" ) )
            {
                Asset::ShaderAssetPtr shader = NULL;
                try
                {
                    shader = Asset::AssetClass::LoadAssetClass< Asset::ShaderAsset >( path );
                }
                catch( const Exception& )
                {
                    shader = NULL;
                }

                if ( shader )
                {
                    Asset::TexturePtr colorMap = Asset::AssetClass::LoadAssetClass< Asset::Texture >( shader->m_ColorMapPath );
                    if ( colorMap.ReferencesObject() )
                    {
                        if ( colorMap->GetContentPath().Exists() && SceneGraph::IsSupportedTexture( colorMap->GetContentPath().Get() ) )
                        {
                            IDirect3DTexture9* texture = NULL;
                            if ( texture = LoadTexture( device, colorMap->GetContentPath().Get() ) )
                            {
                                ThumbnailPtr thumbnail = new Thumbnail( m_Loader.m_DeviceManager, texture );
                                args.m_Textures.push_back( thumbnail );
                            }
                        }
                    }
                }
            }
            else if ( path.Extension() == TXT( "HeliumTexture" ) )
            {
                Asset::TexturePtr textureAsset = NULL;
                
                try
                {
                    textureAsset = Asset::AssetClass::LoadAssetClass< Asset::Texture >( path );
                }
                catch( const Exception& )
                {
                    textureAsset = NULL;
                }

                if ( textureAsset.ReferencesObject() )
                {
                    if ( textureAsset->GetContentPath().Exists() && SceneGraph::IsSupportedTexture( textureAsset->GetContentPath().Get() ) )
                    {
                        IDirect3DTexture9* texture = NULL;
                        if ( texture = LoadTexture( device, textureAsset->GetContentPath().Get() ) )
                        {
                            ThumbnailPtr thumbnail = new Thumbnail( m_Loader.m_DeviceManager, texture );
                            args.m_Textures.push_back( thumbnail );
                        }
                    }
                }
            }
        }

        m_Loader.m_Result.Raise( args );
    }

    return NULL;
}