void App::SaveSettings() { Helium::FilePath path; Helium::GetPreferencesDirectory( path ); path += TXT("EditorSettings.json"); std::string error; if ( !path.MakePath() ) { error = std::string( TXT( "Could not save '" ) ) + path.c_str() + TXT( "': We could not create the directory to store the settings file." ); wxMessageBox( error.c_str(), wxT( "Error" ), wxOK | wxCENTER | wxICON_ERROR ); return; } if ( Helium::IsDebuggerPresent() ) { Persist::ArchiveWriter::WriteToFile( path, m_SettingsManager.Ptr() ); } else { if ( !Persist::ArchiveWriter::WriteToFile( path, m_SettingsManager.Ptr() ) ) { error = std::string( TXT( "Could not save '" ) ) + path.c_str() + TXT( "'." ); wxMessageBox( error.c_str(), wxT( "Error" ), wxOK | wxCENTER | wxICON_ERROR ); } } }
void App::LoadSettings() { Helium::FilePath path; Helium::GetPreferencesDirectory( path ); path += TXT("EditorSettings.json"); if ( !path.Exists() ) { return; } SettingsManagerPtr settingsManager = Reflect::SafeCast< SettingsManager >( Persist::ArchiveReader::ReadFromFile( path ) ); if ( settingsManager.ReferencesObject() ) { settingsManager->Clean(); m_SettingsManager = settingsManager; } else { wxMessageBox( TXT( "Unfortunately, we could not parse your existing settings. Your settings have been reset to defaults. We apologize for the inconvenience." ), wxT( "Error" ), wxOK | wxCENTER | wxICON_ERROR ); } }
void App::LoadSettings() { Helium::FilePath path; Helium::GetPreferencesDirectory( path ); path += TXT("EditorSettings.json"); // Leaving this as XML for now until I can figure out why the well-formed .json file is not parsing. I suspect something subtle with translating maps with pointers. if ( !path.Exists() ) { return; } SettingsManagerPtr settingsManager = Reflect::SafeCast< SettingsManager >( Persist::ArchiveReader::ReadFromFile( path ) ); if ( settingsManager.ReferencesObject() ) { settingsManager->Clean(); m_SettingsManager = settingsManager; } else { wxMessageBox( TXT( "Unfortunately, we could not parse your existing settings. Your settings have been reset to defaults. We apologize for the inconvenience." ), wxT( "Error" ), wxOK | wxCENTER | wxICON_ERROR ); } }
std::string DetailsColumn::Size( const Helium::FilePath& path ) { Status status; status.Read( path.Get().c_str() ); int64_t size = status.m_Size; std::stringstream printSize; if ( size == 0 ) { printSize << "0 KB"; } else if ( size <= 1024 ) { printSize << "1 KB"; } else { size = size / 1024; printSize << size << " KB"; } return printSize.str().c_str(); }
std::string DetailsColumn::FilePath( const Helium::FilePath& path ) { return path.Get(); }
std::string DetailsColumn::Directory( const Helium::FilePath& path ) { return path.Directory().Get(); }
/////////////////////////////////////////////////////////////////////////////// // Called after OnInitCmdLine. The base class handles the /help command line // switch and exits. If we get this far, we need to parse the command line // and determine what mode to launch the app in. // bool App::OnInit() { SetVendorName( HELIUM_APP_NAME ); #if !HELIUM_RELEASE && !HELIUM_PROFILE HELIUM_TRACE_SET_LEVEL( TraceLevels::Debug ); Helium::InitializeSymbols(); #endif // Initialize sibling dynamically loaded modules. Helium::FilePath path ( Helium::GetProcessPath() ); for ( DirectoryIterator itr ( FilePath( path.Directory() ) ); !itr.IsDone(); itr.Next() ) { std::string ext = itr.GetItem().m_Path.Extension(); if ( ext == HELIUM_MODULE_EXTENSION ) { ModuleHandle module = LoadModule( itr.GetItem().m_Path.c_str() ); HELIUM_ASSERT( module != HELIUM_INVALID_MODULE ); } } // don't spend a lot of time updating idle events for windows that don't need it wxUpdateUIEvent::SetMode( wxUPDATE_UI_PROCESS_SPECIFIED ); wxIdleEvent::SetMode( wxIDLE_PROCESS_SPECIFIED ); Helium::FilePath exePath( GetProcessPath() ); Helium::FilePath iconFolder( exePath.Directory() + TXT( "Icons/" ) ); wxInitAllImageHandlers(); wxImageHandler* curHandler = wxImage::FindHandler( wxBITMAP_TYPE_CUR ); if ( curHandler ) { // Force the cursor handler to the end of the list so that it doesn't try to // open TGA files. wxImage::RemoveHandler( curHandler->GetName() ); curHandler = NULL; wxImage::AddHandler( new wxCURHandler ); } ArtProvider* artProvider = new ArtProvider(); wxArtProvider::Push( artProvider ); wxSimpleHelpProvider* helpProvider = new wxSimpleHelpProvider(); wxHelpProvider::Set( helpProvider ); // Make sure various module-specific heaps are initialized from the main thread before use. InitEngineJobsDefaultHeap(); InitGraphicsJobsDefaultHeap(); // Register shutdown for general systems. m_InitializerStack.Push( FileLocations::Shutdown ); m_InitializerStack.Push( Name::Shutdown ); m_InitializerStack.Push( AssetPath::Shutdown ); // Async I/O. AsyncLoader& asyncLoader = AsyncLoader::GetStaticInstance(); HELIUM_VERIFY( asyncLoader.Initialize() ); m_InitializerStack.Push( AsyncLoader::DestroyStaticInstance ); // Asset cache management. FilePath baseDirectory; if ( !FileLocations::GetBaseDirectory( baseDirectory ) ) { HELIUM_TRACE( TraceLevels::Error, TXT( "Could not get base directory." ) ); return false; } HELIUM_VERIFY( CacheManager::InitializeStaticInstance( baseDirectory ) ); m_InitializerStack.Push( CacheManager::DestroyStaticInstance ); // libs Editor::PerforceWaitDialog::EnableWaitDialog( true ); m_InitializerStack.Push( Perforce::Initialize, Perforce::Cleanup ); m_InitializerStack.Push( Reflect::ObjectRefCountSupport::Shutdown ); m_InitializerStack.Push( Asset::Shutdown ); m_InitializerStack.Push( AssetType::Shutdown ); m_InitializerStack.Push( Reflect::Initialize, Reflect::Cleanup ); m_InitializerStack.Push( Editor::Initialize, Editor::Cleanup ); // Asset loader and preprocessor. HELIUM_VERIFY( LooseAssetLoader::InitializeStaticInstance() ); m_InitializerStack.Push( LooseAssetLoader::DestroyStaticInstance ); AssetLoader* pAssetLoader = AssetLoader::GetStaticInstance(); HELIUM_ASSERT( pAssetLoader ); AssetPreprocessor* pAssetPreprocessor = AssetPreprocessor::CreateStaticInstance(); HELIUM_ASSERT( pAssetPreprocessor ); PlatformPreprocessor* pPlatformPreprocessor = new PcPreprocessor; HELIUM_ASSERT( pPlatformPreprocessor ); pAssetPreprocessor->SetPlatformPreprocessor( Cache::PLATFORM_PC, pPlatformPreprocessor ); m_InitializerStack.Push( AssetPreprocessor::DestroyStaticInstance ); m_InitializerStack.Push( ThreadSafeAssetTrackerListener::DestroyStaticInstance ); m_InitializerStack.Push( AssetTracker::DestroyStaticInstance ); m_InitializerStack.Push( InitializeEditorSystem, DestroyEditorSystem ); //HELIUM_ASSERT( g_EditorSystemDefinition.Get() ); // TODO: Figure out why this sometimes doesn't load Helium::Components::Initialize( g_EditorSystemDefinition.Get() ); m_InitializerStack.Push( Components::Cleanup ); // Engine configuration. Config& rConfig = Config::GetStaticInstance(); rConfig.BeginLoad(); while( !rConfig.TryFinishLoad() ) { pAssetLoader->Tick(); } m_InitializerStack.Push( Config::DestroyStaticInstance ); ConfigPc::SaveUserConfig(); LoadSettings(); Connect( wxEVT_CHAR, wxKeyEventHandler( App::OnChar ), NULL, this ); m_Frame = new MainFrame( m_SettingsManager ); #if HELIUM_OS_WIN m_Engine.Initialize( &m_Frame->GetSceneManager(), GetHwndOf( m_Frame ) ); #else m_Engine.Initialize( &m_Frame->GetSceneManager(), NULL ); #endif HELIUM_VERIFY( m_Frame->Initialize() ); m_Frame->Show(); if ( GetSettingsManager()->GetSettings< EditorSettings >()->GetReopenLastProjectOnStartup() ) { const std::vector< std::string >& mruPaths = wxGetApp().GetSettingsManager()->GetSettings<EditorSettings>()->GetMRUProjects(); if ( !mruPaths.empty() ) { FilePath projectPath( *mruPaths.rbegin() ); if ( projectPath.Exists() ) { m_Frame->OpenProject( FilePath( *mruPaths.rbegin() ) ); } } } return true; }
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; } #ifdef VIEWPORT_REFACTOR // 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; } #endif if ( m_Loader.m_Quit ) { break; } Helium::FilePath path; { Helium::Locker< Helium::OrderedSet< Helium::FilePath > >::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; #ifdef VIEWPORT_REFACTOR 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 #endif { #pragma TODO( "When we store the thumbnail in the asset file, fix this." ) if ( path.Extension() == TXT( "HeliumEntity" ) ) { FilePath thumbnailPath( path.Directory() + path.Basename() + TXT( "_thumbnail.png" ) ); if ( thumbnailPath.Exists() ) { #ifdef VIEWPORT_REFACTOR IDirect3DTexture9* texture = NULL; if ( texture = LoadTexture( device, thumbnailPath.Get() ) ) { ThumbnailPtr thumbnail = new Thumbnail( m_Loader.m_DeviceManager, texture ); args.m_Textures.push_back( thumbnail ); } #endif } } // Include the color map of a shader as a possible thumbnail image else if ( path.Extension() == TXT( "HeliumShader" ) ) { #ifdef VIEWPORT_REFACTOR 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 ); } } #endif } else if ( path.Extension() == TXT( "HeliumTexture" ) ) { #ifdef VIEWPORT_REFACTOR 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 ); } } #endif } } m_Loader.m_Result.Raise( args ); } return NULL; }