2016-02-06 23:07:02 +00:00
|
|
|
#ifndef OPENMW_MWWORLD_CELLPRELOADER_H
|
|
|
|
#define OPENMW_MWWORLD_CELLPRELOADER_H
|
|
|
|
|
|
|
|
#include <components/sceneutil/workqueue.hpp>
|
|
|
|
#include <map>
|
2017-03-09 03:18:35 +00:00
|
|
|
#include <osg/Vec3f>
|
2019-06-13 13:37:00 +00:00
|
|
|
#include <osg/Vec4i>
|
2016-02-06 23:07:02 +00:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
2016-02-06 23:36:31 +00:00
|
|
|
class ResourceSystem;
|
2016-02-06 23:07:02 +00:00
|
|
|
class BulletShapeManager;
|
|
|
|
}
|
|
|
|
|
2016-02-09 19:57:30 +00:00
|
|
|
namespace Terrain
|
|
|
|
{
|
|
|
|
class World;
|
2017-03-09 03:18:35 +00:00
|
|
|
class View;
|
2016-02-09 19:57:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 18:04:17 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
class LandManager;
|
|
|
|
}
|
|
|
|
|
2021-09-05 15:43:46 +00:00
|
|
|
namespace Loading
|
|
|
|
{
|
|
|
|
class Listener;
|
|
|
|
}
|
|
|
|
|
2016-02-06 23:07:02 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class CellStore;
|
2019-03-21 13:50:49 +00:00
|
|
|
class TerrainPreloadItem;
|
2016-02-06 23:07:02 +00:00
|
|
|
|
|
|
|
class CellPreloader
|
|
|
|
{
|
|
|
|
public:
|
2017-03-06 18:04:17 +00:00
|
|
|
CellPreloader(Resource::ResourceSystem* resourceSystem, Resource::BulletShapeManager* bulletShapeManager,
|
|
|
|
Terrain::World* terrain, MWRender::LandManager* landManager);
|
2016-02-10 18:08:17 +00:00
|
|
|
~CellPreloader();
|
2016-02-06 23:07:02 +00:00
|
|
|
|
|
|
|
/// Ask a background thread to preload rendering meshes and collision shapes for objects in this cell.
|
|
|
|
/// @note The cell itself must be in State_Loaded or State_Preloaded.
|
2023-04-20 14:27:50 +00:00
|
|
|
void preload(MWWorld::CellStore& cell, double timestamp);
|
2016-02-06 23:07:02 +00:00
|
|
|
|
2016-02-09 17:33:02 +00:00
|
|
|
void notifyLoaded(MWWorld::CellStore* cell);
|
|
|
|
|
2017-02-09 03:03:38 +00:00
|
|
|
void clear();
|
|
|
|
|
2016-02-06 23:07:02 +00:00
|
|
|
/// Removes preloaded cells that have not had a preload request for a while.
|
|
|
|
void updateCache(double timestamp);
|
|
|
|
|
2016-02-07 18:05:55 +00:00
|
|
|
/// How long to keep a preloaded cell in cache after it's no longer requested.
|
|
|
|
void setExpiryDelay(double expiryDelay);
|
|
|
|
|
2016-02-18 16:47:10 +00:00
|
|
|
/// The minimum number of preloaded cells before unused cells get thrown out.
|
|
|
|
void setMinCacheSize(unsigned int num);
|
|
|
|
|
|
|
|
/// The maximum number of preloaded cells.
|
|
|
|
void setMaxCacheSize(unsigned int num);
|
|
|
|
|
2016-03-29 21:28:53 +00:00
|
|
|
/// Enables the creation of instances in the preloading thread.
|
|
|
|
void setPreloadInstances(bool preload);
|
|
|
|
|
2016-03-28 22:48:47 +00:00
|
|
|
unsigned int getMaxCacheSize() const;
|
|
|
|
|
2016-02-06 23:07:02 +00:00
|
|
|
void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue);
|
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
typedef std::pair<osg::Vec3f, osg::Vec4i> PositionCellGrid;
|
|
|
|
void setTerrainPreloadPositions(const std::vector<PositionCellGrid>& positions);
|
2017-03-09 03:18:35 +00:00
|
|
|
|
2023-05-01 14:36:48 +00:00
|
|
|
void syncTerrainLoad(Loading::Listener& listener);
|
2020-05-12 13:37:00 +00:00
|
|
|
void abortTerrainPreloadExcept(const PositionCellGrid* exceptPos);
|
2021-09-16 20:11:19 +00:00
|
|
|
bool isTerrainLoaded(const CellPreloader::PositionCellGrid& position, double referenceTime) const;
|
2023-05-18 22:16:58 +00:00
|
|
|
void setTerrain(Terrain::World* terrain);
|
2020-05-07 13:37:00 +00:00
|
|
|
|
2016-02-06 23:07:02 +00:00
|
|
|
private:
|
2023-05-18 22:16:58 +00:00
|
|
|
void clearAllTasks();
|
|
|
|
|
2016-02-06 23:36:31 +00:00
|
|
|
Resource::ResourceSystem* mResourceSystem;
|
2016-02-06 23:07:02 +00:00
|
|
|
Resource::BulletShapeManager* mBulletShapeManager;
|
2016-02-09 19:57:30 +00:00
|
|
|
Terrain::World* mTerrain;
|
2017-03-06 18:04:17 +00:00
|
|
|
MWRender::LandManager* mLandManager;
|
2016-02-06 23:07:02 +00:00
|
|
|
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
|
2016-02-07 18:05:55 +00:00
|
|
|
double mExpiryDelay;
|
2016-02-18 16:47:10 +00:00
|
|
|
unsigned int mMinCacheSize;
|
|
|
|
unsigned int mMaxCacheSize;
|
2016-03-29 21:28:53 +00:00
|
|
|
bool mPreloadInstances;
|
2016-02-06 23:07:02 +00:00
|
|
|
|
2017-02-03 02:42:21 +00:00
|
|
|
double mLastResourceCacheUpdate;
|
|
|
|
|
2016-02-06 23:07:02 +00:00
|
|
|
struct PreloadEntry
|
|
|
|
{
|
|
|
|
PreloadEntry(double timestamp, osg::ref_ptr<SceneUtil::WorkItem> workItem)
|
|
|
|
: mTimeStamp(timestamp)
|
2023-07-29 08:58:27 +00:00
|
|
|
, mWorkItem(std::move(workItem))
|
2016-02-06 23:07:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
PreloadEntry()
|
|
|
|
: mTimeStamp(0.0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
double mTimeStamp;
|
|
|
|
osg::ref_ptr<SceneUtil::WorkItem> mWorkItem;
|
|
|
|
};
|
|
|
|
typedef std::map<const MWWorld::CellStore*, PreloadEntry> PreloadMap;
|
|
|
|
|
|
|
|
// Cells that are currently being preloaded, or have already finished preloading
|
|
|
|
PreloadMap mPreloadCells;
|
2017-03-09 03:18:35 +00:00
|
|
|
|
2017-03-14 19:27:55 +00:00
|
|
|
std::vector<osg::ref_ptr<Terrain::View>> mTerrainViews;
|
2019-06-13 13:37:00 +00:00
|
|
|
std::vector<PositionCellGrid> mTerrainPreloadPositions;
|
2019-03-21 13:50:49 +00:00
|
|
|
osg::ref_ptr<TerrainPreloadItem> mTerrainPreloadItem;
|
2017-03-14 19:02:22 +00:00
|
|
|
osg::ref_ptr<SceneUtil::WorkItem> mUpdateCacheItem;
|
2021-09-16 20:11:19 +00:00
|
|
|
|
|
|
|
std::vector<PositionCellGrid> mLoadedTerrainPositions;
|
|
|
|
double mLoadedTerrainTimestamp;
|
2016-02-06 23:07:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|