OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
scene.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWWORLD_SCENE_H
2 #define GAME_MWWORLD_SCENE_H
3 
4 #include "ptr.hpp"
5 #include "globals.hpp"
6 
7 #include <set>
8 #include <memory>
9 
10 namespace osg
11 {
12  class Vec3f;
13 }
14 
15 namespace ESM
16 {
17  struct Position;
18 }
19 
20 namespace Files
21 {
22  class Collections;
23 }
24 
25 namespace Loading
26 {
27  class Listener;
28 }
29 
30 namespace MWRender
31 {
32  class SkyManager;
33  class RenderingManager;
34 }
35 
36 namespace MWPhysics
37 {
38  class PhysicsSystem;
39 }
40 
41 namespace MWWorld
42 {
43  class Player;
44  class CellStore;
45  class CellPreloader;
46 
47  class Scene
48  {
49  public:
50 
51  typedef std::set<CellStore *> CellStoreCollection;
52 
53  private:
54 
55  CellStore* mCurrentCell; // the cell the player is in
60  std::unique_ptr<CellPreloader> mPreloader;
66 
71 
72  osg::Vec3f mLastPlayerPos;
73 
74  void insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener);
75 
76  // Load and unload cells as necessary to create a cell grid with "X" and "Y" in the center
77  void changeCellGrid (int X, int Y, bool changeEvent = true);
78 
79  void getGridCenter(int& cellX, int& cellY);
80 
81  void preloadCells(float dt);
82  void preloadTeleportDoorDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos, std::vector<osg::Vec3f>& exteriorPositions);
83  void preloadExteriorGrid(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos);
84  void preloadFastTravelDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos, std::vector<osg::Vec3f>& exteriorPositions);
85 
86  public:
87 
89 
90  ~Scene();
91 
92  void preloadCell(MWWorld::CellStore* cell, bool preloadSurrounding=false);
93  void preloadTerrain(const osg::Vec3f& pos);
94 
95  void unloadCell (CellStoreCollection::iterator iter);
96 
97  void loadCell (CellStore *cell, Loading::Listener* loadingListener, bool respawn);
98 
99  void playerMoved (const osg::Vec3f& pos);
100 
101  void changePlayerCell (CellStore* newCell, const ESM::Position& position, bool adjustPlayerPos);
102 
104 
105  const CellStoreCollection& getActiveCells () const;
106 
107  bool hasCellChanged() const;
109 
110  void changeToInteriorCell (const std::string& cellName, const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true);
113 
114  void changeToExteriorCell (const ESM::Position& position, bool adjustPlayerPos, bool changeEvent=true);
117 
118  void clear();
120 
121  void markCellAsUnchanged();
122 
123  void update (float duration, bool paused);
124 
125  void addObjectToScene (const Ptr& ptr);
127 
128  void removeObjectFromScene (const Ptr& ptr);
130 
131  void updateObjectRotation (const Ptr& ptr, bool inverseRotationOrder);
132  void updateObjectScale(const Ptr& ptr);
133 
134  bool isCellActive(const CellStore &cell);
135 
136  Ptr searchPtrViaActorId (int actorId);
137 
138  void preload(const std::string& mesh, bool useAnim=false);
139  };
140 }
141 
142 #endif
osg::Vec3f mLastPlayerPos
Definition: scene.hpp:72
const CellStoreCollection & getActiveCells() const
Definition: scene.cpp:514
bool mPreloadDoors
Definition: scene.hpp:68
void preload(const std::string &mesh, bool useAnim=false)
Definition: scene.cpp:686
void markCellAsUnchanged()
Definition: scene.cpp:602
void preloadFastTravelDestinations(const osg::Vec3f &playerPos, const osg::Vec3f &predictedPos, std::vector< osg::Vec3f > &exteriorPositions)
Definition: scene.cpp:862
void preloadCell(MWWorld::CellStore *cell, bool preloadSurrounding=false)
Definition: scene.cpp:804
Definition: renderingmanager.hpp:72
void addObjectToScene(const Ptr &ptr)
Add an object that already exists in the world model to the scene.
Definition: scene.cpp:618
void preloadExteriorGrid(const osg::Vec3f &playerPos, const osg::Vec3f &predictedPos)
Definition: scene.cpp:770
CellStoreCollection mActiveCells
Definition: scene.hpp:56
bool mCellChanged
Definition: scene.hpp:57
std::unique_ptr< CellPreloader > mPreloader
Definition: scene.hpp:60
Definition: loadinglistener.hpp:8
Definition: physicssystem.hpp:52
void preloadTeleportDoorDestinations(const osg::Vec3f &playerPos, const osg::Vec3f &predictedPos, std::vector< osg::Vec3f > &exteriorPositions)
Definition: scene.cpp:723
void unloadCell(CellStoreCollection::iterator iter)
Definition: scene.cpp:233
float mPredictionTime
Definition: scene.hpp:70
~Scene()
Definition: scene.cpp:505
void getGridCenter(int &cellX, int &cellY)
Definition: scene.cpp:197
Definition: scene.hpp:47
int mHalfGridSize
Definition: scene.hpp:62
void removeObjectFromScene(const Ptr &ptr)
Remove an object from the scene, but not from the world model.
Definition: scene.cpp:631
void preloadCells(float dt)
Definition: scene.cpp:696
bool hasCellChanged() const
Has the set of active cells changed, since the last frame?
Definition: scene.cpp:509
void playerMoved(const osg::Vec3f &pos)
Definition: scene.cpp:338
Mutable state of a cell.
Definition: cellstore.hpp:51
bool mPreloadEnabled
Definition: scene.hpp:65
bool mPreloadFastTravel
Definition: scene.hpp:69
void changeCellGrid(int X, int Y, bool changeEvent=true)
Definition: scene.cpp:358
float mPreloadTimer
Definition: scene.hpp:61
void changeToInteriorCell(const std::string &cellName, const ESM::Position &position, bool adjustPlayerPos, bool changeEvent=true)
Definition: scene.cpp:519
void insertCell(CellStore &cell, bool rescale, Loading::Listener *loadingListener)
Definition: scene.cpp:607
Scene(MWRender::RenderingManager &rendering, MWPhysics::PhysicsSystem *physics)
Definition: scene.cpp:479
CellStore * mCurrentCell
Definition: scene.hpp:55
MWPhysics::PhysicsSystem * mPhysics
Definition: scene.hpp:58
Definition: defs.hpp:38
CellStore * getCurrentCell()
Definition: scene.cpp:597
void preloadTerrain(const osg::Vec3f &pos)
Definition: scene.cpp:825
void update(float duration, bool paused)
Definition: scene.cpp:219
float mCellLoadingThreshold
Definition: scene.hpp:63
void loadCell(CellStore *cell, Loading::Listener *loadingListener, bool respawn)
Definition: scene.cpp:267
void updateObjectScale(const Ptr &ptr)
Definition: scene.cpp:192
bool isCellActive(const CellStore &cell)
Definition: scene.cpp:641
void clear()
Change into a void.
Definition: scene.cpp:327
std::set< CellStore * > CellStoreCollection
Definition: scene.hpp:51
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
float mPreloadDistance
Definition: scene.hpp:64
void changeToExteriorCell(const ESM::Position &position, bool adjustPlayerPos, bool changeEvent=true)
Definition: scene.cpp:578
void updateObjectRotation(const Ptr &ptr, bool inverseRotationOrder)
Definition: scene.cpp:187
MWRender::RenderingManager & mRendering
Definition: scene.hpp:59
Ptr searchPtrViaActorId(int actorId)
Definition: scene.cpp:653
bool mPreloadExteriorGrid
Definition: scene.hpp:67
void changePlayerCell(CellStore *newCell, const ESM::Position &position, bool adjustPlayerPos)
Definition: scene.cpp:442