mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 21:40:03 +00:00
125b21de20
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!
98 lines
2.4 KiB
C++
98 lines
2.4 KiB
C++
#ifndef GAME_SCRIPT_GLOBALSCRIPTS_H
|
|
#define GAME_SCRIPT_GLOBALSCRIPTS_H
|
|
|
|
#include <cstdint>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <unordered_map>
|
|
#include <utility>
|
|
#include <variant>
|
|
|
|
#include <components/misc/algorithm.hpp>
|
|
#include <components/esm/refid.hpp>
|
|
|
|
#include "locals.hpp"
|
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
namespace ESM
|
|
{
|
|
class ESMWriter;
|
|
class ESMReader;
|
|
struct RefNum;
|
|
}
|
|
|
|
namespace Loading
|
|
{
|
|
class Listener;
|
|
}
|
|
|
|
namespace MWWorld
|
|
{
|
|
class ESMStore;
|
|
}
|
|
|
|
namespace MWScript
|
|
{
|
|
struct GlobalScriptDesc
|
|
{
|
|
bool mRunning;
|
|
Locals mLocals;
|
|
std::variant<MWWorld::Ptr, std::pair<ESM::RefNum, ESM::RefId>> mTarget; // Used to start targeted script
|
|
|
|
GlobalScriptDesc();
|
|
|
|
const MWWorld::Ptr* getPtrIfPresent() const; // Returns a Ptr if one has been resolved
|
|
|
|
MWWorld::Ptr getPtr(); // Resolves mTarget to a Ptr and caches the (potentially empty) result
|
|
|
|
const ESM::RefId& getId() const; // Returns the target's ID -- if any
|
|
};
|
|
|
|
class GlobalScripts
|
|
{
|
|
const MWWorld::ESMStore& mStore;
|
|
std::unordered_map<ESM::RefId, std::shared_ptr<GlobalScriptDesc>>
|
|
mScripts;
|
|
|
|
public:
|
|
GlobalScripts(const MWWorld::ESMStore& store);
|
|
|
|
void addScript(const ESM::RefId& name, const MWWorld::Ptr& target = MWWorld::Ptr());
|
|
|
|
void removeScript(const ESM::RefId& name);
|
|
|
|
bool isRunning(const ESM::RefId& name) const;
|
|
|
|
void run();
|
|
///< run all active global scripts
|
|
|
|
void clear();
|
|
|
|
void addStartup();
|
|
///< Add startup script
|
|
|
|
int countSavedGameRecords() const;
|
|
|
|
void write(ESM::ESMWriter& writer, Loading::Listener& progress) const;
|
|
|
|
bool readRecord(ESM::ESMReader& reader, uint32_t type, const std::map<int, int>& contentFileMap);
|
|
///< Records for variables that do not exist are dropped silently.
|
|
///
|
|
/// \return Known type?
|
|
|
|
Locals& getLocals(const ESM::RefId& name);
|
|
///< If the script \a name has not been added as a global script yet, it is added
|
|
/// automatically, but is not set to running state.
|
|
|
|
const Locals* getLocalsIfPresent(const ESM::RefId& name) const;
|
|
|
|
void updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated);
|
|
///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell.
|
|
};
|
|
}
|
|
|
|
#endif
|