id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
35,842
|
globalmap.hpp
|
OpenMW_openmw/components/esm3/globalmap.hpp
|
#ifndef OPENMW_COMPONENTS_ESM_GLOBALMAP_H
#define OPENMW_COMPONENTS_ESM_GLOBALMAP_H
#include <cstdint>
#include <set>
#include <vector>
#include "components/esm/defs.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
// format 0, saved games only
///< \brief An image containing the explored areas on the global map.
struct GlobalMap
{
constexpr static RecNameInts sRecordId = REC_GMAP;
// The minimum and maximum cell coordinates
struct Bounds
{
int32_t mMinX, mMaxX, mMinY, mMaxY;
};
Bounds mBounds;
std::vector<char> mImageData;
typedef std::pair<int, int> CellId;
std::set<CellId> mMarkers;
void load(ESMReader& esm);
void save(ESMWriter& esm) const;
};
}
#endif
| 811
|
C++
|
.h
| 29
| 22.137931
| 73
| 0.661039
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,843
|
loadsndg.hpp
|
OpenMW_openmw/components/esm3/loadsndg.hpp
|
#ifndef OPENMW_ESM_SNDG_H
#define OPENMW_ESM_SNDG_H
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
* Sound generator. This describes the sounds a creature make.
*/
struct SoundGenerator
{
constexpr static RecNameInts sRecordId = REC_SNDG;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "SoundGenerator"; }
enum Type
{
LeftFoot = 0,
RightFoot = 1,
SwimLeft = 2,
SwimRight = 3,
Moan = 4,
Roar = 5,
Scream = 6,
Land = 7
};
// Type
int32_t mType;
uint32_t mRecordFlags;
RefId mId, mCreature, mSound;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
};
}
#endif
| 1,067
|
C++
|
.h
| 38
| 20.605263
| 108
| 0.593904
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,844
|
loadclot.hpp
|
OpenMW_openmw/components/esm3/loadclot.hpp
|
#ifndef OPENMW_ESM_CLOT_H
#define OPENMW_ESM_CLOT_H
#include <cstdint>
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
#include "loadarmo.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
* Clothing
*/
struct Clothing
{
constexpr static RecNameInts sRecordId = REC_CLOT;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Clothing"; }
enum Type
{
Pants = 0,
Shoes = 1,
Shirt = 2,
Belt = 3,
Robe = 4,
RGlove = 5,
LGlove = 6,
Skirt = 7,
Ring = 8,
Amulet = 9
};
struct CTDTstruct
{
int32_t mType;
float mWeight;
uint16_t mValue;
uint16_t mEnchant;
};
CTDTstruct mData;
PartReferenceList mParts;
uint32_t mRecordFlags;
RefId mId, mEnchant, mScript;
std::string mModel, mIcon, mName;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID).
};
}
#endif
| 1,372
|
C++
|
.h
| 51
| 18.862745
| 108
| 0.56422
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,845
|
loadrace.hpp
|
OpenMW_openmw/components/esm3/loadrace.hpp
|
#ifndef OPENMW_ESM_RACE_H
#define OPENMW_ESM_RACE_H
#include <array>
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
#include "spelllist.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
* Race definition
*/
struct Race
{
constexpr static RecNameInts sRecordId = REC_RACE;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Race"; }
struct SkillBonus
{
int32_t mSkill; // SkillEnum
int32_t mBonus;
};
enum Flags
{
Playable = 0x01,
Beast = 0x02
};
struct RADTstruct
{
// List of skills that get a bonus
std::array<SkillBonus, 7> mBonus;
// Attribute values for male/female
std::array<int32_t, 16> mAttributeValues;
// The actual eye level height (in game units) is (probably) given
// as 'height' times 128. This has not been tested yet.
float mMaleHeight, mFemaleHeight, mMaleWeight, mFemaleWeight;
int32_t mFlags; // 0x1 - playable, 0x2 - beast race
int32_t getAttribute(ESM::RefId attribute, bool male) const;
void setAttribute(ESM::RefId attribute, bool male, int32_t value);
void load(ESMReader& esm);
void save(ESMWriter& esm) const;
}; // Size = 140 bytes
RADTstruct mData;
uint32_t mRecordFlags;
std::string mName, mDescription;
RefId mId;
SpellList mPowers;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID/index).
};
}
#endif
| 1,921
|
C++
|
.h
| 56
| 25.892857
| 108
| 0.60846
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,846
|
loadglob.hpp
|
OpenMW_openmw/components/esm3/loadglob.hpp
|
#ifndef OPENMW_ESM_GLOB_H
#define OPENMW_ESM_GLOB_H
#include <string>
#include "variant.hpp"
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
* Global script variables
*/
struct Global
{
constexpr static RecNameInts sRecordId = REC_GLOB;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Global"; }
uint32_t mRecordFlags;
ESM::RefId mId;
Variant mValue;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID).
};
bool operator==(const Global& left, const Global& right);
}
#endif
| 904
|
C++
|
.h
| 29
| 25.655172
| 108
| 0.670534
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,847
|
loadland.hpp
|
OpenMW_openmw/components/esm3/loadland.hpp
|
#ifndef OPENMW_ESM_LAND_H
#define OPENMW_ESM_LAND_H
#include <array>
#include <cstdint>
#include <memory>
#include <components/misc/constants.hpp>
#include "components/esm/defs.hpp"
#include "components/esm/esmcommon.hpp"
#include "landrecorddata.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
* Landscape data.
*/
struct Land
{
constexpr static RecNameInts sRecordId = REC_LAND;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Land"; }
Land() = default;
Land(const Land& land);
Land(Land&& other) = default;
Land& operator=(const Land& land);
Land& operator=(Land&& land) = default;
// Only first four bits seem to be used, don't know what they mean.
std::uint32_t mFlags = 0;
// Map coordinates.
std::int32_t mX = 0;
std::int32_t mY = 0;
// Plugin index, used to reference the correct material palette.
int getPlugin() const { return mContext.index; }
void setPlugin(int index) { mContext.index = index; }
// File context. This allows the ESM reader to be 'reset' to this
// location later when we are ready to load the full data set.
// In the editor, there may not be a file associated with the Land,
// in which case the filename will be empty.
ESM_Context mContext;
int mDataTypes = 0;
enum
{
DATA_VNML = 1,
DATA_VHGT = 2,
DATA_WNAM = 4,
DATA_VCLR = 8,
DATA_VTEX = 16
};
enum Flags
{
Flag_HeightsNormals = 0x1,
Flag_Colors = 0x2,
Flag_Textures = 0x4
};
// default height to use in case there is no Land record
static constexpr int DEFAULT_HEIGHT = -2048;
// number of vertices per side
static constexpr int LAND_SIZE = LandRecordData::sLandSize;
// cell terrain size in world coords
static constexpr int REAL_SIZE = Constants::CellSizeInUnits;
// total number of vertices
static constexpr int LAND_NUM_VERTS = LandRecordData::sLandNumVerts;
static constexpr int sHeightScale = 8;
// number of textures per side of land
static constexpr int LAND_TEXTURE_SIZE = LandRecordData::sLandTextureSize;
// total number of textures per land
static constexpr int LAND_NUM_TEXTURES = LandRecordData::sLandNumTextures;
static constexpr std::size_t sGlobalMapLodSizeSqrt = 9;
static constexpr std::size_t sGlobalMapLodSize = sGlobalMapLodSizeSqrt * sGlobalMapLodSizeSqrt;
using LandData = ESM::LandRecordData;
// low-LOD heightmap (used for rendering the global map)
std::array<std::int8_t, sGlobalMapLodSize> mWnam;
mutable std::unique_ptr<LandData> mLandData;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
void loadData(int dataTypes) const;
void loadData(int dataTypes, LandData& data) const;
/**
* Frees memory allocated for mLandData
*/
void unloadData();
/// Check if given data type is loaded
bool isDataLoaded(int flags) const;
/// Return land data with at least the data types specified in \a flags loaded (if they
/// are available). Will return a 0-pointer if there is no data for any of the
/// specified types.
const LandData* getLandData(int flags) const;
/// Return land data without loading first anything. Can return a 0-pointer.
const LandData* getLandData() const { return mLandData.get(); }
/// Return land data without loading first anything. Can return a 0-pointer.
LandData* getLandData() { return mLandData.get(); }
/// \attention Must not be called on objects that aren't fully loaded.
///
/// \note Added data fields will be uninitialised
void add(int flags);
};
void loadLandRecordData(int dataTypes, ESMReader& reader, LandRecordData& data);
void generateWnam(const std::array<float, LandRecordData::sLandNumVerts>& heights,
std::array<std::int8_t, Land::sGlobalMapLodSize>& wnam);
}
#endif
| 4,447
|
C++
|
.h
| 102
| 35.215686
| 108
| 0.647209
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,848
|
loaddoor.hpp
|
OpenMW_openmw/components/esm3/loaddoor.hpp
|
#ifndef OPENMW_ESM_DOOR_H
#define OPENMW_ESM_DOOR_H
#include <cstdint>
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
struct Door
{
constexpr static RecNameInts sRecordId = REC_DOOR;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Door"; }
uint32_t mRecordFlags;
RefId mId, mScript, mOpenSound, mCloseSound;
std::string mName, mModel;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID).
};
}
#endif
| 824
|
C++
|
.h
| 25
| 27.6
| 108
| 0.682278
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,849
|
inventorystate.hpp
|
OpenMW_openmw/components/esm3/inventorystate.hpp
|
#ifndef OPENMW_ESM_INVENTORYSTATE_H
#define OPENMW_ESM_INVENTORYSTATE_H
#include <map>
#include <optional>
#include "objectstate.hpp"
#include <components/esm/refid.hpp>
namespace ESM
{
class ESMReader;
class ESMWriter;
// format 0, saved games only
/// \brief State for inventories and containers
struct InventoryState
{
std::vector<ObjectState> mItems;
// <Index in mItems, equipment slot>
std::map<uint32_t, int32_t> mEquipmentSlots;
std::map<ESM::RefId, std::vector<std::pair<float, float>>> mPermanentMagicEffectMagnitudes;
std::optional<uint32_t> mSelectedEnchantItem; // For inventories only
virtual ~InventoryState() = default;
virtual void load(ESMReader& esm);
virtual void save(ESMWriter& esm) const;
};
}
#endif
| 827
|
C++
|
.h
| 25
| 27.96
| 99
| 0.704172
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,850
|
cellid.hpp
|
OpenMW_openmw/components/esm3/cellid.hpp
|
#ifndef OPENMW_ESM_CELLID_H
#define OPENMW_ESM_CELLID_H
#include <components/esm/refid.hpp>
#include <cstdint>
#include <string>
namespace ESM
{
class ESMReader;
class ESMWriter;
struct CellId
{
struct CellIndex
{
int32_t mX;
int32_t mY;
};
std::string mWorldspace;
CellIndex mIndex;
bool mPaged;
void load(ESMReader& esm);
void save(ESMWriter& esm) const;
// TODO tetramir: this probably shouldn't exist, needs it because some CellIds are saved on disk
static CellId extractFromRefId(const ESM::RefId& id);
};
bool operator==(const CellId& left, const CellId& right);
bool operator!=(const CellId& left, const CellId& right);
bool operator<(const CellId& left, const CellId& right);
}
#endif
| 837
|
C++
|
.h
| 29
| 22.896552
| 104
| 0.65625
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,851
|
spellstate.hpp
|
OpenMW_openmw/components/esm3/spellstate.hpp
|
#ifndef OPENMW_ESM_SPELLSTATE_H
#define OPENMW_ESM_SPELLSTATE_H
#include <map>
#include <set>
#include <string>
#include <vector>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
#include "timestamp.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
class RefId;
// NOTE: spell ids must be lower case
struct SpellState
{
struct CorprusStats
{
int32_t mWorsenings;
TimeStamp mNextWorsening;
};
struct PermanentSpellEffectInfo
{
int32_t mId;
int32_t mArg;
float mMagnitude;
};
struct SpellParams
{
std::map<int32_t, float> mEffectRands; // <effect index, normalised random magnitude>
std::set<int32_t> mPurgedEffects; // indices of purged effects
};
std::vector<ESM::RefId> mSpells;
// FIXME: obsolete, used only for old saves
std::map<ESM::RefId, SpellParams> mSpellParams;
std::map<ESM::RefId, std::vector<PermanentSpellEffectInfo>> mPermanentSpellEffects;
std::map<ESM::RefId, CorprusStats> mCorprusSpells;
std::map<ESM::RefId, TimeStamp> mUsedPowers;
ESM::RefId mSelectedSpell;
void load(ESMReader& esm);
void save(ESMWriter& esm) const;
};
}
#endif
| 1,346
|
C++
|
.h
| 45
| 22.955556
| 97
| 0.640031
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,852
|
loadmisc.hpp
|
OpenMW_openmw/components/esm3/loadmisc.hpp
|
#ifndef OPENMW_ESM_MISC_H
#define OPENMW_ESM_MISC_H
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
* Misc inventory items, basically things that have no use but can be
* carried, bought and sold. It also includes keys.
*/
struct Miscellaneous
{
constexpr static RecNameInts sRecordId = REC_MISC;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Miscellaneous"; }
struct MCDTstruct
{
float mWeight;
int32_t mValue;
int32_t mFlags;
};
enum Flags
{
Key = 0x1 // Assigned as a key in the content file that defined the record
};
MCDTstruct mData;
uint32_t mRecordFlags;
RefId mId, mScript;
std::string mName, mModel, mIcon;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID).
};
}
#endif
| 1,237
|
C++
|
.h
| 39
| 24.666667
| 108
| 0.633755
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,853
|
loadsscr.hpp
|
OpenMW_openmw/components/esm3/loadsscr.hpp
|
#ifndef OPENMW_ESM_SSCR_H
#define OPENMW_ESM_SSCR_H
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
Startup script. I think this is simply a 'main' script that is run
from the begining. The SSCR records contain a DATA identifier which
is totally useless (TODO: don't remember what it contains exactly,
document it below later.), and a NAME which is simply a script
reference.
*/
struct StartScript
{
constexpr static RecNameInts sRecordId = REC_SSCR;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "StartScript"; }
std::string mData;
uint32_t mRecordFlags;
RefId mId;
// Load a record and add it to the list
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
};
}
#endif
| 1,077
|
C++
|
.h
| 31
| 29.064516
| 108
| 0.68599
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,854
|
magiceffects.hpp
|
OpenMW_openmw/components/esm3/magiceffects.hpp
|
#ifndef COMPONENTS_ESM_MAGICEFFECTS_H
#define COMPONENTS_ESM_MAGICEFFECTS_H
#include <components/esm/refid.hpp>
#include <map>
#include <string>
#include <tuple>
namespace ESM
{
class ESMReader;
class ESMWriter;
// format 0, saved games only
struct MagicEffects
{
// <Effect Id, Base value, Modifier>
std::map<int32_t, std::pair<int32_t, float>> mEffects;
void load(ESMReader& esm);
void save(ESMWriter& esm) const;
};
struct SummonKey
{
SummonKey(int32_t effectId, const ESM::RefId& sourceId, int32_t index)
: mEffectId(effectId)
, mSourceId(sourceId)
, mEffectIndex(index)
{
}
int32_t mEffectId;
ESM::RefId mSourceId;
int32_t mEffectIndex;
};
inline auto makeTupleRef(const SummonKey& value) noexcept
{
return std::tie(value.mEffectId, value.mSourceId, value.mEffectIndex);
}
inline bool operator==(const SummonKey& l, const SummonKey& r) noexcept
{
return makeTupleRef(l) == makeTupleRef(r);
}
inline bool operator<(const SummonKey& l, const SummonKey& r) noexcept
{
return makeTupleRef(l) < makeTupleRef(r);
}
}
#endif
| 1,246
|
C++
|
.h
| 44
| 22.25
| 78
| 0.648195
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,855
|
timestamp.hpp
|
OpenMW_openmw/components/esm3/timestamp.hpp
|
#ifndef OPENMW_COMPONENTS_ESM3_TIMESTAMP_H
#define OPENMW_COMPONENTS_ESM3_TIMESTAMP_H
#include <cstdint>
#include <components/esm/esmcommon.hpp>
namespace ESM
{
class ESMReader;
struct TimeStamp
{
float mHour;
int32_t mDay;
void load(ESMReader& esm, NAME name = "TIME");
};
}
#endif
| 329
|
C++
|
.h
| 15
| 17.866667
| 54
| 0.701299
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,856
|
creaturelevliststate.hpp
|
OpenMW_openmw/components/esm3/creaturelevliststate.hpp
|
#ifndef OPENMW_ESM_CREATURELEVLISTSTATE_H
#define OPENMW_ESM_CREATURELEVLISTSTATE_H
#include "objectstate.hpp"
namespace ESM
{
// format 0, saved games only
struct CreatureLevListState final : public ObjectState
{
int32_t mSpawnActorId;
bool mSpawn;
void load(ESMReader& esm) override;
void save(ESMWriter& esm, bool inInventory = false) const override;
CreatureLevListState& asCreatureLevListState() override { return *this; }
const CreatureLevListState& asCreatureLevListState() const override { return *this; }
};
}
#endif
| 596
|
C++
|
.h
| 17
| 29.941176
| 93
| 0.731239
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,857
|
loadsoun.hpp
|
OpenMW_openmw/components/esm3/loadsoun.hpp
|
#ifndef OPENMW_ESM_SOUN_H
#define OPENMW_ESM_SOUN_H
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
struct SOUNstruct
{
unsigned char mVolume, mMinRange, mMaxRange;
};
struct Sound
{
constexpr static RecNameInts sRecordId = REC_SOUN;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Sound"; }
SOUNstruct mData;
uint32_t mRecordFlags;
std::string mSound;
RefId mId;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID/index).
};
}
#endif
| 887
|
C++
|
.h
| 29
| 24.827586
| 108
| 0.668632
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,858
|
loadweap.hpp
|
OpenMW_openmw/components/esm3/loadweap.hpp
|
#ifndef OPENMW_ESM_WEAP_H
#define OPENMW_ESM_WEAP_H
#include <array>
#include <string>
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
/*
* Weapon definition
*/
struct Weapon
{
constexpr static RecNameInts sRecordId = REC_WEAP;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Weapon"; }
enum Type
{
First = -4,
PickProbe = -4,
HandToHand = -3,
Spell = -2,
None = -1,
ShortBladeOneHand = 0,
LongBladeOneHand = 1,
LongBladeTwoHand = 2,
BluntOneHand = 3,
BluntTwoClose = 4,
BluntTwoWide = 5,
SpearTwoWide = 6,
AxeOneHand = 7,
AxeTwoHand = 8,
MarksmanBow = 9,
MarksmanCrossbow = 10,
MarksmanThrown = 11,
Arrow = 12,
Bolt = 13,
Last = 13
};
enum AttackType
{
AT_Chop,
AT_Slash,
AT_Thrust
};
enum Flags
{
Magical = 0x01,
Silver = 0x02
};
struct WPDTstruct
{
float mWeight;
int32_t mValue;
int16_t mType;
uint16_t mHealth;
float mSpeed, mReach;
uint16_t mEnchant; // Enchantment points. The real value is mEnchant/10.f
std::array<unsigned char, 2> mChop, mSlash, mThrust; // Min and max
int32_t mFlags;
}; // 32 bytes
WPDTstruct mData;
uint32_t mRecordFlags;
RefId mId, mEnchant, mScript;
std::string mName, mModel, mIcon;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID).
};
struct WeaponType
{
enum Flags
{
TwoHanded = 0x01,
HasHealth = 0x02
};
enum Class
{
Melee = 0,
Ranged = 1,
Thrown = 2,
Ammo = 3
};
// std::string mDisplayName; // TODO: will be needed later for editor
std::string mShortGroup;
std::string mLongGroup;
ESM::RefId mSoundIdDown;
ESM::RefId mSoundIdUp;
std::string mAttachBone;
std::string mSheathingBone;
ESM::RefId mSkill;
Class mWeaponClass;
int mAmmoType;
int mFlags;
WeaponType(std::string shortGroup, std::string longGroup, const std::string& soundId, std::string attachBone,
std::string sheathingBone, ESM::RefId skill, Class weaponClass, int ammoType, int flags)
: mShortGroup(std::move(shortGroup))
, mLongGroup(std::move(longGroup))
, mSoundIdDown(ESM::RefId::stringRefId(soundId + " Down"))
, mSoundIdUp(ESM::RefId::stringRefId(soundId + " Up"))
, mAttachBone(std::move(attachBone))
, mSheathingBone(std::move(sheathingBone))
, mSkill(skill)
, mWeaponClass(weaponClass)
, mAmmoType(ammoType)
, mFlags(flags)
{
}
};
}
#endif
| 3,423
|
C++
|
.h
| 113
| 20.353982
| 117
| 0.53769
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,859
|
savedgame.hpp
|
OpenMW_openmw/components/esm3/savedgame.hpp
|
#ifndef OPENMW_ESM_SAVEDGAME_H
#define OPENMW_ESM_SAVEDGAME_H
#include <string>
#include <vector>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
// format 0, saved games only
struct SavedGame
{
constexpr static RecNameInts sRecordId = REC_SAVE;
std::vector<std::string> mContentFiles;
std::string mPlayerName;
int32_t mPlayerLevel;
// ID of class
ESM::RefId mPlayerClassId;
// Name of the class. When using a custom class, the ID is not really meaningful prior
// to loading the savegame, so the name is stored separately.
std::string mPlayerClassName;
// Name of the cell. Note that this is not an ID.
std::string mPlayerCellName;
EpochTimeStamp mInGameTime;
double mTimePlayed;
std::string mDescription;
std::vector<char> mScreenshot; // raw jpg-encoded data
int32_t mCurrentDay = 0;
float mCurrentHealth = 0;
float mMaximumHealth = 0;
void load(ESMReader& esm);
void save(ESMWriter& esm) const;
std::vector<std::string_view> getMissingContentFiles(const std::vector<std::string>& allContentFiles) const;
};
}
#endif
| 1,296
|
C++
|
.h
| 37
| 28.540541
| 116
| 0.676282
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,860
|
loadrepa.hpp
|
OpenMW_openmw/components/esm3/loadrepa.hpp
|
#ifndef OPENMW_ESM_REPA_H
#define OPENMW_ESM_REPA_H
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
struct Repair
{
constexpr static RecNameInts sRecordId = REC_REPA;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Repair"; }
struct Data
{
float mWeight;
int32_t mValue;
int32_t mUses;
float mQuality;
}; // Size = 16
Data mData;
uint32_t mRecordFlags;
RefId mId, mScript;
std::string mName, mModel, mIcon;
void load(ESMReader& esm, bool& isDeleted);
void save(ESMWriter& esm, bool isDeleted = false) const;
void blank();
///< Set record to default state (does not touch the ID).
};
}
#endif
| 978
|
C++
|
.h
| 32
| 23.5625
| 108
| 0.627409
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,861
|
validate.hpp
|
OpenMW_openmw/components/fallback/validate.hpp
|
#ifndef OPENMW_COMPONENTS_FALLBACK_VALIDATE_H
#define OPENMW_COMPONENTS_FALLBACK_VALIDATE_H
#include <map>
#include <string>
#include <vector>
namespace boost
{
class any;
}
namespace Fallback
{
bool isAllowedIntFallbackKey(std::string_view key);
bool isAllowedFloatFallbackKey(std::string_view key);
bool isAllowedNonNumericFallbackKey(std::string_view key);
bool isAllowedUnusedFallbackKey(std::string_view key); // imported from Morrowind.ini but unused
struct FallbackMap
{
std::map<std::string, std::string> mMap;
};
// Parses and validates a fallback map from boost program_options.
// Note: for boost to pick up the validate function, you need to pull in the namespace e.g.
// by using namespace Fallback;
void validate(boost::any& v, std::vector<std::string> const& tokens, FallbackMap*, int);
}
#endif
| 874
|
C++
|
.h
| 25
| 31.44
| 100
| 0.747031
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,862
|
fallback.hpp
|
OpenMW_openmw/components/fallback/fallback.hpp
|
#ifndef OPENMW_COMPONENTS_FALLBACK_H
#define OPENMW_COMPONENTS_FALLBACK_H
#include <map>
#include <string>
#include <string_view>
#include <osg/Vec4f>
namespace Fallback
{
/// @brief contains settings imported from the Morrowind INI file.
class Map
{
static std::map<std::string, int, std::less<>> mIntFallbackMap;
static std::map<std::string, float, std::less<>> mFloatFallbackMap;
static std::map<std::string, std::string, std::less<>> mNonNumericFallbackMap;
public:
static void init(const std::map<std::string, std::string>& fallback);
static const std::map<std::string, int, std::less<>>& getIntFallbackMap() { return mIntFallbackMap; }
static const std::map<std::string, float, std::less<>>& getFloatFallbackMap() { return mFloatFallbackMap; }
static const std::map<std::string, std::string, std::less<>>& getNonNumericFallbackMap()
{
return mNonNumericFallbackMap;
}
static std::string_view getString(std::string_view fall);
static float getFloat(std::string_view fall);
static int getInt(std::string_view fall);
static bool getBool(std::string_view fall);
static osg::Vec4f getColour(std::string_view fall);
};
}
#endif
| 1,278
|
C++
|
.h
| 30
| 36.6
| 115
| 0.681159
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,863
|
processinvoker.hpp
|
OpenMW_openmw/components/process/processinvoker.hpp
|
#ifndef PROCESSINVOKER_HPP
#define PROCESSINVOKER_HPP
#include <QProcess>
#include <QString>
#include <QStringList>
namespace Process
{
class ProcessInvoker : public QObject
{
Q_OBJECT
public:
ProcessInvoker(QObject* parent = nullptr);
~ProcessInvoker();
// void setProcessName(const QString &name);
// void setProcessArguments(const QStringList &arguments);
QProcess* getProcess();
// QString getProcessName();
// QStringList getProcessArguments();
// inline bool startProcess(bool detached = false) { return startProcess(mName, mArguments, detached); }
inline bool startProcess(const QString& name, bool detached = false)
{
return startProcess(name, QStringList(), detached);
}
bool startProcess(const QString& name, const QStringList& arguments, bool detached = false);
void killProcess();
private:
QProcess* mProcess;
QString mName;
QStringList mArguments;
bool mIgnoreErrors = false;
private slots:
void processError(QProcess::ProcessError error);
void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
};
}
#endif // PROCESSINVOKER_HPP
| 1,299
|
C++
|
.h
| 36
| 29.305556
| 119
| 0.66267
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,864
|
stream.hpp
|
OpenMW_openmw/components/bgsm/stream.hpp
|
#ifndef OPENMW_COMPONENTS_BGSM_STREAM_HPP
#define OPENMW_COMPONENTS_BGSM_STREAM_HPP
#include <array>
#include <cassert>
#include <cstdint>
#include <istream>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <components/files/istreamptr.hpp>
#include <components/misc/endianness.hpp>
#include <osg/Vec2f>
#include <osg/Vec3f>
#include <osg/Vec4f>
namespace Bgsm
{
template <std::size_t numInstances, typename T>
inline void readBufferOfType(Files::IStreamPtr& pIStream, T* dest)
{
static_assert(std::is_arithmetic_v<T>, "Buffer element type is not arithmetic");
pIStream->read(reinterpret_cast<char*>(dest), numInstances * sizeof(T));
if (pIStream->bad())
throw std::runtime_error("Failed to read typed (" + std::string(typeid(T).name()) + ") buffer of "
+ std::to_string(numInstances) + " instances");
if constexpr (Misc::IS_BIG_ENDIAN)
for (std::size_t i = 0; i < numInstances; i++)
Misc::swapEndiannessInplace(dest[i]);
}
template <std::size_t numInstances, typename T>
inline void readBufferOfType(Files::IStreamPtr& pIStream, T (&dest)[numInstances])
{
readBufferOfType<numInstances>(pIStream, static_cast<T*>(dest));
}
class BGSMStream
{
Files::IStreamPtr mStream;
public:
explicit BGSMStream(Files::IStreamPtr&& stream)
: mStream(std::move(stream))
{
}
void skip(size_t size) { mStream->ignore(size); }
/// Read into a single instance of type
template <class T>
void read(T& data)
{
readBufferOfType<1>(mStream, &data);
}
/// Read multiple instances of type into an array
template <class T, size_t size>
void readArray(std::array<T, size>& arr)
{
readBufferOfType<size>(mStream, arr.data());
}
};
template <>
void BGSMStream::read<osg::Vec2f>(osg::Vec2f& vec);
template <>
void BGSMStream::read<osg::Vec3f>(osg::Vec3f& vec);
template <>
void BGSMStream::read<osg::Vec4f>(osg::Vec4f& vec);
template <>
void BGSMStream::read<std::string>(std::string& str);
}
#endif
| 2,236
|
C++
|
.h
| 65
| 28.107692
| 110
| 0.639648
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,865
|
file.hpp
|
OpenMW_openmw/components/bgsm/file.hpp
|
#ifndef OPENMW_COMPONENTS_BGSM_FILE_HPP
#define OPENMW_COMPONENTS_BGSM_FILE_HPP
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include <osg/Vec2f>
#include <osg/Vec3f>
#include <osg/Vec4f>
#include <components/files/istreamptr.hpp>
namespace Bgsm
{
class BGSMStream;
enum class ShaderType
{
Lighting,
Effect,
};
struct MaterialFile
{
ShaderType mShaderType;
std::uint32_t mVersion;
std::uint32_t mClamp;
osg::Vec2f mUVOffset, mUVScale;
float mTransparency;
bool mAlphaBlend;
std::uint32_t mSourceBlendMode;
std::uint32_t mDestinationBlendMode;
std::uint8_t mAlphaTestThreshold;
bool mAlphaTest;
bool mDepthWrite, mDepthTest;
bool mSSR;
bool mWetnessControlSSR;
bool mDecal;
bool mTwoSided;
bool mDecalNoFade;
bool mNonOccluder;
bool mRefraction;
bool mRefractionFalloff;
float mRefractionPower;
bool mEnvMapEnabled;
float mEnvMapMaskScale;
bool mDepthBias;
bool mGrayscaleToPaletteColor;
std::uint8_t mMaskWrites;
MaterialFile() = default;
virtual void read(BGSMStream& stream);
virtual ~MaterialFile() = default;
bool wrapT() const { return mClamp & 1; }
bool wrapS() const { return mClamp & 2; }
};
struct BGSMFile : MaterialFile
{
std::string mDiffuseMap;
std::string mNormalMap;
std::string mSmoothSpecMap;
std::string mGrayscaleMap;
std::string mGlowMap;
std::string mWrinkleMap;
std::string mSpecularMap;
std::string mLightingMap;
std::string mFlowMap;
std::string mDistanceFieldAlphaMap;
std::string mEnvMap;
std::string mInnerLayerMap;
std::string mDisplacementMap;
bool mEnableEditorAlphaThreshold;
bool mTranslucency;
bool mTranslucencyThickObject;
bool mTranslucencyMixAlbedoWithSubsurfaceColor;
osg::Vec3f mTranslucencySubsurfaceColor;
float mTranslucencyTransmissiveScale;
float mTranslucencyTurbulence;
bool mRimLighting;
float mRimPower;
float mBackLightPower;
bool mSubsurfaceLighting;
float mSubsurfaceLightingRolloff;
bool mSpecularEnabled;
osg::Vec3f mSpecularColor;
float mSpecularMult;
float mSmoothness;
float mFresnelPower;
float mWetnessControlSpecScale;
float mWetnessControlSpecPowerScale;
float mWetnessControlSpecMinvar;
float mWetnessControlEnvMapScale;
float mWetnessControlFresnelPower;
float mWetnessControlMetalness;
bool mPBR;
bool mCustomPorosity;
float mPorosityValue;
std::string mRootMaterialPath;
bool mAnisoLighting;
bool mEmitEnabled;
osg::Vec3f mEmittanceColor;
float mEmittanceMult;
bool mModelSpaceNormals;
bool mExternalEmittance;
float mLumEmittance;
bool mUseAdaptiveEmissive;
osg::Vec3f mAdaptiveEmissiveExposureParams;
bool mBackLighting;
bool mReceiveShadows;
bool mHideSecret;
bool mCastShadows;
bool mDissolveFade;
bool mAssumeShadowmask;
bool mGlowMapEnabled;
bool mEnvMapWindow;
bool mEnvMapEye;
bool mHair;
osg::Vec3f mHairTintColor;
bool mTree;
bool mFacegen;
bool mSkinTint;
bool mTessellate;
osg::Vec2f mDisplacementMapParams;
osg::Vec3f mTessellationParams;
float mGrayscaleToPaletteScale;
bool mSkewSpecularAlpha;
bool mTerrain;
osg::Vec3f mTerrainParams;
void read(BGSMStream& stream) override;
};
struct BGEMFile : MaterialFile
{
std::string mBaseMap;
std::string mGrayscaleMap;
std::string mEnvMap;
std::string mNormalMap;
std::string mEnvMapMask;
std::string mSpecularMap;
std::string mLightingMap;
std::string mGlowMap;
bool mBlood;
bool mEffectLighting;
bool mFalloff;
bool mFalloffColor;
bool mGrayscaleToPaletteAlpha;
bool mSoft;
osg::Vec3f mBaseColor;
float mBaseColorScale;
osg::Vec4f mFalloffParams;
float mLightingInfluence;
std::uint8_t mEnvmapMinLOD;
float mSoftDepth;
osg::Vec3f mEmittanceColor;
osg::Vec3f mAdaptiveEmissiveExposureParams;
bool mGlowMapEnabled;
bool mEffectPbrSpecular;
void read(BGSMStream& stream) override;
};
using MaterialFilePtr = std::shared_ptr<const Bgsm::MaterialFile>;
MaterialFilePtr parse(Files::IStreamPtr&& stream);
}
#endif
| 4,861
|
C++
|
.h
| 157
| 22.974522
| 70
| 0.662332
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,866
|
box.hpp
|
OpenMW_openmw/components/widgets/box.hpp
|
#ifndef OPENMW_WIDGETS_BOX_H
#define OPENMW_WIDGETS_BOX_H
#include <MyGUI_Button.h>
#include <MyGUI_ComboBox.h>
#include <MyGUI_EditBox.h>
#include <MyGUI_TextBox.h>
#include <MyGUI_Widget.h>
#include "fontwrapper.hpp"
namespace Gui
{
class Button : public FontWrapper<MyGUI::Button>
{
MYGUI_RTTI_DERIVED(Button)
};
class TextBox : public FontWrapper<MyGUI::TextBox>
{
MYGUI_RTTI_DERIVED(TextBox)
};
class EditBox : public FontWrapper<MyGUI::EditBox>
{
MYGUI_RTTI_DERIVED(EditBox)
};
class AutoSizedWidget
{
public:
AutoSizedWidget()
: mExpandDirection(MyGUI::Align::Right)
{
}
virtual MyGUI::IntSize getRequestedSize() = 0;
virtual ~AutoSizedWidget() = default;
protected:
void notifySizeChange(MyGUI::Widget* w);
MyGUI::Align mExpandDirection;
};
class AutoSizedTextBox : public AutoSizedWidget, public TextBox
{
MYGUI_RTTI_DERIVED(AutoSizedTextBox)
public:
MyGUI::IntSize getRequestedSize() override;
void setCaption(const MyGUI::UString& _value) override;
protected:
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
std::string mFontSize;
};
class AutoSizedEditBox : public AutoSizedWidget, public EditBox
{
MYGUI_RTTI_DERIVED(AutoSizedEditBox)
public:
MyGUI::IntSize getRequestedSize() override;
void setCaption(const MyGUI::UString& _value) override;
void initialiseOverride() override;
protected:
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
int getWidth();
std::string mFontSize;
bool mShrink = false;
bool mWasResized = false;
int mMaxWidth = 0;
};
class AutoSizedButton : public AutoSizedWidget, public Button
{
MYGUI_RTTI_DERIVED(AutoSizedButton)
public:
MyGUI::IntSize getRequestedSize() override;
void setCaption(const MyGUI::UString& _value) override;
protected:
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
std::string mFontSize;
};
/**
* @brief A container widget that automatically sizes its children
* @note the box being an AutoSizedWidget as well allows to put boxes inside a box
*/
class Box : public AutoSizedWidget
{
public:
Box();
virtual ~Box() = default;
void notifyChildrenSizeChanged();
protected:
virtual void align() = 0;
virtual bool _setPropertyImpl(std::string_view _key, std::string_view _value);
int mSpacing; // how much space to put between elements
int mPadding; // outer padding
bool mAutoResize; // auto resize the box so that it exactly fits all elements
};
class Spacer : public AutoSizedWidget, public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(Spacer)
public:
Spacer();
MyGUI::IntSize getRequestedSize() override { return MyGUI::IntSize(0, 0); }
};
class HBox : public Box, public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(HBox)
public:
void setSize(const MyGUI::IntSize& _value) override;
void setCoord(const MyGUI::IntCoord& _value) override;
protected:
void initialiseOverride() override;
void align() override;
MyGUI::IntSize getRequestedSize() override;
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
void onWidgetCreated(MyGUI::Widget* _widget) override;
};
class VBox : public Box, public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(VBox)
public:
void setSize(const MyGUI::IntSize& _value) override;
void setCoord(const MyGUI::IntCoord& _value) override;
protected:
void initialiseOverride() override;
void align() override;
MyGUI::IntSize getRequestedSize() override;
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
void onWidgetCreated(MyGUI::Widget* _widget) override;
};
}
#endif
| 4,215
|
C++
|
.h
| 122
| 27.622951
| 90
| 0.667819
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| true
| false
|
35,867
|
widgets.hpp
|
OpenMW_openmw/components/widgets/widgets.hpp
|
#ifndef OPENMW_COMPONENTS_WIDGETS_H
#define OPENMW_COMPONENTS_WIDGETS_H
extern int GuiFontHeight;
namespace Gui
{
/// Register all widgets from this component with MyGUI's factory manager.
void registerAllWidgets();
}
#endif
| 237
|
C++
|
.h
| 9
| 24
| 78
| 0.803571
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,868
|
imagebutton.hpp
|
OpenMW_openmw/components/widgets/imagebutton.hpp
|
#ifndef OPENMW_COMPONENTS_WIDGETS_IMAGEBUTTON_H
#define OPENMW_COMPONENTS_WIDGETS_IMAGEBUTTON_H
#include <MyGUI_ImageBox.h>
namespace Gui
{
/**
* @brief allows using different image textures depending on the button state
*/
class ImageButton final : public MyGUI::ImageBox
{
MYGUI_RTTI_DERIVED(ImageButton)
public:
MyGUI::IntSize getRequestedSize();
ImageButton();
static void setDefaultNeedKeyFocus(bool enabled);
/// Set mImageNormal, mImageHighlighted and mImagePushed based on file convention (image_idle.ext,
/// image_over.ext and image_pressed.ext)
void setImage(const std::string& image);
void setTextureRect(MyGUI::IntCoord coord);
private:
void updateImage();
static bool sDefaultNeedKeyFocus;
protected:
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
void onMouseLostFocus(MyGUI::Widget* _new) override;
void onMouseSetFocus(MyGUI::Widget* _old) override;
void onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id) override;
void onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id) override;
void onKeySetFocus(MyGUI::Widget* _old) override;
void onKeyLostFocus(MyGUI::Widget* _new) override;
std::string mImageHighlighted;
std::string mImageNormal;
std::string mImagePushed;
bool mMouseFocus;
bool mMousePress;
bool mKeyFocus;
bool mUseWholeTexture;
MyGUI::IntCoord mTextureRect;
};
}
#endif
| 1,621
|
C++
|
.h
| 41
| 32.341463
| 106
| 0.694373
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,869
|
numericeditbox.hpp
|
OpenMW_openmw/components/widgets/numericeditbox.hpp
|
#ifndef OPENMW_NUMERIC_EDIT_BOX_H
#define OPENMW_NUMERIC_EDIT_BOX_H
#include <MyGUI_EditBox.h>
#include "fontwrapper.hpp"
namespace Gui
{
/**
* @brief A variant of the EditBox that only allows integer inputs
*/
class NumericEditBox final : public FontWrapper<MyGUI::EditBox>
{
MYGUI_RTTI_DERIVED(NumericEditBox)
public:
NumericEditBox()
: mValue(0)
, mMinValue(std::numeric_limits<int>::min())
, mMaxValue(std::numeric_limits<int>::max())
{
}
void initialiseOverride() override;
void shutdownOverride() override;
typedef MyGUI::delegates::MultiDelegate<int> EventHandle_ValueChanged;
EventHandle_ValueChanged eventValueChanged;
/// @note Does not trigger eventValueChanged
void setValue(int value);
int getValue();
void setMinValue(int minValue);
void setMaxValue(int maxValue);
private:
void onEditTextChange(MyGUI::EditBox* sender);
void onKeyLostFocus(MyGUI::Widget* _new) override;
void onKeyButtonPressed(MyGUI::KeyCode key, MyGUI::Char character) override;
int mValue;
int mMinValue;
int mMaxValue;
};
}
#endif
| 1,253
|
C++
|
.h
| 38
| 25.763158
| 84
| 0.660283
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| true
| false
|
35,870
|
sharedstatebutton.hpp
|
OpenMW_openmw/components/widgets/sharedstatebutton.hpp
|
#ifndef OPENMW_WIDGETS_SHAREDSTATEBUTTON_HPP
#define OPENMW_WIDGETS_SHAREDSTATEBUTTON_HPP
#include <MyGUI_Button.h>
#include "fontwrapper.hpp"
namespace Gui
{
class SharedStateButton;
typedef std::vector<SharedStateButton*> ButtonGroup;
/// @brief A button that applies its own state changes to other widgets, to do this you define it as part of a
/// ButtonGroup.
class SharedStateButton final : public FontWrapper<MyGUI::Button>
{
MYGUI_RTTI_DERIVED(SharedStateButton)
public:
SharedStateButton();
protected:
void updateButtonState();
void onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id) override;
void onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id) override;
void onMouseSetFocus(MyGUI::Widget* _old) override;
void onMouseLostFocus(MyGUI::Widget* _new) override;
void baseUpdateEnable() override;
void shutdownOverride() override;
bool _setState(const std::string& _value);
public:
void shareStateWith(const ButtonGroup& shared);
/// @note The ButtonGroup connection will be destroyed when any widget in the group gets destroyed.
static void createButtonGroup(ButtonGroup& group);
//! Set button selected state
void setStateSelected(bool _value);
private:
ButtonGroup mSharedWith;
bool mIsMousePressed;
bool mIsMouseFocus;
};
}
#endif
| 1,482
|
C++
|
.h
| 37
| 33.513514
| 114
| 0.712185
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,871
|
fontwrapper.hpp
|
OpenMW_openmw/components/widgets/fontwrapper.hpp
|
#ifndef OPENMW_WIDGETS_WRAPPER_H
#define OPENMW_WIDGETS_WRAPPER_H
#include <MyGUI_Prerequest.h>
#include "components/settings/values.hpp"
#include <string>
namespace Gui
{
/// Wrapper to tell UI element to use font size from settings.cfg
template <class T>
class FontWrapper : public T
{
public:
void setFontName(std::string_view name) override
{
T::setFontName(name);
T::setPropertyOverride("FontHeight", std::to_string(Settings::gui().mFontSize));
}
};
}
#endif
| 541
|
C++
|
.h
| 20
| 22.2
| 92
| 0.680233
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,872
|
windowcaption.hpp
|
OpenMW_openmw/components/widgets/windowcaption.hpp
|
#ifndef OPENMW_WIDGETS_WINDOWCAPTION_H
#define OPENMW_WIDGETS_WINDOWCAPTION_H
#include <MyGUI_EditBox.h>
namespace Gui
{
/// Window caption that automatically adjusts "Left" and "Right" widgets in its skin
/// based on the text size of the caption in the middle
class WindowCaption final : public MyGUI::EditBox
{
MYGUI_RTTI_DERIVED(WindowCaption)
public:
WindowCaption();
void setCaption(const MyGUI::UString& _value) override;
void initialiseOverride() override;
void setSize(const MyGUI::IntSize& _value) override;
void setCoord(const MyGUI::IntCoord& _value) override;
private:
MyGUI::Widget* mLeft;
MyGUI::Widget* mRight;
MyGUI::Widget* mClient;
void align();
};
}
#endif
| 794
|
C++
|
.h
| 24
| 27.208333
| 88
| 0.687254
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,873
|
tags.hpp
|
OpenMW_openmw/components/widgets/tags.hpp
|
#ifndef OPENMW_WIDGETS_TAGS_H
#define OPENMW_WIDGETS_TAGS_H
#include <MyGUI_UString.h>
#include <string_view>
namespace Gui
{
/// Try to replace a tag. Returns true on success and writes the result to \a out.
bool replaceTag(std::string_view tag, MyGUI::UString& out);
}
#endif
| 291
|
C++
|
.h
| 10
| 26.8
| 86
| 0.75
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,874
|
list.hpp
|
OpenMW_openmw/components/widgets/list.hpp
|
#ifndef OPENMW_COMPONENTS_WIDGETS_LIST_HPP
#define OPENMW_COMPONENTS_WIDGETS_LIST_HPP
#include <MyGUI_ScrollView.h>
namespace Gui
{
/**
* \brief a very simple list widget that supports word-wrapping entries
* \note if the width or height of the list changes, you must call adjustSize() method
*/
class MWList : public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MWList)
public:
MWList();
typedef MyGUI::delegates::MultiDelegate<const std::string&, int> EventHandle_StringInt;
typedef MyGUI::delegates::MultiDelegate<MyGUI::Widget*> EventHandle_Widget;
/**
* Event: Item selected with the mouse.
* signature: void method(std::string itemName, int index)
*/
EventHandle_StringInt eventItemSelected;
/**
* Event: Item selected with the mouse.
* signature: void method(MyGUI::Widget* sender)
*/
EventHandle_Widget eventWidgetSelected;
/**
* Call after the size of the list changed, or items were inserted/removed
*/
void adjustSize();
void sort();
void addItem(std::string_view name);
void addSeparator(); ///< add a seperator between the current and the next item.
void removeItem(const std::string& name);
size_t getItemCount();
const std::string& getItemNameAt(size_t at); ///< \attention if there are separators, this method will return ""
///< at the place where the separator is
void clear();
MyGUI::Button* getItemWidget(std::string_view name);
///< get widget for an item name, useful to set up tooltip
void scrollToTop();
void setPropertyOverride(std::string_view _key, std::string_view _value) override;
protected:
void initialiseOverride() override;
void redraw(bool scrollbarShown = false);
void onMouseWheelMoved(MyGUI::Widget* _sender, int _rel);
void onItemSelected(MyGUI::Widget* _sender);
private:
MyGUI::ScrollView* mScrollView;
MyGUI::Widget* mClient;
std::string mListItemSkin;
std::vector<std::string> mItems;
int mItemHeight; // height of all items
};
}
#endif
| 2,295
|
C++
|
.h
| 56
| 32.392857
| 120
| 0.638614
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,875
|
macospath.hpp
|
OpenMW_openmw/components/files/macospath.hpp
|
#ifndef COMPONENTS_FILES_MACOSPATH_H
#define COMPONENTS_FILES_MACOSPATH_H
#if defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
#include <filesystem>
/**
* \namespace Files
*/
namespace Files
{
/**
* \struct MacOsPath
*/
struct MacOsPath
{
MacOsPath(const std::string& application_name);
/**
* \brief Return path to the local directory.
*
* \return std::filesystem::path
*/
std::filesystem::path getUserConfigPath() const;
std::filesystem::path getUserDataPath() const;
/**
* \brief Return path to the global (system) directory.
*
* \return std::filesystem::path
*/
std::filesystem::path getGlobalConfigPath() const;
/**
* \brief Return path to the runtime directory which is the
* place where an application was started.
*
* \return std::filesystem::path
*/
std::filesystem::path getLocalPath() const;
/**
* \brief
*
* \return std::filesystem::path
*/
std::filesystem::path getCachePath() const;
/**
* \brief
*
* \return std::filesystem::path
*/
std::filesystem::path getGlobalDataPath() const;
std::filesystem::path getInstallPath() const;
std::string mName;
};
} /* namespace Files */
#endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */
#endif /* COMPONENTS_FILES_MACOSPATH_H */
| 1,605
|
C++
|
.h
| 53
| 22.792453
| 96
| 0.578399
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,876
|
constrainedfilestream.hpp
|
OpenMW_openmw/components/files/constrainedfilestream.hpp
|
#ifndef OPENMW_CONSTRAINEDFILESTREAM_H
#define OPENMW_CONSTRAINEDFILESTREAM_H
#include "constrainedfilestreambuf.hpp"
#include "istreamptr.hpp"
#include "streamwithbuffer.hpp"
#include <limits>
#include <string>
namespace Files
{
/// A file stream constrained to a specific region in the file, specified by the 'start' and 'length' parameters.
using ConstrainedFileStream = StreamWithBuffer<ConstrainedFileStreamBuf>;
IStreamPtr openConstrainedFileStream(const std::filesystem::path& filename, std::size_t start = 0,
std::size_t length = std::numeric_limits<std::size_t>::max());
}
#endif
| 616
|
C++
|
.h
| 15
| 38.266667
| 117
| 0.782828
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,877
|
streamwithbuffer.hpp
|
OpenMW_openmw/components/files/streamwithbuffer.hpp
|
#ifndef OPENMW_COMPONENTS_FILES_STREAMWITHBUFFER_H
#define OPENMW_COMPONENTS_FILES_STREAMWITHBUFFER_H
#include <istream>
#include <memory>
namespace Files
{
template <class Buffer>
class StreamWithBuffer final : public std::istream
{
public:
explicit StreamWithBuffer(std::unique_ptr<Buffer>&& buffer)
: std::istream(buffer.get())
, mBuffer(std::move(buffer))
{
}
private:
std::unique_ptr<Buffer> mBuffer;
};
}
#endif
| 502
|
C++
|
.h
| 20
| 19.9
| 67
| 0.669456
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,878
|
hash.hpp
|
OpenMW_openmw/components/files/hash.hpp
|
#ifndef COMPONENTS_FILES_HASH_H
#define COMPONENTS_FILES_HASH_H
#include <array>
#include <cstdint>
#include <iosfwd>
#include <string_view>
namespace Files
{
std::array<std::uint64_t, 2> getHash(std::string_view fileName, std::istream& stream);
}
#endif
| 262
|
C++
|
.h
| 11
| 22.181818
| 90
| 0.766129
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,879
|
collections.hpp
|
OpenMW_openmw/components/files/collections.hpp
|
#ifndef COMPONENTS_FILES_COLLECTION_HPP
#define COMPONENTS_FILES_COLLECTION_HPP
#include <filesystem>
#include "multidircollection.hpp"
namespace Files
{
class Collections
{
public:
Collections();
///< Directories are listed with increasing priority.
Collections(const Files::PathContainer& directories);
///< Return a file collection for the given extension. Extension must contain the
/// leading dot and must be all lower-case.
const MultiDirCollection& getCollection(const std::string& extension) const;
std::filesystem::path getPath(const std::string& file) const;
///< Return full path (including filename) of \a file.
///
/// If the file does not exist in any of the collection's
/// directories, an exception is thrown. \a file must include the
/// extension.
bool doesExist(const std::string& file) const;
///< \return Does a file with the given name exist?
const Files::PathContainer& getPaths() const;
private:
typedef std::map<std::string, MultiDirCollection> MultiDirCollectionContainer;
Files::PathContainer mDirectories;
mutable MultiDirCollectionContainer mCollections;
};
}
#endif
| 1,273
|
C++
|
.h
| 31
| 34.419355
| 89
| 0.693745
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,880
|
openfile.hpp
|
OpenMW_openmw/components/files/openfile.hpp
|
#ifndef OPENMW_COMPONENTS_FILES_OPENFILE_H
#define OPENMW_COMPONENTS_FILES_OPENFILE_H
#include <filesystem>
#include <iosfwd>
#include <memory>
#include <string>
namespace Files
{
std::unique_ptr<std::ifstream> openBinaryInputFileStream(const std::filesystem::path& path);
}
#endif
| 289
|
C++
|
.h
| 11
| 24.636364
| 96
| 0.803636
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,881
|
configurationmanager.hpp
|
OpenMW_openmw/components/files/configurationmanager.hpp
|
#ifndef COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP
#define COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP
#include <map>
#include <optional>
#include <stack>
#include <string_view>
#include <components/files/collections.hpp>
#include <components/files/fixedpath.hpp>
namespace boost::program_options
{
class options_description;
class variables_map;
}
/**
* \namespace Files
*/
namespace Files
{
inline constexpr std::string_view openmwCfgFile = "openmw.cfg";
/**
* \struct ConfigurationManager
*/
struct ConfigurationManager
{
ConfigurationManager(bool silent = false); /// @param silent Emit log messages to cout?
virtual ~ConfigurationManager();
void readConfiguration(boost::program_options::variables_map& variables,
const boost::program_options::options_description& description, bool quiet = false);
void filterOutNonExistingPaths(Files::PathContainer& dataDirs) const;
// Replaces tokens (`?local?`, `?global?`, etc.) in paths. Adds `basePath` prefix for relative paths.
void processPath(std::filesystem::path& path, const std::filesystem::path& basePath) const;
void processPaths(Files::PathContainer& dataDirs, const std::filesystem::path& basePath) const;
void processPaths(
boost::program_options::variables_map& variables, const std::filesystem::path& basePath) const;
/**< Fixed paths */
const std::filesystem::path& getGlobalPath() const;
const std::filesystem::path& getLocalPath() const;
const std::filesystem::path& getUserConfigPath() const;
const std::filesystem::path& getUserDataPath() const;
const std::filesystem::path& getLocalDataPath() const;
const std::filesystem::path& getInstallPath() const;
const std::vector<std::filesystem::path>& getActiveConfigPaths() const { return mActiveConfigPaths; }
const std::filesystem::path& getCachePath() const;
const std::filesystem::path& getLogPath() const { return getUserConfigPath(); }
const std::filesystem::path& getScreenshotPath() const;
static void addCommonOptions(boost::program_options::options_description& description);
private:
typedef Files::FixedPath<> FixedPathType;
typedef const std::filesystem::path& (FixedPathType::*path_type_f)() const;
typedef std::map<std::u8string, path_type_f> TokensMappingContainer;
std::optional<boost::program_options::variables_map> loadConfig(
const std::filesystem::path& path, const boost::program_options::options_description& description) const;
void addExtraConfigDirs(
std::stack<std::filesystem::path>& dirs, const boost::program_options::variables_map& variables) const;
void setupTokensMapping();
std::vector<std::filesystem::path> mActiveConfigPaths;
FixedPathType mFixedPath;
std::filesystem::path mUserDataPath;
std::filesystem::path mScreenshotPath;
TokensMappingContainer mTokensMapping;
bool mSilent;
};
boost::program_options::variables_map separateComposingVariables(boost::program_options::variables_map& variables,
const boost::program_options::options_description& description);
void mergeComposingVariables(boost::program_options::variables_map& first,
boost::program_options::variables_map& second, const boost::program_options::options_description& description);
void parseArgs(int argc, const char* const argv[], boost::program_options::variables_map& variables,
const boost::program_options::options_description& description);
void parseConfig(std::istream& stream, boost::program_options::variables_map& variables,
const boost::program_options::options_description& description);
class MaybeQuotedPath : public std::filesystem::path
{
};
std::istream& operator>>(std::istream& istream, MaybeQuotedPath& MaybeQuotedPath);
typedef std::vector<MaybeQuotedPath> MaybeQuotedPathContainer;
PathContainer asPathContainer(const MaybeQuotedPathContainer& MaybeQuotedPathContainer);
} /* namespace Files */
#endif /* COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP */
| 4,242
|
C++
|
.h
| 78
| 47.576923
| 119
| 0.726701
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,882
|
multidircollection.hpp
|
OpenMW_openmw/components/files/multidircollection.hpp
|
#ifndef COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
#define COMPONENTS_FILES_MULTIDIRSOLLECTION_HPP
#include <cctype>
#include <filesystem>
#include <map>
#include <string>
#include <vector>
#include <components/misc/strings/algorithm.hpp>
namespace Files
{
typedef std::vector<std::filesystem::path> PathContainer;
/// \brief File collection across several directories
///
/// This class lists all files with one specific extensions within one or more
/// directories. If the same file appears more than once, the file in the directory
/// with the higher priority is used.
class MultiDirCollection
{
public:
typedef std::map<std::string, std::filesystem::path, Misc::StringUtils::CiComp> TContainer;
typedef TContainer::const_iterator TIter;
private:
TContainer mFiles;
public:
MultiDirCollection(const Files::PathContainer& directories, const std::string& extension);
///< Directories are listed with increasing priority.
/// \param extension The extension that should be listed in this collection. Must
/// contain the leading dot.
/// \param foldCase Ignore filename case
std::filesystem::path getPath(const std::string& file) const;
///< Return full path (including filename) of \a file.
///
/// If the file does not exist, an exception is thrown. \a file must include
/// the extension.
bool doesExist(const std::string& file) const;
///< \return Does a file with the given name exist?
TIter begin() const;
///< Return iterator pointing to the first file.
TIter end() const;
///< Return iterator pointing past the last file.
};
}
#endif
| 1,751
|
C++
|
.h
| 43
| 34.813953
| 99
| 0.690631
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,883
|
constrainedfilestreambuf.hpp
|
OpenMW_openmw/components/files/constrainedfilestreambuf.hpp
|
#ifndef OPENMW_CONSTRAINEDFILESTREAMBUF_H
#define OPENMW_CONSTRAINEDFILESTREAMBUF_H
#include <filesystem>
#include <streambuf>
#include <components/platform/file.hpp>
namespace Files
{
/// A file streambuf constrained to a specific region in the file, specified by the 'start' and 'length' parameters.
class ConstrainedFileStreamBuf final : public std::streambuf
{
public:
ConstrainedFileStreamBuf(const std::filesystem::path& fname, std::size_t start, std::size_t length);
int_type underflow() final;
pos_type seekoff(off_type offset, std::ios_base::seekdir whence, std::ios_base::openmode mode) final;
pos_type seekpos(pos_type pos, std::ios_base::openmode mode) final;
private:
std::size_t mOrigin;
std::size_t mSize;
Platform::File::ScopedHandle mFile;
char mBuffer[8192]{ 0 };
};
}
#endif
| 890
|
C++
|
.h
| 23
| 33.521739
| 120
| 0.712456
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,884
|
fixedpath.hpp
|
OpenMW_openmw/components/files/fixedpath.hpp
|
#ifndef COMPONENTS_FILES_FIXEDPATH_HPP
#define COMPONENTS_FILES_FIXEDPATH_HPP
#include <filesystem>
#include <string>
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
#ifndef ANDROID
#include <components/files/linuxpath.hpp>
namespace Files
{
typedef LinuxPath TargetPathType;
}
#else
#include <components/files/androidpath.hpp>
namespace Files
{
typedef AndroidPath TargetPathType;
}
#endif
#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WIN32)
#include <components/files/windowspath.hpp>
namespace Files
{
typedef WindowsPath TargetPathType;
}
#elif defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
#include <components/files/macospath.hpp>
namespace Files
{
typedef MacOsPath TargetPathType;
}
#else
#error "Unknown platform!"
#endif
/**
* \namespace Files
*/
namespace Files
{
/**
* \struct Path
*
* \tparam P - Path strategy class type (depends on target system)
*
*/
template <class P = TargetPathType>
struct FixedPath
{
typedef P PathType;
/**
* \brief Path constructor.
*
* \param [in] application_name - Name of the application
*/
FixedPath(const std::string& application_name)
: mPath(application_name + "/")
, mUserConfigPath(mPath.getUserConfigPath())
, mUserDataPath(mPath.getUserDataPath())
, mGlobalConfigPath(mPath.getGlobalConfigPath())
, mLocalPath(mPath.getLocalPath())
, mGlobalDataPath(mPath.getGlobalDataPath())
, mCachePath(mPath.getCachePath())
, mInstallPath(mPath.getInstallPath())
{
}
/**
* \brief Return path pointing to the user local configuration directory.
*/
const std::filesystem::path& getUserConfigPath() const { return mUserConfigPath; }
const std::filesystem::path& getUserDataPath() const { return mUserDataPath; }
/**
* \brief Return path pointing to the global (system) configuration directory.
*/
const std::filesystem::path& getGlobalConfigPath() const { return mGlobalConfigPath; }
/**
* \brief Return path pointing to the directory where application was started.
*/
const std::filesystem::path& getLocalPath() const { return mLocalPath; }
const std::filesystem::path& getInstallPath() const { return mInstallPath; }
const std::filesystem::path& getGlobalDataPath() const { return mGlobalDataPath; }
const std::filesystem::path& getCachePath() const { return mCachePath; }
private:
PathType mPath;
std::filesystem::path mUserConfigPath; /**< User path */
std::filesystem::path mUserDataPath;
std::filesystem::path mGlobalConfigPath; /**< Global path */
std::filesystem::path mLocalPath; /**< It is the same directory where application was run */
std::filesystem::path mGlobalDataPath; /**< Global application data path */
std::filesystem::path mCachePath;
std::filesystem::path mInstallPath;
};
} /* namespace Files */
#endif /* COMPONENTS_FILES_FIXEDPATH_HPP */
| 3,267
|
C++
|
.h
| 92
| 29.532609
| 101
| 0.667089
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,885
|
istreamptr.hpp
|
OpenMW_openmw/components/files/istreamptr.hpp
|
#ifndef OPENMW_COMPONENTS_FILES_ISTREAMPTR_H
#define OPENMW_COMPONENTS_FILES_ISTREAMPTR_H
#include <iosfwd>
#include <memory>
namespace Files
{
using IStreamPtr = std::unique_ptr<std::istream>;
}
#endif
| 210
|
C++
|
.h
| 9
| 21.555556
| 53
| 0.79798
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,886
|
androidpath.hpp
|
OpenMW_openmw/components/files/androidpath.hpp
|
#ifndef COMPONENTS_FILES_ANDROIDPATH_H
#define COMPONENTS_FILES_ANDROIDPATH_H
#if defined(__ANDROID__)
#include <filesystem>
/**
* \namespace Files
*/
namespace Files
{
struct AndroidPath
{
AndroidPath(const std::string& application_name);
/**
* \brief Return path to the user directory.
*/
std::filesystem::path getUserConfigPath() const;
std::filesystem::path getUserDataPath() const;
/**
* \brief Return path to the global (system) directory where config files can be placed.
*/
std::filesystem::path getGlobalConfigPath() const;
/**
* \brief Return path to the runtime configuration directory which is the
* place where an application was started.
*/
std::filesystem::path getLocalPath() const;
/**
* \brief Return path to the global (system) directory where game files can be placed.
*/
std::filesystem::path getGlobalDataPath() const;
/**
* \brief
*/
std::filesystem::path getCachePath() const;
std::filesystem::path getInstallPath() const;
};
} /* namespace Files */
#endif /* defined(__Android__) */
#endif /* COMPONENTS_FILES_ANDROIDPATH_H */
| 1,283
|
C++
|
.h
| 39
| 25.974359
| 96
| 0.628455
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| true
| false
|
35,887
|
configfileparser.hpp
|
OpenMW_openmw/components/files/configfileparser.hpp
|
#ifndef COMPONENTS_FILES_CONFIGFILEPARSER_HPP
#define COMPONENTS_FILES_CONFIGFILEPARSER_HPP
#include <boost/program_options/parsers.hpp>
namespace Files
{
namespace bpo = boost::program_options;
template <class charT>
bpo::basic_parsed_options<charT> parse_config_file(
std::basic_istream<charT>&, const bpo::options_description&, bool allow_unregistered = false);
}
#endif // COMPONENTS_FILES_CONFIGFILEPARSER_HPP
| 440
|
C++
|
.h
| 11
| 36.727273
| 102
| 0.78066
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,888
|
linuxpath.hpp
|
OpenMW_openmw/components/files/linuxpath.hpp
|
#ifndef COMPONENTS_FILES_LINUXPATH_H
#define COMPONENTS_FILES_LINUXPATH_H
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
#include <filesystem>
/**
* \namespace Files
*/
namespace Files
{
/**
* \struct LinuxPath
*/
struct LinuxPath
{
LinuxPath(const std::string& application_name);
/**
* \brief Return path to the user directory.
*/
std::filesystem::path getUserConfigPath() const;
std::filesystem::path getUserDataPath() const;
/**
* \brief Return path to the global (system) directory where config files can be placed.
*/
std::filesystem::path getGlobalConfigPath() const;
/**
* \brief Return path to the runtime configuration directory which is the
* place where an application was started.
*/
std::filesystem::path getLocalPath() const;
/**
* \brief Return path to the global (system) directory where game files can be placed.
*/
std::filesystem::path getGlobalDataPath() const;
/**
* \brief
*/
std::filesystem::path getCachePath() const;
/**
* \brief Gets the path of the installed Morrowind version if there is one.
*/
std::filesystem::path getInstallPath() const;
std::string mName;
};
} /* namespace Files */
#endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) */
#endif /* COMPONENTS_FILES_LINUXPATH_H */
| 1,604
|
C++
|
.h
| 46
| 27.782609
| 110
| 0.610499
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,889
|
windowspath.hpp
|
OpenMW_openmw/components/files/windowspath.hpp
|
#ifndef COMPONENTS_FILES_WINDOWSPATH_HPP
#define COMPONENTS_FILES_WINDOWSPATH_HPP
#if defined(_WIN32) || defined(__WINDOWS__)
#include <filesystem>
/**
* \namespace Files
*/
namespace Files
{
/**
* \struct WindowsPath
*/
struct WindowsPath
{
/**
* \brief WindowsPath constructor.
*
* \param [in] application_name - The name of the application.
*/
WindowsPath(const std::string& application_name);
/**
* \brief Returns user path i.e.:
* "X:\Documents And Settings\<User name>\My Documents\My Games\"
*
* \return std::filesystem::path
*/
std::filesystem::path getUserConfigPath() const;
std::filesystem::path getUserDataPath() const;
/**
* \brief Returns "X:\Program Files\"
*
* \return std::filesystem::path
*/
std::filesystem::path getGlobalConfigPath() const;
/**
* \brief Return local path which is a location where
* an application was started
*
* \return std::filesystem::path
*/
std::filesystem::path getLocalPath() const;
/**
* \brief
*
* \return std::filesystem::path
*/
std::filesystem::path getCachePath() const;
/**
* \brief Return same path like getGlobalPath
*
* \return std::filesystem::path
*/
std::filesystem::path getGlobalDataPath() const;
/**
* \brief Gets the path of the installed Morrowind version if there is one.
*
* \return std::filesystem::path
*/
std::filesystem::path getInstallPath() const;
std::string mName;
};
} /* namespace Files */
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
#endif /* COMPONENTS_FILES_WINDOWSPATH_HPP */
| 1,905
|
C++
|
.h
| 64
| 21.875
| 83
| 0.567908
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,890
|
qtconversion.hpp
|
OpenMW_openmw/components/files/qtconversion.hpp
|
#ifndef COMPONENTS_FILES_QTCONVERSION_HPP
#define COMPONENTS_FILES_QTCONVERSION_HPP
#include <QString>
#include <filesystem>
namespace Files
{
QString pathToQString(const std::filesystem::path& path);
QString pathToQString(std::filesystem::path&& path);
std::filesystem::path pathFromQString(QStringView path);
std::filesystem::path pathFromQString(QString&& path);
}
#endif // COMPONENTS_FILES_QTCONVERSION_HPP
| 434
|
C++
|
.h
| 12
| 33.333333
| 61
| 0.790865
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,891
|
conversion.hpp
|
OpenMW_openmw/components/files/conversion.hpp
|
#ifndef COMPONENTS_FILES_CONVERSION_HPP
#define COMPONENTS_FILES_CONVERSION_HPP
#include <filesystem>
namespace Files
{
std::string pathToUnicodeString(const std::filesystem::path& path);
std::string pathToUnicodeString(std::filesystem::path&& path);
std::filesystem::path pathFromUnicodeString(std::string_view path);
std::filesystem::path pathFromUnicodeString(std::string&& path);
std::filesystem::path pathFromUnicodeString(const char* path);
}
#endif // COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP
| 528
|
C++
|
.h
| 12
| 40.75
| 71
| 0.789784
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,892
|
memorystream.hpp
|
OpenMW_openmw/components/files/memorystream.hpp
|
#ifndef OPENMW_COMPONENTS_FILES_MEMORYSTREAM_H
#define OPENMW_COMPONENTS_FILES_MEMORYSTREAM_H
#include <istream>
namespace Files
{
struct MemBuf : std::streambuf
{
MemBuf(char const* buffer, size_t size)
// a streambuf isn't specific to istreams, so we need a non-const pointer :/
: bufferStart(const_cast<char*>(buffer))
, bufferEnd(bufferStart + size)
{
this->setg(bufferStart, bufferStart, bufferEnd);
}
pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which) override
{
if (dir == std::ios_base::cur)
gbump(off);
else
setg(bufferStart, (dir == std::ios_base::beg ? bufferStart : bufferEnd) + off, bufferEnd);
return gptr() - bufferStart;
}
pos_type seekpos(pos_type pos, std::ios_base::openmode which) override
{
return seekoff(pos, std::ios_base::beg, which);
}
protected:
char* bufferStart;
char* bufferEnd;
};
/// @brief A variant of std::istream that reads from a constant in-memory buffer.
struct IMemStream : virtual MemBuf, std::istream
{
IMemStream(char const* buffer, size_t size)
: MemBuf(buffer, size)
, std::istream(static_cast<std::streambuf*>(this))
{
}
};
}
#endif
| 1,424
|
C++
|
.h
| 41
| 26.268293
| 106
| 0.595047
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,893
|
qtconfigpath.hpp
|
OpenMW_openmw/components/files/qtconfigpath.hpp
|
#ifndef OPENMW_COMPONENTS_FILES_QTCONFIGPATH_H
#define OPENMW_COMPONENTS_FILES_QTCONFIGPATH_H
#include "configurationmanager.hpp"
#include "qtconversion.hpp"
#include <QString>
namespace Files
{
inline QString getLocalConfigPathQString(const Files::ConfigurationManager& cfgMgr)
{
return Files::pathToQString(cfgMgr.getLocalPath() / openmwCfgFile);
}
inline QString getUserConfigPathQString(const Files::ConfigurationManager& cfgMgr)
{
return Files::pathToQString(cfgMgr.getUserConfigPath() / openmwCfgFile);
}
inline QString getGlobalConfigPathQString(const Files::ConfigurationManager& cfgMgr)
{
return Files::pathToQString(cfgMgr.getGlobalPath() / openmwCfgFile);
}
inline QStringList getActiveConfigPathsQString(const Files::ConfigurationManager& cfgMgr)
{
const auto& activePaths = cfgMgr.getActiveConfigPaths();
QStringList result;
result.reserve(static_cast<int>(activePaths.size()));
for (const auto& path : activePaths)
result.append(Files::pathToQString(path / openmwCfgFile));
return result;
}
}
#endif // OPENMW_COMPONENTS_FILES_QTCONFIGPATH_H
| 1,187
|
C++
|
.h
| 30
| 34.2
| 93
| 0.749565
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,894
|
streamerrorhandler.hpp
|
OpenMW_openmw/components/compiler/streamerrorhandler.hpp
|
#ifndef COMPILER_STREAMERRORHANDLER_H_INCLUDED
#define COMPILER_STREAMERRORHANDLER_H_INCLUDED
#include "errorhandler.hpp"
namespace Compiler
{
class ContextOverride;
/// \brief Error handler implementation: Write errors into logging stream
class StreamErrorHandler : public ErrorHandler
{
std::string mContext;
friend class ContextOverride;
// not implemented
StreamErrorHandler(const StreamErrorHandler&);
StreamErrorHandler& operator=(const StreamErrorHandler&);
void report(const std::string& message, const TokenLoc& loc, Type type) override;
///< Report error to the user.
void report(const std::string& message, Type type) override;
///< Report a file related error
public:
void setContext(const std::string& context);
// constructors
StreamErrorHandler();
///< constructor
};
class ContextOverride
{
StreamErrorHandler& mHandler;
const std::string mContext;
public:
ContextOverride(StreamErrorHandler& handler, const std::string& context);
ContextOverride(const ContextOverride&) = delete;
ContextOverride& operator=(const ContextOverride&) = delete;
~ContextOverride();
};
}
#endif
| 1,297
|
C++
|
.h
| 36
| 29.277778
| 89
| 0.696629
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,895
|
locals.hpp
|
OpenMW_openmw/components/compiler/locals.hpp
|
#ifndef COMPILER_LOCALS_H_INCLUDED
#define COMPILER_LOCALS_H_INCLUDED
#include <iosfwd>
#include <string>
#include <string_view>
#include <vector>
namespace Compiler
{
/// \brief Local variable declarations
class Locals
{
std::vector<std::string> mShorts;
std::vector<std::string> mLongs;
std::vector<std::string> mFloats;
std::vector<std::string>& get(char type);
public:
char getType(std::string_view name) const;
///< 's': short, 'l': long, 'f': float, ' ': does not exist.
int getIndex(std::string_view name) const;
///< return index for local variable \a name (-1: does not exist).
bool search(char type, std::string_view name) const;
/// Return index for local variable \a name of type \a type (-1: variable does not
/// exit).
int searchIndex(char type, std::string_view name) const;
const std::vector<std::string>& get(char type) const;
void write(std::ostream& localFile) const;
///< write declarations to file.
void declare(char type, std::string_view name);
///< declares a variable.
void clear();
///< remove all declarations.
};
}
#endif
| 1,236
|
C++
|
.h
| 34
| 29.911765
| 90
| 0.631623
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,896
|
scanner.hpp
|
OpenMW_openmw/components/compiler/scanner.hpp
|
#ifndef COMPILER_SCANNER_H_INCLUDED
#define COMPILER_SCANNER_H_INCLUDED
#include <cctype>
#include <iosfwd>
#include <istream>
#include <string>
#include <vector>
#include "tokenloc.hpp"
namespace Compiler
{
class ErrorHandler;
class Parser;
class Extensions;
/// \brief Scanner
///
/// This class translate a char-stream to a token stream (delivered via
/// parser-callbacks).
class MultiChar
{
public:
MultiChar() { blank(); }
explicit MultiChar(const char ch)
{
blank();
mData[0] = ch;
mLength = getCharLength(ch);
}
static int getCharLength(const char ch)
{
unsigned char c = ch;
if (c <= 127)
return 0;
else if ((c & 0xE0) == 0xC0)
return 1;
else if ((c & 0xF0) == 0xE0)
return 2;
else if ((c & 0xF8) == 0xF0)
return 3;
else
return -1;
}
bool operator==(const char ch) const
{
return mData[0] == ch && mData[1] == 0 && mData[2] == 0 && mData[3] == 0;
}
bool operator==(const MultiChar& ch) const
{
return mData[0] == ch.mData[0] && mData[1] == ch.mData[1] && mData[2] == ch.mData[2]
&& mData[3] == ch.mData[3];
}
bool operator!=(const char ch) const
{
return mData[0] != ch || mData[1] != 0 || mData[2] != 0 || mData[3] != 0;
}
bool isWhitespace() const
{
return (mData[0] == ' ' || mData[0] == '\t' || mData[0] == ',') && mData[1] == 0 && mData[2] == 0
&& mData[3] == 0;
}
bool isDigit() const
{
return std::isdigit(static_cast<unsigned char>(mData[0])) && mData[1] == 0 && mData[2] == 0
&& mData[3] == 0;
}
bool isMinusSign() const
{
if (mData[0] == '-' && mData[1] == 0 && mData[2] == 0 && mData[3] == 0)
return true;
return mData[0] == '\xe2' && mData[1] == '\x80' && mData[2] == '\x93' && mData[3] == 0;
}
bool isAlpha() const
{
if (isMinusSign())
return false;
return std::isalpha(static_cast<unsigned char>(mData[0])) || mData[1] != 0 || mData[2] != 0
|| mData[3] != 0;
}
void appendTo(std::string& str) const
{
for (int i = 0; i <= mLength; i++)
str += mData[i];
}
void putback(std::istream& in) const
{
for (int i = mLength; i >= 0; i--)
in.putback(mData[i]);
}
bool getFrom(std::istream& in)
{
blank();
char ch = static_cast<char>(in.peek());
if (!in.good())
return false;
int length = getCharLength(ch);
if (length < 0)
return false;
for (int i = 0; i <= length; i++)
{
in.get(ch);
if (!in.good())
return false;
mData[i] = ch;
}
mLength = length;
return true;
}
bool peek(std::istream& in)
{
std::streampos p_orig = in.tellg();
char ch = static_cast<char>(in.peek());
if (!in.good())
return false;
int length = getCharLength(ch);
if (length < 0)
return false;
for (int i = 0; i <= length; i++)
{
in.get(ch);
if (!in.good())
return false;
mData[i] = ch;
}
mLength = length;
in.seekg(p_orig);
return true;
}
void blank()
{
std::fill(std::begin(mData), std::end(mData), '\0');
mLength = -1;
}
std::string data() const
{
// NB: mLength is the number of the last element in the array
return std::string(mData, mLength + 1);
}
private:
char mData[4]{};
int mLength{};
};
class Scanner
{
enum putback_type
{
Putback_None,
Putback_Special,
Putback_Integer,
Putback_Float,
Putback_Name,
Putback_Keyword
};
ErrorHandler& mErrorHandler;
TokenLoc mLoc;
TokenLoc mPrevLoc;
std::istream& mStream;
const Extensions* mExtensions;
putback_type mPutback;
int mPutbackCode;
int mPutbackInteger;
float mPutbackFloat;
std::string mPutbackName;
TokenLoc mPutbackLoc;
bool mStrictKeywords;
bool mTolerantNames;
bool mIgnoreNewline;
bool mExpectName;
bool mIgnoreSpecial;
public:
enum keyword
{
K_begin,
K_end,
K_short,
K_long,
K_float,
K_if,
K_endif,
K_else,
K_elseif,
K_while,
K_endwhile,
K_return,
K_messagebox,
K_set,
K_to
};
enum special
{
S_newline,
S_open,
S_close,
S_cmpEQ,
S_cmpNE,
S_cmpLT,
S_cmpLE,
S_cmpGT,
S_cmpGE,
S_plus,
S_minus,
S_mult,
S_div,
S_ref,
S_member
};
private:
// not implemented
Scanner(const Scanner&);
Scanner& operator=(const Scanner&);
bool get(MultiChar& c);
void putback(MultiChar& c);
bool scanToken(Parser& parser);
bool scanInt(MultiChar& c, Parser& parser, bool& cont);
bool scanFloat(const std::string& intValue, Parser& parser, bool& cont);
bool scanName(MultiChar& c, Parser& parser, bool& cont, std::string name = {});
/// \param name May contain the start of the name (one or more characters)
bool scanName(std::string& name);
bool scanSpecial(MultiChar& c, Parser& parser, bool& cont);
bool isStringCharacter(MultiChar& c, bool lookAhead = true);
public:
Scanner(ErrorHandler& errorHandler, std::istream& inputStream, const Extensions* extensions = nullptr);
///< constructor
void scan(Parser& parser);
///< Scan a token and deliver it to the parser.
void putbackSpecial(int code, const TokenLoc& loc);
///< put back a special token
void putbackInt(int value, const TokenLoc& loc);
///< put back an integer token
void putbackFloat(float value, const TokenLoc& loc);
///< put back a float token
void putbackName(const std::string& name, const TokenLoc& loc);
///< put back a name token
void putbackKeyword(int keyword, const TokenLoc& loc);
///< put back a keyword token
void listKeywords(std::vector<std::string>& keywords);
///< Append all known keywords to \a keywords.
/// Treat newline character as a part of script command.
///
/// \attention This mode lasts only until the next keyword is reached.
void enableIgnoreNewlines();
/// Do not accept keywords in quotation marks anymore.
///
/// \attention This mode lasts only until the next newline is reached.
void enableStrictKeywords();
/// Continue parsing a name when hitting a '.' or a '-'
///
/// \attention This mode lasts only until the next newline is reached.
void enableTolerantNames();
/// Treat '.' and '-' as the start of a name.
///
/// \attention This mode lasts only until the next newline is reached or the call to scan ends.
void enableExpectName();
};
}
#endif
| 8,133
|
C++
|
.h
| 254
| 21.318898
| 111
| 0.493279
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,897
|
fileparser.hpp
|
OpenMW_openmw/components/compiler/fileparser.hpp
|
#ifndef COMPILER_FILEPARSER_H_INCLUDED
#define COMPILER_FILEPARSER_H_INCLUDED
#include "locals.hpp"
#include "parser.hpp"
#include "scriptparser.hpp"
namespace Compiler
{
// Top-level parser, to be used for global scripts, local scripts and targeted scripts
class FileParser : public Parser
{
enum State
{
BeginState,
NameState,
BeginCompleteState,
EndNameState,
EndCompleteState
};
ScriptParser mScriptParser;
State mState;
std::string mName;
Locals mLocals;
public:
FileParser(ErrorHandler& errorHandler, Context& context);
Interpreter::Program getProgram() const;
const Locals& getLocals() const;
///< get local variable declarations.
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
void parseEOF(Scanner& scanner) override;
///< Handle EOF token.
void reset() override;
///< Reset parser to clean state.
};
}
#endif
| 1,496
|
C++
|
.h
| 43
| 27.162791
| 96
| 0.644444
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,898
|
generator.hpp
|
OpenMW_openmw/components/compiler/generator.hpp
|
#ifndef COMPILER_GENERATOR_H_INCLUDED
#define COMPILER_GENERATOR_H_INCLUDED
#include <cassert>
#include <string>
#include <vector>
#include <components/interpreter/types.hpp>
namespace Compiler
{
class Literals;
namespace Generator
{
typedef std::vector<Interpreter::Type_Code> CodeContainer;
inline Interpreter::Type_Code segment0(unsigned int c, unsigned int arg0)
{
assert(c < 64);
return (c << 24) | (arg0 & 0xffffff);
}
inline Interpreter::Type_Code segment1(unsigned int c, unsigned int arg0, unsigned int arg1)
{
assert(c < 64);
return 0x40000000 | (c << 24) | ((arg0 & 0xfff) << 12) | (arg1 & 0xfff);
}
inline Interpreter::Type_Code segment2(unsigned int c, unsigned int arg0)
{
assert(c < 1024);
return 0x80000000 | (c << 20) | (arg0 & 0xfffff);
}
inline Interpreter::Type_Code segment3(unsigned int c, unsigned int arg0)
{
assert(c < 262144);
return 0xc0000000 | (c << 8) | (arg0 & 0xff);
}
inline Interpreter::Type_Code segment4(unsigned int c, unsigned int arg0, unsigned int arg1)
{
assert(c < 1024);
return 0xc4000000 | (c << 16) | ((arg0 & 0xff) << 8) | (arg1 & 0xff);
}
inline Interpreter::Type_Code segment5(unsigned int c)
{
assert(c < 67108864);
return 0xc8000000 | c;
}
void pushInt(CodeContainer& code, Literals& literals, int value);
void pushFloat(CodeContainer& code, Literals& literals, float value);
void pushString(CodeContainer& code, Literals& literals, const std::string& value);
void assignToLocal(
CodeContainer& code, char localType, int localIndex, const CodeContainer& value, char valueType);
void negate(CodeContainer& code, char valueType);
void add(CodeContainer& code, char valueType1, char valueType2);
void sub(CodeContainer& code, char valueType1, char valueType2);
void mul(CodeContainer& code, char valueType1, char valueType2);
void div(CodeContainer& code, char valueType1, char valueType2);
void convert(CodeContainer& code, char fromType, char toType);
void exit(CodeContainer& code);
void message(CodeContainer& code, Literals& literals, const std::string& message, int buttons);
void report(CodeContainer& code, Literals& literals, const std::string& message);
void fetchLocal(CodeContainer& code, char localType, int localIndex);
void jump(CodeContainer& code, int offset);
void jumpOnZero(CodeContainer& code, int offset);
void compare(CodeContainer& code, char op, char valueType1, char valueType2);
void assignToGlobal(CodeContainer& code, Literals& literals, char localType, const std::string& name,
const CodeContainer& value, char valueType);
void fetchGlobal(CodeContainer& code, Literals& literals, char localType, const std::string& name);
void assignToMember(CodeContainer& code, Literals& literals, char memberType, const std::string& name,
const std::string& id, const CodeContainer& value, char valueType, bool global);
///< \param global Member of a global script instead of a script of a reference.
void fetchMember(CodeContainer& code, Literals& literals, char memberType, const std::string& name,
const std::string& id, bool global);
///< \param global Member of a global script instead of a script of a reference.
}
}
#endif
| 3,670
|
C++
|
.h
| 72
| 41.972222
| 110
| 0.65788
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,899
|
declarationparser.hpp
|
OpenMW_openmw/components/compiler/declarationparser.hpp
|
#ifndef COMPILER_DECLARATIONPARSER_H_INCLUDED
#define COMPILER_DECLARATIONPARSER_H_INCLUDED
#include "parser.hpp"
namespace Compiler
{
class Locals;
class DeclarationParser : public Parser
{
enum State
{
State_Begin,
State_Name,
State_End
};
Locals& mLocals;
State mState;
char mType;
public:
DeclarationParser(ErrorHandler& errorHandler, const Context& context, Locals& locals);
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
void reset() override;
};
}
#endif
| 1,214
|
C++
|
.h
| 35
| 27.2
| 96
| 0.642123
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,900
|
output.hpp
|
OpenMW_openmw/components/compiler/output.hpp
|
#ifndef COMPILER_OUTPUT_H_INCLUDED
#define COMPILER_OUTPUT_H_INCLUDED
#include "literals.hpp"
#include <vector>
#include <components/interpreter/program.hpp>
#include <components/interpreter/types.hpp>
namespace Compiler
{
class Locals;
class Output
{
Literals mLiterals;
std::vector<Interpreter::Type_Code> mCode;
Locals& mLocals;
public:
Output(Locals& locals);
Interpreter::Program getProgram() const;
const Literals& getLiterals() const;
const Locals& getLocals() const;
const std::vector<Interpreter::Type_Code>& getCode() const;
Literals& getLiterals();
std::vector<Interpreter::Type_Code>& getCode();
Locals& getLocals();
void clear();
};
}
#endif
| 786
|
C++
|
.h
| 27
| 23.259259
| 67
| 0.677419
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,901
|
extensions.hpp
|
OpenMW_openmw/components/compiler/extensions.hpp
|
#ifndef COMPILER_EXTENSIONS_H_INCLUDED
#define COMPILER_EXTENSIONS_H_INCLUDED
#include <map>
#include <string>
#include <vector>
#include <components/interpreter/types.hpp>
namespace Compiler
{
class Literals;
/// Typedef for script arguments string
/** Every character reperesents an argument to the command. All arguments are required until a /, after which
every argument is optional. <BR>
Eg: fff/f represents 3 required floats followed by one optional float <BR>
f - Float <BR>
c - String, case smashed <BR>
l - Integer <BR>
s - Short <BR>
S - String, case preserved <BR>
x - Optional, ignored string argument. Emits a parser warning when this argument is supplied. <BR>
X - Optional, ignored numeric expression. Emits a parser warning when this argument is supplied. <BR>
z - Optional, ignored string or numeric argument. Emits a parser warning when this argument is supplied. <BR>
j - A piece of junk (either . or a specific keyword)
**/
typedef std::string ScriptArgs;
/// Typedef for script return char
/** The character represents the type of data being returned. <BR>
f - float <BR>
S - String (Cell names) <BR>
l - Integer
**/
typedef char ScriptReturn;
/// \brief Collection of compiler extensions
class Extensions
{
struct Function
{
char mReturn;
ScriptArgs mArguments;
int mCode;
int mCodeExplicit;
int mSegment;
};
struct Instruction
{
ScriptArgs mArguments;
int mCode;
int mCodeExplicit;
int mSegment;
};
int mNextKeywordIndex;
std::map<std::string, int> mKeywords;
std::map<int, Function> mFunctions;
std::map<int, Instruction> mInstructions;
public:
Extensions();
int searchKeyword(const std::string& keyword) const;
///< Return extension keyword code, that is assigned to the string \a keyword.
/// - if no match is found 0 is returned.
/// - keyword must be all lower case.
bool isFunction(int keyword, ScriptReturn& returnType, ScriptArgs& argumentType, bool& explicitReference) const;
///< Is this keyword registered with a function? If yes, return return and argument
/// types.
/// \param explicitReference In: has explicit reference; Out: set to false, if
/// explicit reference is not available for this instruction.
bool isInstruction(int keyword, ScriptArgs& argumentType, bool& explicitReference) const;
///< Is this keyword registered with a function? If yes, return argument types.
/// \param explicitReference In: has explicit reference; Out: set to false, if
/// explicit reference is not available for this instruction.
void registerFunction(std::string_view keyword, ScriptReturn returnType, std::string_view argumentType,
int code, int codeExplicit = -1);
///< Register a custom function
/// - keyword must be all lower case.
/// - keyword must be unique
/// - if explicit references are not supported, segment5codeExplicit must be set to -1
/// \note Currently only segment 3 and segment 5 opcodes are supported.
void registerInstruction(
std::string_view keyword, std::string_view argumentType, int code, int codeExplicit = -1);
///< Register a custom instruction
/// - keyword must be all lower case.
/// - keyword must be unique
/// - if explicit references are not supported, segment5codeExplicit must be set to -1
/// \note Currently only segment 3 and segment 5 opcodes are supported.
void generateFunctionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals,
const std::string& id, int optionalArguments) const;
///< Append code for function to \a code.
void generateInstructionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals,
const std::string& id, int optionalArguments) const;
///< Append code for function to \a code.
void listKeywords(std::vector<std::string>& keywords) const;
///< Append all known keywords to \a kaywords.
};
}
#endif
| 4,426
|
C++
|
.h
| 93
| 39.290323
| 120
| 0.658322
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,902
|
stringparser.hpp
|
OpenMW_openmw/components/compiler/stringparser.hpp
|
#ifndef COMPILER_STRINGPARSER_H_INCLUDED
#define COMPILER_STRINGPARSER_H_INCLUDED
#include <vector>
#include <components/interpreter/types.hpp>
#include "parser.hpp"
#include "tokenloc.hpp"
namespace Compiler
{
class Literals;
class StringParser : public Parser
{
Literals& mLiterals;
std::vector<Interpreter::Type_Code> mCode;
bool mSmashCase;
TokenLoc mTokenLoc;
bool mDiscard;
public:
StringParser(ErrorHandler& errorHandler, const Context& context, Literals& literals);
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
void append(std::vector<Interpreter::Type_Code>& code);
///< Append code for parsed string.
void smashCase();
///< Transform all scanned strings to lower case
void reset() override;
///< Reset parser to clean state (this includes the smashCase function).
/// Returns TokenLoc object for string. If no string has been parsed, the TokenLoc
/// object will be default initialised.
const TokenLoc& getTokenLoc() const;
/// If parsing a string, do not add it to the literal table and do not create code
/// for it.
void discard();
};
}
#endif
| 1,686
|
C++
|
.h
| 42
| 33.166667
| 96
| 0.667281
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,903
|
skipparser.hpp
|
OpenMW_openmw/components/compiler/skipparser.hpp
|
#ifndef COMPILER_SKIPPARSER_H_INCLUDED
#define COMPILER_SKIPPARSER_H_INCLUDED
#include "parser.hpp"
namespace Compiler
{
// \brief Skip parser for skipping a line
//
// This parser is mainly intended for skipping the rest of a faulty line.
class SkipParser : public Parser
{
bool mReportStrayArguments;
void reportStrayArgument(const TokenLoc& loc);
public:
SkipParser(ErrorHandler& errorHandler, const Context& context, bool reportStrayArguments = false);
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a float token.
/// \return fetch another token?
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
};
}
#endif
| 1,362
|
C++
|
.h
| 32
| 35.84375
| 106
| 0.679303
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,904
|
nullerrorhandler.hpp
|
OpenMW_openmw/components/compiler/nullerrorhandler.hpp
|
#ifndef COMPILER_NULLERRORHANDLER_H_INCLUDED
#define COMPILER_NULLERRORHANDLER_H_INCLUDED
#include "errorhandler.hpp"
namespace Compiler
{
/// \brief Error handler implementation: Ignore all error messages
class NullErrorHandler : public ErrorHandler
{
void report(const std::string& message, const TokenLoc& loc, Type type) override;
///< Report error to the user.
void report(const std::string& message, Type type) override;
///< Report a file related error
};
}
#endif
| 525
|
C++
|
.h
| 15
| 30.466667
| 89
| 0.726733
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,905
|
context.hpp
|
OpenMW_openmw/components/compiler/context.hpp
|
#ifndef COMPILER_CONTEXT_H_INCLUDED
#define COMPILER_CONTEXT_H_INCLUDED
#include <string>
namespace ESM
{
class RefId;
}
namespace Compiler
{
class Extensions;
class Context
{
const Extensions* mExtensions;
public:
Context()
: mExtensions(nullptr)
{
}
virtual ~Context() = default;
virtual bool canDeclareLocals() const = 0;
///< Is the compiler allowed to declare local variables?
void setExtensions(const Extensions* extensions = nullptr) { mExtensions = extensions; }
const Extensions* getExtensions() const { return mExtensions; }
virtual char getGlobalType(const std::string& name) const = 0;
///< 'l: long, 's': short, 'f': float, ' ': does not exist.
virtual std::pair<char, bool> getMemberType(const std::string& name, const ESM::RefId& id) const = 0;
///< Return type of member variable \a name in script \a id or in script of reference of
/// \a id
/// \return first: 'l: long, 's': short, 'f': float, ' ': does not exist.
/// second: true: script of reference
virtual bool isId(const ESM::RefId& name) const = 0;
///< Does \a name match an ID, that can be referenced?
};
}
#endif
| 1,283
|
C++
|
.h
| 35
| 30.171429
| 109
| 0.630259
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,906
|
exprparser.hpp
|
OpenMW_openmw/components/compiler/exprparser.hpp
|
#ifndef COMPILER_EXPRPARSER_H_INCLUDED
#define COMPILER_EXPRPARSER_H_INCLUDED
#include <vector>
#include <components/interpreter/types.hpp>
#include "parser.hpp"
#include "tokenloc.hpp"
namespace Compiler
{
class Locals;
class Literals;
class ExprParser : public Parser
{
Locals& mLocals;
Literals& mLiterals;
std::vector<char> mOperands;
std::vector<char> mOperators;
bool mNextOperand;
TokenLoc mTokenLoc;
std::vector<Interpreter::Type_Code> mCode;
bool mFirst;
bool mArgument;
std::string mExplicit;
bool mRefOp;
bool mMemberOp;
static int getPriority(char op);
char getOperandType(int Index = 0) const;
char getOperator() const;
bool isOpen() const;
void popOperator();
void popOperand();
void replaceBinaryOperands();
void pop();
void pushIntegerLiteral(int value);
void pushFloatLiteral(float value);
void pushBinaryOperator(char c);
void close();
int parseArguments(const std::string& arguments, Scanner& scanner);
bool handleMemberAccess(const std::string& name);
public:
ExprParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals,
bool argument = false);
///< constructor
/// \param argument Parser is used to parse function- or instruction-
/// arguments (this influences the precedence rules).
char getType() const;
///< Return type of parsed expression ('l' integer, 'f' float)
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a float token.
/// \return fetch another token?
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
void reset() override;
///< Reset parser to clean state.
char append(std::vector<Interpreter::Type_Code>& code);
///< Generate code for parsed expression.
/// \return Type ('l': integer, 'f': float)
int parseArguments(const std::string& arguments, Scanner& scanner, std::vector<Interpreter::Type_Code>& code,
int ignoreKeyword = -1, bool expectNames = false);
///< Parse sequence of arguments specified by \a arguments.
/// \param arguments Uses ScriptArgs typedef
/// \see Compiler::ScriptArgs
/// \param invert Store arguments in reverted order.
/// \param ignoreKeyword A keyword that is seen as junk
/// \return number of optional arguments
const TokenLoc& getTokenLoc() const;
};
}
#endif
| 3,292
|
C++
|
.h
| 78
| 34.038462
| 117
| 0.649073
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,907
|
extensions0.hpp
|
OpenMW_openmw/components/compiler/extensions0.hpp
|
#ifndef COMPILER_EXTENSIONS0_H
#define COMPILER_EXTENSIONS0_H
namespace Compiler
{
class Extensions;
void registerExtensions(Extensions& extensions, bool consoleOnly = false);
namespace Ai
{
void registerExtensions(Extensions& extensions);
}
namespace Animation
{
void registerExtensions(Extensions& extensions);
}
namespace Cell
{
void registerExtensions(Extensions& extensions);
}
namespace Console
{
void registerExtensions(Extensions& extensions);
}
namespace Container
{
void registerExtensions(Extensions& extensions);
}
namespace Control
{
void registerExtensions(Extensions& extensions);
}
namespace Dialogue
{
void registerExtensions(Extensions& extensions);
}
namespace Gui
{
void registerExtensions(Extensions& extensions);
}
namespace Misc
{
void registerExtensions(Extensions& extensions);
}
namespace Sky
{
void registerExtensions(Extensions& extensions);
}
namespace Sound
{
void registerExtensions(Extensions& extensions);
}
namespace Stats
{
void registerExtensions(Extensions& extensions);
}
namespace Transformation
{
void registerExtensions(Extensions& extensions);
}
namespace User
{
void registerExtensions(Extensions& extensions);
}
}
#endif
| 1,470
|
C++
|
.h
| 64
| 17.203125
| 78
| 0.683225
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| true
| true
| true
| false
|
35,908
|
exception.hpp
|
OpenMW_openmw/components/compiler/exception.hpp
|
#ifndef COMPILER_EXCEPTION_H_INCLUDED
#define COMPILER_EXCEPTION_H_INCLUDED
#include <exception>
namespace Compiler
{
/// \brief Exception: Error while parsing the source
class SourceException : public std::exception
{
public:
const char* what() const noexcept override { return "Compile error"; }
///< Return error message
};
/// \brief Exception: File error
class FileException : public SourceException
{
public:
const char* what() const noexcept override { return "Can't read file"; }
///< Return error message
};
/// \brief Exception: EOF condition encountered
class EOFException : public SourceException
{
public:
const char* what() const noexcept override { return "End of file"; }
///< Return error message
};
}
#endif
| 842
|
C++
|
.h
| 28
| 24.928571
| 80
| 0.672457
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,909
|
parser.hpp
|
OpenMW_openmw/components/compiler/parser.hpp
|
#ifndef COMPILER_PARSER_H_INCLUDED
#define COMPILER_PARSER_H_INCLUDED
#include <string>
namespace Compiler
{
class Scanner;
struct TokenLoc;
class ErrorHandler;
class Context;
/// \brief Parser base class
///
/// This class defines a callback-parser.
class Parser
{
ErrorHandler& mErrorHandler;
const Context& mContext;
bool mOptional;
bool mEmpty;
protected:
[[noreturn]] void reportSeriousError(const std::string& message, const TokenLoc& loc);
///< Report the error and throw a exception.
void reportWarning(const std::string& message, const TokenLoc& loc);
///< Report the warning without throwing an exception.
[[noreturn]] void reportEOF();
///< Report an unexpected EOF condition.
ErrorHandler& getErrorHandler();
///< Return error handler
const Context& getContext() const;
///< Return context
static std::string toLower(const std::string& name);
public:
Parser(ErrorHandler& errorHandler, const Context& context);
///< constructor
virtual ~Parser();
///< destructor
virtual bool parseInt(int value, const TokenLoc& loc, Scanner& scanner);
///< Handle an int token.
/// \return fetch another token?
///
/// - Default-implementation: Report an error.
virtual bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner);
///< Handle a float token.
/// \return fetch another token?
///
/// - Default-implementation: Report an error.
virtual bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner);
///< Handle a name token.
/// \return fetch another token?
///
/// - Default-implementation: Report an error.
virtual bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner);
///< Handle a keyword token.
/// \return fetch another token?
///
/// - Default-implementation: Report an error.
virtual bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner);
///< Handle a special character token.
/// \return fetch another token?
///
/// - Default-implementation: Report an error.
virtual bool parseComment(const std::string& comment, const TokenLoc& loc, Scanner& scanner);
///< Handle comment token.
/// \return fetch another token?
///
/// - Default-implementation: ignored (and return true).
virtual void parseEOF(Scanner& scanner);
///< Handle EOF token.
///
/// - Default-implementation: Report an error.
virtual void reset();
///< Reset parser to clean state.
void setOptional(bool optional);
///< Optional mode: If nothign has been parsed yet and an unexpected token is delivered, stop
/// parsing without raising an exception (after a reset the parser is in non-optional mode).
void start();
///< Mark parser as non-empty (at least one token has been parser).
bool isEmpty() const;
///< Has anything been parsed?
};
}
#endif
| 3,256
|
C++
|
.h
| 81
| 32.185185
| 101
| 0.62742
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,910
|
scriptparser.hpp
|
OpenMW_openmw/components/compiler/scriptparser.hpp
|
#ifndef COMPILER_SCRIPTPARSER_H_INCLUDED
#define COMPILER_SCRIPTPARSER_H_INCLUDED
#include "controlparser.hpp"
#include "lineparser.hpp"
#include "output.hpp"
#include "parser.hpp"
namespace Compiler
{
class Locals;
// Script parser, to be used in dialogue scripts and as part of FileParser
class ScriptParser : public Parser
{
Output mOutput;
LineParser mLineParser;
ControlParser mControlParser;
bool mEnd;
public:
/// \param end of script is marked by end keyword.
ScriptParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, bool end = false);
Interpreter::Program getProgram() const;
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
void parseEOF(Scanner& scanner) override;
///< Handle EOF token.
void reset() override;
///< Reset parser to clean state.
};
}
#endif
| 1,378
|
C++
|
.h
| 36
| 31.833333
| 107
| 0.678195
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,911
|
opcodes.hpp
|
OpenMW_openmw/components/compiler/opcodes.hpp
|
#ifndef COMPILER_OPCODES_H
#define COMPILER_OPCODES_H
namespace Compiler
{
namespace Ai
{
const int opcodeAiTravel = 0x20000;
const int opcodeAiTravelExplicit = 0x20001;
const int opcodeAiEscort = 0x20002;
const int opcodeAiEscortExplicit = 0x20003;
const int opcodeGetAiPackageDone = 0x200007c;
const int opcodeGetAiPackageDoneExplicit = 0x200007d;
const int opcodeGetCurrentAiPackage = 0x20001ef;
const int opcodeGetCurrentAiPackageExplicit = 0x20001f0;
const int opcodeGetDetected = 0x20001f1;
const int opcodeGetDetectedExplicit = 0x20001f2;
const int opcodeAiWander = 0x20010;
const int opcodeAiWanderExplicit = 0x20011;
const int opcodeAIActivate = 0x2001e;
const int opcodeAIActivateExplicit = 0x2001f;
const int opcodeAiEscortCell = 0x20020;
const int opcodeAiEscortCellExplicit = 0x20021;
const int opcodeAiFollow = 0x20022;
const int opcodeAiFollowExplicit = 0x20023;
const int opcodeAiFollowCell = 0x20024;
const int opcodeAiFollowCellExplicit = 0x20025;
const int opcodeSetHello = 0x200015c;
const int opcodeSetHelloExplicit = 0x200015d;
const int opcodeSetFight = 0x200015e;
const int opcodeSetFightExplicit = 0x200015f;
const int opcodeSetFlee = 0x2000160;
const int opcodeSetFleeExplicit = 0x2000161;
const int opcodeSetAlarm = 0x2000162;
const int opcodeSetAlarmExplicit = 0x2000163;
const int opcodeModHello = 0x20001b7;
const int opcodeModHelloExplicit = 0x20001b8;
const int opcodeModFight = 0x20001b9;
const int opcodeModFightExplicit = 0x20001ba;
const int opcodeModFlee = 0x20001bb;
const int opcodeModFleeExplicit = 0x20001bc;
const int opcodeModAlarm = 0x20001bd;
const int opcodeModAlarmExplicit = 0x20001be;
const int opcodeGetHello = 0x20001bf;
const int opcodeGetHelloExplicit = 0x20001c0;
const int opcodeGetFight = 0x20001c1;
const int opcodeGetFightExplicit = 0x20001c2;
const int opcodeGetFlee = 0x20001c3;
const int opcodeGetFleeExplicit = 0x20001c4;
const int opcodeGetAlarm = 0x20001c5;
const int opcodeGetAlarmExplicit = 0x20001c6;
const int opcodeGetLineOfSight = 0x2000222;
const int opcodeGetLineOfSightExplicit = 0x2000223;
const int opcodeToggleAI = 0x2000224;
const int opcodeGetTarget = 0x2000238;
const int opcodeGetTargetExplicit = 0x2000239;
const int opcodeStartCombat = 0x200023a;
const int opcodeStartCombatExplicit = 0x200023b;
const int opcodeStopCombat = 0x200023c;
const int opcodeStopCombatExplicit = 0x200023d;
const int opcodeFace = 0x200024c;
const int opcodeFaceExplicit = 0x200024d;
}
namespace Animation
{
const int opcodeSkipAnim = 0x2000138;
const int opcodeSkipAnimExplicit = 0x2000139;
const int opcodePlayAnim = 0x20006;
const int opcodePlayAnimExplicit = 0x20007;
const int opcodeLoopAnim = 0x20008;
const int opcodeLoopAnimExplicit = 0x20009;
}
namespace Cell
{
const int opcodeCellChanged = 0x2000000;
const int opcodeTestCells = 0x200030e;
const int opcodeTestInteriorCells = 0x200030f;
const int opcodeCOC = 0x2000026;
const int opcodeCOE = 0x2000226;
const int opcodeGetInterior = 0x2000131;
const int opcodeGetPCCell = 0x2000136;
const int opcodeGetWaterLevel = 0x2000141;
const int opcodeSetWaterLevel = 0x2000142;
const int opcodeModWaterLevel = 0x2000143;
}
namespace Console
{
}
namespace Container
{
const int opcodeAddItem = 0x2000076;
const int opcodeAddItemExplicit = 0x2000077;
const int opcodeGetItemCount = 0x2000078;
const int opcodeGetItemCountExplicit = 0x2000079;
const int opcodeRemoveItem = 0x200007a;
const int opcodeRemoveItemExplicit = 0x200007b;
const int opcodeEquip = 0x20001b3;
const int opcodeEquipExplicit = 0x20001b4;
const int opcodeGetArmorType = 0x20001d1;
const int opcodeGetArmorTypeExplicit = 0x20001d2;
const int opcodeHasItemEquipped = 0x20001d5;
const int opcodeHasItemEquippedExplicit = 0x20001d6;
const int opcodeHasSoulGem = 0x20001de;
const int opcodeHasSoulGemExplicit = 0x20001df;
const int opcodeGetWeaponType = 0x20001e0;
const int opcodeGetWeaponTypeExplicit = 0x20001e1;
}
namespace Control
{
const int numberOfControls = 7;
extern const char* controls[numberOfControls];
const int opcodeEnable = 0x200007e;
const int opcodeDisable = 0x2000085;
const int opcodeToggleCollision = 0x2000130;
const int opcodeClearForceRun = 0x2000154;
const int opcodeClearForceRunExplicit = 0x2000155;
const int opcodeForceRun = 0x2000156;
const int opcodeForceRunExplicit = 0x2000157;
const int opcodeClearForceJump = 0x2000258;
const int opcodeClearForceJumpExplicit = 0x2000259;
const int opcodeForceJump = 0x200025a;
const int opcodeForceJumpExplicit = 0x200025b;
const int opcodeClearForceMoveJump = 0x200025c;
const int opcodeClearForceMoveJumpExplicit = 0x200025d;
const int opcodeForceMoveJump = 0x200025e;
const int opcodeForceMoveJumpExplicit = 0x200025f;
const int opcodeClearForceSneak = 0x2000158;
const int opcodeClearForceSneakExplicit = 0x2000159;
const int opcodeForceSneak = 0x200015a;
const int opcodeForceSneakExplicit = 0x200015b;
const int opcodeGetDisabled = 0x2000175;
const int opcodeGetPcRunning = 0x20001c9;
const int opcodeGetPcSneaking = 0x20001ca;
const int opcodeGetForceRun = 0x20001cb;
const int opcodeGetForceSneak = 0x20001cc;
const int opcodeGetForceRunExplicit = 0x20001cd;
const int opcodeGetForceSneakExplicit = 0x20001ce;
const int opcodeGetForceJump = 0x2000260;
const int opcodeGetForceMoveJump = 0x2000262;
const int opcodeGetForceJumpExplicit = 0x2000261;
const int opcodeGetForceMoveJumpExplicit = 0x2000263;
}
namespace Dialogue
{
const int opcodeJournal = 0x2000133;
const int opcodeJournalExplicit = 0x200030b;
const int opcodeSetJournalIndex = 0x2000134;
const int opcodeGetJournalIndex = 0x2000135;
const int opcodeAddTopic = 0x200013a;
const int opcodeChoice = 0x2000a;
const int opcodeForceGreeting = 0x200014f;
const int opcodeForceGreetingExplicit = 0x2000150;
const int opcodeGoodbye = 0x2000152;
const int opcodeSetReputation = 0x20001ad;
const int opcodeModReputation = 0x20001ae;
const int opcodeSetReputationExplicit = 0x20001af;
const int opcodeModReputationExplicit = 0x20001b0;
const int opcodeGetReputation = 0x20001b1;
const int opcodeGetReputationExplicit = 0x20001b2;
const int opcodeSameFaction = 0x20001b5;
const int opcodeSameFactionExplicit = 0x20001b6;
const int opcodeModFactionReaction = 0x2000242;
const int opcodeSetFactionReaction = 0x20002ff;
const int opcodeGetFactionReaction = 0x2000243;
const int opcodeClearInfoActor = 0x2000245;
const int opcodeClearInfoActorExplicit = 0x2000246;
}
namespace Gui
{
const int opcodeEnableBirthMenu = 0x200000e;
const int opcodeEnableClassMenu = 0x200000f;
const int opcodeEnableNameMenu = 0x2000010;
const int opcodeEnableRaceMenu = 0x2000011;
const int opcodeEnableStatsReviewMenu = 0x2000012;
const int opcodeEnableInventoryMenu = 0x2000013;
const int opcodeEnableMagicMenu = 0x2000014;
const int opcodeEnableMapMenu = 0x2000015;
const int opcodeEnableStatsMenu = 0x2000016;
const int opcodeEnableRest = 0x2000017;
const int opcodeEnableLevelupMenu = 0x2000300;
const int opcodeShowRestMenu = 0x2000018;
const int opcodeShowRestMenuExplicit = 0x2000234;
const int opcodeGetButtonPressed = 0x2000137;
const int opcodeToggleFogOfWar = 0x2000145;
const int opcodeToggleFullHelp = 0x2000151;
const int opcodeShowMap = 0x20001a0;
const int opcodeFillMap = 0x20001a1;
const int opcodeMenuTest = 0x2002c;
const int opcodeToggleMenus = 0x200024b;
}
namespace Misc
{
const int opcodeXBox = 0x200000c;
const int opcodeOnActivate = 0x200000d;
const int opcodeOnActivateExplicit = 0x2000306;
const int opcodeActivate = 0x2000075;
const int opcodeActivateExplicit = 0x2000244;
const int opcodeLock = 0x20004;
const int opcodeLockExplicit = 0x20005;
const int opcodeUnlock = 0x200008c;
const int opcodeUnlockExplicit = 0x200008d;
const int opcodeToggleCollisionDebug = 0x2000132;
const int opcodeToggleCollisionBoxes = 0x20001ac;
const int opcodeToggleWireframe = 0x200013b;
const int opcodeFadeIn = 0x200013c;
const int opcodeFadeOut = 0x200013d;
const int opcodeFadeTo = 0x200013e;
const int opcodeToggleWater = 0x2000144;
const int opcodeToggleWorld = 0x20002f5;
const int opcodeTogglePathgrid = 0x2000146;
const int opcodeDontSaveObject = 0x2000153;
const int opcodePcForce1stPerson = 0x20002f6;
const int opcodePcForce3rdPerson = 0x20002f7;
const int opcodePcGet3rdPerson = 0x20002f8;
const int opcodeToggleVanityMode = 0x2000174;
const int opcodeGetPcSleep = 0x200019f;
const int opcodeGetPcJumping = 0x2000233;
const int opcodeWakeUpPc = 0x20001a2;
const int opcodeGetLocked = 0x20001c7;
const int opcodeGetLockedExplicit = 0x20001c8;
const int opcodeGetEffect = 0x20001cf;
const int opcodeGetEffectExplicit = 0x20001d0;
const int opcodeBetaComment = 0x2002d;
const int opcodeBetaCommentExplicit = 0x2002e;
const int opcodeAddSoulGem = 0x20001f3;
const int opcodeAddSoulGemExplicit = 0x20001f4;
const int opcodeRemoveSoulGem = 0x20027;
const int opcodeRemoveSoulGemExplicit = 0x20028;
const int opcodeDrop = 0x20001f8;
const int opcodeDropExplicit = 0x20001f9;
const int opcodeDropSoulGem = 0x20001fa;
const int opcodeDropSoulGemExplicit = 0x20001fb;
const int opcodeGetAttacked = 0x20001d3;
const int opcodeGetAttackedExplicit = 0x20001d4;
const int opcodeGetWeaponDrawn = 0x20001d7;
const int opcodeGetWeaponDrawnExplicit = 0x20001d8;
const int opcodeGetSpellReadied = 0x2000231;
const int opcodeGetSpellReadiedExplicit = 0x2000232;
const int opcodeGetSpellEffects = 0x20001db;
const int opcodeGetSpellEffectsExplicit = 0x20001dc;
const int opcodeGetCurrentTime = 0x20001dd;
const int opcodeSetDelete = 0x20001e5;
const int opcodeSetDeleteExplicit = 0x20001e6;
const int opcodeGetSquareRoot = 0x20001e7;
const int opcodeFall = 0x200020a;
const int opcodeFallExplicit = 0x200020b;
const int opcodeGetStandingPc = 0x200020c;
const int opcodeGetStandingPcExplicit = 0x200020d;
const int opcodeGetStandingActor = 0x200020e;
const int opcodeGetStandingActorExplicit = 0x200020f;
const int opcodeGetCollidingPc = 0x2000250;
const int opcodeGetCollidingPcExplicit = 0x2000251;
const int opcodeGetCollidingActor = 0x2000252;
const int opcodeGetCollidingActorExplicit = 0x2000253;
const int opcodeHurtStandingActor = 0x2000254;
const int opcodeHurtStandingActorExplicit = 0x2000255;
const int opcodeHurtCollidingActor = 0x2000256;
const int opcodeHurtCollidingActorExplicit = 0x2000257;
const int opcodeGetWindSpeed = 0x2000212;
const int opcodePlayBink = 0x20001f7;
const int opcodeGoToJail = 0x2000235;
const int opcodePayFine = 0x2000236;
const int opcodePayFineThief = 0x2000237;
const int opcodeHitOnMe = 0x2000213;
const int opcodeHitOnMeExplicit = 0x2000214;
const int opcodeHitAttemptOnMe = 0x20002f9;
const int opcodeHitAttemptOnMeExplicit = 0x20002fa;
const int opcodeDisableTeleporting = 0x2000215;
const int opcodeEnableTeleporting = 0x2000216;
const int opcodeShowVars = 0x200021d;
const int opcodeShowVarsExplicit = 0x200021e;
const int opcodeShow = 0x2000304;
const int opcodeShowExplicit = 0x2000305;
const int opcodeToggleGodMode = 0x200021f;
const int opcodeToggleScripts = 0x2000301;
const int opcodeDisableLevitation = 0x2000220;
const int opcodeEnableLevitation = 0x2000221;
const int opcodeCast = 0x2000227;
const int opcodeCastExplicit = 0x2000228;
const int opcodeExplodeSpell = 0x2000229;
const int opcodeExplodeSpellExplicit = 0x200022a;
const int opcodeGetPcInJail = 0x200023e;
const int opcodeGetPcTraveling = 0x200023f;
const int opcodeAddToLevCreature = 0x20002fb;
const int opcodeRemoveFromLevCreature = 0x20002fc;
const int opcodeAddToLevItem = 0x20002fd;
const int opcodeRemoveFromLevItem = 0x20002fe;
const int opcodeShowSceneGraph = 0x2002f;
const int opcodeShowSceneGraphExplicit = 0x20030;
const int opcodeToggleBorders = 0x2000307;
const int opcodeToggleNavMesh = 0x2000308;
const int opcodeToggleActorsPaths = 0x2000309;
const int opcodeSetNavMeshNumberToRender = 0x200030a;
const int opcodeRepairedOnMe = 0x200030c;
const int opcodeRepairedOnMeExplicit = 0x200030d;
const int opcodeToggleRecastMesh = 0x2000310;
const int opcodeMenuMode = 0x2000311;
const int opcodeRandom = 0x2000312;
const int opcodeScriptRunning = 0x2000313;
const int opcodeStartScript = 0x2000314;
const int opcodeStopScript = 0x2000315;
const int opcodeGetSecondsPassed = 0x2000316;
const int opcodeEnable = 0x2000317;
const int opcodeDisable = 0x2000318;
const int opcodeGetDisabled = 0x2000319;
const int opcodeEnableExplicit = 0x200031a;
const int opcodeDisableExplicit = 0x200031b;
const int opcodeGetDisabledExplicit = 0x200031c;
const int opcodeStartScriptExplicit = 0x200031d;
const int opcodeHelp = 0x2000320;
const int opcodeReloadLua = 0x2000321;
const int opcodeTestModels = 0x2000325;
}
namespace Sky
{
const int opcodeToggleSky = 0x2000021;
const int opcodeTurnMoonWhite = 0x2000022;
const int opcodeTurnMoonRed = 0x2000023;
const int opcodeGetMasserPhase = 0x2000024;
const int opcodeGetSecundaPhase = 0x2000025;
const int opcodeGetCurrentWeather = 0x200013f;
const int opcodeChangeWeather = 0x2000140;
const int opcodeModRegion = 0x20026;
}
namespace Sound
{
const int opcodeSay = 0x2000001;
const int opcodeSayDone = 0x2000002;
const int opcodeStreamMusic = 0x2000003;
const int opcodePlaySound = 0x2000004;
const int opcodePlaySoundVP = 0x2000005;
const int opcodePlaySound3D = 0x2000006;
const int opcodePlaySound3DVP = 0x2000007;
const int opcodePlayLoopSound3D = 0x2000008;
const int opcodePlayLoopSound3DVP = 0x2000009;
const int opcodeStopSound = 0x200000a;
const int opcodeGetSoundPlaying = 0x200000b;
const int opcodeSayExplicit = 0x2000019;
const int opcodeSayDoneExplicit = 0x200001a;
const int opcodePlaySound3DExplicit = 0x200001b;
const int opcodePlaySound3DVPExplicit = 0x200001c;
const int opcodePlayLoopSound3DExplicit = 0x200001d;
const int opcodePlayLoopSound3DVPExplicit = 0x200001e;
const int opcodeStopSoundExplicit = 0x200001f;
const int opcodeGetSoundPlayingExplicit = 0x2000020;
}
namespace Stats
{
const int numberOfAttributes = 8;
const int numberOfDynamics = 3;
const int numberOfSkills = 27;
const int numberOfMagicEffects = 24;
const int opcodeGetAttribute = 0x2000027;
const int opcodeGetAttributeExplicit = 0x200002f;
const int opcodeSetAttribute = 0x2000037;
const int opcodeSetAttributeExplicit = 0x200003f;
const int opcodeModAttribute = 0x2000047;
const int opcodeModAttributeExplicit = 0x200004f;
const int opcodeGetDynamic = 0x2000057;
const int opcodeGetDynamicExplicit = 0x200005a;
const int opcodeSetDynamic = 0x200005d;
const int opcodeSetDynamicExplicit = 0x2000060;
const int opcodeModDynamic = 0x2000063;
const int opcodeModDynamicExplicit = 0x2000066;
const int opcodeModCurrentDynamic = 0x2000069;
const int opcodeModCurrentDynamicExplicit = 0x200006c;
const int opcodeGetDynamicGetRatio = 0x200006f;
const int opcodeGetDynamicGetRatioExplicit = 0x2000072;
const int opcodeGetSkill = 0x200008e;
const int opcodeGetSkillExplicit = 0x20000a9;
const int opcodeSetSkill = 0x20000c4;
const int opcodeSetSkillExplicit = 0x20000df;
const int opcodeModSkill = 0x20000fa;
const int opcodeModSkillExplicit = 0x2000115;
const int opcodeGetMagicEffect = 0x2000264;
const int opcodeGetMagicEffectExplicit = 0x200027c;
const int opcodeSetMagicEffect = 0x2000294;
const int opcodeSetMagicEffectExplicit = 0x20002ac;
const int opcodeModMagicEffect = 0x20002c4;
const int opcodeModMagicEffectExplicit = 0x20002dc;
const int opcodeGetPCCrimeLevel = 0x20001ec;
const int opcodeSetPCCrimeLevel = 0x20001ed;
const int opcodeModPCCrimeLevel = 0x20001ee;
const int opcodeAddSpell = 0x2000147;
const int opcodeAddSpellExplicit = 0x2000148;
const int opcodeRemoveSpell = 0x2000149;
const int opcodeRemoveSpellExplicit = 0x200014a;
const int opcodeGetSpell = 0x200014b;
const int opcodeGetSpellExplicit = 0x200014c;
const int opcodePCRaiseRank = 0x2000b;
const int opcodePCLowerRank = 0x2000c;
const int opcodePCJoinFaction = 0x2000d;
const int opcodePCRaiseRankExplicit = 0x20029;
const int opcodePCLowerRankExplicit = 0x2002a;
const int opcodePCJoinFactionExplicit = 0x2002b;
const int opcodeGetPCRank = 0x2000e;
const int opcodeGetPCRankExplicit = 0x2000f;
const int opcodeModDisposition = 0x200014d;
const int opcodeModDispositionExplicit = 0x200014e;
const int opcodeSetDisposition = 0x20001a4;
const int opcodeSetDispositionExplicit = 0x20001a5;
const int opcodeGetDisposition = 0x20001a6;
const int opcodeGetDispositionExplicit = 0x20001a7;
const int opcodeGetLevel = 0x200018c;
const int opcodeGetLevelExplicit = 0x200018d;
const int opcodeSetLevel = 0x200018e;
const int opcodeSetLevelExplicit = 0x200018f;
const int opcodeGetDeadCount = 0x20001a3;
const int opcodeGetPCFacRep = 0x20012;
const int opcodeGetPCFacRepExplicit = 0x20013;
const int opcodeSetPCFacRep = 0x20014;
const int opcodeSetPCFacRepExplicit = 0x20015;
const int opcodeModPCFacRep = 0x20016;
const int opcodeModPCFacRepExplicit = 0x20017;
const int opcodeGetCommonDisease = 0x20001a8;
const int opcodeGetCommonDiseaseExplicit = 0x20001a9;
const int opcodeGetBlightDisease = 0x20001aa;
const int opcodeGetBlightDiseaseExplicit = 0x20001ab;
const int opcodeGetRace = 0x20001d9;
const int opcodeGetRaceExplicit = 0x20001da;
const int opcodePcExpelled = 0x20018;
const int opcodePcExpelledExplicit = 0x20019;
const int opcodePcExpell = 0x2001a;
const int opcodePcExpellExplicit = 0x2001b;
const int opcodePcClearExpelled = 0x2001c;
const int opcodePcClearExpelledExplicit = 0x2001d;
const int opcodeRaiseRank = 0x20001e8;
const int opcodeRaiseRankExplicit = 0x20001e9;
const int opcodeLowerRank = 0x20001ea;
const int opcodeLowerRankExplicit = 0x20001eb;
const int opcodeOnDeath = 0x20001fc;
const int opcodeOnDeathExplicit = 0x2000205;
const int opcodeOnMurder = 0x2000249;
const int opcodeOnMurderExplicit = 0x200024a;
const int opcodeOnKnockout = 0x2000240;
const int opcodeOnKnockoutExplicit = 0x2000241;
const int opcodeBecomeWerewolf = 0x2000217;
const int opcodeBecomeWerewolfExplicit = 0x2000218;
const int opcodeUndoWerewolf = 0x2000219;
const int opcodeUndoWerewolfExplicit = 0x200021a;
const int opcodeSetWerewolfAcrobatics = 0x200021b;
const int opcodeSetWerewolfAcrobaticsExplicit = 0x200021c;
const int opcodeIsWerewolf = 0x20001fd;
const int opcodeIsWerewolfExplicit = 0x20001fe;
const int opcodeGetWerewolfKills = 0x20001e2;
const int opcodeRemoveSpellEffects = 0x200022b;
const int opcodeRemoveSpellEffectsExplicit = 0x200022c;
const int opcodeRemoveEffects = 0x200022d;
const int opcodeRemoveEffectsExplicit = 0x200022e;
const int opcodeResurrect = 0x200022f;
const int opcodeResurrectExplicit = 0x2000230;
const int opcodeGetStat = 0x200024e;
const int opcodeGetStatExplicit = 0x200024f;
const int opcodeGetPCVisionBonus = 0x2000322;
const int opcodeSetPCVisionBonus = 0x2000323;
const int opcodeModPCVisionBonus = 0x2000324;
}
namespace Transformation
{
const int opcodeSetScale = 0x2000164;
const int opcodeSetScaleExplicit = 0x2000165;
const int opcodeSetAngle = 0x2000166;
const int opcodeSetAngleExplicit = 0x2000167;
const int opcodeGetScale = 0x2000168;
const int opcodeGetScaleExplicit = 0x2000169;
const int opcodeGetAngle = 0x200016a;
const int opcodeGetAngleExplicit = 0x200016b;
const int opcodeGetPos = 0x2000190;
const int opcodeGetPosExplicit = 0x2000191;
const int opcodeSetPos = 0x2000192;
const int opcodeSetPosExplicit = 0x2000193;
const int opcodeGetStartingPos = 0x2000194;
const int opcodeGetStartingPosExplicit = 0x2000195;
const int opcodeGetStartingAngle = 0x2000210;
const int opcodeGetStartingAngleExplicit = 0x2000211;
const int opcodePosition = 0x2000196;
const int opcodePositionExplicit = 0x2000197;
const int opcodePositionCell = 0x2000198;
const int opcodePositionCellExplicit = 0x2000199;
const int opcodePlaceItemCell = 0x200019a;
const int opcodePlaceItem = 0x200019b;
const int opcodePlaceAtPc = 0x200019c;
const int opcodePlaceAtMe = 0x200019d;
const int opcodePlaceAtMeExplicit = 0x200019e;
const int opcodeModScale = 0x20001e3;
const int opcodeModScaleExplicit = 0x20001e4;
const int opcodeRotate = 0x20001ff;
const int opcodeRotateExplicit = 0x2000200;
const int opcodeRotateWorld = 0x2000201;
const int opcodeRotateWorldExplicit = 0x2000202;
const int opcodeSetAtStart = 0x2000203;
const int opcodeSetAtStartExplicit = 0x2000204;
const int opcodeMove = 0x2000206;
const int opcodeMoveExplicit = 0x2000207;
const int opcodeMoveWorld = 0x2000208;
const int opcodeMoveWorldExplicit = 0x2000209;
const int opcodeResetActors = 0x20002f4;
const int opcodeFixme = 0x2000302;
const int opcodeGetDistance = 0x200031e;
const int opcodeGetDistanceExplicit = 0x200031f;
}
namespace User
{
const int opcodeUser1 = 0x200016c;
const int opcodeUser2 = 0x200016d;
const int opcodeUser3 = 0x200016e;
const int opcodeUser3Explicit = 0x200016f;
const int opcodeUser4 = 0x2000170;
const int opcodeUser4Explicit = 0x2000171;
}
}
#endif
| 24,513
|
C++
|
.h
| 511
| 39.315068
| 66
| 0.720182
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,912
|
literals.hpp
|
OpenMW_openmw/components/compiler/literals.hpp
|
#ifndef COMPILER_LITERALS_H_INCLUDED
#define COMPILER_LITERALS_H_INCLUDED
#include <string>
#include <vector>
#include <components/interpreter/types.hpp>
namespace Compiler
{
/// \brief Literal values.
class Literals
{
std::vector<Interpreter::Type_Integer> mIntegers;
std::vector<Interpreter::Type_Float> mFloats;
std::vector<std::string> mStrings;
public:
const std::vector<Interpreter::Type_Integer>& getIntegers() const { return mIntegers; }
const std::vector<Interpreter::Type_Float>& getFloats() const { return mFloats; }
const std::vector<std::string>& getStrings() const { return mStrings; }
int addInteger(Interpreter::Type_Integer value);
///< add integer liternal and return index.
int addFloat(Interpreter::Type_Float value);
///< add float literal and return value.
int addString(const std::string& value);
///< add string literal and return value.
void clear();
///< remove all literals.
};
}
#endif
| 1,058
|
C++
|
.h
| 28
| 31.642857
| 95
| 0.676817
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,913
|
lineparser.hpp
|
OpenMW_openmw/components/compiler/lineparser.hpp
|
#ifndef COMPILER_LINEPARSER_H_INCLUDED
#define COMPILER_LINEPARSER_H_INCLUDED
#include <string>
#include <vector>
#include <components/interpreter/types.hpp>
#include <components/misc/messageformatparser.hpp>
#include "exprparser.hpp"
#include "parser.hpp"
namespace Compiler
{
class Locals;
class Literals;
/// \brief Line parser, to be used in console scripts and as part of ScriptParser
class LineParser : public Parser
{
enum State
{
BeginState,
SetState,
SetLocalVarState,
SetGlobalVarState,
SetPotentialMemberVarState,
SetMemberVarState,
SetMemberVarState2,
MessageState,
MessageButtonState,
EndState,
PotentialExplicitState,
ExplicitState,
MemberState
};
Locals& mLocals;
Literals& mLiterals;
std::vector<Interpreter::Type_Code>& mCode;
State mState;
std::string mName;
std::string mMemberName;
bool mReferenceMember;
int mButtons;
std::string mExplicit;
char mType;
ExprParser mExprParser;
bool mAllowExpression;
void parseExpression(Scanner& scanner, const TokenLoc& loc);
public:
LineParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals,
std::vector<Interpreter::Type_Code>& code, bool allowExpression = false);
///< \param allowExpression Allow lines consisting of a naked expression
/// (result is send to the messagebox interface)
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a float token.
/// \return fetch another token?
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
void reset() override;
///< Reset parser to clean state.
};
class GetArgumentsFromMessageFormat : public ::Misc::MessageFormatParser
{
private:
std::string mArguments;
protected:
void visitedPlaceholder(
Placeholder placeholder, char padding, int width, int precision, Notation notation) override;
void visitedCharacter(char c) override {}
public:
void process(std::string_view message) override
{
mArguments.clear();
::Misc::MessageFormatParser::process(message);
}
std::string getArguments() const { return mArguments; }
};
}
#endif
| 3,149
|
C++
|
.h
| 85
| 28.764706
| 106
| 0.648276
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,914
|
errorhandler.hpp
|
OpenMW_openmw/components/compiler/errorhandler.hpp
|
#ifndef COMPILER_ERRORHANDLER_H_INCLUDED
#define COMPILER_ERRORHANDLER_H_INCLUDED
#include <string>
namespace Compiler
{
struct TokenLoc;
/// \brief Error handling
///
/// This class collects errors and provides an interface for reporting them to the user.
class ErrorHandler
{
int mWarnings;
int mErrors;
int mWarningsMode;
bool mDowngradeErrors;
protected:
enum Type
{
WarningMessage,
ErrorMessage
};
private:
// mutators
virtual void report(const std::string& message, const TokenLoc& loc, Type type) = 0;
///< Report error to the user.
virtual void report(const std::string& message, Type type) = 0;
///< Report a file related error
public:
ErrorHandler();
///< constructor
virtual ~ErrorHandler();
///< destructor
bool isGood() const;
///< Was compiling successful?
int countErrors() const;
///< Return number of errors
int countWarnings() const;
///< Return number of warnings
void warning(const std::string& message, const TokenLoc& loc);
///< Generate a warning message.
void error(const std::string& message, const TokenLoc& loc);
///< Generate an error message.
void endOfFile();
///< Generate an error message for an unexpected EOF.
virtual void reset();
///< Remove all previous error/warning events
void setWarningsMode(int mode);
///< // 0 ignore, 1 rate as warning, 2 rate as error
/// Treat errors as warnings.
void downgradeErrors(bool downgrade);
};
class ErrorDowngrade
{
ErrorHandler& mHandler;
/// not implemented
ErrorDowngrade(const ErrorDowngrade&);
/// not implemented
ErrorDowngrade& operator=(const ErrorDowngrade&);
public:
explicit ErrorDowngrade(ErrorHandler& handler);
~ErrorDowngrade();
};
}
#endif
| 2,064
|
C++
|
.h
| 64
| 24.484375
| 92
| 0.621266
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,915
|
discardparser.hpp
|
OpenMW_openmw/components/compiler/discardparser.hpp
|
#ifndef COMPILER_DISCARDPARSER_H_INCLUDED
#define COMPILER_DISCARDPARSER_H_INCLUDED
#include "parser.hpp"
#include "tokenloc.hpp"
namespace Compiler
{
/// \brief Parse a single optional numeric value or string and discard it
class DiscardParser : public Parser
{
enum State
{
StartState,
MinusState
};
State mState;
TokenLoc mTokenLoc;
public:
DiscardParser(ErrorHandler& errorHandler, const Context& context);
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a float token.
/// \return fetch another token?
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
void reset() override;
///< Reset parser to clean state.
/// Returns TokenLoc object for value. If no value has been parsed, the TokenLoc
/// object will be default initialised.
const TokenLoc& getTokenLoc() const;
};
}
#endif
| 1,445
|
C++
|
.h
| 38
| 30.736842
| 96
| 0.654728
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,916
|
quickfileparser.hpp
|
OpenMW_openmw/components/compiler/quickfileparser.hpp
|
#ifndef COMPILER_QUICKFILEPARSER_H_INCLUDED
#define COMPILER_QUICKFILEPARSER_H_INCLUDED
#include "declarationparser.hpp"
#include "parser.hpp"
namespace Compiler
{
class Locals;
/// \brief File parser variant that ignores everything but variable declarations
class QuickFileParser : public Parser
{
DeclarationParser mDeclarationParser;
public:
QuickFileParser(ErrorHandler& errorHandler, const Context& context, Locals& locals);
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
void parseEOF(Scanner& scanner) override;
///< Handle EOF token.
};
}
#endif
| 1,083
|
C++
|
.h
| 27
| 34.037037
| 96
| 0.702006
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,917
|
junkparser.hpp
|
OpenMW_openmw/components/compiler/junkparser.hpp
|
#ifndef COMPILER_JUNKPARSER_H_INCLUDED
#define COMPILER_JUNKPARSER_H_INCLUDED
#include "parser.hpp"
namespace Compiler
{
/// \brief Parse an optional single junk token
class JunkParser : public Parser
{
int mIgnoreKeyword;
public:
JunkParser(ErrorHandler& errorHandler, const Context& context, int ignoreKeyword = -1);
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
bool parseFloat(float value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a float token.
/// \return fetch another token?
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
};
}
#endif
| 1,206
|
C++
|
.h
| 29
| 34.896552
| 96
| 0.671233
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,918
|
tokenloc.hpp
|
OpenMW_openmw/components/compiler/tokenloc.hpp
|
#ifndef COMPILER_TOKENLOC_H_INCLUDED
#define COMPILER_TOKENLOC_H_INCLUDED
#include <string>
namespace Compiler
{
/// \brief Location of a token in a source file
struct TokenLoc
{
int mColumn;
int mLine;
std::string mLiteral;
TokenLoc()
: mColumn(0)
, mLine(0)
, mLiteral()
{
}
};
}
#endif // TOKENLOC_H_INCLUDED
| 417
|
C++
|
.h
| 20
| 14.6
| 51
| 0.579082
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,919
|
controlparser.hpp
|
OpenMW_openmw/components/compiler/controlparser.hpp
|
#ifndef COMPILER_CONTROLPARSER_H_INCLUDED
#define COMPILER_CONTROLPARSER_H_INCLUDED
#include <vector>
#include <components/interpreter/types.hpp>
#include "exprparser.hpp"
#include "lineparser.hpp"
#include "parser.hpp"
namespace Compiler
{
class Locals;
class Literals;
// Control structure parser
class ControlParser : public Parser
{
enum State
{
StartState,
IfEndState,
IfBodyState,
IfElseifEndState,
IfElseifBodyState,
IfElseEndState,
IfElseBodyState,
IfEndifState,
WhileEndState,
WhileBodyState,
WhileEndwhileState,
IfElseJunkState
};
typedef std::vector<Interpreter::Type_Code> Codes;
typedef std::vector<std::pair<Codes, Codes>> IfCodes;
Locals& mLocals;
Literals& mLiterals;
Codes mCode;
Codes mCodeBlock;
IfCodes mIfCode; // condition, body
LineParser mLineParser;
ExprParser mExprParser;
State mState;
bool parseIfBody(int keyword, const TokenLoc& loc, Scanner& scanner);
bool parseWhileBody(int keyword, const TokenLoc& loc, Scanner& scanner);
public:
ControlParser(ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals);
void appendCode(std::vector<Interpreter::Type_Code>& code) const;
///< store generated code in \a code.
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a special character token.
/// \return fetch another token?
void reset() override;
///< Reset parser to clean state.
};
}
#endif
| 2,100
|
C++
|
.h
| 59
| 27.457627
| 110
| 0.646739
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| true
| false
|
35,920
|
protocol.hpp
|
OpenMW_openmw/components/navmeshtool/protocol.hpp
|
#ifndef OPENMW_COMPONENTS_NAVMESHTOOL_PROTOCOL_H
#define OPENMW_COMPONENTS_NAVMESHTOOL_PROTOCOL_H
#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include <variant>
#include <vector>
namespace NavMeshTool
{
inline constexpr char messageMagic[] = { 'n', 'v', 't', 'm' };
enum class MessageType : std::uint64_t
{
ExpectedCells = 1,
ProcessedCells = 2,
ExpectedTiles = 3,
GeneratedTiles = 4,
};
struct Message
{
std::uint64_t mType = 0;
std::uint64_t mSize = 0;
const std::byte* mData = nullptr;
};
struct ExpectedCells
{
static constexpr MessageType sMessageType = MessageType::ExpectedCells;
std::uint64_t mCount = 0;
};
struct ProcessedCells
{
static constexpr MessageType sMessageType = MessageType::ProcessedCells;
std::uint64_t mCount = 0;
};
struct ExpectedTiles
{
static constexpr MessageType sMessageType = MessageType::ExpectedTiles;
std::uint64_t mCount = 0;
};
struct GeneratedTiles
{
static constexpr MessageType sMessageType = MessageType::GeneratedTiles;
std::uint64_t mCount = 0;
};
using TypedMessage = std::variant<ExpectedCells, ProcessedCells, ExpectedTiles, GeneratedTiles>;
std::vector<std::byte> serialize(const ExpectedCells& value);
std::vector<std::byte> serialize(const ProcessedCells& value);
std::vector<std::byte> serialize(const ExpectedTiles& value);
std::vector<std::byte> serialize(const GeneratedTiles& value);
const std::byte* deserialize(const std::byte* begin, const std::byte* end, Message& message);
TypedMessage decode(const Message& message);
}
#endif
| 1,742
|
C++
|
.h
| 52
| 27.884615
| 100
| 0.68638
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,921
|
scripttracker.hpp
|
OpenMW_openmw/components/lua/scripttracker.hpp
|
#ifndef COMPONENTS_LUA_SCRIPTTRACKER_H
#define COMPONENTS_LUA_SCRIPTTRACKER_H
#include <memory>
#include <queue>
#include <utility>
#include "scriptscontainer.hpp"
namespace LuaUtil
{
class ScriptTracker
{
using Frame = unsigned int;
using TrackedScriptContainer = std::pair<ScriptsContainer::WeakPtr, Frame>;
std::queue<TrackedScriptContainer> mLoadedScripts;
Frame mFrame = 0;
public:
void unloadInactiveScripts(LuaView& lua);
void onLoad(ScriptsContainer& container);
std::size_t size() const { return mLoadedScripts.size(); }
};
}
#endif // COMPONENTS_LUA_SCRIPTTRACKER_H
| 655
|
C++
|
.h
| 21
| 26.428571
| 83
| 0.722488
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,922
|
utilpackage.hpp
|
OpenMW_openmw/components/lua/utilpackage.hpp
|
#ifndef COMPONENTS_LUA_UTILPACKAGE_H
#define COMPONENTS_LUA_UTILPACKAGE_H
#include <osg/Matrix>
#include <osg/Quat>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <sol/sol.hpp>
namespace LuaUtil
{
using Vec2 = osg::Vec2f;
using Vec3 = osg::Vec3f;
using Vec4 = osg::Vec4f;
// For performance reasons "Transform" is implemented as 2 types with the same interface.
// Transform supports only composition, inversion, and applying to a 3d vector.
struct TransformM
{
osg::Matrixf mM;
};
struct TransformQ
{
osg::Quat mQ;
};
inline TransformM asTransform(const osg::Matrixf& m)
{
return { m };
}
inline TransformQ asTransform(const osg::Quat& q)
{
return { q };
}
inline bool isTransform(const sol::object& obj)
{
return obj.is<TransformM>() || obj.is<TransformQ>();
}
sol::table initUtilPackage(lua_State*);
}
#endif // COMPONENTS_LUA_UTILPACKAGE_H
| 998
|
C++
|
.h
| 38
| 21.789474
| 93
| 0.668067
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,923
|
storage.hpp
|
OpenMW_openmw/components/lua/storage.hpp
|
#ifndef COMPONENTS_LUA_STORAGE_H
#define COMPONENTS_LUA_STORAGE_H
#include <map>
#include <sol/sol.hpp>
#include <stdexcept>
#include "asyncpackage.hpp"
#include "serialization.hpp"
namespace LuaUtil
{
class LuaView;
class LuaStorage
{
public:
static void initLuaBindings(LuaUtil::LuaView& view);
static sol::table initGlobalPackage(LuaUtil::LuaView& view, LuaStorage* globalStorage);
static sol::table initLocalPackage(LuaUtil::LuaView& view, LuaStorage* globalStorage);
static sol::table initPlayerPackage(
LuaUtil::LuaView& view, LuaStorage* globalStorage, LuaStorage* playerStorage);
static sol::table initMenuPackage(LuaUtil::LuaView& view, LuaStorage* globalStorage, LuaStorage* playerStorage);
explicit LuaStorage() {}
void clearTemporaryAndRemoveCallbacks();
void load(lua_State* L, const std::filesystem::path& path);
void save(lua_State* L, const std::filesystem::path& path) const;
sol::object getSection(lua_State* L, std::string_view sectionName, bool readOnly, bool forMenuScripts = false);
sol::object getMutableSection(lua_State* L, std::string_view sectionName, bool forMenuScripts = false)
{
return getSection(L, sectionName, false, forMenuScripts);
}
sol::object getReadOnlySection(lua_State* L, std::string_view sectionName)
{
return getSection(L, sectionName, true);
}
sol::table getAllSections(lua_State* L, bool readOnly = false);
void setSingleValue(std::string_view section, std::string_view key, const sol::object& value)
{
getSection(section)->set(key, value);
}
void setSectionValues(std::string_view section, const sol::optional<sol::table>& values)
{
getSection(section)->setAll(values);
}
class Listener
{
public:
virtual ~Listener() = default;
virtual void valueChanged(
std::string_view section, std::string_view key, const sol::object& value) const = 0;
virtual void sectionReplaced(std::string_view section, const sol::optional<sol::table>& values) const = 0;
};
void setListener(const Listener* listener) { mListener = listener; }
void setActive(bool active) { mActive = active; }
private:
class Value
{
public:
Value() {}
Value(const sol::object& value)
: mSerializedValue(serialize(value))
{
}
sol::object getCopy(lua_State* L) const;
sol::object getReadOnly(lua_State* L) const;
private:
std::string mSerializedValue;
mutable sol::object mReadOnlyValue = sol::nil;
};
struct Section
{
enum LifeTime
{
Persistent,
GameSession,
Temporary
};
explicit Section(LuaStorage* storage, std::string name)
: mStorage(storage)
, mSectionName(std::move(name))
{
}
const Value& get(std::string_view key) const;
void set(std::string_view key, const sol::object& value);
void setAll(const sol::optional<sol::table>& values);
sol::table asTable(lua_State* L);
void runCallbacks(sol::optional<std::string_view> changedKey);
void throwIfCallbackRecursionIsTooDeep();
LuaStorage* mStorage;
std::string mSectionName;
std::map<std::string, Value, std::less<>> mValues;
std::vector<Callback> mCallbacks;
std::vector<Callback> mMenuScriptsCallbacks; // menu callbacks are in a separate vector because we don't
// remove them in clear()
LifeTime mLifeTime = Persistent;
static Value sEmpty;
void checkIfActive() const { mStorage->checkIfActive(); }
};
struct SectionView
{
std::shared_ptr<Section> mSection;
bool mReadOnly;
bool mForMenuScripts = false;
};
const std::shared_ptr<Section>& getSection(std::string_view sectionName);
std::map<std::string_view, std::shared_ptr<Section>> mData;
const Listener* mListener = nullptr;
std::set<const Section*> mRunningCallbacks;
bool mActive = false;
void checkIfActive() const
{
if (!mActive)
throw std::logic_error("Trying to access inactive storage");
}
static void registerLifeTime(LuaUtil::LuaView& view, sol::table& res);
};
}
#endif // COMPONENTS_LUA_STORAGE_H
| 4,826
|
C++
|
.h
| 115
| 31.391304
| 120
| 0.607333
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,924
|
scriptscontainer.hpp
|
OpenMW_openmw/components/lua/scriptscontainer.hpp
|
#ifndef COMPONENTS_LUA_SCRIPTSCONTAINER_H
#define COMPONENTS_LUA_SCRIPTSCONTAINER_H
#include <map>
#include <set>
#include <string>
#include <variant>
#include <components/debug/debuglog.hpp>
#include <components/esm/luascripts.hpp>
#include "luastate.hpp"
#include "serialization.hpp"
namespace LuaUtil
{
class ScriptTracker;
// ScriptsContainer is a base class for all scripts containers (LocalScripts,
// GlobalScripts, PlayerScripts, etc). Each script runs in a separate sandbox.
// Scripts from different containers can interact to each other only via events.
// Scripts within one container can interact via interfaces.
// All scripts from one container have the same set of API packages available.
//
// Each script should return a table in a specific format that describes its
// handlers and interfaces. Every section of the table is optional. Basic structure:
//
// local function update(dt)
// print("Update")
// end
//
// local function someEventHandler(eventData)
// print("'SomeEvent' received")
// end
//
// return {
// -- Provides interface for other scripts in the same container
// interfaceName = "InterfaceName",
// interface = {
// someFunction = function() print("someFunction was called from another script") end,
// },
//
// -- Script interface for the engine. Not available for other script.
// -- An error is printed if unknown handler is specified.
// engineHandlers = {
// onUpdate = update,
// onInit = function(initData) ... end, -- used when the script is just created (not loaded)
// onSave = function() return ... end,
// onLoad = function(state, initData) ... end, -- "state" is the data that was earlier returned by
// onSave
//
// -- Works only if a child class has passed a EngineHandlerList
// -- for 'onSomethingElse' to ScriptsContainer::registerEngineHandlers.
// onSomethingElse = function() print("something else") end
// },
//
// -- Handlers for events, sent from other scripts. Engine itself never sent events. Any name can be used
// for an event. eventHandlers = {
// SomeEvent = someEventHandler
// }
// }
class ScriptsContainer
{
public:
// ScriptId of each script is stored with this key in Script::mHiddenData.
// Removed from mHiddenData when the script if removed.
constexpr static std::string_view sScriptIdKey = "_id";
// Debug identifier of each script is stored with this key in Script::mHiddenData.
// Present in mHiddenData even after removal of the script from ScriptsContainer.
constexpr static std::string_view sScriptDebugNameKey = "_name";
using TimerType = ESM::LuaTimer::Type;
// `namePrefix` is a common prefix for all scripts in the container. Used in logs for error messages and `print`
// output. `tracker` is a tracker for managing the container's state. `load` specifies whether the container
// should be constructed in a loaded state.
ScriptsContainer(
LuaState* lua, std::string_view namePrefix, ScriptTracker* tracker = nullptr, bool load = true);
ScriptsContainer(const ScriptsContainer&) = delete;
ScriptsContainer(ScriptsContainer&&) = delete;
virtual ~ScriptsContainer();
// `conf` specifies the list of scripts that should be autostarted in this container; the script
// names themselves are stored in ScriptsConfiguration.
void setAutoStartConf(ScriptIdsWithInitializationData conf) { mAutoStartScripts = std::move(conf); }
const ScriptIdsWithInitializationData& getAutoStartConf() const { return mAutoStartScripts; }
// Adds package that will be available (via `require`) for all scripts in the container.
// Automatically applies LuaUtil::makeReadOnly to the package.
void addPackage(std::string packageName, sol::object package);
// Gets script with given id from ScriptsConfiguration, finds the source in the virtual file system, starts as a
// new script, adds it to the container, and calls onInit for this script. Returns `true` if the script was
// successfully added. The script should have CUSTOM flag. If the flag is not set, or file not found, or has
// syntax errors, returns false. If such script already exists in the container, then also returns false.
bool addCustomScript(int scriptId, std::string_view initData = {});
bool hasScript(int scriptId) const;
void removeScript(int scriptId);
void processTimers(double simulationTime, double gameTime);
// Calls `onUpdate` (if present) for every script in the container.
// Handlers are called in the same order as scripts were added.
void update(float dt) { callEngineHandlers(mUpdateHandlers, dt); }
// Calls event handlers `eventName` (if present) for every script.
// If several scripts register handlers for `eventName`, they are called in reverse order.
// If some handler returns `false`, all remaining handlers are ignored. Any other return value
// (including `nil`) has no effect.
void receiveEvent(std::string_view eventName, std::string_view eventData);
// Serializer defines how to serialize/deserialize userdata. If serializer is not provided,
// only built-in types and types from util package can be serialized.
void setSerializer(const UserdataSerializer* serializer) { mSerializer = serializer; }
// Special deserializer to use when load data from saves. Can be used to remap content files in Refnums.
void setSavedDataDeserializer(const UserdataSerializer* serializer) { mSavedDataDeserializer = serializer; }
// Starts scripts according to `autoStartMode` and calls `onInit` for them. Not needed if `load` is used.
void addAutoStartedScripts();
// Removes all scripts including the auto started.
void removeAllScripts();
// Calls engineHandler "onSave" for every script and saves the list of the scripts with serialized data to
// ESM::LuaScripts.
void save(ESM::LuaScripts&);
// Removes all scripts; starts scripts according to `autoStartMode` and
// loads the savedScripts. Runs "onLoad" for each script.
void load(const ESM::LuaScripts& savedScripts);
// Callbacks for serializable timers should be registered in advance.
// The script with the given path should already present in the container.
void registerTimerCallback(int scriptId, std::string_view callbackName, sol::main_protected_function callback);
// Sets up a timer, that can be automatically saved and loaded.
// type - the type of timer, either SIMULATION_TIME or GAME_TIME.
// time - the absolute game time (in seconds or in hours) when the timer should be executed.
// scriptPath - script path in VFS is used as script id. The script with the given path should already present
// in the container. callbackName - callback (should be registered in advance) for this timer. callbackArg -
// parameter for the callback (should be serializable).
void setupSerializableTimer(
TimerType type, double time, int scriptId, std::string_view callbackName, sol::main_object callbackArg);
// Creates a timer. `callback` is an arbitrary Lua function. These timers are called "unsavable"
// because they can not be stored in saves. I.e. loading a saved game will not fully restore the state.
void setupUnsavableTimer(TimerType type, double time, int scriptId, sol::main_protected_function callback);
// Informs that new frame is started. Needed to track Lua instruction count per frame.
void statsNextFrame();
struct ScriptStats
{
float mAvgInstructionCount = 0; // averaged number of Lua instructions per frame
int64_t mMemoryUsage = 0; // bytes
};
void collectStats(std::vector<ScriptStats>& stats) const;
static int64_t getInstanceCount() { return sInstanceCount; }
virtual bool isActive() const { return false; }
protected:
struct Handler
{
int mScriptId;
sol::function mFn;
};
struct EngineHandlerList
{
std::string_view mName;
std::vector<Handler> mList;
// "name" must be string literal
explicit EngineHandlerList(std::string_view name)
: mName(name)
{
}
};
// Calls given handlers in direct order.
template <typename... Args>
void callEngineHandlers(EngineHandlerList& handlers, const Args&... args)
{
ensureLoaded();
for (Handler& handler : handlers.mList)
{
try
{
LuaUtil::call({ this, handler.mScriptId }, handler.mFn, args...);
}
catch (std::exception& e)
{
Log(Debug::Error) << mNamePrefix << "[" << scriptPath(handler.mScriptId) << "] " << handlers.mName
<< " failed. " << e.what();
}
}
}
// To add a new engine handler a derived class should register the corresponding EngineHandlerList and define
// a public function (see how ScriptsContainer::update is implemented) that calls `callEngineHandlers`.
void registerEngineHandlers(std::initializer_list<EngineHandlerList*> handlers);
const std::string mNamePrefix;
LuaUtil::LuaState& mLua;
private:
struct Script
{
std::optional<sol::function> mOnSave;
std::optional<sol::function> mOnOverride;
std::optional<sol::table> mInterface;
std::string mInterfaceName;
sol::table mHiddenData;
std::map<std::string, sol::main_protected_function> mRegisteredCallbacks;
std::map<int64_t, sol::main_protected_function> mTemporaryCallbacks;
VFS::Path::Normalized mPath;
ScriptStats mStats;
~Script();
};
struct Timer
{
double mTime;
bool mSerializable;
int mScriptId;
std::variant<std::string, int64_t> mCallback; // string if serializable, integer otherwise
sol::main_object mArg;
std::string mSerializedArg;
bool operator<(const Timer& t) const { return mTime > t.mTime; }
};
using EventHandlerList = std::vector<Handler>;
friend class LuaState;
void addInstructionCount(int scriptId, int64_t instructionCount);
void addMemoryUsage(int scriptId, int64_t memoryDelta);
// Add to container without calling onInit/onLoad.
bool addScript(
LuaView& view, int scriptId, std::optional<sol::function>& onInit, std::optional<sol::function>& onLoad);
// Returns script by id (throws an exception if doesn't exist)
Script& getScript(int scriptId);
void printError(int scriptId, std::string_view msg, const std::exception& e);
const VFS::Path::Normalized& scriptPath(int scriptId) const
{
return mLua.getConfiguration()[scriptId].mScriptPath;
}
void callOnInit(LuaView& view, int scriptId, const sol::function& onInit, std::string_view data);
void callTimer(const Timer& t);
void updateTimerQueue(std::vector<Timer>& timerQueue, double time);
static void insertTimer(std::vector<Timer>& timerQueue, Timer&& t);
static void insertHandler(std::vector<Handler>& list, int scriptId, sol::function fn);
static void removeHandler(std::vector<Handler>& list, int scriptId);
void insertInterface(int scriptId, const Script& script);
void removeInterface(int scriptId, const Script& script);
ScriptIdsWithInitializationData mAutoStartScripts;
const UserdataSerializer* mSerializer = nullptr;
const UserdataSerializer* mSavedDataDeserializer = nullptr;
std::map<std::string, sol::object> mAPI;
struct LoadedData
{
std::map<int, Script> mScripts;
sol::table mPublicInterfaces;
std::map<std::string, EventHandlerList, std::less<>> mEventHandlers;
std::vector<Timer> mSimulationTimersQueue;
std::vector<Timer> mGameTimersQueue;
};
using UnloadedData = ESM::LuaScripts;
// Unloads the container to free resources held by the shared Lua state. This method serializes the container's
// state. The serialized data is automatically restored to the Lua state as required. Unloading and reloading
// the container is functionally equivalent to saving and loading the game, meaning the appropriate engine
// handlers are invoked.
UnloadedData& ensureUnloaded(LuaView& lua);
LoadedData& ensureLoaded();
EngineHandlerList mUpdateHandlers{ "onUpdate" };
std::map<std::string_view, EngineHandlerList*> mEngineHandlers;
std::variant<UnloadedData, LoadedData> mData;
int64_t mTemporaryCallbackCounter = 0;
std::map<int, int64_t> mRemovedScriptsMemoryUsage;
using WeakPtr = std::shared_ptr<ScriptsContainer*>;
WeakPtr mThis; // used by LuaState to track ownership of memory allocations
ScriptTracker* mTracker;
bool mRequiredLoading = false;
friend class ScriptTracker;
static int64_t sInstanceCount; // debug information, shown in Lua profiler
};
}
#endif // COMPONENTS_LUA_SCRIPTSCONTAINER_H
| 14,131
|
C++
|
.h
| 254
| 46.586614
| 120
| 0.659842
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,925
|
serialization.hpp
|
OpenMW_openmw/components/lua/serialization.hpp
|
#ifndef COMPONENTS_LUA_SERIALIZATION_H
#define COMPONENTS_LUA_SERIALIZATION_H
#include <sol/sol.hpp>
#include <components/esm3/cellref.hpp>
namespace LuaUtil
{
// Note: it can contain \0
using BinaryData = std::string;
class UserdataSerializer
{
public:
virtual ~UserdataSerializer() {}
// Appends serialized sol::userdata to the end of BinaryData.
// Returns false if this type of userdata is not supported by this serializer.
virtual bool serialize(BinaryData&, const sol::userdata&) const = 0;
// Deserializes userdata of type "typeName" from binaryData. Should push the result on stack using
// sol::stack::push. Returns false if this type is not supported by this serializer.
virtual bool deserialize(std::string_view typeName, std::string_view binaryData, lua_State*) const = 0;
protected:
static void append(BinaryData&, std::string_view typeName, const void* data, size_t dataSize);
static constexpr std::string_view sRefNumTypeName = "o";
static void appendRefNum(BinaryData&, ESM::RefNum);
static ESM::RefNum loadRefNum(std::string_view data);
};
// Serializer that can load Lua data from content files and saved games, but doesn't depend on apps/openmw.
// Instead of LObject/GObject (that are defined in apps/openmw) it loads refnums directly as ESM::RefNum.
class BasicSerializer final : public UserdataSerializer
{
public:
BasicSerializer() = default;
explicit BasicSerializer(std::function<int(int)> adjustContentFileIndexFn)
: mAdjustContentFilesIndexFn(std::move(adjustContentFileIndexFn))
{
}
private:
bool serialize(LuaUtil::BinaryData& out, const sol::userdata& data) const override;
bool deserialize(std::string_view typeName, std::string_view binaryData, lua_State* lua) const override;
std::function<int(int)> mAdjustContentFilesIndexFn;
};
BinaryData serialize(const sol::object&, const UserdataSerializer* customSerializer = nullptr);
sol::object deserialize(lua_State* lua, std::string_view binaryData,
const UserdataSerializer* customSerializer = nullptr, bool readOnly = false);
}
#endif // COMPONENTS_LUA_SERIALIZATION_H
| 2,293
|
C++
|
.h
| 44
| 45.590909
| 112
| 0.720233
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,926
|
inputactions.hpp
|
OpenMW_openmw/components/lua/inputactions.hpp
|
#ifndef COMPONENTS_LUA_INPUTACTIONS
#define COMPONENTS_LUA_INPUTACTIONS
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include <sol/sol.hpp>
#include <components/lua/asyncpackage.hpp>
#include <components/lua/scriptscontainer.hpp>
#include <components/misc/algorithm.hpp>
namespace LuaUtil::InputAction
{
enum class Type
{
Boolean,
Number,
Range,
};
struct Info
{
std::string mKey;
Type mType;
std::string mL10n;
std::string mName;
std::string mDescription;
sol::main_object mDefaultValue;
};
class MultiTree
{
public:
using Node = size_t;
Node insert();
bool multiEdge(Node target, const std::vector<Node>& source);
size_t size() const { return mParents.size(); }
template <typename Function> // Function = void(Node)
void traverse(Function callback) const;
void clear()
{
mParents.clear();
mChildren.clear();
}
private:
std::vector<std::vector<Node>> mParents;
std::vector<std::vector<Node>> mChildren;
bool validateTree() const;
};
class Registry
{
public:
using ConstIterator = std::vector<Info>::const_iterator;
void insert(const Info& info);
size_t size() const { return mKeys.size(); }
std::optional<std::string> firstKey() const { return mKeys.empty() ? std::nullopt : std::optional(mKeys[0]); }
std::optional<std::string> nextKey(std::string_view key) const;
std::optional<Info> operator[](std::string_view actionKey);
bool bind(
std::string_view key, const LuaUtil::Callback& callback, const std::vector<std::string_view>& dependencies);
sol::object valueOfType(std::string_view key, Type type);
void update(double dt);
void registerHandler(std::string_view key, const LuaUtil::Callback& handler)
{
mHandlers[safeIdByKey(key)].push_back(handler);
}
void clear()
{
mKeys.clear();
mIds.clear();
mInfo.clear();
mHandlers.clear();
mBindings.clear();
mValues.clear();
mBindingTree.clear();
}
private:
using Id = MultiTree::Node;
Id safeIdByKey(std::string_view key);
struct Binding
{
LuaUtil::Callback mCallback;
std::vector<Id> mDependencies;
};
std::vector<std::string> mKeys;
std::unordered_map<std::string, Id, Misc::StringUtils::StringHash, std::equal_to<>> mIds;
std::vector<Info> mInfo;
std::vector<std::vector<LuaUtil::Callback>> mHandlers;
std::vector<std::vector<Binding>> mBindings;
std::vector<sol::object> mValues;
MultiTree mBindingTree;
};
}
namespace LuaUtil::InputTrigger
{
struct Info
{
std::string mKey;
std::string mL10n;
std::string mName;
std::string mDescription;
};
class Registry
{
public:
std::optional<std::string> firstKey() const
{
return mIds.empty() ? std::nullopt : std::optional(mIds.begin()->first);
}
std::optional<std::string> nextKey(std::string_view key) const
{
auto it = mIds.find(key);
if (it == mIds.end() || ++it == mIds.end())
return std::nullopt;
return it->first;
}
std::optional<Info> operator[](std::string_view key);
void insert(const Info& info);
void registerHandler(std::string_view key, const LuaUtil::Callback& callback);
void activate(std::string_view key);
void clear()
{
mInfo.clear();
mHandlers.clear();
mIds.clear();
}
private:
using Id = size_t;
Id safeIdByKey(std::string_view key);
std::unordered_map<std::string, Id, Misc::StringUtils::StringHash, std::equal_to<>> mIds;
std::vector<Info> mInfo;
std::vector<std::vector<LuaUtil::Callback>> mHandlers;
};
}
#endif // COMPONENTS_LUA_INPUTACTIONS
| 4,229
|
C++
|
.h
| 132
| 24
| 120
| 0.594118
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,927
|
configuration.hpp
|
OpenMW_openmw/components/lua/configuration.hpp
|
#ifndef COMPONENTS_LUA_CONFIGURATION_H
#define COMPONENTS_LUA_CONFIGURATION_H
#include <map>
#include <optional>
#include <components/esm/luascripts.hpp>
#include <components/esm3/refnum.hpp>
#include <components/vfs/pathutil.hpp>
namespace LuaUtil
{
using ScriptIdsWithInitializationData = std::map<int, std::string_view>;
class ScriptsConfiguration
{
public:
void init(ESM::LuaScriptsCfg);
size_t size() const { return mScripts.size(); }
const ESM::LuaScriptCfg& operator[](int id) const { return mScripts[id]; }
std::optional<int> findId(VFS::Path::NormalizedView path) const;
bool isCustomScript(int id) const { return mScripts[id].mFlags & ESM::LuaScriptCfg::sCustom; }
ScriptIdsWithInitializationData getMenuConf() const { return getConfByFlag(ESM::LuaScriptCfg::sMenu); }
ScriptIdsWithInitializationData getGlobalConf() const { return getConfByFlag(ESM::LuaScriptCfg::sGlobal); }
ScriptIdsWithInitializationData getPlayerConf() const { return getConfByFlag(ESM::LuaScriptCfg::sPlayer); }
ScriptIdsWithInitializationData getLocalConf(
uint32_t type, const ESM::RefId& recordId, ESM::RefNum refnum) const;
private:
ScriptIdsWithInitializationData getConfByFlag(ESM::LuaScriptCfg::Flags flag) const;
std::vector<ESM::LuaScriptCfg> mScripts;
std::map<VFS::Path::Normalized, int, std::less<>> mPathToIndex;
struct DetailedConf
{
int mScriptId;
bool mAttach;
std::string_view mInitializationData;
};
std::map<uint32_t, std::vector<int>> mScriptsPerType;
std::map<ESM::RefId, std::vector<DetailedConf>, std::less<>> mScriptsPerRecordId;
std::map<ESM::RefNum, std::vector<DetailedConf>> mScriptsPerRefNum;
};
// Parse ESM::LuaScriptsCfg from text and add to `cfg`.
void parseOMWScripts(ESM::LuaScriptsCfg& cfg, std::string_view data);
std::string scriptCfgToString(const ESM::LuaScriptCfg& script);
}
#endif // COMPONENTS_LUA_CONFIGURATION_H
| 2,084
|
C++
|
.h
| 42
| 42.833333
| 115
| 0.71337
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,928
|
utf8.hpp
|
OpenMW_openmw/components/lua/utf8.hpp
|
#ifndef COMPONENTS_LUA_UTF8_H
#define COMPONENTS_LUA_UTF8_H
#include <sol/sol.hpp>
namespace LuaUtf8
{
sol::table initUtf8Package(sol::state_view&);
}
#endif
| 165
|
C++
|
.h
| 8
| 18.75
| 49
| 0.779221
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,929
|
yamlloader.hpp
|
OpenMW_openmw/components/lua/yamlloader.hpp
|
#ifndef COMPONENTS_LUA_YAMLLOADER_H
#define COMPONENTS_LUA_YAMLLOADER_H
#include <iosfwd>
#include <string>
#include <sol/forward.hpp>
namespace LuaUtil
{
sol::object loadYaml(const std::string& input, const sol::state_view& lua);
sol::object loadYaml(std::istream& input, const sol::state_view& lua);
}
#endif // COMPONENTS_LUA_YAMLLOADER_H
| 355
|
C++
|
.h
| 11
| 30.090909
| 79
| 0.764012
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,930
|
asyncpackage.hpp
|
OpenMW_openmw/components/lua/asyncpackage.hpp
|
#ifndef COMPONENTS_LUA_ASYNCPACKAGE_H
#define COMPONENTS_LUA_ASYNCPACKAGE_H
#include "scriptscontainer.hpp"
namespace LuaUtil
{
struct AsyncPackageId
{
ScriptsContainer* mContainer;
int mScriptId;
sol::table mHiddenData;
};
sol::function getAsyncPackageInitializer(
lua_State* L, std::function<double()> simulationTimeFn, std::function<double()> gameTimeFn);
// Wrapper for a Lua function.
// Holds information about the script the function belongs to.
// Needed to prevent callback calls if the script was removed.
struct Callback
{
sol::main_protected_function mFunc;
sol::table mHiddenData; // same object as Script::mHiddenData in ScriptsContainer
static bool isLuaCallback(const sol::object&);
static Callback fromLua(const sol::table&);
static sol::table makeMetatable(lua_State* L);
static sol::table make(const AsyncPackageId& asyncId, sol::main_protected_function fn, sol::table metatable);
bool isValid() const { return mHiddenData[ScriptsContainer::sScriptIdKey] != sol::nil; }
template <typename... Args>
sol::object call(Args&&... args) const
{
sol::optional<ScriptId> scriptId = mHiddenData[ScriptsContainer::sScriptIdKey];
if (scriptId.has_value())
return LuaUtil::call(scriptId.value(), mFunc, std::forward<Args>(args)...);
else
Log(Debug::Debug) << "Ignored callback to the removed script "
<< mHiddenData.get<std::string>(ScriptsContainer::sScriptDebugNameKey);
return sol::nil;
}
template <typename... Args>
void tryCall(Args&&... args) const
{
try
{
this->call(std::forward<Args>(args)...);
}
catch (std::exception& e)
{
Log(Debug::Error) << "Error in callback: " << e.what();
}
}
};
}
#endif // COMPONENTS_LUA_ASYNCPACKAGE_H
| 2,064
|
C++
|
.h
| 51
| 31.27451
| 117
| 0.617456
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,931
|
l10n.hpp
|
OpenMW_openmw/components/lua/l10n.hpp
|
#ifndef COMPONENTS_LUA_L10N_H
#define COMPONENTS_LUA_L10N_H
#include <sol/sol.hpp>
namespace l10n
{
class Manager;
}
namespace LuaUtil
{
sol::function initL10nLoader(lua_State*, l10n::Manager* manager);
}
#endif // COMPONENTS_LUA_L10N_H
| 249
|
C++
|
.h
| 12
| 18.75
| 69
| 0.76824
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,932
|
luastate.hpp
|
OpenMW_openmw/components/lua/luastate.hpp
|
#ifndef COMPONENTS_LUA_LUASTATE_H
#define COMPONENTS_LUA_LUASTATE_H
#include <filesystem>
#include <map>
#include <typeinfo>
#include <sol/sol.hpp>
#include <components/vfs/pathutil.hpp>
#include "configuration.hpp"
namespace VFS
{
class Manager;
}
namespace LuaUtil
{
std::string getLuaVersion();
class ScriptsContainer;
struct ScriptId
{
ScriptsContainer* mContainer = nullptr;
int mIndex = -1; // index in LuaUtil::ScriptsConfiguration
};
struct LuaStateSettings
{
uint64_t mInstructionLimit = 0; // 0 is unlimited
uint64_t mMemoryLimit = 0; // 0 is unlimited
uint64_t mSmallAllocMaxSize = 1024 * 1024; // big default value efficiently disables memory tracking
bool mLogMemoryUsage = false;
};
class LuaState;
class LuaView
{
sol::state_view mSol;
LuaView(const LuaView&) = delete;
LuaView(lua_State* L)
: mSol(L)
{
}
public:
friend class LuaState;
// Returns underlying sol::state.
sol::state_view& sol() { return mSol; }
// A shortcut to create a new Lua table.
sol::table newTable() { return sol::table(mSol, sol::create); }
};
template <typename Key, typename Value>
sol::table tableFromPairs(lua_State* L, std::initializer_list<std::pair<Key, Value>> list)
{
sol::table res(L, sol::create);
for (const auto& [k, v] : list)
res[k] = v;
return res;
}
// Holds Lua state.
// Provides additional features:
// - Load scripts from the virtual filesystem;
// - Caching of loaded scripts;
// - Disable unsafe Lua functions;
// - Run every instance of every script in a separate sandbox;
// - Forbid any interactions between sandboxes except than via provided API;
// - Access to common read-only resources from different sandboxes;
// - Replace standard `require` with a safe version that allows to search
// Lua libraries (only source, no dll's) in the virtual filesystem;
// - Make `print` to add the script name to every message and
// write to the Log rather than directly to stdout;
class LuaState
{
public:
explicit LuaState(const VFS::Manager* vfs, const ScriptsConfiguration* conf,
const LuaStateSettings& settings = LuaStateSettings{});
LuaState(const LuaState&) = delete;
LuaState(LuaState&&) = delete;
// Pushing to the stack from outside a Lua context crashes the engine if no memory can be allocated to grow the
// stack
template <class Lambda>
[[nodiscard]] int invokeProtectedCall(Lambda&& f) const
{
if (!lua_checkstack(mSol.lua_state(), 2))
return LUA_ERRMEM;
lua_pushcfunction(mSol.lua_state(), [](lua_State* L) {
void* f = lua_touserdata(L, 1);
LuaView view(L);
(*static_cast<Lambda*>(f))(view);
return 0;
});
lua_pushlightuserdata(mSol.lua_state(), &f);
return lua_pcall(mSol.lua_state(), 1, 0, 0);
}
template <class Lambda>
void protectedCall(Lambda&& f) const
{
int result = invokeProtectedCall(std::forward<Lambda>(f));
switch (result)
{
case LUA_OK:
break;
case LUA_ERRMEM:
throw std::runtime_error("Lua error: out of memory");
case LUA_ERRRUN:
{
sol::optional<std::string> error = sol::stack::check_get<std::string>(mSol.lua_state());
if (error)
throw std::runtime_error(*error);
}
[[fallthrough]];
default:
throw std::runtime_error("Lua error: " + std::to_string(result));
}
}
// Note that constructing a sol::state_view is only safe from a Lua context. Use protectedCall to get one
lua_State* unsafeState() const { return mSol.lua_state(); }
// Can be used by a C++ function that is called from Lua to get the Lua traceback.
// Makes no sense if called not from Lua code.
// Note: It is a slow function, should be used for debug purposes only.
std::string debugTraceback() { return mSol["debug"]["traceback"]().get<std::string>(); }
// Registers a package that will be available from every sandbox via `require(name)`.
// The package can be either a sol::table with an API or a sol::function. If it is a function,
// it will be evaluated (once per sandbox) the first time when requested. If the package
// is a table, then `makeReadOnly` is applied to it automatically (but not to other tables it contains).
void addCommonPackage(std::string packageName, sol::object package);
// Creates a new sandbox, runs a script, and returns the result
// (the result is expected to be an interface of the script).
// Args:
// path: path to the script in the virtual filesystem;
// envName: sandbox name.
// packages: additional packages that should be available from the sandbox via `require`. Each package
// should be either a sol::table or a sol::function. If it is a function, it will be evaluated
// (once per sandbox) with the argument 'hiddenData' the first time when requested.
sol::protected_function_result runInNewSandbox(const VFS::Path::Normalized& path,
const std::string& envName = "unnamed", const std::map<std::string, sol::object>& packages = {},
const sol::object& hiddenData = sol::nil);
void dropScriptCache() { mCompiledScripts.clear(); }
const ScriptsConfiguration& getConfiguration() const { return *mConf; }
// Load internal Lua library. All libraries are loaded in one sandbox and shouldn't be exposed to scripts
// directly.
void addInternalLibSearchPath(const std::filesystem::path& path) { mLibSearchPaths.push_back(path); }
sol::function loadInternalLib(std::string_view libName);
sol::function loadFromVFS(const VFS::Path::Normalized& path);
sol::environment newInternalLibEnvironment();
uint64_t getTotalMemoryUsage() const { return mSol.memory_used(); }
uint64_t getSmallAllocMemoryUsage() const { return mSmallAllocMemoryUsage; }
uint64_t getMemoryUsageByScriptIndex(unsigned id) const
{
return id < mMemoryUsage.size() ? mMemoryUsage[id] : 0;
}
const LuaStateSettings& getSettings() const { return mSettings; }
// Note: Lua profiler can not be re-enabled after disabling.
static void disableProfiler() { sProfilerEnabled = false; }
static bool isProfilerEnabled() { return sProfilerEnabled; }
static sol::protected_function_result throwIfError(sol::protected_function_result&&);
private:
template <typename... Args>
friend sol::protected_function_result call(const sol::protected_function& fn, Args&&... args);
template <typename... Args>
friend sol::protected_function_result call(
ScriptId scriptId, const sol::protected_function& fn, Args&&... args);
sol::function loadScriptAndCache(const VFS::Path::Normalized& path);
static void countHook(lua_State* L, lua_Debug* ar);
static void* trackingAllocator(void* ud, void* ptr, size_t osize, size_t nsize);
lua_State* createLuaRuntime(LuaState* luaState);
struct AllocOwner
{
std::shared_ptr<ScriptsContainer*> mContainer;
int mScriptIndex;
};
const LuaStateSettings mSettings;
// Needed to track resource usage per script, must be initialized before mLuaHolder.
std::vector<ScriptId> mActiveScriptIdStack;
uint64_t mWatchdogInstructionCounter = 0;
std::map<void*, AllocOwner> mBigAllocOwners;
uint64_t mTotalMemoryUsage = 0;
uint64_t mSmallAllocMemoryUsage = 0;
std::vector<int64_t> mMemoryUsage;
class LuaStateHolder
{
public:
LuaStateHolder(lua_State* L)
: L(L)
{
sol::set_default_state(L);
}
~LuaStateHolder() { lua_close(L); }
LuaStateHolder(const LuaStateHolder&) = delete;
LuaStateHolder(LuaStateHolder&&) = delete;
lua_State* get() { return L; }
private:
lua_State* L;
};
// Must be declared before mSol and all sol-related objects. Then on exit it will be destructed the last.
LuaStateHolder mLuaHolder;
sol::state_view mSol;
const ScriptsConfiguration* mConf;
sol::table mSandboxEnv;
std::map<VFS::Path::Normalized, sol::bytecode> mCompiledScripts;
std::map<std::string, sol::object> mCommonPackages;
const VFS::Manager* mVFS;
std::vector<std::filesystem::path> mLibSearchPaths;
static bool sProfilerEnabled;
};
// LuaUtil::call should be used for every call of every Lua function.
// 1) It is a workaround for a bug in `sol`. See https://github.com/ThePhD/sol2/issues/1078
// 2) When called with ScriptId it tracks resource usage (scriptId refers to the script that is responsible for this
// call).
template <typename... Args>
sol::protected_function_result call(const sol::protected_function& fn, Args&&... args)
{
try
{
auto res = LuaState::throwIfError(fn(std::forward<Args>(args)...));
return res;
}
catch (std::exception&)
{
throw;
}
catch (...)
{
throw std::runtime_error("Unknown error");
}
}
// Lua must be initialized through LuaUtil::LuaState, otherwise this function will segfault.
template <typename... Args>
sol::protected_function_result call(ScriptId scriptId, const sol::protected_function& fn, Args&&... args)
{
LuaState* luaState = nullptr;
if (LuaState::sProfilerEnabled && scriptId.mContainer)
{
(void)lua_getallocf(fn.lua_state(), reinterpret_cast<void**>(&luaState));
luaState->mActiveScriptIdStack.push_back(scriptId);
luaState->mWatchdogInstructionCounter = 0;
}
try
{
auto res = LuaState::throwIfError(fn(std::forward<Args>(args)...));
if (luaState)
luaState->mActiveScriptIdStack.pop_back();
return res;
}
catch (std::exception&)
{
if (luaState)
luaState->mActiveScriptIdStack.pop_back();
throw;
}
catch (...)
{
if (luaState)
luaState->mActiveScriptIdStack.pop_back();
throw std::runtime_error("Unknown error");
}
}
// work around for a (likely) sol3 bug
// when the index meta method throws, simply calling table.get crashes instead of re-throwing the error
template <class Key>
sol::object safeGet(const sol::table& table, const Key& key)
{
auto index = table.traverse_raw_get<sol::optional<sol::main_protected_function>>(
sol::metatable_key, sol::meta_function::index);
if (index)
{
sol::protected_function_result result = index.value()(table, key);
if (result.valid())
return result.get<sol::object>();
else
throw result.get<sol::error>();
}
else
return table.raw_get<sol::object>(key);
}
// getFieldOrNil(table, "a", "b", "c") returns table["a"]["b"]["c"] or nil if some of the fields doesn't exist.
template <class... Str>
sol::object getFieldOrNil(const sol::object& table, std::string_view first, const Str&... str)
{
if (!table.is<sol::table>())
return sol::nil;
sol::object value = safeGet(table.as<sol::table>(), first);
if constexpr (sizeof...(str) == 0)
return value;
else
return getFieldOrNil(value, str...);
}
template <class... Str>
void setDeepField(sol::table& table, const sol::object& value, std::string_view first, const Str&... str)
{
if constexpr (sizeof...(str) == 0)
table[first] = value;
else
{
if (table[first] == sol::nil)
table[first] = sol::table(table.lua_state(), sol::create);
sol::table nextTable = table[first];
setDeepField(nextTable, value, str...);
}
}
// String representation of a Lua object. Should be used for debugging/logging purposes only.
std::string toString(const sol::object&);
namespace internal
{
std::string formatCastingError(const sol::object& obj, const std::type_info&);
}
template <class T>
decltype(auto) cast(const sol::object& obj)
{
if (!obj.is<T>())
throw std::runtime_error(internal::formatCastingError(obj, typeid(T)));
return obj.as<T>();
}
template <class T>
T getValueOrDefault(const sol::object& obj, const T& defaultValue)
{
if (obj == sol::nil)
return defaultValue;
return cast<T>(obj);
}
// Makes a table read only (when accessed from Lua) by wrapping it with an empty userdata.
// Needed to forbid any changes in common resources that can be accessed from different sandboxes.
// `strictIndex = true` replaces default `__index` with a strict version that throws an error if key is not found.
sol::table makeReadOnly(const sol::table&, bool strictIndex = false);
inline sol::table makeStrictReadOnly(const sol::table& tbl)
{
return makeReadOnly(tbl, true);
}
sol::table getMutableFromReadOnly(const sol::userdata&);
}
#endif // COMPONENTS_LUA_LUASTATE_H
| 14,168
|
C++
|
.h
| 324
| 34.564815
| 120
| 0.615691
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,933
|
util.hpp
|
OpenMW_openmw/components/lua/util.hpp
|
#ifndef COMPONENTS_LUA_UTIL_H
#define COMPONENTS_LUA_UTIL_H
#include <cstdint>
#include <string>
#include <sol/sol.hpp>
#include <components/esm/refid.hpp>
namespace LuaUtil
{
// Lua arrays index from 1
constexpr inline std::int64_t fromLuaIndex(std::int64_t i)
{
return i - 1;
}
constexpr inline std::int64_t toLuaIndex(std::int64_t i)
{
return i + 1;
}
inline sol::optional<std::string> serializeRefId(ESM::RefId id)
{
if (id.empty())
return sol::nullopt;
return id.serializeText();
}
}
#endif
| 587
|
C++
|
.h
| 25
| 18.84
| 67
| 0.65045
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,934
|
box.hpp
|
OpenMW_openmw/components/lua/shapes/box.hpp
|
#ifndef COMPONENTS_LUA_SHAPES_BOX_H
#define COMPONENTS_LUA_SHAPES_BOX_H
#include <array>
#include <osg/Matrix>
#include <osg/Quat>
#include <osg/Vec3f>
namespace LuaUtil
{
class Box
{
public:
Box(const osg::Vec3f& center, const osg::Vec3f& halfSize, const osg::Quat& rotation = osg::Quat());
Box(const osg::Matrix& transform);
std::array<osg::Vec3f, 8> vertices() const;
osg::Matrix asTransform() const;
// TODO: Add `contains` and `intersects` methods
bool operator==(const Box& other) const;
osg::Vec3f mCenter;
osg::Vec3f mHalfSize;
osg::Quat mRotation;
};
}
#endif // COMPONENTS_LUA_SHAPES_BOX_H
| 696
|
C++
|
.h
| 23
| 25.086957
| 107
| 0.657143
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,935
|
file.hpp
|
OpenMW_openmw/components/vfs/file.hpp
|
#ifndef OPENMW_COMPONENTS_VFS_FILE_H
#define OPENMW_COMPONENTS_VFS_FILE_H
#include <filesystem>
#include <components/files/istreamptr.hpp>
namespace VFS
{
class File
{
public:
virtual ~File() = default;
virtual Files::IStreamPtr open() = 0;
virtual std::filesystem::path getPath() = 0;
};
}
#endif
| 344
|
C++
|
.h
| 15
| 18.866667
| 52
| 0.684211
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,936
|
pathutil.hpp
|
OpenMW_openmw/components/vfs/pathutil.hpp
|
#ifndef OPENMW_COMPONENTS_VFS_PATHUTIL_H
#define OPENMW_COMPONENTS_VFS_PATHUTIL_H
#include <components/misc/strings/lower.hpp>
#include <algorithm>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
namespace VFS::Path
{
inline constexpr char separator = '/';
inline constexpr char extensionSeparator = '.';
inline constexpr char normalize(char c)
{
return c == '\\' ? separator : Misc::StringUtils::toLower(c);
}
inline constexpr bool isNormalized(std::string_view name)
{
return std::all_of(name.begin(), name.end(), [](char v) { return v == normalize(v); });
}
inline void normalizeFilenameInPlace(auto begin, auto end)
{
std::transform(begin, end, begin, normalize);
}
inline void normalizeFilenameInPlace(std::string& name)
{
normalizeFilenameInPlace(name.begin(), name.end());
}
/// Normalize the given filename, making slashes/backslashes consistent, and lower-casing.
[[nodiscard]] inline std::string normalizeFilename(std::string_view name)
{
std::string out(name);
normalizeFilenameInPlace(out);
return out;
}
struct PathCharLess
{
bool operator()(char x, char y) const { return normalize(x) < normalize(y); }
};
inline bool pathLess(std::string_view x, std::string_view y)
{
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), PathCharLess());
}
inline bool pathEqual(std::string_view x, std::string_view y)
{
if (std::size(x) != std::size(y))
return false;
return std::equal(
std::begin(x), std::end(x), std::begin(y), [](char l, char r) { return normalize(l) == normalize(r); });
}
struct PathLess
{
using is_transparent = void;
bool operator()(std::string_view left, std::string_view right) const { return pathLess(left, right); }
};
inline constexpr auto findSeparatorOrExtensionSeparator(auto begin, auto end)
{
return std::find_if(begin, end, [](char v) { return v == extensionSeparator || v == separator; });
}
class Normalized;
class NormalizedView
{
public:
constexpr NormalizedView() noexcept = default;
constexpr explicit NormalizedView(const char* value)
: mValue(value)
{
if (!isNormalized(mValue))
throw std::invalid_argument("NormalizedView value is not normalized: \"" + std::string(mValue) + "\"");
}
NormalizedView(const Normalized& value) noexcept;
explicit NormalizedView(const std::string&) = delete;
explicit NormalizedView(std::string&&) = delete;
constexpr std::string_view value() const noexcept { return mValue; }
constexpr bool empty() const noexcept { return mValue.empty(); }
friend constexpr bool operator==(const NormalizedView& lhs, const NormalizedView& rhs) = default;
friend constexpr bool operator==(const NormalizedView& lhs, const auto& rhs) { return lhs.mValue == rhs; }
#if defined(_MSC_VER) && _MSC_VER <= 1935
friend constexpr bool operator==(const auto& lhs, const NormalizedView& rhs)
{
return lhs == rhs.mValue;
}
#endif
friend constexpr bool operator<(const NormalizedView& lhs, const NormalizedView& rhs)
{
return lhs.mValue < rhs.mValue;
}
friend constexpr bool operator<(const NormalizedView& lhs, const auto& rhs)
{
return lhs.mValue < rhs;
}
friend constexpr bool operator<(const auto& lhs, const NormalizedView& rhs)
{
return lhs < rhs.mValue;
}
friend std::ostream& operator<<(std::ostream& stream, const NormalizedView& value)
{
return stream << value.mValue;
}
private:
std::string_view mValue;
};
class Normalized
{
public:
Normalized() = default;
explicit Normalized(std::string_view value)
: mValue(normalizeFilename(value))
{
}
explicit Normalized(const char* value)
: Normalized(std::string_view(value))
{
}
Normalized(const std::string& value)
: Normalized(std::string_view(value))
{
}
explicit Normalized(std::string&& value)
: mValue(std::move(value))
{
normalizeFilenameInPlace(mValue);
}
explicit Normalized(NormalizedView value)
: mValue(value.value())
{
}
const std::string& value() const& { return mValue; }
std::string value() && { return std::move(mValue); }
std::string_view view() const { return mValue; }
bool empty() const { return mValue.empty(); }
operator std::string_view() const { return mValue; }
operator const std::string&() const { return mValue; }
bool changeExtension(std::string_view extension)
{
if (findSeparatorOrExtensionSeparator(extension.begin(), extension.end()) != extension.end())
throw std::invalid_argument("Invalid extension: " + std::string(extension));
const auto it = findSeparatorOrExtensionSeparator(mValue.rbegin(), mValue.rend());
if (it == mValue.rend() || *it == separator)
return false;
const std::string::difference_type pos = mValue.rend() - it;
mValue.replace(pos, mValue.size(), extension);
normalizeFilenameInPlace(mValue.begin() + pos, mValue.end());
return true;
}
void clear() { mValue.clear(); }
Normalized& operator=(NormalizedView value)
{
mValue = value.value();
return *this;
}
Normalized& operator/=(NormalizedView value)
{
mValue.reserve(mValue.size() + value.value().size() + 1);
mValue += separator;
mValue += value.value();
return *this;
}
Normalized& operator/=(std::string_view value)
{
mValue.reserve(mValue.size() + value.size() + 1);
mValue += separator;
const std::size_t offset = mValue.size();
mValue += value;
normalizeFilenameInPlace(mValue.begin() + offset, mValue.end());
return *this;
}
friend bool operator==(const Normalized& lhs, const Normalized& rhs) = default;
friend bool operator==(const Normalized& lhs, const auto& rhs) { return lhs.mValue == rhs; }
#if defined(_MSC_VER) && _MSC_VER <= 1935
friend bool operator==(const auto& lhs, const Normalized& rhs)
{
return lhs == rhs.mValue;
}
#endif
friend bool operator==(const Normalized& lhs, const NormalizedView& rhs)
{
return lhs.mValue == rhs.value();
}
friend bool operator<(const Normalized& lhs, const Normalized& rhs)
{
return lhs.mValue < rhs.mValue;
}
friend bool operator<(const Normalized& lhs, const auto& rhs)
{
return lhs.mValue < rhs;
}
friend bool operator<(const auto& lhs, const Normalized& rhs)
{
return lhs < rhs.mValue;
}
friend bool operator<(const Normalized& lhs, const NormalizedView& rhs)
{
return lhs.mValue < rhs.value();
}
friend bool operator<(const NormalizedView& lhs, const Normalized& rhs)
{
return lhs.value() < rhs.mValue;
}
friend std::ostream& operator<<(std::ostream& stream, const Normalized& value)
{
return stream << value.mValue;
}
private:
std::string mValue;
};
inline NormalizedView::NormalizedView(const Normalized& value) noexcept
: mValue(value.view())
{
}
inline Normalized operator/(NormalizedView lhs, NormalizedView rhs)
{
Normalized result(lhs);
result /= rhs;
return result;
}
struct Hash
{
using is_transparent = void;
[[nodiscard]] std::size_t operator()(std::string_view sv) const { return std::hash<std::string_view>{}(sv); }
[[nodiscard]] std::size_t operator()(const std::string& s) const { return std::hash<std::string>{}(s); }
[[nodiscard]] std::size_t operator()(const Normalized& s) const { return std::hash<std::string>{}(s.value()); }
[[nodiscard]] std::size_t operator()(NormalizedView s) const
{
return std::hash<std::string_view>{}(s.value());
}
};
// A special function to be removed once conversion to VFS::Path::Normalized* is complete
template <class T>
Normalized toNormalized(T&& value)
{
return Normalized(std::forward<T>(value));
}
}
#endif
| 8,963
|
C++
|
.h
| 235
| 29.553191
| 119
| 0.602933
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,937
|
bsaarchive.hpp
|
OpenMW_openmw/components/vfs/bsaarchive.hpp
|
#ifndef VFS_BSAARCHIVE_HPP_
#define VFS_BSAARCHIVE_HPP_
#include "archive.hpp"
#include "file.hpp"
#include "pathutil.hpp"
#include <components/bsa/ba2dx10file.hpp>
#include <components/bsa/ba2gnrlfile.hpp>
#include <components/bsa/bsa_file.hpp>
#include <components/bsa/compressedbsafile.hpp>
#include <algorithm>
#include <memory>
#include <stdexcept>
namespace VFS
{
template <typename FileType>
class BsaArchiveFile : public File
{
public:
BsaArchiveFile(const Bsa::BSAFile::FileStruct* info, FileType* bsa)
: mInfo(info)
, mFile(bsa)
{
}
Files::IStreamPtr open() override { return mFile->getFile(mInfo); }
std::filesystem::path getPath() override { return mInfo->name(); }
const Bsa::BSAFile::FileStruct* mInfo;
FileType* mFile;
};
template <typename BSAFileType>
class BsaArchive : public Archive
{
public:
BsaArchive(const std::filesystem::path& filename)
: Archive()
{
mFile = std::make_unique<BSAFileType>();
mFile->open(filename);
const Bsa::BSAFile::FileList& filelist = mFile->getList();
for (Bsa::BSAFile::FileList::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
{
mResources.emplace_back(&*it, mFile.get());
mFiles.emplace_back(it->name());
}
std::sort(mFiles.begin(), mFiles.end());
}
void listResources(FileMap& out) override
{
for (auto& resource : mResources)
out[VFS::Path::Normalized(resource.mInfo->name())] = &resource;
}
bool contains(Path::NormalizedView file) const override
{
return std::binary_search(mFiles.begin(), mFiles.end(), file);
}
std::string getDescription() const override { return std::string{ "BSA: " } + mFile->getFilename(); }
private:
std::unique_ptr<BSAFileType> mFile;
std::vector<BsaArchiveFile<BSAFileType>> mResources;
std::vector<VFS::Path::Normalized> mFiles;
};
inline std::unique_ptr<VFS::Archive> makeBsaArchive(const std::filesystem::path& path)
{
switch (Bsa::BSAFile::detectVersion(path))
{
case Bsa::BsaVersion::Unknown:
break;
case Bsa::BsaVersion::Uncompressed:
return std::make_unique<BsaArchive<Bsa::BSAFile>>(path);
case Bsa::BsaVersion::Compressed:
return std::make_unique<BsaArchive<Bsa::CompressedBSAFile>>(path);
case Bsa::BsaVersion::BA2GNRL:
return std::make_unique<BsaArchive<Bsa::BA2GNRLFile>>(path);
case Bsa::BsaVersion::BA2DX10:
return std::make_unique<BsaArchive<Bsa::BA2DX10File>>(path);
}
throw std::runtime_error("Unknown archive type '" + Files::pathToUnicodeString(path) + "'");
}
}
#endif
| 2,985
|
C++
|
.h
| 79
| 29.227848
| 109
| 0.613707
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,938
|
recursivedirectoryiterator.hpp
|
OpenMW_openmw/components/vfs/recursivedirectoryiterator.hpp
|
#ifndef OPENMW_COMPONENTS_VFS_RECURSIVEDIRECTORYITERATOR_H
#define OPENMW_COMPONENTS_VFS_RECURSIVEDIRECTORYITERATOR_H
#include <string>
#include "filemap.hpp"
#include "pathutil.hpp"
namespace VFS
{
class RecursiveDirectoryIterator
{
public:
RecursiveDirectoryIterator(FileMap::const_iterator it)
: mIt(it)
{
}
const Path::Normalized& operator*() const { return mIt->first; }
const Path::Normalized* operator->() const { return &mIt->first; }
RecursiveDirectoryIterator& operator++()
{
++mIt;
return *this;
}
friend bool operator==(const RecursiveDirectoryIterator& lhs, const RecursiveDirectoryIterator& rhs) = default;
private:
FileMap::const_iterator mIt;
};
class RecursiveDirectoryRange
{
public:
RecursiveDirectoryRange(RecursiveDirectoryIterator first, RecursiveDirectoryIterator last)
: mBegin(first)
, mEnd(last)
{
}
RecursiveDirectoryIterator begin() const { return mBegin; }
RecursiveDirectoryIterator end() const { return mEnd; }
private:
RecursiveDirectoryIterator mBegin;
RecursiveDirectoryIterator mEnd;
};
}
#endif
| 1,280
|
C++
|
.h
| 41
| 24.146341
| 119
| 0.668026
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,939
|
filesystemarchive.hpp
|
OpenMW_openmw/components/vfs/filesystemarchive.hpp
|
#ifndef OPENMW_COMPONENTS_RESOURCE_FILESYSTEMARCHIVE_H
#define OPENMW_COMPONENTS_RESOURCE_FILESYSTEMARCHIVE_H
#include "archive.hpp"
#include "file.hpp"
#include <filesystem>
#include <string>
namespace VFS
{
class FileSystemArchiveFile : public File
{
public:
FileSystemArchiveFile(const std::filesystem::path& path);
Files::IStreamPtr open() override;
std::filesystem::path getPath() override { return mPath; }
private:
std::filesystem::path mPath;
};
class FileSystemArchive : public Archive
{
public:
FileSystemArchive(const std::filesystem::path& path);
void listResources(FileMap& out) override;
bool contains(Path::NormalizedView file) const override;
std::string getDescription() const override;
private:
std::map<VFS::Path::Normalized, FileSystemArchiveFile, std::less<>> mIndex;
std::filesystem::path mPath;
};
}
#endif
| 964
|
C++
|
.h
| 30
| 26.666667
| 83
| 0.706522
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,940
|
filemap.hpp
|
OpenMW_openmw/components/vfs/filemap.hpp
|
#ifndef OPENMW_COMPONENTS_VFS_FILEMAP_H
#define OPENMW_COMPONENTS_VFS_FILEMAP_H
#include <map>
#include <string>
namespace VFS
{
class File;
namespace Path
{
class Normalized;
}
using FileMap = std::map<Path::Normalized, File*, std::less<>>;
}
#endif
| 284
|
C++
|
.h
| 14
| 16.928571
| 67
| 0.701887
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
35,941
|
manager.hpp
|
OpenMW_openmw/components/vfs/manager.hpp
|
#ifndef OPENMW_COMPONENTS_RESOURCEMANAGER_H
#define OPENMW_COMPONENTS_RESOURCEMANAGER_H
#include <components/files/istreamptr.hpp>
#include <filesystem>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "filemap.hpp"
#include "pathutil.hpp"
namespace VFS
{
class Archive;
class RecursiveDirectoryRange;
/// @brief The main class responsible for loading files from a virtual file system.
/// @par Various archive types (e.g. directories on the filesystem, or compressed archives)
/// can be registered, and will be merged into a single file tree. If the same filename is
/// contained in multiple archives, the last added archive will have priority.
/// @par Most of the methods in this class are considered thread-safe, see each method documentation for details.
class Manager
{
public:
Manager();
~Manager();
// Empty the file index and unregister archives.
void reset();
/// Register the given archive. All files contained in it will be added to the index on the next buildIndex()
/// call.
void addArchive(std::unique_ptr<Archive>&& archive);
/// Build the file index. Should be called when all archives have been registered.
void buildIndex();
/// Does a file with this name exist?
/// @note May be called from any thread once the index has been built.
bool exists(const Path::Normalized& name) const;
bool exists(Path::NormalizedView name) const;
// Returns open file if exists or nullptr.
Files::IStreamPtr find(Path::NormalizedView name) const;
/// Retrieve a file by name.
/// @note Throws an exception if the file can not be found.
/// @note May be called from any thread once the index has been built.
Files::IStreamPtr get(const Path::Normalized& name) const;
Files::IStreamPtr get(Path::NormalizedView name) const;
/// Retrieve a file by name (name is already normalized).
/// @note Throws an exception if the file can not be found.
/// @note May be called from any thread once the index has been built.
Files::IStreamPtr getNormalized(std::string_view normalizedName) const;
std::string getArchive(const Path::Normalized& name) const;
/// Recursively iterate over the elements of the given path
/// In practice it return all files of the VFS starting with the given path
/// @note the path is normalized
/// @note May be called from any thread once the index has been built.
RecursiveDirectoryRange getRecursiveDirectoryIterator(std::string_view path) const;
RecursiveDirectoryRange getRecursiveDirectoryIterator(VFS::Path::NormalizedView path) const;
RecursiveDirectoryRange getRecursiveDirectoryIterator() const;
/// Retrieve the absolute path to the file
/// @note Throws an exception if the file can not be found.
/// @note May be called from any thread once the index has been built.
std::filesystem::path getAbsoluteFileName(const std::filesystem::path& name) const;
private:
std::vector<std::unique_ptr<Archive>> mArchives;
FileMap mIndex;
inline Files::IStreamPtr findNormalized(std::string_view normalizedPath) const;
};
}
#endif
| 3,373
|
C++
|
.h
| 65
| 44.969231
| 117
| 0.702406
|
OpenMW/openmw
| 5,318
| 933
| 0
|
GPL-3.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.