2012-06-29 16:48:50 +02:00
|
|
|
#ifndef GAME_MWWORLD_CELLSTORE_H
|
|
|
|
#define GAME_MWWORLD_CELLSTORE_H
|
2010-05-20 18:59:36 +02:00
|
|
|
|
2011-06-13 13:47:59 +02:00
|
|
|
#include <algorithm>
|
2022-09-08 20:52:00 +02:00
|
|
|
#include <map>
|
2017-05-05 21:21:11 +02:00
|
|
|
#include <memory>
|
2014-02-23 21:21:27 +01:00
|
|
|
#include <stdexcept>
|
2015-02-22 12:12:54 -06:00
|
|
|
#include <string>
|
2022-08-27 13:07:59 +02:00
|
|
|
#include <string_view>
|
2022-09-08 20:52:00 +02:00
|
|
|
#include <tuple>
|
2015-02-22 12:12:54 -06:00
|
|
|
#include <typeinfo>
|
2022-09-08 20:52:00 +02:00
|
|
|
#include <vector>
|
2010-07-02 13:48:48 +02:00
|
|
|
|
2023-01-27 01:13:17 +01:00
|
|
|
#include "cell.hpp"
|
2014-02-23 20:11:05 +01:00
|
|
|
#include "cellreflist.hpp"
|
2013-04-04 11:23:17 +02:00
|
|
|
#include "livecellref.hpp"
|
2012-06-29 18:54:23 +02:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
#include <components/esm/refid.hpp>
|
2022-10-18 09:26:55 +02:00
|
|
|
#include <components/esm3/fogstate.hpp>
|
2022-09-08 20:52:00 +02:00
|
|
|
#include <components/misc/tuplemeta.hpp>
|
2014-05-11 02:07:28 +02:00
|
|
|
|
2015-12-10 17:47:55 -08:00
|
|
|
#include "ptr.hpp"
|
2014-05-17 09:05:41 +02:00
|
|
|
#include "timestamp.hpp"
|
|
|
|
|
2014-01-23 11:29:40 +01:00
|
|
|
namespace ESM
|
|
|
|
{
|
2022-06-01 22:53:18 +02:00
|
|
|
class ReadersCache;
|
2017-11-27 18:30:31 +01:00
|
|
|
struct Cell;
|
2014-01-23 11:29:40 +01:00
|
|
|
struct CellState;
|
2023-04-07 02:14:32 +02:00
|
|
|
struct FormId;
|
|
|
|
using RefNum = FormId;
|
2022-09-08 20:52:00 +02:00
|
|
|
struct Activator;
|
|
|
|
struct Potion;
|
|
|
|
struct Apparatus;
|
|
|
|
struct Armor;
|
|
|
|
struct Book;
|
|
|
|
struct Clothing;
|
|
|
|
struct Container;
|
|
|
|
struct Creature;
|
|
|
|
struct Door;
|
|
|
|
struct Ingredient;
|
|
|
|
struct CreatureLevList;
|
|
|
|
struct ItemLevList;
|
|
|
|
struct Light;
|
|
|
|
struct Lockpick;
|
|
|
|
struct Miscellaneous;
|
|
|
|
struct NPC;
|
|
|
|
struct Probe;
|
|
|
|
struct Repair;
|
|
|
|
struct Static;
|
|
|
|
struct Weapon;
|
|
|
|
struct BodyPart;
|
2023-01-22 23:40:55 +01:00
|
|
|
struct CellCommon;
|
2014-01-23 11:29:40 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 12:18:20 +01:00
|
|
|
namespace ESM4
|
|
|
|
{
|
|
|
|
class Reader;
|
|
|
|
struct Cell;
|
2023-01-22 19:03:19 +01:00
|
|
|
struct Reference;
|
|
|
|
struct Static;
|
2023-02-06 20:22:17 +01:00
|
|
|
struct Light;
|
2023-04-09 14:16:58 +02:00
|
|
|
struct Activator;
|
|
|
|
struct Potion;
|
|
|
|
struct Ammunition;
|
|
|
|
struct Armor;
|
|
|
|
struct Book;
|
|
|
|
struct Clothing;
|
|
|
|
struct Container;
|
|
|
|
struct Door;
|
2023-05-20 18:43:55 +02:00
|
|
|
struct Furniture;
|
2023-04-09 14:16:58 +02:00
|
|
|
struct Ingredient;
|
|
|
|
struct MiscItem;
|
2023-05-20 18:43:55 +02:00
|
|
|
struct Tree;
|
2023-04-09 14:16:58 +02:00
|
|
|
struct Weapon;
|
2023-01-22 12:18:20 +01:00
|
|
|
}
|
|
|
|
|
2012-06-29 16:48:50 +02:00
|
|
|
namespace MWWorld
|
2010-05-20 18:59:36 +02:00
|
|
|
{
|
2014-12-19 09:23:16 +01:00
|
|
|
class ESMStore;
|
2022-09-08 20:52:00 +02:00
|
|
|
struct CellStoreImp;
|
2023-01-22 19:03:19 +01:00
|
|
|
|
2022-09-08 20:52:00 +02:00
|
|
|
using CellStoreTuple = std::tuple<CellRefList<ESM::Activator>, CellRefList<ESM::Potion>,
|
|
|
|
CellRefList<ESM::Apparatus>, CellRefList<ESM::Armor>, CellRefList<ESM::Book>, CellRefList<ESM::Clothing>,
|
|
|
|
CellRefList<ESM::Container>, CellRefList<ESM::Creature>, CellRefList<ESM::Door>, CellRefList<ESM::Ingredient>,
|
|
|
|
CellRefList<ESM::CreatureLevList>, CellRefList<ESM::ItemLevList>, CellRefList<ESM::Light>,
|
|
|
|
CellRefList<ESM::Lockpick>, CellRefList<ESM::Miscellaneous>, CellRefList<ESM::NPC>, CellRefList<ESM::Probe>,
|
2023-01-22 19:03:19 +01:00
|
|
|
CellRefList<ESM::Repair>, CellRefList<ESM::Static>, CellRefList<ESM::Weapon>, CellRefList<ESM::BodyPart>,
|
|
|
|
|
2023-04-09 14:16:58 +02:00
|
|
|
CellRefList<ESM4::Static>, CellRefList<ESM4::Light>, CellRefList<ESM4::Activator>, CellRefList<ESM4::Potion>,
|
|
|
|
CellRefList<ESM4::Ammunition>, CellRefList<ESM4::Armor>, CellRefList<ESM4::Book>, CellRefList<ESM4::Clothing>,
|
2023-05-20 18:43:55 +02:00
|
|
|
CellRefList<ESM4::Container>, CellRefList<ESM4::Door>, CellRefList<ESM4::Ingredient>, CellRefList<ESM4::Tree>,
|
|
|
|
CellRefList<ESM4::MiscItem>, CellRefList<ESM4::Weapon>, CellRefList<ESM4::Furniture>>;
|
2014-05-11 02:07:28 +02:00
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
/// \brief Mutable state of a cell
|
|
|
|
class CellStore
|
2011-01-29 14:33:44 +01:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2014-02-23 21:39:18 +01:00
|
|
|
enum State
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2014-02-23 21:39:18 +01:00
|
|
|
State_Unloaded,
|
|
|
|
State_Preloaded,
|
|
|
|
State_Loaded
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
|
|
|
|
2015-12-17 20:34:50 +01:00
|
|
|
/// Should this reference be accessible to the outside world (i.e. to scripts / game logic)?
|
|
|
|
/// Determined based on the deletion flags. By default, objects deleted by content files are never accessible;
|
|
|
|
/// objects deleted by setCount(0) are still accessible *if* they came from a content file (needed for vanilla
|
|
|
|
/// scripting compatibility, and the fact that objects may be "un-deleted" in the original game).
|
|
|
|
static bool isAccessible(const MWWorld::RefData& refdata, const MWWorld::CellRef& cref)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2015-12-17 20:34:50 +01:00
|
|
|
return !refdata.isDeletedByContentFile() && (cref.hasContentFile() || refdata.getCount() > 0);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2015-11-14 17:44:16 +01:00
|
|
|
/// Moves object from this cell to the given cell.
|
|
|
|
/// @note automatically updates given cell by calling cellToMoveTo->moveFrom(...)
|
2015-12-04 19:46:02 +01:00
|
|
|
/// @note throws exception if cellToMoveTo == this
|
|
|
|
/// @return updated MWWorld::Ptr with the new CellStore pointer set.
|
|
|
|
MWWorld::Ptr moveTo(const MWWorld::Ptr& object, MWWorld::CellStore* cellToMoveTo);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2019-01-25 20:04:35 +04:00
|
|
|
void rest(double hours);
|
2018-12-15 10:23:50 +04:00
|
|
|
void recharge(float duration);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-11-14 17:25:00 +01:00
|
|
|
/// Make a copy of the given object and insert it into this cell.
|
|
|
|
/// @note If you get a linker error here, this means the given type can not be inserted into a cell.
|
|
|
|
/// The supported types are defined at the bottom of this file.
|
2015-11-14 17:12:05 +01:00
|
|
|
template <typename T>
|
2015-12-06 20:19:07 +01:00
|
|
|
LiveCellRefBase* insert(const LiveCellRef<T>* ref)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2015-12-06 20:19:07 +01:00
|
|
|
mHasState = true;
|
|
|
|
CellRefList<T>& list = get<T>();
|
|
|
|
LiveCellRefBase* ret = &list.insert(*ref);
|
2023-05-11 01:00:50 +02:00
|
|
|
requestMergedRefsUpdate();
|
2015-12-06 20:19:07 +01:00
|
|
|
return ret;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2015-12-06 18:03:55 +01:00
|
|
|
/// @param readerList The readers to use for loading of the cell on-demand.
|
2023-01-27 01:13:17 +01:00
|
|
|
CellStore(MWWorld::Cell cell, const MWWorld::ESMStore& store, ESM::ReadersCache& readers);
|
2022-09-08 20:52:00 +02:00
|
|
|
CellStore(CellStore&&);
|
|
|
|
~CellStore();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-01-27 01:13:17 +01:00
|
|
|
const MWWorld::Cell* getCell() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
State getState() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
const std::vector<ESM::RefId>& getPreloadedIds() const;
|
2016-02-07 00:07:02 +01:00
|
|
|
///< Get Ids of objects in this cell, only valid in State_Preloaded
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-02-24 10:03:04 +01:00
|
|
|
bool hasState() const;
|
|
|
|
///< Does this cell have state that needs to be stored in a saved game file?
|
2022-09-22 21:26:05 +03:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
bool hasId(const ESM::RefId& id) const;
|
2014-02-23 21:39:18 +01:00
|
|
|
///< May return true for deleted IDs when in preload state. Will return false, if cell is
|
|
|
|
/// unloaded.
|
2015-12-04 19:46:02 +01:00
|
|
|
/// @note Will not account for moved references which may exist in Loaded state. Use search() instead if the
|
|
|
|
/// cell is loaded.
|
2022-09-22 21:26:05 +03:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
Ptr search(const ESM::RefId& id);
|
2014-02-23 21:39:18 +01:00
|
|
|
///< Will return an empty Ptr if cell is not loaded. Does not check references in
|
|
|
|
/// containers.
|
2015-12-17 22:37:18 +01:00
|
|
|
/// @note Triggers CellStore hasState flag.
|
2022-09-22 21:26:05 +03:00
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
ConstPtr searchConst(const ESM::RefId& id) const;
|
2014-02-23 21:39:18 +01:00
|
|
|
///< Will return an empty Ptr if cell is not loaded. Does not check references in
|
|
|
|
/// containers.
|
2015-12-18 14:33:15 +01:00
|
|
|
/// @note Does not trigger CellStore hasState flag.
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-04-29 15:27:49 +02:00
|
|
|
Ptr searchViaActorId(int id);
|
2014-02-23 21:39:18 +01:00
|
|
|
///< Will return an empty Ptr if cell is not loaded.
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
float getWaterLevel() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2018-11-20 21:53:27 +04:00
|
|
|
bool movedHere(const MWWorld::Ptr& ptr) const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
void setWaterLevel(float level);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2022-04-08 22:04:32 +02:00
|
|
|
void setFog(std::unique_ptr<ESM::FogState>&& fog);
|
2014-05-11 02:07:28 +02:00
|
|
|
///< \note Takes ownership of the pointer
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-05-11 02:07:28 +02:00
|
|
|
ESM::FogState* getFog() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2018-04-01 16:48:25 +03:00
|
|
|
std::size_t count() const;
|
2014-02-23 21:39:18 +01:00
|
|
|
///< Return total number of references, including deleted ones.
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-12-06 18:03:55 +01:00
|
|
|
void load();
|
2014-02-23 21:39:18 +01:00
|
|
|
///< Load references from content file.
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-12-06 18:03:55 +01:00
|
|
|
void preload();
|
2014-02-23 21:39:18 +01:00
|
|
|
///< Build ID list from content file.
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-12-17 23:59:18 +01:00
|
|
|
/// Call visitor (MWWorld::Ptr) for each reference. visitor must return a bool. Returning
|
2014-02-23 21:39:18 +01:00
|
|
|
/// false will abort the iteration.
|
2015-12-17 23:59:18 +01:00
|
|
|
/// \note Prefer using forEachConst when possible.
|
2016-02-05 18:29:33 +01:00
|
|
|
/// \note Do not modify this cell (i.e. remove/add objects) during the forEach, doing this may result in
|
2015-05-07 16:46:59 +02:00
|
|
|
/// unintended behaviour. \attention This function also lists deleted (count 0) objects! \return Iteration
|
2014-02-23 21:39:18 +01:00
|
|
|
/// completed?
|
2015-12-06 20:19:07 +01:00
|
|
|
template <class Visitor>
|
2020-02-11 22:24:18 +01:00
|
|
|
bool forEach(Visitor&& visitor)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2015-12-04 19:46:02 +01:00
|
|
|
if (mState != State_Loaded)
|
|
|
|
return false;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-05-11 01:00:50 +02:00
|
|
|
if (mMergedRefsNeedsUpdate)
|
|
|
|
updateMergedRefs();
|
2016-07-02 20:33:37 +02:00
|
|
|
if (mMergedRefs.empty())
|
|
|
|
return true;
|
2022-09-08 20:52:00 +02:00
|
|
|
|
|
|
|
mHasState = true;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < mMergedRefs.size(); ++i)
|
|
|
|
{
|
2015-11-14 17:44:16 +01:00
|
|
|
if (!isAccessible(mMergedRefs[i]->mData, mMergedRefs[i]->mRef))
|
|
|
|
continue;
|
2018-12-15 10:23:50 +04:00
|
|
|
|
2015-12-17 20:34:50 +01:00
|
|
|
if (!visitor(MWWorld::Ptr(mMergedRefs[i], this)))
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-04 19:46:02 +01:00
|
|
|
return true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2015-12-04 19:46:02 +01:00
|
|
|
/// Call visitor (MWWorld::ConstPtr) for each reference. visitor must return a bool. Returning
|
2015-11-14 17:25:00 +01:00
|
|
|
/// false will abort the iteration.
|
|
|
|
/// \note Do not modify this cell (i.e. remove/add objects) during the forEach, doing this may result in
|
|
|
|
/// unintended behaviour. \attention This function also lists deleted (count 0) objects! \return Iteration
|
|
|
|
/// completed?
|
2015-11-14 17:12:05 +01:00
|
|
|
template <class Visitor>
|
2015-12-06 20:19:07 +01:00
|
|
|
bool forEachConst(Visitor&& visitor) const
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2015-12-04 19:46:02 +01:00
|
|
|
if (mState != State_Loaded)
|
2015-12-06 20:19:07 +01:00
|
|
|
return false;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-05-11 01:00:50 +02:00
|
|
|
if (mMergedRefsNeedsUpdate)
|
|
|
|
updateMergedRefs();
|
|
|
|
|
2015-12-06 20:19:07 +01:00
|
|
|
for (unsigned int i = 0; i < mMergedRefs.size(); ++i)
|
|
|
|
{
|
|
|
|
if (!isAccessible(mMergedRefs[i]->mData, mMergedRefs[i]->mRef))
|
|
|
|
continue;
|
2015-11-14 17:12:05 +01:00
|
|
|
|
2018-11-20 21:53:27 +04:00
|
|
|
if (!visitor(MWWorld::ConstPtr(mMergedRefs[i], this)))
|
2015-12-04 19:46:02 +01:00
|
|
|
return false;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2015-12-04 19:46:02 +01:00
|
|
|
return true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2015-12-06 20:19:07 +01:00
|
|
|
/// Call visitor (ref) for each reference of given type. visitor must return a bool. Returning
|
2015-12-17 23:59:18 +01:00
|
|
|
/// false will abort the iteration.
|
2016-02-05 18:29:33 +01:00
|
|
|
/// \note Do not modify this cell (i.e. remove/add objects) during the forEach, doing this may result in
|
2015-12-17 23:59:18 +01:00
|
|
|
/// unintended behaviour. \attention This function also lists deleted (count 0) objects! \return Iteration
|
|
|
|
/// completed?
|
2015-12-06 20:19:07 +01:00
|
|
|
template <class T, class Visitor>
|
|
|
|
bool forEachType(Visitor& visitor)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2015-12-17 23:59:18 +01:00
|
|
|
if (mState != State_Loaded)
|
|
|
|
return false;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-05-11 01:00:50 +02:00
|
|
|
if (mMergedRefsNeedsUpdate)
|
|
|
|
updateMergedRefs();
|
2016-07-02 20:33:37 +02:00
|
|
|
if (mMergedRefs.empty())
|
2015-12-17 23:59:18 +01:00
|
|
|
return true;
|
2014-02-23 21:39:18 +01:00
|
|
|
|
2014-10-24 18:49:38 +02:00
|
|
|
mHasState = true;
|
2015-12-04 19:46:02 +01:00
|
|
|
|
2015-12-06 18:13:04 +01:00
|
|
|
CellRefList<T>& list = get<T>();
|
2014-10-24 18:49:38 +02:00
|
|
|
|
2015-12-17 23:59:18 +01:00
|
|
|
for (typename CellRefList<T>::List::iterator it(list.mList.begin()); it != list.mList.end(); ++it)
|
|
|
|
{
|
|
|
|
LiveCellRefBase* base = &*it;
|
|
|
|
if (mMovedToAnotherCell.find(base) != mMovedToAnotherCell.end())
|
|
|
|
continue;
|
|
|
|
if (!isAccessible(base->mData, base->mRef))
|
2015-12-06 20:19:07 +01:00
|
|
|
continue;
|
|
|
|
if (!visitor(MWWorld::Ptr(base, this)))
|
2015-12-17 23:59:18 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-05 18:29:33 +01:00
|
|
|
for (MovedRefTracker::const_iterator it = mMovedHere.begin(); it != mMovedHere.end(); ++it)
|
2015-12-06 20:19:07 +01:00
|
|
|
{
|
|
|
|
LiveCellRefBase* base = it->first;
|
|
|
|
if (dynamic_cast<LiveCellRef<T>*>(base))
|
|
|
|
if (!visitor(MWWorld::Ptr(base, this)))
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-02 20:33:37 +02:00
|
|
|
return true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2015-12-06 20:19:07 +01:00
|
|
|
|
2015-12-06 21:58:25 +01:00
|
|
|
// NOTE: does not account for moved references
|
|
|
|
// Should be phased out when we have const version of forEach
|
|
|
|
inline const CellRefList<ESM::Door>& getReadOnlyDoors() const { return get<ESM::Door>(); }
|
2023-05-20 02:31:51 +02:00
|
|
|
inline const CellRefList<ESM4::Door>& getReadOnlyEsm4Doors() const { return get<ESM4::Door>(); }
|
2015-12-06 21:58:25 +01:00
|
|
|
inline const CellRefList<ESM::Static>& getReadOnlyStatics() const { return get<ESM::Static>(); }
|
2023-01-22 19:03:19 +01:00
|
|
|
inline const CellRefList<ESM4::Static>& getReadOnlyEsm4Statics() const { return get<ESM4::Static>(); }
|
2015-12-06 21:58:25 +01:00
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
bool isExterior() const;
|
|
|
|
|
2022-08-19 14:51:52 +00:00
|
|
|
bool isQuasiExterior() const;
|
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
Ptr searchInContainer(const ESM::RefId& id);
|
2014-02-23 21:39:18 +01:00
|
|
|
|
|
|
|
void loadState(const ESM::CellState& state);
|
|
|
|
|
|
|
|
void saveState(ESM::CellState& state) const;
|
|
|
|
|
2014-05-11 02:07:28 +02:00
|
|
|
void writeFog(ESM::ESMWriter& writer) const;
|
|
|
|
|
|
|
|
void readFog(ESM::ESMReader& reader);
|
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
void writeReferences(ESM::ESMWriter& writer) const;
|
|
|
|
|
2015-12-06 19:53:06 +01:00
|
|
|
struct GetCellStoreCallback
|
|
|
|
{
|
2018-10-09 10:21:12 +04:00
|
|
|
///@note must return nullptr if the cell is not found
|
2023-02-19 17:42:37 +01:00
|
|
|
virtual CellStore* getCellStore(const ESM::RefId& cellId) = 0;
|
2020-03-26 12:07:32 +04:00
|
|
|
virtual ~GetCellStoreCallback() = default;
|
2015-12-06 19:53:06 +01:00
|
|
|
};
|
2014-02-23 21:39:18 +01:00
|
|
|
|
2014-05-17 09:05:41 +02:00
|
|
|
/// @param callback to use for retrieving of additional CellStore objects by ID (required for resolving moved
|
2015-12-06 19:53:06 +01:00
|
|
|
/// references)
|
2014-05-17 09:05:41 +02:00
|
|
|
void readReferences(
|
|
|
|
ESM::ESMReader& reader, const std::map<int, int>& contentFileMap, GetCellStoreCallback* callback);
|
|
|
|
|
2021-12-06 13:46:56 +00:00
|
|
|
void respawn();
|
|
|
|
///< Check mLastRespawn and respawn references if necessary. This is a no-op if the cell is not loaded.
|
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
Ptr getMovedActor(int actorId) const;
|
|
|
|
|
2023-05-26 19:23:43 +02:00
|
|
|
Ptr getPtr(ESM::RefId id);
|
|
|
|
|
2023-01-22 19:03:19 +01:00
|
|
|
bool operator==(const CellStore& right) const;
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
private:
|
2023-03-05 18:45:53 +01:00
|
|
|
friend struct CellStoreImp;
|
|
|
|
|
|
|
|
const MWWorld::ESMStore& mStore;
|
|
|
|
ESM::ReadersCache& mReaders;
|
|
|
|
|
|
|
|
// Even though fog actually belongs to the player and not cells,
|
|
|
|
// it makes sense to store it here since we need it once for each cell.
|
|
|
|
// Note this is nullptr until the cell is explored to save some memory
|
|
|
|
std::unique_ptr<ESM::FogState> mFogState;
|
|
|
|
|
|
|
|
MWWorld::Cell mCellVariant;
|
|
|
|
State mState;
|
|
|
|
bool mHasState;
|
|
|
|
std::vector<ESM::RefId> mIds;
|
|
|
|
float mWaterLevel;
|
|
|
|
|
|
|
|
MWWorld::TimeStamp mLastRespawn;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static constexpr std::size_t getTypeIndex()
|
|
|
|
{
|
|
|
|
static_assert(Misc::TupleHasType<CellRefList<T>, CellStoreTuple>::value);
|
|
|
|
return Misc::TupleTypeIndex<CellRefList<T>, CellStoreTuple>::value;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CellStoreImp> mCellStoreImp;
|
|
|
|
std::vector<CellRefListBase*> mCellRefLists;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
CellRefList<T>& get()
|
|
|
|
{
|
|
|
|
mHasState = true;
|
|
|
|
return static_cast<CellRefList<T>&>(*mCellRefLists[getTypeIndex<T>()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
const CellRefList<T>& get() const
|
|
|
|
{
|
|
|
|
return static_cast<const CellRefList<T>&>(*mCellRefLists[getTypeIndex<T>()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::map<LiveCellRefBase*, MWWorld::CellStore*> MovedRefTracker;
|
|
|
|
// References owned by a different cell that have been moved here.
|
|
|
|
// <reference, cell the reference originally came from>
|
|
|
|
MovedRefTracker mMovedHere;
|
|
|
|
// References owned by this cell that have been moved to another cell.
|
|
|
|
// <reference, cell the reference was moved to>
|
|
|
|
MovedRefTracker mMovedToAnotherCell;
|
|
|
|
|
|
|
|
// Merged list of ref's currently in this cell - i.e. with added refs from mMovedHere, removed refs from
|
|
|
|
// mMovedToAnotherCell
|
2023-05-11 01:00:50 +02:00
|
|
|
mutable std::vector<LiveCellRefBase*> mMergedRefs;
|
|
|
|
mutable bool mMergedRefsNeedsUpdate = false;
|
2023-03-05 18:45:53 +01:00
|
|
|
|
|
|
|
// Get the Ptr for the given ref which originated from this cell (possibly moved to another cell at this point).
|
|
|
|
Ptr getCurrentPtr(MWWorld::LiveCellRefBase* ref);
|
|
|
|
|
|
|
|
/// Moves object from the given cell to this cell.
|
|
|
|
void moveFrom(const MWWorld::Ptr& object, MWWorld::CellStore* from);
|
|
|
|
|
|
|
|
/// Repopulate mMergedRefs.
|
2023-05-11 01:00:50 +02:00
|
|
|
void requestMergedRefsUpdate();
|
|
|
|
void updateMergedRefs() const;
|
2023-03-05 18:45:53 +01:00
|
|
|
|
|
|
|
// (item, max charge)
|
|
|
|
typedef std::vector<std::pair<LiveCellRefBase*, float>> TRechargingItems;
|
|
|
|
TRechargingItems mRechargingItems;
|
|
|
|
|
|
|
|
bool mRechargingItemsUpToDate;
|
|
|
|
|
|
|
|
void updateRechargingItems();
|
|
|
|
void rechargeItems(float duration);
|
|
|
|
void checkItem(const Ptr& ptr);
|
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
/// Run through references and store IDs
|
2023-02-04 18:45:53 +01:00
|
|
|
void listRefs(const ESM::Cell& cell);
|
|
|
|
void listRefs(const ESM4::Cell& cell);
|
2015-12-06 18:03:55 +01:00
|
|
|
void listRefs();
|
2014-02-23 21:39:18 +01:00
|
|
|
|
2023-01-27 15:29:05 +01:00
|
|
|
void loadRefs(const ESM::Cell& cell, std::map<ESM::RefNum, ESM::RefId>& refNumToID);
|
|
|
|
void loadRefs(const ESM4::Cell& cell, std::map<ESM::RefNum, ESM::RefId>& refNumToID);
|
|
|
|
|
2015-12-06 18:03:55 +01:00
|
|
|
void loadRefs();
|
2014-02-23 21:39:18 +01:00
|
|
|
|
2023-01-22 19:03:19 +01:00
|
|
|
void loadRef(const ESM4::Reference& ref, bool deleted);
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
void loadRef(ESM::CellRef& ref, bool deleted, std::map<ESM::RefNum, ESM::RefId>& refNumToID);
|
2014-02-23 21:39:18 +01:00
|
|
|
///< Make case-adjustments to \a ref and insert it into the respective container.
|
|
|
|
///
|
|
|
|
/// Invalid \a ref objects are silently dropped.
|
2023-01-22 19:03:19 +01:00
|
|
|
///
|
2014-02-23 21:39:18 +01:00
|
|
|
};
|
2014-02-23 21:21:27 +01:00
|
|
|
|
2010-05-20 18:59:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|