| 1840 | } |
| 1841 | |
| 1842 | bool LoadLevelFile(int levelIndex) |
| 1843 | { |
| 1844 | const auto& level = *g_GameFlow->GetLevel(levelIndex); |
| 1845 | |
| 1846 | auto assetDir = g_GameFlow->GetGameDir(); |
| 1847 | auto levelPath = assetDir + level.FileName; |
| 1848 | |
| 1849 | bool isDummyLevel = false; |
| 1850 | |
| 1851 | if (!std::filesystem::is_regular_file(levelPath)) |
| 1852 | { |
| 1853 | if (levelIndex == 0) |
| 1854 | { |
| 1855 | levelPath = assetDir + DUMMY_LEVEL_NAME; |
| 1856 | GenerateDummyLevel(levelPath); |
| 1857 | TENLog("Title level file not found, using dummy level.", LogLevel::Info); |
| 1858 | isDummyLevel = true; |
| 1859 | } |
| 1860 | else |
| 1861 | { |
| 1862 | TENLog("Level file not found: " + levelPath, LogLevel::Error); |
| 1863 | return false; |
| 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | if (!isDummyLevel) |
| 1868 | TENLog("Loading level file: " + levelPath, LogLevel::Info); |
| 1869 | |
| 1870 | auto timestamp = std::filesystem::last_write_time(levelPath); |
| 1871 | bool fastReload = (g_GameFlow->GetSettings()->System.FastReload && |
| 1872 | levelIndex == CurrentLevel && timestamp == LastLevelTimestamp && levelPath == LastLevelFilePath); |
| 1873 | |
| 1874 | // If fast reload is in action, draw last game frame instead of loading screen. |
| 1875 | auto loadingScreenPath = TEN::Utils::ToWString(assetDir + level.LoadScreenFileName); |
| 1876 | g_Renderer.SetLoadingScreen(fastReload ? std::wstring{} : loadingScreenPath); |
| 1877 | |
| 1878 | BackupLara(); |
| 1879 | StopAllSounds(); |
| 1880 | CleanUp(); |
| 1881 | FreeLevel(fastReload); |
| 1882 | |
| 1883 | LevelLoadTask = std::async(std::launch::async, LoadLevel, levelPath, fastReload); |
| 1884 | bool loadSuccess = LevelLoadTask.get(); |
| 1885 | |
| 1886 | if (loadSuccess && isDummyLevel) |
| 1887 | std::filesystem::remove(levelPath); |
| 1888 | |
| 1889 | return loadSuccess; |
| 1890 | } |
| 1891 | |
| 1892 | void LoadSprites() |
| 1893 | { |
no test coverage detected