1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00
OpenMW/apps/openmw/mwworld/refdata.hpp
fteppe 125b21de20 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-12-27 19:15:54 +01:00

163 lines
4.5 KiB
C++

#ifndef GAME_MWWORLD_REFDATA_H
#define GAME_MWWORLD_REFDATA_H
#include <components/esm/defs.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/animationstate.hpp>
#include "../mwscript/locals.hpp"
#include "../mwworld/customdata.hpp"
#include <osg/ref_ptr>
#include <memory>
#include <string>
namespace SceneUtil
{
class PositionAttitudeTransform;
}
namespace ESM
{
class Script;
class CellRef;
struct ObjectState;
}
namespace MWLua
{
class LocalScripts;
}
namespace MWWorld
{
class CustomData;
class RefData
{
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mBaseNode;
MWScript::Locals mLocals;
std::shared_ptr<MWLua::LocalScripts> mLuaScripts;
/// separate delete flag used for deletion by a content file
/// @note not stored in the save game file.
bool mDeletedByContentFile : 1;
bool mEnabled : 1;
public:
bool mPhysicsPostponed : 1;
private:
/// 0: deleted
int mCount;
ESM::Position mPosition;
ESM::AnimationState mAnimationState;
std::unique_ptr<CustomData> mCustomData;
void copy(const RefData& refData);
void cleanup();
bool mChanged;
unsigned int mFlags;
public:
RefData();
/// @param cellRef Used to copy constant data such as position into this class where it can
/// be altered without affecting the original data. This makes it possible
/// to reset the position as the original data is still held in the CellRef
RefData(const ESM::CellRef& cellRef);
RefData(const ESM::ObjectState& objectState, bool deletedByContentFile);
///< Ignores local variables and custom data (not enough context available here to
/// perform these operations).
RefData(const RefData& refData);
RefData(RefData&& other);
~RefData();
void write(ESM::ObjectState& objectState,const ESM::RefId& scriptId = ESM::RefId::sEmpty) const;
///< Ignores custom data (not enough context available here to
/// perform this operations).
RefData& operator=(const RefData& refData);
RefData& operator=(RefData&& other);
/// Return base node (can be a null pointer).
SceneUtil::PositionAttitudeTransform* getBaseNode();
/// Return base node (can be a null pointer).
const SceneUtil::PositionAttitudeTransform* getBaseNode() const;
/// Set base node (can be a null pointer).
void setBaseNode(osg::ref_ptr<SceneUtil::PositionAttitudeTransform> base);
int getCount(bool absolute = true) const;
void setLocals(const ESM::Script& script);
MWLua::LocalScripts* getLuaScripts() { return mLuaScripts.get(); }
void setLuaScripts(std::shared_ptr<MWLua::LocalScripts>&&);
void setCount(int count);
///< Set object count (an object pile is a simple object with a count >1).
///
/// \warning Do not call setCount() to add or remove objects from a
/// container or an actor's inventory. Call ContainerStore::add() or
/// ContainerStore::remove() instead.
/// This flag is only used for content stack loading and will not be stored in the savegame.
/// If the object was deleted by gameplay, then use setCount(0) instead.
void setDeletedByContentFile(bool deleted);
/// Returns true if the object was either deleted by the content file or by gameplay.
bool isDeleted() const;
/// Returns true if the object was deleted by a content file.
bool isDeletedByContentFile() const;
MWScript::Locals& getLocals();
bool isEnabled() const;
void enable();
void disable();
void setPosition(const ESM::Position& pos);
const ESM::Position& getPosition() const;
void setCustomData(std::unique_ptr<CustomData>&& value) noexcept;
///< Set custom data (potentially replacing old custom data). The ownership of \a data is
/// transferred to this.
CustomData* getCustomData();
///< May return a 0-pointer. The ownership of the return data object is not transferred.
const CustomData* getCustomData() const;
bool activate();
bool onActivate();
bool activateByScript();
bool hasChanged() const;
///< Has this RefData changed since it was originally loaded?
const ESM::AnimationState& getAnimationState() const;
ESM::AnimationState& getAnimationState();
};
}
#endif