1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-03 17:37:18 +00:00
OpenMW/apps/openmw/mwstate/quicksavemanager.cpp
2022-09-22 21:35:26 +03:00

39 lines
947 B
C++

#include "quicksavemanager.hpp"
MWState::QuickSaveManager::QuickSaveManager(std::string& saveName, unsigned int maxSaves)
: mSaveName(saveName)
, mMaxSaves(maxSaves)
, mSlotsVisited(0)
, mOldestSlotVisited(nullptr)
{
}
void MWState::QuickSaveManager::visitSave(const Slot* saveSlot)
{
if (mSaveName == saveSlot->mProfile.mDescription)
{
++mSlotsVisited;
if (isOldestSave(saveSlot))
mOldestSlotVisited = saveSlot;
}
}
bool MWState::QuickSaveManager::isOldestSave(const Slot* compare) const
{
if (mOldestSlotVisited == nullptr)
return true;
return (compare->mTimeStamp <= mOldestSlotVisited->mTimeStamp);
}
bool MWState::QuickSaveManager::shouldCreateNewSlot() const
{
return (mSlotsVisited < mMaxSaves);
}
const MWState::Slot* MWState::QuickSaveManager::getNextQuickSaveSlot()
{
if (shouldCreateNewSlot())
return nullptr;
return mOldestSlotVisited;
}