1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00
OpenMW/apps/openmw/mwlua/worldview.hpp

89 lines
3.2 KiB
C++
Raw Normal View History

2020-12-18 22:21:10 +00:00
#ifndef MWLUA_WORLDVIEW_H
#define MWLUA_WORLDVIEW_H
#include "object.hpp"
namespace ESM
{
class ESMWriter;
class ESMReader;
}
2020-12-18 22:21:10 +00:00
namespace MWLua
{
// Tracks all used game objects.
class WorldView
{
public:
void update(); // Should be called every frame.
void clear(); // Should be called every time before starting or loading a new game.
// Whether the world is paused (i.e. game time is not changing and actors don't move).
bool isPaused() const { return mPaused; }
// The number of seconds passed from the beginning of the game.
double getSimulationTime() const { return mSimulationTime; }
void setSimulationTime(double t) { mSimulationTime = t; }
double getSimulationTimeScale() const { return 1.0; }
2021-03-12 17:29:51 +00:00
// The game time (in game seconds) passed from the beginning of the game.
// Note that game time generally goes faster than the simulation time.
double getGameTime() const;
double getGameTimeScale() const { return MWBase::Environment::get().getWorld()->getTimeScaleFactor(); }
void setGameTimeScale(double s) { MWBase::Environment::get().getWorld()->setGlobalFloat("timescale", s); }
2021-03-12 17:29:51 +00:00
2021-01-29 00:54:54 +00:00
ObjectIdList getActivatorsInScene() const { return mActivatorsInScene.mList; }
2020-12-18 22:21:10 +00:00
ObjectIdList getActorsInScene() const { return mActorsInScene.mList; }
2021-01-29 00:54:54 +00:00
ObjectIdList getContainersInScene() const { return mContainersInScene.mList; }
ObjectIdList getDoorsInScene() const { return mDoorsInScene.mList; }
2020-12-18 22:21:10 +00:00
ObjectIdList getItemsInScene() const { return mItemsInScene.mList; }
ObjectRegistry* getObjectRegistry() { return &mObjectRegistry; }
void objectUnloaded(const MWWorld::Ptr& ptr) { mObjectRegistry.deregisterPtr(ptr); }
void objectAddedToScene(const MWWorld::Ptr& ptr);
void objectRemovedFromScene(const MWWorld::Ptr& ptr);
2021-02-17 21:56:14 +00:00
// Returns list of objects that meets the `query` criteria.
// If onlyActive = true, then search only among the objects that are currently in the scene.
// TODO: ObjectIdList selectObjects(const Queries::Query& query, bool onlyActive);
2021-04-17 09:50:20 +00:00
MWWorld::CellStore* findCell(const std::string& name, osg::Vec3f position);
MWWorld::CellStore* findNamedCell(const std::string& name);
MWWorld::CellStore* findExteriorCell(int x, int y);
void load(ESM::ESMReader& esm);
void save(ESM::ESMWriter& esm) const;
2020-12-18 22:21:10 +00:00
private:
struct ObjectGroup
{
void updateList();
void clear();
bool mChanged = false;
ObjectIdList mList = std::make_shared<std::vector<ObjectId>>();
std::set<ObjectId> mSet;
};
2021-01-29 00:54:54 +00:00
ObjectGroup* chooseGroup(const MWWorld::Ptr& ptr);
2020-12-18 22:21:10 +00:00
void addToGroup(ObjectGroup& group, const MWWorld::Ptr& ptr);
void removeFromGroup(ObjectGroup& group, const MWWorld::Ptr& ptr);
ObjectRegistry mObjectRegistry;
2021-01-29 00:54:54 +00:00
ObjectGroup mActivatorsInScene;
2020-12-18 22:21:10 +00:00
ObjectGroup mActorsInScene;
2021-01-29 00:54:54 +00:00
ObjectGroup mContainersInScene;
ObjectGroup mDoorsInScene;
2020-12-18 22:21:10 +00:00
ObjectGroup mItemsInScene;
2021-03-12 17:29:51 +00:00
double mSimulationTime = 0;
bool mPaused = false;
2020-12-18 22:21:10 +00:00
};
}
#endif // MWLUA_WORLDVIEW_H