Get rid of some templates, exceptions instead of assert, and other small changes.

new-script-api
Kyle Cooley 7 years ago
parent 2abf7f1752
commit 50d9d9f78f

@ -1,7 +1,80 @@
#include "columnimp.hpp"
#include <stdexcept>
namespace CSMWorld
{
/* LandTextureNicknameColumn */
LandTextureNicknameColumn::LandTextureNicknameColumn()
: Column<LandTexture>(Columns::ColumnId_TextureNickname, ColumnBase::Display_String)
{
}
QVariant LandTextureNicknameColumn::get(const Record<LandTexture>& record) const
{
return QString::fromUtf8(record.get().mId.c_str());
}
void LandTextureNicknameColumn::set(Record<LandTexture>& record, const QVariant& data)
{
LandTexture copy = record.get();
copy.mId = data.toString().toUtf8().constData();
record.setModified(copy);
}
bool LandTextureNicknameColumn::isEditable() const
{
return true;
}
/* LandTextureIndexColumn */
LandTextureIndexColumn::LandTextureIndexColumn()
: Column<LandTexture>(Columns::ColumnId_TextureIndex, ColumnBase::Display_Integer)
{
}
QVariant LandTextureIndexColumn::get(const Record<LandTexture>& record) const
{
return record.get().mIndex;
}
bool LandTextureIndexColumn::isEditable() const
{
return false;
}
/* LandPluginIndexColumn */
LandPluginIndexColumn::LandPluginIndexColumn()
: Column<Land>(Columns::ColumnId_PluginIndex, ColumnBase::Display_Integer, 0)
{
}
QVariant LandPluginIndexColumn::get(const Record<Land>& record) const
{
return record.get().mPlugin;
}
bool LandPluginIndexColumn::isEditable() const
{
return false;
}
/* LandTexturePluginIndexColumn */
LandTexturePluginIndexColumn::LandTexturePluginIndexColumn()
: Column<LandTexture>(Columns::ColumnId_PluginIndex, ColumnBase::Display_Integer, 0)
{
}
QVariant LandTexturePluginIndexColumn::get(const Record<LandTexture>& record) const
{
return record.get().mPluginIndex;
}
bool LandTexturePluginIndexColumn::isEditable() const
{
return false;
}
/* LandMapLodColumn */
LandMapLodColumn::LandMapLodColumn()
: Column<Land>(Columns::ColumnId_LandMapLodIndex, ColumnBase::Display_String, 0)
@ -30,7 +103,9 @@ namespace CSMWorld
{
QByteArray array = data.toByteArray();
const signed char* rawData = reinterpret_cast<const signed char*>(array.data());
assert (array.count() == Land::LAND_GLOBAL_MAP_LOD_SIZE);
if (array.count() != Land::LAND_GLOBAL_MAP_LOD_SIZE)
throw std::runtime_error("invalid land map LOD data");
Land copy = record.get();
copy.setDataLoaded(Land::DATA_WNAM);
@ -76,7 +151,9 @@ namespace CSMWorld
{
QByteArray array = data.toByteArray();
const signed char* rawData = reinterpret_cast<const signed char*>(array.data());
assert (array.count() == Land::LAND_NUM_VERTS * 3);
if (array.count() != Land::LAND_NUM_VERTS * 3)
throw std::runtime_error("invalid land normals data");
Land copy = record.get();
copy.setDataLoaded(Land::DATA_VNML);
@ -121,7 +198,9 @@ namespace CSMWorld
{
QByteArray array = data.toByteArray();
const float* rawData = reinterpret_cast<const float*>(array.data());
assert (array.count() == Land::LAND_NUM_VERTS * sizeof(float));
if (array.count() != Land::LAND_NUM_VERTS * sizeof(float))
throw std::runtime_error("invalid land heights data");
Land copy = record.get();
copy.setDataLoaded(Land::DATA_VHGT);
@ -167,7 +246,9 @@ namespace CSMWorld
{
QByteArray array = data.toByteArray();
const unsigned char* rawData = reinterpret_cast<const unsigned char*>(array.data());
assert (array.count() == Land::LAND_NUM_VERTS * 3);
if (array.count() != Land::LAND_NUM_VERTS * 3)
throw std::runtime_error("invalid land colours data");
Land copy = record.get();
copy.setDataLoaded(Land::DATA_VCLR);
@ -212,7 +293,9 @@ namespace CSMWorld
{
QByteArray array = data.toByteArray();
const uint16_t* rawData = reinterpret_cast<const uint16_t*>(array.data());
assert (array.count() == Land::LAND_NUM_TEXTURES * sizeof(uint16_t));
if (array.count() != Land::LAND_NUM_TEXTURES * sizeof(uint16_t))
throw std::runtime_error("invalid land textures data");
Land copy = record.get();
copy.setDataLoaded(Land::DATA_VTEX);

@ -67,14 +67,14 @@ namespace CSMWorld
inline QVariant StringIdColumn<Land>::get(const Record<Land>& record) const
{
const Land& land = record.get();
return QString(Land::createUniqueRecordId(land.mX, land.mY).c_str());
return QString::fromUtf8(Land::createUniqueRecordId(land.mX, land.mY).c_str());
}
template<>
inline QVariant StringIdColumn<LandTexture>::get(const Record<LandTexture>& record) const
{
const LandTexture& ltex = record.get();
return QString(LandTexture::createUniqueRecordId(ltex.mPluginIndex, ltex.mIndex).c_str());
return QString::fromUtf8(LandTexture::createUniqueRecordId(ltex.mPluginIndex, ltex.mIndex).c_str());
}
template<typename ESXRecordT>
@ -2435,78 +2435,38 @@ namespace CSMWorld
}
};
template<typename ESXRecordT>
struct TextureHandleColumn : public Column<ESXRecordT>
struct LandTextureNicknameColumn : public Column<LandTexture>
{
TextureHandleColumn()
: Column<ESXRecordT> (Columns::ColumnId_TextureHandle, ColumnBase::Display_String)
{}
QVariant get(const Record<ESXRecordT>& record) const override
{
return QString::fromUtf8(record.get().mId.c_str());
}
LandTextureNicknameColumn();
void set(Record<ESXRecordT>& record, const QVariant& data) override
{
ESXRecordT copy = record.get();
copy.mId = data.toString().toUtf8().constData();
record.setModified(copy);
}
bool isEditable() const override
{
return true;
}
QVariant get(const Record<LandTexture>& record) const override;
void set(Record<LandTexture>& record, const QVariant& data) override;
bool isEditable() const override;
};
template<typename ESXRecordT>
struct TextureIndexColumn : public Column<ESXRecordT>
struct LandTextureIndexColumn : public Column<LandTexture>
{
TextureIndexColumn()
: Column<ESXRecordT> (Columns::ColumnId_TextureIndex, ColumnBase::Display_Integer)
{}
LandTextureIndexColumn();
QVariant get(const Record<ESXRecordT>& record) const override
{
return record.get().mIndex;
}
bool isEditable() const override
{
return false;
}
QVariant get(const Record<LandTexture>& record) const override;
bool isEditable() const override;
};
template<typename ESXRecordT>
struct PluginIndexColumn : public Column<ESXRecordT>
struct LandPluginIndexColumn : public Column<Land>
{
PluginIndexColumn()
: Column<ESXRecordT> (Columns::ColumnId_PluginIndex, ColumnBase::Display_Integer,0)
{}
QVariant get(const Record<ESXRecordT>& record) const override
{
return -1;
}
LandPluginIndexColumn();
bool isEditable() const override
{
return false;
}
QVariant get(const Record<Land>& record) const override;
bool isEditable() const override;
};
template<>
inline QVariant PluginIndexColumn<Land>::get (const Record<Land>& record) const
struct LandTexturePluginIndexColumn : public Column<LandTexture>
{
return record.get().mPlugin;
}
LandTexturePluginIndexColumn();
template<>
inline QVariant PluginIndexColumn<LandTexture>::get (const Record<LandTexture>& record) const
{
return record.get().mPluginIndex;
}
QVariant get(const Record<LandTexture>& record) const override;
bool isEditable() const override;
};
struct LandMapLodColumn : public Column<Land>
{

@ -330,7 +330,7 @@ namespace CSMWorld
{ ColumnId_WeatherChance, "Percent Chance" },
{ ColumnId_Text, "Text" },
{ ColumnId_TextureHandle, "Texture Handle" },
{ ColumnId_TextureNickname, "Texture Nickname" },
{ ColumnId_PluginIndex, "Plugin Index" },
{ ColumnId_TextureIndex, "Texture Index" },
{ ColumnId_LandMapLodIndex, "Land map height LOD" },

@ -329,7 +329,7 @@ namespace CSMWorld
ColumnId_Text = 297,
ColumnId_TextureHandle = 298,
ColumnId_TextureNickname = 298,
ColumnId_PluginIndex = 299,
ColumnId_TextureIndex = 300,
ColumnId_LandMapLodIndex = 301,

@ -48,7 +48,7 @@ CSMWorld::ImportLandTexturesCommand::ImportLandTexturesCommand(IdTable& landTabl
, mLtexs(ltexTable)
, mOldState(0)
{
setText("Import land textures");
setText("Copy land textures to current plugin");
}
void CSMWorld::ImportLandTexturesCommand::redo()

@ -415,7 +415,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, bool fsStrict, const Files::Pat
mLand.addColumn (new StringIdColumn<Land>);
mLand.addColumn (new RecordStateColumn<Land>);
mLand.addColumn (new FixedRecordTypeColumn<Land>(UniversalId::Type_Land));
mLand.addColumn (new PluginIndexColumn<Land>);
mLand.addColumn (new LandPluginIndexColumn);
mLand.addColumn (new LandMapLodColumn);
mLand.addColumn (new LandNormalsColumn);
mLand.addColumn (new LandHeightsColumn);
@ -425,9 +425,9 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, bool fsStrict, const Files::Pat
mLandTextures.addColumn (new StringIdColumn<LandTexture>(true));
mLandTextures.addColumn (new RecordStateColumn<LandTexture>);
mLandTextures.addColumn (new FixedRecordTypeColumn<LandTexture>(UniversalId::Type_LandTexture));
mLandTextures.addColumn (new TextureHandleColumn<LandTexture>);
mLandTextures.addColumn (new PluginIndexColumn<LandTexture>);
mLandTextures.addColumn (new TextureIndexColumn<LandTexture>);
mLandTextures.addColumn (new LandTextureNicknameColumn);
mLandTextures.addColumn (new LandTexturePluginIndexColumn);
mLandTextures.addColumn (new LandTextureIndexColumn);
mLandTextures.addColumn (new TextureColumn<LandTexture>);
mPathgrids.addColumn (new StringIdColumn<Pathgrid>);

@ -45,7 +45,7 @@ namespace CSVWorld
CSMWorld::IdTable& table = dynamic_cast<CSMWorld::IdTable&>(*getData().getTableModel(getCollectionId()));
int column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureHandle);
int column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureNickname);
mNameEdit->setText((table.data(table.getModelIndex(originId, column)).toString()));
column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureIndex);
@ -79,7 +79,7 @@ namespace CSVWorld
GenericCreator::configureCreateCommand(command);
CSMWorld::IdTable& table = dynamic_cast<CSMWorld::IdTable&>(*getData().getTableModel(getCollectionId()));
int column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureHandle);
int column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureNickname);
command.addValue(column, mName.c_str());
}

@ -177,17 +177,14 @@ namespace ESM
void Land::blank()
{
if (mLandData)
{
delete mLandData;
}
mPlugin = 0;
for (int i = 0; i < LAND_GLOBAL_MAP_LOD_SIZE; ++i)
mWnam[0] = 0;
mLandData = new LandData;
if (!mLandData)
mLandData = new LandData;
mLandData->mHeightOffset = 0;
for (int i = 0; i < LAND_NUM_VERTS; ++i)
mLandData->mHeights[i] = 0;

Loading…
Cancel
Save