Skip to content

Commit

Permalink
Merge branch 'sizedreads' into 'master'
Browse files Browse the repository at this point in the history
Replace more sized reads

See merge request OpenMW/openmw!3425
  • Loading branch information
psi29a committed Sep 15, 2023
2 parents 64e4a33 + b59739a commit 59f8034
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 152 deletions.
10 changes: 2 additions & 8 deletions apps/esmtool/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,8 @@ namespace EsmTool
std::cout << " Level: " << mData.mData.mLevel << std::endl;

std::cout << " Attributes:" << std::endl;
std::cout << " Strength: " << mData.mData.mStrength << std::endl;
std::cout << " Intelligence: " << mData.mData.mIntelligence << std::endl;
std::cout << " Willpower: " << mData.mData.mWillpower << std::endl;
std::cout << " Agility: " << mData.mData.mAgility << std::endl;
std::cout << " Speed: " << mData.mData.mSpeed << std::endl;
std::cout << " Endurance: " << mData.mData.mEndurance << std::endl;
std::cout << " Personality: " << mData.mData.mPersonality << std::endl;
std::cout << " Luck: " << mData.mData.mLuck << std::endl;
for (size_t i = 0; i < mData.mData.mAttributes.size(); ++i)
std::cout << " " << ESM::Attribute::indexToRefId(i) << ": " << mData.mData.mAttributes[i] << std::endl;

