mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-10 06:39:49 +00:00
3affe9913f
Use LRU cache for ESMReaders. When cache capacity is reached close least recently used ESMReader. Remember the file name if a reader was open. Once the reader requested again open the file if there is stored name for it. Put released ESMReader to the back of the free items list. Close ESMReader's from the front of the free items list. Cached item can be used only by one client at the same time. If the same item is requested twice exception is thrown. This should never happen in practice. If this happens need to fix the client logic. It's allowed to go over the capacity limit when requesting different readers. Ideally this should never happen but there will be system error anyway signalizing about too many open files. Need to fix client logic in this case. All places that were using a vector of ESMReaders now using the cache. Cache is local for each use case and there is no need for a thread safety.
97 lines
2.9 KiB
C++
97 lines
2.9 KiB
C++
#ifndef GAME_MWWORLD_CELLS_H
|
|
#define GAME_MWWORLD_CELLS_H
|
|
|
|
#include <map>
|
|
#include <list>
|
|
#include <string>
|
|
|
|
#include "ptr.hpp"
|
|
|
|
namespace ESM
|
|
{
|
|
class ESMReader;
|
|
class ESMWriter;
|
|
class ReadersCache;
|
|
struct CellId;
|
|
struct Cell;
|
|
struct RefNum;
|
|
}
|
|
|
|
namespace Loading
|
|
{
|
|
class Listener;
|
|
}
|
|
|
|
namespace MWWorld
|
|
{
|
|
class ESMStore;
|
|
|
|
/// \brief Cell container
|
|
class Cells
|
|
{
|
|
typedef std::vector<std::pair<std::string, CellStore *> > IdCache;
|
|
const MWWorld::ESMStore& mStore;
|
|
ESM::ReadersCache& mReaders;
|
|
mutable std::map<std::string, CellStore> mInteriors;
|
|
mutable std::map<std::pair<int, int>, CellStore> mExteriors;
|
|
IdCache mIdCache;
|
|
std::size_t mIdCacheIndex;
|
|
|
|
Cells (const Cells&);
|
|
Cells& operator= (const Cells&);
|
|
|
|
CellStore *getCellStore (const ESM::Cell *cell);
|
|
|
|
Ptr getPtrAndCache (const std::string& name, CellStore& cellStore);
|
|
|
|
Ptr getPtr(CellStore& cellStore, const std::string& id, const ESM::RefNum& refNum);
|
|
|
|
void writeCell (ESM::ESMWriter& writer, CellStore& cell) const;
|
|
|
|
public:
|
|
|
|
void clear();
|
|
|
|
explicit Cells(const MWWorld::ESMStore& store, ESM::ReadersCache& reader);
|
|
|
|
CellStore *getExterior (int x, int y);
|
|
|
|
CellStore *getInterior (const std::string& name);
|
|
|
|
CellStore *getCell (const ESM::CellId& id);
|
|
|
|
Ptr getPtr (const std::string& name, CellStore& cellStore, bool searchInContainers = false);
|
|
///< \param searchInContainers Only affect loaded cells.
|
|
/// @note name must be lower case
|
|
|
|
/// @note name must be lower case
|
|
Ptr getPtr (const std::string& name);
|
|
|
|
Ptr getPtr(const std::string& id, const ESM::RefNum& refNum);
|
|
|
|
void rest (double hours);
|
|
void recharge (float duration);
|
|
|
|
/// Get all Ptrs referencing \a name in exterior cells
|
|
/// @note Due to the current implementation of getPtr this only supports one Ptr per cell.
|
|
/// @note name must be lower case
|
|
void getExteriorPtrs (const std::string& name, std::vector<MWWorld::Ptr>& out);
|
|
|
|
/// Get all Ptrs referencing \a name in interior cells
|
|
/// @note Due to the current implementation of getPtr this only supports one Ptr per cell.
|
|
/// @note name must be lower case
|
|
void getInteriorPtrs (const std::string& name, std::vector<MWWorld::Ptr>& out);
|
|
|
|
std::vector<MWWorld::Ptr> getAll(const std::string& id);
|
|
|
|
int countSavedGameRecords() const;
|
|
|
|
void write (ESM::ESMWriter& writer, Loading::Listener& progress) const;
|
|
|
|
bool readRecord (ESM::ESMReader& reader, uint32_t type,
|
|
const std::map<int, int>& contentFileMap);
|
|
};
|
|
}
|
|
|
|
#endif
|