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/Vec2i>
|
|
|
|
#include <osg/Vec4i>
|
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
|
|
|
|
2016-02-07 00:36:31 +01:00
|
|
|
#include <memory>
|
2021-09-06 00:40:13 +02:00
|
|
|
#include <optional>
|
2015-04-01 17:02:15 +02:00
|
|
|
#include <set>
|
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
|
|
|
|
2023-05-05 10:31:06 +02:00
|
|
|
#include <components/esm/util.hpp>
|
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;
|
2022-09-05 09:23:14 +02:00
|
|
|
class UpdateGuard;
|
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;
|
2022-05-06 21:03:02 +02:00
|
|
|
class World;
|
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-09-04 09:48:50 +02:00
|
|
|
|
2013-05-15 17:54:18 +02:00
|
|
|
private:
|
2011-11-15 23:31:18 -05:00
|
|
|
struct ChangeCellGridRequest
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2011-11-15 23:31:18 -05:00
|
|
|
osg::Vec3f mPosition;
|
2023-05-05 10:31:06 +02:00
|
|
|
ESM::ExteriorCellIndex mCellIndex;
|
2011-08-01 03:33:02 +02:00
|
|
|
bool mChangeEvent;
|
2016-02-07 18:01:14 +01:00
|
|
|
};
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2013-05-15 17:54:18 +02:00
|
|
|
CellStore* mCurrentCell; // the cell the player is in
|
2016-02-09 01:58:07 +01:00
|
|
|
CellStoreCollection mActiveCells;
|
2011-08-01 03:33:02 +02:00
|
|
|
bool mCellChanged;
|
2021-09-18 15:52:03 +02:00
|
|
|
bool mCellLoaded = false;
|
2022-05-06 21:03:02 +02:00
|
|
|
MWWorld::World& mWorld;
|
2016-02-09 01:58:07 +01:00
|
|
|
MWPhysics::PhysicsSystem* mPhysics;
|
|
|
|
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-09 01:58:07 +01:00
|
|
|
bool mPreloadEnabled;
|
|
|
|
|
2020-06-16 18:43:01 +04:00
|
|
|
bool mPreloadExteriorGrid;
|
|
|
|
bool mPreloadDoors;
|
|
|
|
bool mPreloadFastTravel;
|
|
|
|
float mPredictionTime;
|
|
|
|
|
2017-02-09 01:24:13 +01:00
|
|
|
static const int mHalfGridSize = Constants::CellGridRadius;
|
|
|
|
|
2022-07-26 21:53:06 +02:00
|
|
|
osg::Vec3f mLastPlayerPos;
|
2020-05-10 13:37:00 +00:00
|
|
|
|
2021-07-11 14:43:52 +02:00
|
|
|
std::vector<ESM::RefNum> mPagedRefs;
|
|
|
|
|
2021-09-06 00:40:13 +02:00
|
|
|
std::vector<osg::ref_ptr<SceneUtil::WorkItem>> mWorkItems;
|
|
|
|
|
2022-09-05 09:23:14 +02:00
|
|
|
std::optional<ChangeCellGridRequest> mChangeCellGridRequest;
|
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
void insertCell(CellStore& cell, Loading::Listener* loadingListener,
|
|
|
|
const DetourNavigator::UpdateGuard* navigatorUpdateGuard);
|
2013-08-27 15:48:13 +02:00
|
|
|
|
2020-05-12 13:37:00 +00:00
|
|
|
osg::Vec2i mCurrentGridCenter;
|
2014-10-02 16:30:23 +02:00
|
|
|
|
2021-09-06 00:40:13 +02:00
|
|
|
// Load and unload cells as necessary to create a cell grid with "X" and "Y" in the center
|
2023-05-05 10:31:06 +02:00
|
|
|
void changeCellGrid(const osg::Vec3f& pos, ESM::ExteriorCellIndex playerCellIndex, bool changeEvent = true);
|
2021-09-06 00:40:13 +02:00
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
void requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, 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;
|
|
|
|
|
|
|
|
void preloadCells(float dt);
|
|
|
|
void preloadTeleportDoorDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos,
|
|
|
|
std::vector<PositionCellGrid>& exteriorPositions);
|
|
|
|
void preloadExteriorGrid(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos);
|
|
|
|
void preloadFastTravelDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos,
|
|
|
|
std::vector<PositionCellGrid>& exteriorPositions);
|
2016-02-09 01:51:23 +01:00
|
|
|
|
2022-09-05 09:23:14 +02:00
|
|
|
osg::Vec4i gridCenterToBounds(const osg::Vec2i& centerCell) const;
|
|
|
|
osg::Vec2i getNewGridCenter(const osg::Vec3f& pos, const osg::Vec2i* currentGridCenter = nullptr) const;
|
2021-02-05 14:55:42 +01:00
|
|
|
|
2022-09-05 09:23:14 +02:00
|
|
|
void unloadCell(CellStore* cell, const DetourNavigator::UpdateGuard* navigatorUpdateGuard);
|
2023-04-20 16:16:17 +02:00
|
|
|
void loadCell(CellStore& cell, Loading::Listener* loadingListener, bool respawn, const osg::Vec3f& position,
|
2022-09-05 09:23:14 +02:00
|
|
|
const DetourNavigator::UpdateGuard* navigatorUpdateGuard);
|
2011-08-01 03:33:02 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2022-05-06 21:03:02 +02:00
|
|
|
Scene(MWWorld::World& world, MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem* physics,
|
2018-08-26 23:27:38 +03:00
|
|
|
DetourNavigator::Navigator& navigator);
|
2011-08-01 03:33:02 +02:00
|
|
|
|
|
|
|
~Scene();
|
|
|
|
|
2023-04-20 16:16:17 +02: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
|
|
|
|
2023-04-20 16:16:17 +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
|
|
|
|
2021-09-18 15:52:03 +02:00
|
|
|
bool hasCellLoaded() const { return mCellLoaded; }
|
|
|
|
|
|
|
|
void resetCellLoaded() { mCellLoaded = false; }
|
|
|
|
|
2016-03-24 17:18:08 +01:00
|
|
|
void changeToInteriorCell(
|
2023-01-19 17:31:45 +01:00
|
|
|
std::string_view 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
|
|
|
|
2023-02-19 19:19:11 +01:00
|
|
|
void changeToExteriorCell(
|
|
|
|
const ESM::RefId& extCellId, 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
|
|
|
|
2022-05-06 20:12:17 +02:00
|
|
|
void update(float duration);
|
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
|
|
|
|
2022-06-19 20:16:31 +02:00
|
|
|
void addPostponedPhysicsObjects();
|
|
|
|
|
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);
|
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
|