1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-28 14:53:58 +00:00

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

208 lines
5.7 KiB
C++
Raw Normal View History

#ifndef GAME_MWWORLD_SCENE_H
#define GAME_MWWORLD_SCENE_H
#include <osg/Vec2i>
#include <osg/Vec4i>
#include <osg/ref_ptr>
#include "ptr.hpp"
2011-08-01 03:33:02 +02:00
#include <memory>
#include <optional>
#include <set>
2018-07-20 22:11:34 +03:00
#include <unordered_map>
#include <vector>
#include <components/esm/util.hpp>
2020-06-16 18:43:01 +04:00
#include <components/misc/constants.hpp>
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;
class UpdateGuard;
2018-07-20 22:11:34 +03:00
}
namespace MWRender
{
class SkyManager;
class RenderingManager;
}
namespace MWPhysics
{
class PhysicsSystem;
}
namespace SceneUtil
{
class WorkItem;
}
namespace MWWorld
{
2011-08-01 03:33:02 +02:00
class Player;
class CellStore;
class CellPreloader;
class World;
2011-08-01 03:33:02 +02:00
enum class RotationOrder
{
direct,
inverse
};
class Scene
{
public:
using CellStoreCollection = std::set<CellStore*>;
2011-09-04 09:48:50 +02:00
2013-05-15 17:54:18 +02:00
private:
struct ChangeCellGridRequest
2022-09-22 21:26:05 +03:00
{
osg::Vec3f mPosition;
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
CellStoreCollection mActiveCells;
2011-08-01 03:33:02 +02:00
bool mCellChanged;
bool mCellLoaded = false;
MWWorld::World& mWorld;
MWPhysics::PhysicsSystem* mPhysics;
MWRender::RenderingManager& mRendering;
DetourNavigator::Navigator& mNavigator;
std::unique_ptr<CellPreloader> mPreloader;
2016-02-07 07:37:56 -08:00
float mCellLoadingThreshold;
float mPreloadDistance;
bool mPreloadEnabled;
2020-06-16 18:43:01 +04:00
bool mPreloadExteriorGrid;
bool mPreloadDoors;
bool mPreloadFastTravel;
float mPredictionTime;
static const int mHalfGridSize = Constants::CellGridRadius;
osg::Vec3f mLastPlayerPos;
std::vector<ESM::RefNum> mPagedRefs;
std::vector<osg::ref_ptr<SceneUtil::WorkItem>> mWorkItems;
std::optional<ChangeCellGridRequest> mChangeCellGridRequest;
void insertCell(CellStore& cell, Loading::Listener* loadingListener,
const DetourNavigator::UpdateGuard* navigatorUpdateGuard);
osg::Vec2i mCurrentGridCenter;
// Load and unload cells as necessary to create a cell grid with "X" and "Y" in the center
void changeCellGrid(const osg::Vec3f& pos, ESM::ExteriorCellIndex playerCellIndex, bool changeEvent = true);
void requestChangeCellGrid(const osg::Vec3f& position, const osg::Vec2i& cell, bool changeEvent = true);
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
osg::Vec4i gridCenterToBounds(const osg::Vec2i& centerCell) const;
osg::Vec2i getNewGridCenter(const osg::Vec3f& pos, const osg::Vec2i* currentGridCenter = nullptr) const;
void unloadCell(CellStore* cell, const DetourNavigator::UpdateGuard* navigatorUpdateGuard);
void loadCell(CellStore& cell, Loading::Listener* loadingListener, bool respawn, const osg::Vec3f& position,
const DetourNavigator::UpdateGuard* navigatorUpdateGuard);
2011-08-01 03:33:02 +02:00
2022-09-22 21:26:05 +03:00
public:
Scene(MWWorld::World& world, MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem* physics,
DetourNavigator::Navigator& navigator);
2011-08-01 03:33:02 +02:00
~Scene();
void preloadCell(MWWorld::CellStore& cell, bool preloadSurrounding = false);
void preloadTerrain(const osg::Vec3f& pos, bool sync = false);
void reloadTerrain();
void playerMoved(const osg::Vec3f& pos);
void changePlayerCell(CellStore& newCell, const ESM::Position& position, bool adjustPlayerPos);
2011-08-09 09:56:09 +02:00
CellStore* getCurrentCell();
2011-08-09 09:56:09 +02:00
const CellStoreCollection& getActiveCells() const;
2011-08-01 03:33:02 +02:00
bool hasCellChanged() const;
///< Has the set of active cells changed, since the last frame?
2011-08-01 03:33:02 +02:00
bool hasCellLoaded() const { return mCellLoaded; }
void resetCellLoaded() { mCellLoaded = false; }
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.
/// @param changeEvent Set cellChanged flag?
2011-08-01 03:33:02 +02: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.
/// @param changeEvent Set cellChanged flag?
2011-08-01 03:33:02 +02: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
void update(float duration);
void addObjectToScene(const Ptr& ptr);
///< Add an object that already exists in the world model to the scene.
void removeObjectFromScene(const Ptr& ptr, bool keepActive = false);
///< Remove an object from the scene, but not from the world model.
void addPostponedPhysicsObjects();
void removeFromPagedRefs(const Ptr& ptr);
void updateObjectRotation(const Ptr& ptr, RotationOrder order);
void updateObjectScale(const Ptr& ptr);
bool isCellActive(const CellStore& cell);
2014-04-29 15:27:49 +02:00
Ptr searchPtrViaActorId(int actorId);
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
};
}
#endif