2020-12-18 22:21:10 +00:00
|
|
|
#ifndef MWLUA_WORLDVIEW_H
|
|
|
|
#define MWLUA_WORLDVIEW_H
|
|
|
|
|
|
|
|
#include "object.hpp"
|
|
|
|
|
2022-05-16 15:04:41 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
2023-02-06 23:37:55 +00:00
|
|
|
#include "../mwworld/globals.hpp"
|
|
|
|
|
2022-05-16 15:04:41 +00:00
|
|
|
#include <set>
|
|
|
|
|
2021-01-29 01:38:09 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
class ESMWriter;
|
|
|
|
class ESMReader;
|
|
|
|
}
|
|
|
|
|
2020-12-18 22:21:10 +00:00
|
|
|
namespace MWLua
|
|
|
|
{
|
|
|
|
|
2022-12-23 18:57:12 +00:00
|
|
|
// WorldView is a kind of an extension to mwworld. It was created on initial stage of
|
|
|
|
// OpenMW Lua development in order to minimize the risk of merge conflicts.
|
|
|
|
// TODO: Move get*InScene functions to mwworld/scene
|
|
|
|
// TODO: Move time-related stuff to mwworld; maybe create a new class TimeManager.
|
|
|
|
// TODO: Remove WorldView.
|
2020-12-18 22:21:10 +00:00
|
|
|
class WorldView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void update(); // Should be called every frame.
|
|
|
|
void clear(); // Should be called every time before starting or loading a new game.
|
|
|
|
|
2021-12-13 23:51:18 +00:00
|
|
|
// Whether the world is paused (i.e. game time is not changing and actors don't move).
|
|
|
|
bool isPaused() const { return mPaused; }
|
|
|
|
|
2021-12-01 20:28:05 +00:00
|
|
|
// The number of seconds passed from the beginning of the game.
|
|
|
|
double getSimulationTime() const { return mSimulationTime; }
|
|
|
|
void setSimulationTime(double t) { mSimulationTime = t; }
|
2021-03-12 17:29:51 +00:00
|
|
|
|
2021-12-01 20:28:05 +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(); }
|
2023-02-06 23:37:55 +00:00
|
|
|
void setGameTimeScale(double s)
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWorld()->setGlobalFloat(MWWorld::Globals::sTimeScale, 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; }
|
2023-06-17 17:56:25 +00:00
|
|
|
ObjectIdList getPlayers() const { return mPlayers; }
|
2020-12-18 22:21:10 +00:00
|
|
|
|
|
|
|
void objectAddedToScene(const MWWorld::Ptr& ptr);
|
|
|
|
void objectRemovedFromScene(const MWWorld::Ptr& ptr);
|
|
|
|
|
2023-06-17 17:56:25 +00:00
|
|
|
void setPlayer(const MWWorld::Ptr& player) { *mPlayers = { getId(player) }; }
|
|
|
|
|
2021-01-29 01:38:09 +00:00
|
|
|
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);
|
|
|
|
|
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;
|
2023-06-17 17:56:25 +00:00
|
|
|
ObjectIdList mPlayers = std::make_shared<std::vector<ObjectId>>();
|
2021-03-12 17:29:51 +00:00
|
|
|
|
2021-12-01 20:28:05 +00:00
|
|
|
double mSimulationTime = 0;
|
2021-12-13 23:51:18 +00:00
|
|
|
bool mPaused = false;
|
2020-12-18 22:21:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MWLUA_WORLDVIEW_H
|