std::cout << " Health: " << mData.mData.mHealth << std::endl;
std::cout << " Magicka: " << mData.mData.mMana << std::endl;
Expand Down
22 changes: 6 additions & 16 deletions apps/opencs/model/tools/referenceablecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,22 +456,12 @@ void CSMTools::ReferenceableCheckStage::creatureCheck(
if (creature.mData.mLevel <= 0)
messages.add(id, "Level is non-positive", "", CSMDoc::Message::Severity_Warning);

if (creature.mData.mStrength < 0)
messages.add(id, "Strength is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mIntelligence < 0)
messages.add(id, "Intelligence is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mWillpower < 0)
messages.add(id, "Willpower is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mAgility < 0)
messages.add(id, "Agility is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mSpeed < 0)
messages.add(id, "Speed is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mEndurance < 0)
messages.add(id, "Endurance is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mPersonality < 0)
messages.add(id, "Personality is negative", "", CSMDoc::Message::Severity_Warning);
if (creature.mData.mLuck < 0)
messages.add(id, "Luck is negative", "", CSMDoc::Message::Severity_Warning);
for (size_t i = 0; i < creature.mData.mAttributes.size(); ++i)
{
if (creature.mData.mAttributes[i] < 0)
messages.add(id, ESM::Attribute::indexToRefId(i).toDebugString() + " is negative", {},
CSMDoc::Message::Severity_Warning);
}

if (creature.mData.mCombat < 0)
messages.add(id, "Combat is negative", "", CSMDoc::Message::Severity_Warning);
Expand Down
69 changes: 10 additions & 59 deletions apps/opencs/model/world/refidadapterimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,73 +1315,24 @@ QVariant CSMWorld::CreatureAttributesRefIdAdapter::getNestedData(

if (subColIndex == 0)
return subRowIndex;
else if (subColIndex == 1)
switch (subRowIndex)
{
case 0:
return creature.mData.mStrength;
case 1:
return creature.mData.mIntelligence;
case 2:
return creature.mData.mWillpower;
case 3:
return creature.mData.mAgility;
case 4:
return creature.mData.mSpeed;
case 5:
return creature.mData.mEndurance;
case 6:
return creature.mData.mPersonality;
case 7:
return creature.mData.mLuck;
default:
return QVariant(); // throw an exception here?
}
else
return QVariant(); // throw an exception here?
else if (subColIndex == 1 && subRowIndex > 0 && subRowIndex < ESM::Attribute::Length)
return creature.mData.mAttributes[subRowIndex];
return QVariant(); // throw an exception here?
}

void CSMWorld::CreatureAttributesRefIdAdapter::setNestedData(
const RefIdColumn* column, RefIdData& data, int row, const QVariant& value, int subRowIndex, int subColIndex) const
{
Record<ESM::Creature>& record
= static_cast<Record<ESM::Creature>&>(data.getRecord(RefIdData::LocalIndex(row, UniversalId::Type_Creature)));
ESM::Creature creature = record.get();

if (subColIndex == 1)
switch (subRowIndex)
{
case 0:
creature.mData.mStrength = value.toInt();
break;
case 1:
creature.mData.mIntelligence = value.toInt();
break;
case 2:
creature.mData.mWillpower = value.toInt();
break;
case 3:
creature.mData.mAgility = value.toInt();
break;
case 4:
creature.mData.mSpeed = value.toInt();
break;
case 5:
creature.mData.mEndurance = value.toInt();
break;
case 6:
creature.mData.mPersonality = value.toInt();
break;
case 7:
creature.mData.mLuck = value.toInt();
break;
default:
return; // throw an exception here?
}
else
return; // throw an exception here?

record.setModified(creature);
if (subColIndex == 1 && subRowIndex > 0 && subRowIndex < ESM::Attribute::Length)
{
ESM::Creature creature = record.get();
creature.mData.mAttributes[subRowIndex] = value.toInt();
record.setModified(creature);
}
// throw an exception here?
}

int CSMWorld::CreatureAttributesRefIdAdapter::getNestedColumnsCount(
Expand Down
10 changes: 2 additions & 8 deletions apps/openmw/mwclass/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,8 @@ namespace MWClass
MWWorld::LiveCellRef<ESM::Creature>* ref = ptr.get<ESM::Creature>();

// creature stats
data->mCreatureStats.setAttribute(ESM::Attribute::Strength, ref->mBase->mData.mStrength);
data->mCreatureStats.setAttribute(ESM::Attribute::Intelligence, ref->mBase->mData.mIntelligence);
data->mCreatureStats.setAttribute(ESM::Attribute::Willpower, ref->mBase->mData.mWillpower);
data->mCreatureStats.setAttribute(ESM::Attribute::Agility, ref->mBase->mData.mAgility);
data->mCreatureStats.setAttribute(ESM::Attribute::Speed, ref->mBase->mData.mSpeed);
data->mCreatureStats.setAttribute(ESM::Attribute::Endurance, ref->mBase->mData.mEndurance);
data->mCreatureStats.setAttribute(ESM::Attribute::Personality, ref->mBase->mData.mPersonality);
data->mCreatureStats.setAttribute(ESM::Attribute::Luck, ref->mBase->mData.mLuck);
for (size_t i = 0; i < ref->mBase->mData.mAttributes.size(); ++i)
data->mCreatureStats.setAttribute(ESM::Attribute::indexToRefId(i), ref->mBase->mData.mAttributes[i]);
data->mCreatureStats.setHealth(static_cast<float>(ref->mBase->mData.mHealth));
data->mCreatureStats.setMagicka(static_cast<float>(ref->mBase->mData.mMana));
data->mCreatureStats.setFatigue(static_cast<float>(ref->mBase->mData.mFatigue));
Expand Down
4 changes: 2 additions & 2 deletions components/esm3/loadcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace ESM
mName = esm.getHString();
break;
case fourCC("DATA"):
esm.getHTSized<12>(mData);
esm.getHT(mData.mFlags, mData.mX, mData.mY);
hasData = true;
break;
case SREC_DELE:
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace ESM
mWater = waterLevel;
break;
case fourCC("AMBI"):
esm.getHTSized<16>(mAmbi);
esm.getHT(mAmbi.mAmbient, mAmbi.mSunlight, mAmbi.mFog, mAmbi.mFogDensity);
mHasAmbi = true;
break;
case fourCC("RGNN"):
Expand Down
8 changes: 4 additions & 4 deletions components/esm3/loadcell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ namespace ESM

struct DATAstruct
{
int mFlags{ 0 };
int mX{ 0 }, mY{ 0 };
int32_t mFlags{ 0 };
int32_t mX{ 0 }, mY{ 0 };
};

struct AMBIstruct
Expand Down Expand Up @@ -132,11 +132,11 @@ namespace ESM

float mWater; // Water level
bool mWaterInt;
int mMapColor;
int32_t mMapColor;
// Counter for RefNums. This is only used during content file editing and has no impact on gameplay.
// It prevents overwriting previous refNums, even if they were deleted.
// as that would collide with refs when a content file is upgraded.
int mRefNumCounter;
int32_t mRefNumCounter;

// References "leased" from another cell (i.e. a different cell
// introduced this ref, and it has been moved here by a plugin)
Expand Down
6 changes: 3 additions & 3 deletions components/esm3/loadcrea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace ESM
mScript = esm.getRefId();
break;
case fourCC("NPDT"):
esm.getHTSized<96>(mData);
esm.getHT(mData.mType, mData.mLevel, mData.mAttributes, mData.mHealth, mData.mMana, mData.mFatigue,
mData.mSoul, mData.mCombat, mData.mMagic, mData.mStealth, mData.mAttack, mData.mGold);
hasNpdt = true;
break;
case fourCC("FLAG"):
Expand Down Expand Up @@ -139,8 +140,7 @@ namespace ESM
mRecordFlags = 0;
mData.mType = 0;
mData.mLevel = 0;
mData.mStrength = mData.mIntelligence = mData.mWillpower = mData.mAgility = mData.mSpeed = mData.mEndurance
= mData.mPersonality = mData.mLuck = 0;
mData.mAttributes.fill(0);
mData.mHealth = mData.mMana = mData.mFatigue = 0;
mData.mSoul = 0;
mData.mCombat = mData.mMagic = mData.mStealth = 0;
Expand Down
22 changes: 12 additions & 10 deletions components/esm3/loadcrea.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#ifndef OPENMW_ESM_CREA_H
#define OPENMW_ESM_CREA_H

#include <array>
#include <string>

#include "aipackage.hpp"
#include "loadcont.hpp"
#include "spelllist.hpp"
#include "transport.hpp"

#include "components/esm/attr.hpp"
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"

Expand Down Expand Up @@ -52,30 +54,30 @@ namespace ESM

struct NPDTstruct
{
int mType;
int32_t mType;
// For creatures we obviously have to use ints, not shorts and
// bytes like we use for NPCs.... this file format just makes so
// much sense! (Still, _much_ easier to decode than the NIFs.)
int mLevel;
int mStrength, mIntelligence, mWillpower, mAgility, mSpeed, mEndurance, mPersonality, mLuck;
int32_t mLevel;
std::array<int32_t, Attribute::Length> mAttributes;

int mHealth, mMana, mFatigue; // Stats
int mSoul; // The creatures soul value (used with soul gems.)
int32_t mHealth, mMana, mFatigue; // Stats
int32_t mSoul; // The creatures soul value (used with soul gems.)
// Creatures have generalized combat, magic and stealth stats which substitute for
// the specific skills (in the same way as specializations).
int mCombat, mMagic, mStealth;
int mAttack[6]; // AttackMin1, AttackMax1, ditto2, ditto3
int mGold;
int32_t mCombat, mMagic, mStealth;
int32_t mAttack[6]; // AttackMin1, AttackMax1, ditto2, ditto3
int32_t mGold;
}; // 96 byte

NPDTstruct mData;

int mBloodType;
int32_t mBloodType;
unsigned char mFlags;

float mScale;

unsigned int mRecordFlags;
uint32_t mRecordFlags;
RefId mId, mScript;
std::string mModel;
std::string mName;
Expand Down
20 changes: 10 additions & 10 deletions components/esm3/loadfact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace ESM
{
int& Faction::FADTstruct::getSkill(int index, bool)
int32_t& Faction::FADTstruct::getSkill(size_t index, bool)
{
return mSkills.at(index);
}

int Faction::FADTstruct::getSkill(int index, bool) const
int32_t Faction::FADTstruct::getSkill(size_t index, bool) const
{
return mSkills.at(index);
}
Expand All @@ -23,10 +23,10 @@ namespace ESM
mRecordFlags = esm.getRecordFlags();

mReactions.clear();
for (int i = 0; i < 10; ++i)
mRanks[i].clear();
for (auto& rank : mRanks)
rank.clear();

int rankCounter = 0;
size_t rankCounter = 0;
bool hasName = false;
bool hasData = false;
while (esm.hasMoreSubs())
Expand All @@ -42,7 +42,7 @@ namespace ESM
mName = esm.getHString();
break;
case fourCC("RNAM"):
if (rankCounter >= 10)
if (rankCounter >= mRanks.size())
esm.fail("Rank out of range");
mRanks[rankCounter++] = esm.getHString();
break;
Expand All @@ -55,7 +55,7 @@ namespace ESM
case fourCC("ANAM"):
{
ESM::RefId faction = esm.getRefId();
int reaction;
int32_t reaction;
esm.getHNT(reaction, "INTV");
// Prefer the lowest reaction in case a faction is listed multiple times
auto it = mReactions.find(faction);
Expand Down Expand Up @@ -93,12 +93,12 @@ namespace ESM

esm.writeHNOCString("FNAM", mName);

for (int i = 0; i < 10; i++)
for (const auto& rank : mRanks)
{
if (mRanks[i].empty())
if (rank.empty())
break;

esm.writeHNString("RNAM", mRanks[i], 32);
esm.writeHNString("RNAM", rank, 32);
}

esm.writeHNT("FADT", mData, 240);
Expand Down
22 changes: 11 additions & 11 deletions components/esm3/loadfact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ namespace ESM
// Requirements for each rank
struct RankData
{
int mAttribute1, mAttribute2; // Attribute level
int32_t mAttribute1, mAttribute2; // Attribute level

// Skill level (faction skills given in
// skillID below.) You need one skill at
// level 'mPrimarySkill' and two skills at level
// 'mFavouredSkill' to advance to this rank.
int mPrimarySkill, mFavouredSkill;
int32_t mPrimarySkill, mFavouredSkill;

int mFactReaction; // Reaction from faction members
int32_t mFactReaction; // Reaction from faction members
};

struct Faction
Expand All @@ -39,33 +39,33 @@ namespace ESM
/// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string_view getRecordType() { return "Faction"; }

unsigned int mRecordFlags;
uint32_t mRecordFlags;
std::string mName;
RefId mId;

struct FADTstruct
{
// Which attributes we like
std::array<int, 2> mAttribute;
std::array<int32_t, 2> mAttribute;

std::array<RankData, 10> mRankData;

std::array<int, 7> mSkills; // IDs of skills this faction require
// Each element will either contain an Skill index, or -1.
std::array<int32_t, 7> mSkills; // IDs of skills this faction require
// Each element will either contain an Skill index, or -1.

int mIsHidden; // 1 - hidden from player
int32_t mIsHidden; // 1 - hidden from player

int& getSkill(int index, bool ignored = false);
int32_t& getSkill(size_t index, bool ignored = false);
///< Throws an exception for invalid values of \a index.

int getSkill(int index, bool ignored = false) const;
int32_t getSkill(size_t index, bool ignored = false) const;
///< Throws an exception for invalid values of \a index.
}; // 240 bytes

FADTstruct mData;

// <Faction ID, Reaction>
std::map<ESM::RefId, int> mReactions;
std::map<ESM::RefId, int32_t> mReactions;

// Name of faction ranks (may be empty for NPC factions)
std::array<std::string, 10> mRanks;
Expand Down
Loading

0 comments on commit 59f8034

Please sign in to comment.