I'm making a thread for beginner/beginner-intermediate coders questions on understanding C++ code of OpenMW. Googling etc. goes far, but then there comes a point where it's easier to understand by asking questions directly related to OpenMW. This hopefully doesn't take time away from actual development, but instead gives an opportunity for experienced developers to help us beginners. And why not, beginners might be able to help other beginners too!
* * * * * Here comes the first question * * * * *
I've learned quite a bit this week, but there are still common structures in code that I don't properly grasp. Currently I'm trying to understand what's in struct CSMWorld::LandHeightsColumn. I understand that it's a struct, based on Column that's a template, based on CSMWorld::NestableColumn, finally based on struct ColumnBase. With the following code, I've been able to cout basic integers belonging to LandHeightsColumn's part that's based on ColumnBase.
(code requires #include columnimp.hpp)
Code: Select all
CSMWorld::LandHeightsColumn MyLandHeightsColumn; // struct LandHeightsColumn : public Column<Land>
std::cout << MyLandHeightsColumn.mColumnId << std::endl;
std::cout << MyLandHeightsColumn.getId() << std::endl;
To understand this further - there are more defining questions: Is LandHeightsColumn::get() a function that returns a QVariant that has "values"? Or is it a QVariant variable? Should the following code work, if I had a proper argument?
Code: Select all
QVariant MyAlsoLandHeightsColumn;
MyAlsoLandHeightsColumn = MyLandHeightsColumn.get(ARGUMENT?);
int i[] = MyAlsoLandHeightsColumn.toInt();
Code: Select all
LandHeightsColumn::LandHeightsColumn()
: Column<Land>(Columns::ColumnId_LandHeightsIndex, ColumnBase::Display_String, 0)
{
}
QVariant LandHeightsColumn::get(const Record<Land>& record) const
{
const int Size = Land::LAND_NUM_VERTS;
const Land& land = record.get();
DataType values(Size, 0);
if (land.isDataLoaded(Land::DATA_VHGT))
{
for (int i = 0; i < Size; ++i)
values[i] = land.getLandData()->mHeights[i];
}
QVariant variant;
variant.setValue(values);
return variant;
}