1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00
OpenMW/apps/openmw/mwstate/quicksavemanager.cpp

39 lines
947 B
C++
Raw Normal View History

#include "quicksavemanager.hpp"
2022-09-22 21:26:05 +03:00
MWState::QuickSaveManager::QuickSaveManager(std::string& saveName, unsigned int maxSaves)
: mSaveName(saveName)
, mMaxSaves(maxSaves)
, mSlotsVisited(0)
, mOldestSlotVisited(nullptr)
2018-01-12 20:02:43 -05:00
{
}
2022-09-22 21:26:05 +03:00
void MWState::QuickSaveManager::visitSave(const Slot* saveSlot)
2018-01-12 20:02:43 -05:00
{
2022-09-22 21:26:05 +03:00
if (mSaveName == saveSlot->mProfile.mDescription)
2018-01-12 20:02:43 -05:00
{
++mSlotsVisited;
2022-09-22 21:26:05 +03:00
if (isOldestSave(saveSlot))
2018-01-12 20:02:43 -05:00
mOldestSlotVisited = saveSlot;
}
}
2022-09-22 21:26:05 +03:00
bool MWState::QuickSaveManager::isOldestSave(const Slot* compare) const
2018-01-12 20:02:43 -05:00
{
2022-09-22 21:26:05 +03:00
if (mOldestSlotVisited == nullptr)
return true;
2018-01-12 20:02:43 -05:00
return (compare->mTimeStamp <= mOldestSlotVisited->mTimeStamp);
}
2021-03-29 19:44:23 +02:00
bool MWState::QuickSaveManager::shouldCreateNewSlot() const
2018-01-12 20:02:43 -05:00
{
return (mSlotsVisited < mMaxSaves);
}
2022-09-22 21:26:05 +03:00
const MWState::Slot* MWState::QuickSaveManager::getNextQuickSaveSlot()
2018-01-12 20:02:43 -05:00
{
2022-09-22 21:26:05 +03:00
if (shouldCreateNewSlot())
2018-10-09 10:21:12 +04:00
return nullptr;
2018-01-12 20:02:43 -05:00
return mOldestSlotVisited;
}