2011-07-31 17:07:11 +02:00
|
|
|
#ifndef GAME_MWWORLD_SCENE_H
|
|
|
|
#define GAME_MWWORLD_SCENE_H
|
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
#include <osg/Vec4i>
|
|
|
|
#include <osg/Vec2i>
|
2021-07-11 14:43:52 +02:00
|
|
|
#include <osg/ref_ptr>
|
2019-06-13 13:37:00 +00:00
|
|
|
|
2013-02-07 12:11:10 -08:00
|
|
|
#include "ptr.hpp"
|
2011-08-01 03:33:02 +02:00
|
|
|
#include "globals.hpp"
|
|
|
|
|
2015-04-01 17:02:15 +02:00
|
|
|
#include <set>
|
2016-02-07 00:36:31 +01:00
|
|
|
#include <memory>
|
2018-07-20 22:11:34 +03:00
|
|
|
#include <unordered_map>
|
2021-07-11 14:43:52 +02:00
|
|
|
#include <vector>
|
2015-04-01 17:02:15 +02:00
|
|
|
|
2020-06-16 18:43:01 +04:00
|
|
|
#include <components/misc/constants.hpp>
|
|
|
|
|
2015-04-12 15:34:50 +02:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Vec3f;
|
|
|
|
}
|
|
|
|
|
2011-08-01 03:33:02 +02:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
struct Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Files
|
|
|
|
{
|
|
|
|
class Collections;
|
|
|
|
}
|
|
|
|
|
2014-02-23 20:11:05 +01:00
|
|
|
namespace Loading
|
|
|
|
{
|
|
|
|
class Listener;
|
|
|
|
}
|
|
|
|
|
2018-07-20 22:11:34 +03:00
|
|
|
namespace DetourNavigator
|
|
|
|
{
|
2019-02-16 15:27:02 +03:00
|
|
|
struct Navigator;
|
2018-07-20 22:11:34 +03:00
|
|
|
}
|
|
|
|
|
2011-07-31 17:07:11 +02:00
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
class SkyManager;
|
2015-04-01 17:02:15 +02:00
|
|
|
class RenderingManager;
|
2011-07-31 17:07:11 +02:00
|
|
|
}
|
|
|
|
|
2015-05-10 01:09:00 +02:00
|
|
|
namespace MWPhysics
|
2011-07-31 17:07:11 +02:00
|
|
|
{
|
2013-02-07 12:11:10 -08:00
|
|
|
class PhysicsSystem;
|
2015-05-10 01:09:00 +02:00
|
|
|
}
|
|
|
|
|
2021-07-11 14:43:52 +02:00
|
|
|
namespace SceneUtil
|
|
|
|
{
|
|
|
|
class WorkItem;
|
|
|
|
}
|
|
|
|
|
2015-05-10 01:09:00 +02:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
2011-08-01 03:33:02 +02:00
|
|
|
class Player;
|
2012-07-03 13:55:53 +02:00
|
|
|
class CellStore;
|
2016-02-07 00:36:31 +01:00
|
|
|
class CellPreloader;
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2019-11-30 12:29:31 +01:00
|
|
|
enum class RotationOrder
|
|
|
|
{
|
|
|
|
direct,
|
|
|
|
inverse
|
|
|
|
};
|
|
|
|
|
2011-07-31 17:07:11 +02:00
|
|
|
class Scene
|
|
|
|
{
|
|
|
|
public:
|
2021-02-05 14:55:42 +01:00
|
|
|
using CellStoreCollection = std::set<CellStore *>;
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2011-09-04 09:48:50 +02:00
|
|
|
private:
|
|
|
|
|
2013-05-15 17:54:18 +02:00
|
|
|
CellStore* mCurrentCell; // the cell the player is in
|
2011-11-15 23:31:18 -05:00
|
|
|
CellStoreCollection mActiveCells;
|
2021-02-05 14:55:42 +01:00
|
|
|
CellStoreCollection mInactiveCells;
|
2011-08-01 03:33:02 +02:00
|
|
|
bool mCellChanged;
|
2015-05-10 01:09:00 +02:00
|
|
|
MWPhysics::PhysicsSystem *mPhysics;
|
2015-04-12 15:34:50 +02:00
|
|
|
MWRender::RenderingManager& mRendering;
|
2018-08-26 23:27:38 +03:00
|
|
|
DetourNavigator::Navigator& mNavigator;
|
2017-04-28 17:30:26 +02:00
|
|
|
std::unique_ptr<CellPreloader> mPreloader;
|
2016-02-07 07:37:56 -08:00
|
|
|
float mCellLoadingThreshold;
|
|
|
|
float mPreloadDistance;
|
2016-02-07 18:01:14 +01:00
|
|
|
bool mPreloadEnabled;
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2016-02-09 01:58:07 +01:00
|
|
|
bool mPreloadExteriorGrid;
|
|
|
|
bool mPreloadDoors;
|
|
|
|
bool mPreloadFastTravel;
|
2017-07-19 16:43:29 +02:00
|
|
|
float mPredictionTime;
|
2016-02-09 01:58:07 +01:00
|
|
|
|
2020-06-16 18:43:01 +04:00
|
|
|
static const int mHalfGridSize = Constants::CellGridRadius;
|
|
|
|
|
2017-02-09 01:24:13 +01:00
|
|
|
osg::Vec3f mLastPlayerPos;
|
|
|
|
|
2020-05-10 13:37:00 +00:00
|
|
|
std::set<ESM::RefNum> mPagedRefs;
|
|
|
|
|
2021-07-11 14:43:52 +02:00
|
|
|
std::vector<osg::ref_ptr<SceneUtil::WorkItem>> mWorkItems;
|
|
|
|
|
2021-09-24 22:23:55 +02:00
|
|
|
void insertCell(CellStore &cell, Loading::Listener* loadingListener, bool onlyObjects);
|
2019-06-13 13:37:00 +00:00
|
|
|
osg::Vec2i mCurrentGridCenter;
|
2013-08-27 15:48:13 +02:00
|
|
|
|
2014-10-02 16:30:23 +02:00
|
|
|
// Load and unload cells as necessary to create a cell grid with "X" and "Y" in the center
|
2020-05-12 13:37:00 +00:00
|
|
|
void changeCellGrid (const osg::Vec3f &pos, int playerCellX, int playerCellY, bool changeEvent = true);
|
2014-10-02 16:30:23 +02:00
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
typedef std::pair<osg::Vec3f, osg::Vec4i> PositionCellGrid;
|
2014-10-02 16:30:23 +02:00
|
|
|
|
2017-02-09 01:24:13 +01:00
|
|
|
void preloadCells(float dt);
|
2019-06-13 13:37:00 +00:00
|
|
|
void preloadTeleportDoorDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos, std::vector<PositionCellGrid>& exteriorPositions);
|
2017-02-09 01:24:13 +01:00
|
|
|
void preloadExteriorGrid(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos);
|
2019-06-13 13:37:00 +00:00
|
|
|
void preloadFastTravelDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos, std::vector<PositionCellGrid>& exteriorPositions);
|
|
|
|
|
|
|
|
osg::Vec4i gridCenterToBounds(const osg::Vec2i ¢erCell) const;
|
|
|
|
osg::Vec2i getNewGridCenter(const osg::Vec3f &pos, const osg::Vec2i *currentGridCenter = nullptr) const;
|
2016-02-09 01:51:23 +01:00
|
|
|
|
2021-09-24 22:23:55 +02:00
|
|
|
void unloadInactiveCell(CellStore* cell);
|
|
|
|
void deactivateCell(CellStore* cell);
|
|
|
|
void activateCell(CellStore *cell, Loading::Listener* loadingListener, bool respawn);
|
|
|
|
void loadInactiveCell(CellStore *cell, Loading::Listener* loadingListener);
|
2021-02-05 14:55:42 +01:00
|
|
|
|
2011-08-01 03:33:02 +02:00
|
|
|
public:
|
|
|
|
|
2018-08-26 23:27:38 +03:00
|
|
|
Scene (MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics,
|
|
|
|
DetourNavigator::Navigator& navigator);
|
2011-08-01 03:33:02 +02:00
|
|
|
|
|
|
|
~Scene();
|
|
|
|
|
2017-02-09 03:47:36 +01:00
|
|
|
void preloadCell(MWWorld::CellStore* cell, bool preloadSurrounding=false);
|
2020-05-12 13:37:00 +00:00
|
|
|
void preloadTerrain(const osg::Vec3f& pos, bool sync=false);
|
2020-05-08 13:37:00 +00:00
|
|
|
void reloadTerrain();
|
2017-02-09 03:47:36 +01:00
|
|
|
|
2015-04-12 15:34:50 +02:00
|
|
|
void playerMoved (const osg::Vec3f& pos);
|
2014-10-02 16:30:23 +02:00
|
|
|
|
|
|
|
void changePlayerCell (CellStore* newCell, const ESM::Position& position, bool adjustPlayerPos);
|
2011-08-09 09:56:09 +02:00
|
|
|
|
2014-10-02 16:30:23 +02:00
|
|
|
CellStore *getCurrentCell();
|
2011-08-09 09:56:09 +02:00
|
|
|
|
2011-11-15 23:31:18 -05:00
|
|
|
const CellStoreCollection& getActiveCells () const;
|
2011-08-01 04:06:38 +02:00
|
|
|
|
2011-08-01 03:33:02 +02:00
|
|
|
bool hasCellChanged() const;
|
2014-10-02 16:30:23 +02:00
|
|
|
///< Has the set of active cells changed, since the last frame?
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2016-03-24 17:18:08 +01:00
|
|
|
void changeToInteriorCell (const std::string& cellName, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true);
|
2011-08-01 03:33:02 +02:00
|
|
|
///< Move to interior cell.
|
2016-02-27 12:53:07 +01:00
|
|
|
/// @param changeEvent Set cellChanged flag?
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2016-02-27 12:53:07 +01:00
|
|
|
void changeToExteriorCell (const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true);
|
2011-08-01 03:33:02 +02:00
|
|
|
///< Move to exterior cell.
|
2016-02-27 12:53:07 +01:00
|
|
|
/// @param changeEvent Set cellChanged flag?
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2017-02-09 04:03:38 +01:00
|
|
|
void clear();
|
2013-05-15 17:54:18 +02:00
|
|
|
///< Change into a void
|
|
|
|
|
2011-08-09 09:56:09 +02:00
|
|
|
void markCellAsUnchanged();
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2012-11-03 19:29:55 +00:00
|
|
|
void update (float duration, bool paused);
|
2012-05-25 17:28:27 +02:00
|
|
|
|
|
|
|
void addObjectToScene (const Ptr& ptr);
|
|
|
|
///< Add an object that already exists in the world model to the scene.
|
|
|
|
|
2021-08-28 14:36:30 +02:00
|
|
|
void removeObjectFromScene (const Ptr& ptr, bool keepActive = false);
|
2012-05-25 17:28:27 +02:00
|
|
|
///< Remove an object from the scene, but not from the world model.
|
2012-07-26 16:14:11 +04:00
|
|
|
|
2020-05-11 13:37:00 +00:00
|
|
|
void removeFromPagedRefs(const Ptr &ptr);
|
|
|
|
|
2019-11-30 12:29:31 +01:00
|
|
|
void updateObjectRotation(const Ptr& ptr, RotationOrder order);
|
2015-04-24 14:49:20 +02:00
|
|
|
void updateObjectScale(const Ptr& ptr);
|
2020-05-11 13:37:00 +00:00
|
|
|
void updateObjectPosition(const Ptr &ptr, const osg::Vec3f &pos, bool movePhysics);
|
2014-06-14 17:56:41 +02:00
|
|
|
|
2012-07-26 16:14:11 +04:00
|
|
|
bool isCellActive(const CellStore &cell);
|
2014-04-29 15:27:49 +02:00
|
|
|
|
|
|
|
Ptr searchPtrViaActorId (int actorId);
|
2017-02-15 00:55:35 +01:00
|
|
|
|
2017-02-20 19:58:00 +01:00
|
|
|
void preload(const std::string& mesh, bool useAnim=false);
|
2019-11-24 17:40:19 +04:00
|
|
|
|
|
|
|
void testExteriorCells();
|
|
|
|
void testInteriorCells();
|
2011-08-01 03:33:02 +02:00
|
|
|
};
|
2011-07-31 17:07:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|