forked from teamnwah/openmw-tes3coop
Get rid of some templates, exceptions instead of assert, and other small changes.
This commit is contained in:
parent
2abf7f1752
commit
50d9d9f78f
8 changed files with 120 additions and 80 deletions
|
@ -1,7 +1,80 @@
|
||||||
#include "columnimp.hpp"
|
#include "columnimp.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace CSMWorld
|
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::LandMapLodColumn()
|
LandMapLodColumn::LandMapLodColumn()
|
||||||
: Column<Land>(Columns::ColumnId_LandMapLodIndex, ColumnBase::Display_String, 0)
|
: Column<Land>(Columns::ColumnId_LandMapLodIndex, ColumnBase::Display_String, 0)
|
||||||
|
@ -30,7 +103,9 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
QByteArray array = data.toByteArray();
|
QByteArray array = data.toByteArray();
|
||||||
const signed char* rawData = reinterpret_cast<const signed char*>(array.data());
|
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();
|
Land copy = record.get();
|
||||||
copy.setDataLoaded(Land::DATA_WNAM);
|
copy.setDataLoaded(Land::DATA_WNAM);
|
||||||
|
@ -76,7 +151,9 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
QByteArray array = data.toByteArray();
|
QByteArray array = data.toByteArray();
|
||||||
const signed char* rawData = reinterpret_cast<const signed char*>(array.data());
|
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();
|
Land copy = record.get();
|
||||||
copy.setDataLoaded(Land::DATA_VNML);
|
copy.setDataLoaded(Land::DATA_VNML);
|
||||||
|
@ -121,7 +198,9 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
QByteArray array = data.toByteArray();
|
QByteArray array = data.toByteArray();
|
||||||
const float* rawData = reinterpret_cast<const float*>(array.data());
|
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();
|
Land copy = record.get();
|
||||||
copy.setDataLoaded(Land::DATA_VHGT);
|
copy.setDataLoaded(Land::DATA_VHGT);
|
||||||
|
@ -167,7 +246,9 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
QByteArray array = data.toByteArray();
|
QByteArray array = data.toByteArray();
|
||||||
const unsigned char* rawData = reinterpret_cast<const unsigned char*>(array.data());
|
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();
|
Land copy = record.get();
|
||||||
copy.setDataLoaded(Land::DATA_VCLR);
|
copy.setDataLoaded(Land::DATA_VCLR);
|
||||||
|
@ -212,7 +293,9 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
QByteArray array = data.toByteArray();
|
QByteArray array = data.toByteArray();
|
||||||
const uint16_t* rawData = reinterpret_cast<const uint16_t*>(array.data());
|
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();
|
Land copy = record.get();
|
||||||
copy.setDataLoaded(Land::DATA_VTEX);
|
copy.setDataLoaded(Land::DATA_VTEX);
|
||||||
|
|
|
@ -67,14 +67,14 @@ namespace CSMWorld
|
||||||
inline QVariant StringIdColumn<Land>::get(const Record<Land>& record) const
|
inline QVariant StringIdColumn<Land>::get(const Record<Land>& record) const
|
||||||
{
|
{
|
||||||
const Land& land = record.get();
|
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<>
|
template<>
|
||||||
inline QVariant StringIdColumn<LandTexture>::get(const Record<LandTexture>& record) const
|
inline QVariant StringIdColumn<LandTexture>::get(const Record<LandTexture>& record) const
|
||||||
{
|
{
|
||||||
const LandTexture& ltex = record.get();
|
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>
|
template<typename ESXRecordT>
|
||||||
|
@ -2435,78 +2435,38 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ESXRecordT>
|
struct LandTextureNicknameColumn : public Column<LandTexture>
|
||||||
struct TextureHandleColumn : public Column<ESXRecordT>
|
|
||||||
{
|
{
|
||||||
TextureHandleColumn()
|
LandTextureNicknameColumn();
|
||||||
: Column<ESXRecordT> (Columns::ColumnId_TextureHandle, ColumnBase::Display_String)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QVariant get(const Record<ESXRecordT>& record) const override
|
QVariant get(const Record<LandTexture>& record) const override;
|
||||||
{
|
void set(Record<LandTexture>& record, const QVariant& data) override;
|
||||||
return QString::fromUtf8(record.get().mId.c_str());
|
bool isEditable() const override;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ESXRecordT>
|
struct LandTextureIndexColumn : public Column<LandTexture>
|
||||||
struct TextureIndexColumn : public Column<ESXRecordT>
|
|
||||||
{
|
{
|
||||||
TextureIndexColumn()
|
LandTextureIndexColumn();
|
||||||
: Column<ESXRecordT> (Columns::ColumnId_TextureIndex, ColumnBase::Display_Integer)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QVariant get(const Record<ESXRecordT>& record) const override
|
QVariant get(const Record<LandTexture>& record) const override;
|
||||||
{
|
bool isEditable() const override;
|
||||||
return record.get().mIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isEditable() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ESXRecordT>
|
struct LandPluginIndexColumn : public Column<Land>
|
||||||
struct PluginIndexColumn : public Column<ESXRecordT>
|
|
||||||
{
|
{
|
||||||
PluginIndexColumn()
|
LandPluginIndexColumn();
|
||||||
: Column<ESXRecordT> (Columns::ColumnId_PluginIndex, ColumnBase::Display_Integer,0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QVariant get(const Record<ESXRecordT>& record) const override
|
QVariant get(const Record<Land>& record) const override;
|
||||||
{
|
bool isEditable() const override;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isEditable() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
struct LandTexturePluginIndexColumn : public Column<LandTexture>
|
||||||
inline QVariant PluginIndexColumn<Land>::get (const Record<Land>& record) const
|
|
||||||
{
|
{
|
||||||
return record.get().mPlugin;
|
LandTexturePluginIndexColumn();
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
QVariant get(const Record<LandTexture>& record) const override;
|
||||||
inline QVariant PluginIndexColumn<LandTexture>::get (const Record<LandTexture>& record) const
|
bool isEditable() const override;
|
||||||
{
|
};
|
||||||
return record.get().mPluginIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct LandMapLodColumn : public Column<Land>
|
struct LandMapLodColumn : public Column<Land>
|
||||||
{
|
{
|
||||||
|
|
|
@ -330,7 +330,7 @@ namespace CSMWorld
|
||||||
{ ColumnId_WeatherChance, "Percent Chance" },
|
{ ColumnId_WeatherChance, "Percent Chance" },
|
||||||
|
|
||||||
{ ColumnId_Text, "Text" },
|
{ ColumnId_Text, "Text" },
|
||||||
{ ColumnId_TextureHandle, "Texture Handle" },
|
{ ColumnId_TextureNickname, "Texture Nickname" },
|
||||||
{ ColumnId_PluginIndex, "Plugin Index" },
|
{ ColumnId_PluginIndex, "Plugin Index" },
|
||||||
{ ColumnId_TextureIndex, "Texture Index" },
|
{ ColumnId_TextureIndex, "Texture Index" },
|
||||||
{ ColumnId_LandMapLodIndex, "Land map height LOD" },
|
{ ColumnId_LandMapLodIndex, "Land map height LOD" },
|
||||||
|
|
|
@ -329,7 +329,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
ColumnId_Text = 297,
|
ColumnId_Text = 297,
|
||||||
|
|
||||||
ColumnId_TextureHandle = 298,
|
ColumnId_TextureNickname = 298,
|
||||||
ColumnId_PluginIndex = 299,
|
ColumnId_PluginIndex = 299,
|
||||||
ColumnId_TextureIndex = 300,
|
ColumnId_TextureIndex = 300,
|
||||||
ColumnId_LandMapLodIndex = 301,
|
ColumnId_LandMapLodIndex = 301,
|
||||||
|
|
|
@ -48,7 +48,7 @@ CSMWorld::ImportLandTexturesCommand::ImportLandTexturesCommand(IdTable& landTabl
|
||||||
, mLtexs(ltexTable)
|
, mLtexs(ltexTable)
|
||||||
, mOldState(0)
|
, mOldState(0)
|
||||||
{
|
{
|
||||||
setText("Import land textures");
|
setText("Copy land textures to current plugin");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::ImportLandTexturesCommand::redo()
|
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 StringIdColumn<Land>);
|
||||||
mLand.addColumn (new RecordStateColumn<Land>);
|
mLand.addColumn (new RecordStateColumn<Land>);
|
||||||
mLand.addColumn (new FixedRecordTypeColumn<Land>(UniversalId::Type_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 LandMapLodColumn);
|
||||||
mLand.addColumn (new LandNormalsColumn);
|
mLand.addColumn (new LandNormalsColumn);
|
||||||
mLand.addColumn (new LandHeightsColumn);
|
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 StringIdColumn<LandTexture>(true));
|
||||||
mLandTextures.addColumn (new RecordStateColumn<LandTexture>);
|
mLandTextures.addColumn (new RecordStateColumn<LandTexture>);
|
||||||
mLandTextures.addColumn (new FixedRecordTypeColumn<LandTexture>(UniversalId::Type_LandTexture));
|
mLandTextures.addColumn (new FixedRecordTypeColumn<LandTexture>(UniversalId::Type_LandTexture));
|
||||||
mLandTextures.addColumn (new TextureHandleColumn<LandTexture>);
|
mLandTextures.addColumn (new LandTextureNicknameColumn);
|
||||||
mLandTextures.addColumn (new PluginIndexColumn<LandTexture>);
|
mLandTextures.addColumn (new LandTexturePluginIndexColumn);
|
||||||
mLandTextures.addColumn (new TextureIndexColumn<LandTexture>);
|
mLandTextures.addColumn (new LandTextureIndexColumn);
|
||||||
mLandTextures.addColumn (new TextureColumn<LandTexture>);
|
mLandTextures.addColumn (new TextureColumn<LandTexture>);
|
||||||
|
|
||||||
mPathgrids.addColumn (new StringIdColumn<Pathgrid>);
|
mPathgrids.addColumn (new StringIdColumn<Pathgrid>);
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace CSVWorld
|
||||||
|
|
||||||
CSMWorld::IdTable& table = dynamic_cast<CSMWorld::IdTable&>(*getData().getTableModel(getCollectionId()));
|
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()));
|
mNameEdit->setText((table.data(table.getModelIndex(originId, column)).toString()));
|
||||||
|
|
||||||
column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureIndex);
|
column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureIndex);
|
||||||
|
@ -79,7 +79,7 @@ namespace CSVWorld
|
||||||
GenericCreator::configureCreateCommand(command);
|
GenericCreator::configureCreateCommand(command);
|
||||||
|
|
||||||
CSMWorld::IdTable& table = dynamic_cast<CSMWorld::IdTable&>(*getData().getTableModel(getCollectionId()));
|
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());
|
command.addValue(column, mName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,17 +177,14 @@ namespace ESM
|
||||||
|
|
||||||
void Land::blank()
|
void Land::blank()
|
||||||
{
|
{
|
||||||
if (mLandData)
|
|
||||||
{
|
|
||||||
delete mLandData;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPlugin = 0;
|
mPlugin = 0;
|
||||||
|
|
||||||
for (int i = 0; i < LAND_GLOBAL_MAP_LOD_SIZE; ++i)
|
for (int i = 0; i < LAND_GLOBAL_MAP_LOD_SIZE; ++i)
|
||||||
mWnam[0] = 0;
|
mWnam[0] = 0;
|
||||||
|
|
||||||
mLandData = new LandData;
|
if (!mLandData)
|
||||||
|
mLandData = new LandData;
|
||||||
|
|
||||||
mLandData->mHeightOffset = 0;
|
mLandData->mHeightOffset = 0;
|
||||||
for (int i = 0; i < LAND_NUM_VERTS; ++i)
|
for (int i = 0; i < LAND_NUM_VERTS; ++i)
|
||||||
mLandData->mHeights[i] = 0;
|
mLandData->mHeights[i] = 0;
|
||||||
|
|
Loading…
Reference in a new issue