MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / Save

Method Save

TombEngine/Game/savegame.cpp:1776–1818  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1774}
1775
1776bool SaveGame::Save(int slot)
1777{
1778 if (!IsSaveGameSlotValid(slot))
1779 return false;
1780
1781 g_GameScript->OnSave();
1782 HandleAllGlobalEvents(EventType::Save, (Activator)short(LaraItem->Index));
1783
1784 // Savegame infos need to be reloaded so that last savegame counter properly increases.
1785 LoadHeaders();
1786
1787 auto filename = GetSavegameFilename(slot);
1788 TENLog(fmt::format("Saving to savegame {}.", filename), LogLevel::Info);
1789
1790 if (!std::filesystem::is_directory(FullSaveDirectory))
1791 std::filesystem::create_directory(FullSaveDirectory);
1792
1793 std::ofstream fileOut{};
1794 fileOut.open(filename, std::ios_base::binary | std::ios_base::out);
1795
1796 // Write current level save data.
1797 auto currentLevelState = SaveGame::Build();
1798 int size = (int)currentLevelState.size();
1799 fileOut.write(reinterpret_cast<const char*>(&size), sizeof(size));
1800 fileOut.write(reinterpret_cast<const char*>(currentLevelState.data()), size);
1801
1802 // Write hub data.
1803 int hubCount = (int)Hub.size();
1804 fileOut.write(reinterpret_cast<const char*>(&hubCount), sizeof(hubCount));
1805
1806 for (auto& level : Hub)
1807 {
1808 fileOut.write(reinterpret_cast<const char*>(&level.first), sizeof(level.first));
1809
1810 size = (int)level.second.size();
1811 fileOut.write(reinterpret_cast<const char*>(&size), sizeof(size));
1812 fileOut.write(reinterpret_cast<const char*>(level.second.data()), size);
1813 }
1814
1815 fileOut.close();
1816
1817 return true;
1818}
1819
1820bool SaveGame::Load(int slot)
1821{

Callers

nothing calls this directly

Calls 9

HandleAllGlobalEventsFunction · 0.85
TENLogFunction · 0.85
OnSaveMethod · 0.80
openMethod · 0.80
formatFunction · 0.50
sizeMethod · 0.45
writeMethod · 0.45
dataMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected