Merge branch 'downsized' into 'master'

Remove explicitly sized reads

See merge request OpenMW/openmw!3663
This commit is contained in:
jvoisin 2023-12-21 22:50:10 +00:00
commit 2873f971a6
55 changed files with 395 additions and 437 deletions

View file

@ -41,17 +41,17 @@ void CSMTools::RaceCheckStage::performPerRecord(int stage, CSMDoc::Messages& mes
messages.add(id, "Description is missing", "", CSMDoc::Message::Severity_Warning);
// test for positive height
if (race.mData.mHeight.mMale <= 0)
if (race.mData.mMaleHeight <= 0)
messages.add(id, "Male height is non-positive", "", CSMDoc::Message::Severity_Error);
if (race.mData.mHeight.mFemale <= 0)
if (race.mData.mFemaleHeight <= 0)
messages.add(id, "Female height is non-positive", "", CSMDoc::Message::Severity_Error);
// test for non-negative weight
if (race.mData.mWeight.mMale < 0)
if (race.mData.mMaleWeight < 0)
messages.add(id, "Male weight is negative", "", CSMDoc::Message::Severity_Error);
if (race.mData.mWeight.mFemale < 0)
if (race.mData.mFemaleWeight < 0)
messages.add(id, "Female weight is negative", "", CSMDoc::Message::Severity_Error);
/// \todo check data members that can't be edited in the table view

View file

@ -693,22 +693,12 @@ void CSMTools::ReferenceableCheckStage::npcCheck(
}
else if (npc.mNpdt.mHealth != 0)
{
if (npc.mNpdt.mStrength == 0)
messages.add(id, "Strength is equal to zero", "", CSMDoc::Message::Severity_Warning);
if (npc.mNpdt.mIntelligence == 0)
messages.add(id, "Intelligence is equal to zero", "", CSMDoc::Message::Severity_Warning);
if (npc.mNpdt.mWillpower == 0)
messages.add(id, "Willpower is equal to zero", "", CSMDoc::Message::Severity_Warning);
if (npc.mNpdt.mAgility == 0)
messages.add(id, "Agility is equal to zero", "", CSMDoc::Message::Severity_Warning);
if (npc.mNpdt.mSpeed == 0)
messages.add(id, "Speed is equal to zero", "", CSMDoc::Message::Severity_Warning);
if (npc.mNpdt.mEndurance == 0)
messages.add(id, "Endurance is equal to zero", "", CSMDoc::Message::Severity_Warning);
if (npc.mNpdt.mPersonality == 0)
messages.add(id, "Personality is equal to zero", "", CSMDoc::Message::Severity_Warning);
if (npc.mNpdt.mLuck == 0)
messages.add(id, "Luck is equal to zero", "", CSMDoc::Message::Severity_Warning);
for (size_t i = 0; i < npc.mNpdt.mAttributes.size(); ++i)
{
if (npc.mNpdt.mAttributes[i] == 0)
messages.add(id, ESM::Attribute::indexToRefId(i).getRefIdString() + " is equal to zero", {},
CSMDoc::Message::Severity_Warning);
}
}
if (level <= 0)

View file

@ -570,19 +570,34 @@ namespace CSMWorld
QVariant get(const Record<ESXRecordT>& record) const override
{
const ESM::Race::MaleFemaleF& value = mWeight ? record.get().mData.mWeight : record.get().mData.mHeight;
return mMale ? value.mMale : value.mFemale;
if (mWeight)
{
if (mMale)
return record.get().mData.mMaleWeight;
return record.get().mData.mFemaleWeight;
}
if (mMale)
return record.get().mData.mMaleHeight;
return record.get().mData.mFemaleHeight;
}
void set(Record<ESXRecordT>& record, const QVariant& data) override
{
ESXRecordT record2 = record.get();
ESM::Race::MaleFemaleF& value = mWeight ? record2.mData.mWeight : record2.mData.mHeight;
(mMale ? value.mMale : value.mFemale) = data.toFloat();
if (mWeight)
{
if (mMale)
record2.mData.mMaleWeight = data.toFloat();
else
record2.mData.mFemaleWeight = data.toFloat();
}
else
{
if (mMale)
record2.mData.mMaleHeight = data.toFloat();
else
record2.mData.mFemaleHeight = data.toFloat();
}
record.setModified(record2);
}

View file

@ -741,8 +741,8 @@ namespace CSMWorld
QVariant RaceAttributeAdapter::getData(const Record<ESM::Race>& record, int subRowIndex, int subColIndex) const
{
ESM::Race race = record.get();
if (subRowIndex < 0 || subRowIndex >= ESM::Attribute::Length)
ESM::RefId attribute = ESM::Attribute::indexToRefId(subRowIndex);
if (attribute.empty())
throw std::runtime_error("index out of range");
switch (subColIndex)
@ -750,9 +750,9 @@ namespace CSMWorld
case 0:
return subRowIndex;
case 1:
return race.mData.mAttributeValues[subRowIndex].mMale;
return race.mData.getAttribute(attribute, true);
case 2:
return race.mData.mAttributeValues[subRowIndex].mFemale;
return race.mData.getAttribute(attribute, false);
default:
throw std::runtime_error("Race Attribute subcolumn index out of range");
}
@ -762,8 +762,8 @@ namespace CSMWorld
Record<ESM::Race>& record, const QVariant& value, int subRowIndex, int subColIndex) const
{
ESM::Race race = record.get();
if (subRowIndex < 0 || subRowIndex >= ESM::Attribute::Length)
ESM::RefId attribute = ESM::Attribute::indexToRefId(subRowIndex);
if (attribute.empty())
throw std::runtime_error("index out of range");
switch (subColIndex)
@ -771,10 +771,10 @@ namespace CSMWorld
case 0:
return; // throw an exception here?
case 1:
race.mData.mAttributeValues[subRowIndex].mMale = value.toInt();
race.mData.setAttribute(attribute, true, value.toInt());
break;
case 2:
race.mData.mAttributeValues[subRowIndex].mFemale = value.toInt();
race.mData.setAttribute(attribute, false, value.toInt());
break;
default:
throw std::runtime_error("Race Attribute subcolumn index out of range");

View file

@ -938,30 +938,9 @@ QVariant CSMWorld::NpcAttributesRefIdAdapter::getNestedData(
if (subColIndex == 0)
return subRowIndex;
else if (subColIndex == 1)
switch (subRowIndex)
{
case 0:
return static_cast<int>(npcStruct.mStrength);
case 1:
return static_cast<int>(npcStruct.mIntelligence);
case 2:
return static_cast<int>(npcStruct.mWillpower);
case 3:
return static_cast<int>(npcStruct.mAgility);
case 4:
return static_cast<int>(npcStruct.mSpeed);
case 5:
return static_cast<int>(npcStruct.mEndurance);
case 6:
return static_cast<int>(npcStruct.mPersonality);
case 7:
return static_cast<int>(npcStruct.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 static_cast<int>(npcStruct.mAttributes[subRowIndex]);
return QVariant(); // throw an exception here?
}
void CSMWorld::NpcAttributesRefIdAdapter::setNestedData(
@ -972,36 +951,8 @@ void CSMWorld::NpcAttributesRefIdAdapter::setNestedData(
ESM::NPC npc = record.get();
ESM::NPC::NPDTstruct52& npcStruct = npc.mNpdt;
if (subColIndex == 1)
switch (subRowIndex)
{
case 0:
npcStruct.mStrength = static_cast<unsigned char>(value.toInt());
break;
case 1:
npcStruct.mIntelligence = static_cast<unsigned char>(value.toInt());
break;
case 2:
npcStruct.mWillpower = static_cast<unsigned char>(value.toInt());
break;
case 3:
npcStruct.mAgility = static_cast<unsigned char>(value.toInt());
break;
case 4:
npcStruct.mSpeed = static_cast<unsigned char>(value.toInt());
break;
case 5:
npcStruct.mEndurance = static_cast<unsigned char>(value.toInt());
break;
case 6:
npcStruct.mPersonality = static_cast<unsigned char>(value.toInt());
break;
case 7:
npcStruct.mLuck = static_cast<unsigned char>(value.toInt());
break;
default:
return; // throw an exception here?
}
if (subColIndex == 1 && subRowIndex >= 0 && subRowIndex < ESM::Attribute::Length)
npcStruct.mAttributes[subRowIndex] = static_cast<unsigned char>(value.toInt());
else
return; // throw an exception here?