2010-07-02 14:31:29 +02:00
|
|
|
#ifndef GAME_SCRIPT_LOCALS_H
|
|
|
|
#define GAME_SCRIPT_LOCALS_H
|
|
|
|
|
2022-05-21 12:41:56 +02:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
2010-07-02 14:31:29 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2023-01-07 20:52:36 +01:00
|
|
|
#include <components/esm/refid.hpp>
|
2010-07-02 14:31:29 +02:00
|
|
|
#include <components/interpreter/types.hpp>
|
|
|
|
|
2013-04-04 12:27:57 +02:00
|
|
|
namespace ESM
|
|
|
|
{
|
2015-03-06 21:36:42 +13:00
|
|
|
class Script;
|
2013-12-15 16:16:50 +01:00
|
|
|
struct Locals;
|
2023-02-15 23:19:51 +01:00
|
|
|
class RefId;
|
2013-04-04 12:27:57 +02:00
|
|
|
}
|
|
|
|
|
2010-07-02 14:31:29 +02:00
|
|
|
namespace MWScript
|
|
|
|
{
|
2013-02-03 13:27:27 +00:00
|
|
|
class Locals
|
2010-07-02 14:31:29 +02:00
|
|
|
{
|
2015-09-15 13:58:07 +02:00
|
|
|
bool mInitialised;
|
2023-01-07 20:52:36 +01:00
|
|
|
ESM::RefId mScriptId;
|
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
|
|
|
void ensure(const ESM::RefId& scriptName);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-02-03 13:27:27 +00:00
|
|
|
public:
|
|
|
|
std::vector<Interpreter::Type_Short> mShorts;
|
|
|
|
std::vector<Interpreter::Type_Integer> mLongs;
|
|
|
|
std::vector<Interpreter::Type_Float> mFloats;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
Locals();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2023-01-07 20:52:36 +01:00
|
|
|
const ESM::RefId& getScriptId() const { return mScriptId; }
|
|
|
|
|
2014-06-26 01:21:15 +02:00
|
|
|
/// Are there any locals?
|
2015-09-15 13:58:07 +02:00
|
|
|
///
|
|
|
|
/// \note Will return false, if locals have not been configured yet.
|
2014-06-26 01:21:15 +02:00
|
|
|
bool isEmpty() const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
/// \return Did the state of *this change from uninitialised to initialised?
|
|
|
|
bool configure(const ESM::Script& script);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2014-09-11 19:20:04 +02:00
|
|
|
/// @note var needs to be in lowercase
|
2015-09-15 13:58:07 +02:00
|
|
|
///
|
|
|
|
/// \note Locals will be automatically configured first, if necessary
|
2023-01-07 20:52:36 +01:00
|
|
|
bool setVarByInt(const ESM::RefId& script, std::string_view var, int val) { return setVar(script, var, val); }
|
|
|
|
bool setVar(const ESM::RefId& script, std::string_view var, double val);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
/// \note Locals will be automatically configured first, if necessary
|
|
|
|
//
|
|
|
|
// \note If it can not be determined if the variable exists, the error will be
|
|
|
|
// ignored and false will be returned.
|
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 hasVar(const ESM::RefId& script, std::string_view var);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-01-31 02:08:37 +01:00
|
|
|
/// if var does not exist, returns 0
|
2014-09-11 19:20:04 +02:00
|
|
|
/// @note var needs to be in lowercase
|
2015-09-15 13:58:07 +02:00
|
|
|
///
|
|
|
|
/// \note Locals will be automatically configured first, if necessary
|
2023-01-07 20:52:36 +01:00
|
|
|
double getVarAsDouble(const ESM::RefId& script, std::string_view var);
|
|
|
|
int getIntVar(const ESM::RefId& script, std::string_view var)
|
|
|
|
{
|
|
|
|
return static_cast<int>(getVarAsDouble(script, var));
|
|
|
|
}
|
|
|
|
float getFloatVar(const ESM::RefId& script, std::string_view var)
|
|
|
|
{
|
|
|
|
return static_cast<float>(getVarAsDouble(script, var));
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
/// \note If locals have not been configured yet, no data is written.
|
|
|
|
///
|
|
|
|
/// \return Locals written?
|
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 write(ESM::Locals& locals, const ESM::RefId& script) const;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2015-09-15 13:58:07 +02:00
|
|
|
/// \note Locals will be automatically configured first, if necessary
|
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 read(const ESM::Locals& locals, const ESM::RefId& script);
|
2010-07-02 14:31:29 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|