Array cleanup.

This commit is contained in:
Leonardo Zide 2019-07-04 17:06:26 -07:00
parent 3d9395e175
commit 4493c3f6f2
7 changed files with 59 additions and 58 deletions

View file

@ -3,7 +3,7 @@
#include "lc_file.h"
#include <float.h>
lcArray<lcColor> gColorList;
std::vector<lcColor> gColorList;
lcColorGroup gColorGroups[LC_NUM_COLORGROUPS];
int gNumUserColors;
int gEdgeColor;
@ -184,13 +184,13 @@ int lcGetBrickLinkColor(int ColorIndex)
bool lcLoadColorFile(lcFile& File)
{
char Line[1024], Token[1024];
lcArray<lcColor>& Colors = gColorList;
std::vector<lcColor>& Colors = gColorList;
lcColor Color, MainColor, EdgeColor;
Colors.RemoveAll();
Colors.clear();
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
gColorGroups[GroupIdx].Colors.RemoveAll();
gColorGroups[GroupIdx].Colors.clear();
gColorGroups[0].Name = QApplication::tr("Solid Colors", "Colors");
gColorGroups[1].Name = QApplication::tr("Translucent Colors", "Colors");
@ -335,11 +335,11 @@ bool lcLoadColorFile(lcFile& File)
bool Duplicate = false;
for (int i = 0; i < Colors.GetSize(); i++)
for (lcColor& ExistingColor : Colors)
{
if (Colors[i].Code == Color.Code)
if (ExistingColor.Code == Color.Code)
{
Colors[i] = Color;
ExistingColor = Color;
Duplicate = true;
break;
}
@ -360,26 +360,26 @@ bool lcLoadColorFile(lcFile& File)
continue;
}
Colors.Add(Color);
Colors.push_back(Color);
if (GroupSpecial)
gColorGroups[LC_COLORGROUP_SPECIAL].Colors.Add(Colors.GetSize() - 1);
gColorGroups[LC_COLORGROUP_SPECIAL].Colors.push_back((int)Colors.size() - 1);
else if (GroupTranslucent)
gColorGroups[LC_COLORGROUP_TRANSLUCENT].Colors.Add(Colors.GetSize() - 1);
gColorGroups[LC_COLORGROUP_TRANSLUCENT].Colors.push_back((int)Colors.size() - 1);
else
gColorGroups[LC_COLORGROUP_SOLID].Colors.Add(Colors.GetSize() - 1);
gColorGroups[LC_COLORGROUP_SOLID].Colors.push_back((int)Colors.size() - 1);
}
gDefaultColor = Colors.GetSize();
Colors.Add(MainColor);
gColorGroups[LC_COLORGROUP_SOLID].Colors.Add(gDefaultColor);
gDefaultColor = (int)Colors.size();
Colors.push_back(MainColor);
gColorGroups[LC_COLORGROUP_SOLID].Colors.push_back(gDefaultColor);
gNumUserColors = Colors.GetSize();
gNumUserColors = (int)Colors.size();
gEdgeColor = Colors.GetSize();
Colors.Add(EdgeColor);
gEdgeColor = (int)Colors.size();
Colors.push_back(EdgeColor);
return Colors.GetSize() > 2;
return Colors.size() > 2;
}
void lcLoadDefaultColors()
@ -405,7 +405,7 @@ void lcLoadDefaultColors()
int lcGetColorIndex(quint32 ColorCode)
{
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
for (int ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
if (gColorList[ColorIdx].Code == ColorCode)
return ColorIdx;
@ -437,6 +437,6 @@ int lcGetColorIndex(quint32 ColorCode)
sprintf(Color.SafeName, "Color_%03d", ColorCode);
}
gColorList.Add(Color);
return gColorList.GetSize() - 1;
gColorList.push_back(Color);
return (int)gColorList.size() - 1;
}

View file

@ -26,7 +26,7 @@ enum
struct lcColorGroup
{
lcArray<int> Colors;
std::vector<int> Colors;
QString Name;
};
@ -44,7 +44,7 @@ enum lcInterfaceColor
};
extern lcVector4 gInterfaceColors[LC_NUM_INTERFACECOLORS];
extern lcArray<lcColor> gColorList;
extern std::vector<lcColor> gColorList;
extern lcColorGroup gColorGroups[LC_NUM_COLORGROUPS];
extern int gNumUserColors;
extern int gEdgeColor;

View file

@ -125,9 +125,9 @@ void lcPiecesLibrary::Unload()
delete PrimitiveIt.second;
mPrimitives.clear();
for (int TextureIdx = 0; TextureIdx < mTextures.GetSize(); TextureIdx++)
delete mTextures[TextureIdx];
mTextures.RemoveAll();
for (lcTexture* Texture : mTextures)
delete Texture;
mTextures.clear();
mNumOfficialPieces = 0;
delete mZipFiles[LC_ZIPFILE_OFFICIAL];
@ -266,9 +266,9 @@ PieceInfo* lcPiecesLibrary::FindPiece(const char* PieceName, Project* CurrentPro
lcTexture* lcPiecesLibrary::FindTexture(const char* TextureName, Project* CurrentProject, bool SearchProjectFolder)
{
for (int TextureIdx = 0; TextureIdx < mTextures.GetSize(); TextureIdx++)
if (!strcmp(TextureName, mTextures[TextureIdx]->mName))
return mTextures[TextureIdx];
for (lcTexture* Texture : mTextures)
if (!strcmp(TextureName, Texture->mName))
return Texture;
QString ProjectPath;
if (SearchProjectFolder)
@ -289,7 +289,7 @@ lcTexture* lcPiecesLibrary::FindTexture(const char* TextureName, Project* Curren
if (Texture)
{
mTextures.Add(Texture);
mTextures.push_back(Texture);
return Texture;
}
}
@ -423,7 +423,7 @@ bool lcPiecesLibrary::OpenArchive(lcFile* File, const QString& FileName, lcZipFi
(ZipFileType == LC_ZIPFILE_UNOFFICIAL && !memcmp(Name, "PARTS/TEXTURES/", 15)))
{
lcTexture* Texture = new lcTexture();
mTextures.Add(Texture);
mTextures.push_back(Texture);
*Dst = 0;
strncpy(Texture->mName, Name + (ZipFileType == LC_ZIPFILE_OFFICIAL ? 21 : 15), sizeof(Texture->mName));
@ -623,7 +623,7 @@ bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
QDir Dir(LibraryDir.absoluteFilePath(QLatin1String("parts/textures/")), QLatin1String("*.png"), QDir::SortFlags(QDir::Name | QDir::IgnoreCase), QDir::Files | QDir::Hidden | QDir::Readable);
QStringList FileList = Dir.entryList();
mTextures.AllocGrow(FileList.size());
mTextures.reserve(FileList.size());
for (int FileIdx = 0; FileIdx < FileList.size(); FileIdx++)
{
@ -654,7 +654,7 @@ bool lcPiecesLibrary::OpenDirectory(const QDir& LibraryDir, bool ShowProgress)
*Dst = 0;
lcTexture* Texture = new lcTexture();
mTextures.Add(Texture);
mTextures.push_back(Texture);
strncpy(Texture->mName, Name, sizeof(Texture->mName));
Texture->mName[sizeof(Texture->mName) - 1] = 0;
@ -1884,7 +1884,9 @@ void lcPiecesLibrary::ReleaseTexture(lcTexture* Texture)
if (Texture->Release() == 0 && Texture->IsTemporary())
{
mTextures.Remove(Texture);
std::vector<lcTexture*>::iterator TextureIt = std::find(mTextures.begin(), mTextures.end(), Texture);
if (TextureIt != mTextures.end())
mTextures.erase(TextureIt);
delete Texture;
}
}

View file

@ -248,7 +248,7 @@ public:
std::map<std::string, lcLibraryPrimitive*> mPrimitives;
int mNumOfficialPieces;
lcArray<lcTexture*> mTextures;
std::vector<lcTexture*> mTextures;
QDir mLibraryDir;

View file

@ -1506,13 +1506,13 @@ void lcModel::SaveCheckpoint(const QString& Description)
void lcModel::LoadCheckPoint(lcModelHistoryEntry* CheckPoint)
{
lcPiecesLibrary* Library = lcGetPiecesLibrary();
lcArray<PieceInfo*> Infos;
std::vector<PieceInfo*> LoadedInfos;
for (lcPiece* Piece : mPieces)
{
PieceInfo* Info = Piece->mPieceInfo;
Library->LoadPieceInfo(Info, true, true);
Infos.Add(Info);
LoadedInfos.push_back(Info);
}
DeleteModel();
@ -1527,8 +1527,8 @@ void lcModel::LoadCheckPoint(lcModelHistoryEntry* CheckPoint)
gMainWindow->UpdateSelectedObjects(true);
gMainWindow->UpdateAllViews();
for (int InfoIdx = 0; InfoIdx < Infos.GetSize(); InfoIdx++)
Library->ReleasePieceInfo(Infos[InfoIdx]);
for (PieceInfo* Info : LoadedInfos)
Library->ReleasePieceInfo(Info);
}
void lcModel::SetActive(bool Active)

View file

@ -713,7 +713,7 @@ void Project::Export3DStudio(const QString& FileName)
const int MaterialNameLength = 11;
char MaterialName[32];
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
for (int ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
{
lcColor* Color = &gColorList[ColorIdx];
@ -1685,7 +1685,7 @@ QImage Project::CreatePartsListImage(lcModel* Model, lcStep Step)
void Project::CreateHTMLPieceList(QTextStream& Stream, lcModel* Model, lcStep Step, bool Images)
{
std::vector<int> ColorsUsed(gColorList.GetSize(), 0);
std::vector<int> ColorsUsed(gColorList.size(), 0);
int NumColors = 0;
lcPartsList PartsList;
@ -1701,7 +1701,7 @@ void Project::CreateHTMLPieceList(QTextStream& Stream, lcModel* Model, lcStep St
Stream << QLatin1String("<br><table border=1><tr><td><center>Piece</center></td>\r\n");
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
for (int ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
{
if (ColorsUsed[ColorIdx])
{
@ -2060,7 +2060,7 @@ bool Project::ExportPOVRay(const QString& FileName)
lcPiecesLibrary* Library = lcGetPiecesLibrary();
std::map<const PieceInfo*, std::pair<char[LC_PIECE_NAME_LEN], int>> PieceTable;
int NumColors = gColorList.GetSize();
size_t NumColors = gColorList.size();
std::vector<std::array<char, LC_MAX_COLOR_NAME>> ColorTable(NumColors);
enum
@ -2192,7 +2192,7 @@ bool Project::ExportPOVRay(const QString& FileName)
POVFile.WriteLine("\n");
}
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
for (int ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
{
lcColor* Color = &gColorList[ColorIdx];
@ -2391,13 +2391,12 @@ void Project::ExportWavefront(const QString& FileName)
}
MaterialFile.WriteLine("# Colors used by LeoCAD\n\n");
for (int ColorIdx = 0; ColorIdx < gColorList.GetSize(); ColorIdx++)
for (const lcColor& Color : gColorList)
{
lcColor* Color = &gColorList[ColorIdx];
if (Color->Translucent)
sprintf(Line, "newmtl %s\nKd %.2f %.2f %.2f\nD %.2f\n\n", Color->SafeName, Color->Value[0], Color->Value[1], Color->Value[2], Color->Value[3]);
if (Color.Translucent)
sprintf(Line, "newmtl %s\nKd %.2f %.2f %.2f\nD %.2f\n\n", Color.SafeName, Color.Value[0], Color.Value[1], Color.Value[2], Color.Value[3]);
else
sprintf(Line, "newmtl %s\nKd %.2f %.2f %.2f\n\n", Color->SafeName, Color->Value[0], Color->Value[1], Color->Value[2]);
sprintf(Line, "newmtl %s\nKd %.2f %.2f %.2f\n\n", Color.SafeName, Color.Value[0], Color.Value[1], Color.Value[2]);
MaterialFile.WriteLine(Line);
}

View file

@ -18,10 +18,10 @@ lcQColorList::lcQColorList(QWidget *parent)
{
lcColorGroup* Group = &gColorGroups[GroupIdx];
for (int ColorIdx = 0; ColorIdx < Group->Colors.GetSize(); ColorIdx++)
mCellColors[mNumCells++] = Group->Colors[ColorIdx];
for (int Color: Group->Colors)
mCellColors[mNumCells++] = Color;
mRows += (Group->Colors.GetSize() + mColumns - 1) / mColumns;
mRows += ((int)Group->Colors.size() + mColumns - 1) / mColumns;
}
mWidth = 0;
@ -187,7 +187,7 @@ void lcQColorList::keyPressEvent(QKeyEvent *event)
for (CurGroup = 0; CurGroup < LC_NUM_COLORGROUPS; CurGroup++)
{
int NumColors = gColorGroups[CurGroup].Colors.GetSize();
int NumColors = (int)gColorGroups[CurGroup].Colors.size();
if (mCurCell < NumCells + NumColors)
break;
@ -204,7 +204,7 @@ void lcQColorList::keyPressEvent(QKeyEvent *event)
NewCell = mCurCell - mColumns;
else if (CurGroup > 0)
{
int NumColors = gColorGroups[CurGroup - 1].Colors.GetSize();
size_t NumColors = gColorGroups[CurGroup - 1].Colors.size();
int NumColumns = NumColors % mColumns;
if (NumColumns <= Column + 1)
@ -215,7 +215,7 @@ void lcQColorList::keyPressEvent(QKeyEvent *event)
}
else if (event->key() == Qt::Key_Down)
{
int NumColors = gColorGroups[CurGroup].Colors.GetSize();
size_t NumColors = gColorGroups[CurGroup].Colors.size();
if (mCurCell + mColumns < NumCells + NumColors)
NewCell = mCurCell + mColumns;
@ -274,7 +274,7 @@ void lcQColorList::resizeEvent(QResizeEvent *event)
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
{
lcColorGroup* Group = &gColorGroups[GroupIdx];
mRows += (Group->Colors.GetSize() + mColumns - 1) / mColumns;
mRows += ((int)Group->Colors.size() + mColumns - 1) / mColumns;
}
CellWidth = (float)(width() + 1) / (float)mColumns;
@ -292,7 +292,7 @@ void lcQColorList::resizeEvent(QResizeEvent *event)
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
{
lcColorGroup* Group = &gColorGroups[GroupIdx];
mRows += (Group->Colors.GetSize() + mColumns - 1) / mColumns;
mRows += ((int)Group->Colors.size() + mColumns - 1) / mColumns;
}
CellWidth = (float)(width() + 1) / (float)mColumns;
@ -315,7 +315,7 @@ void lcQColorList::resizeEvent(QResizeEvent *event)
mGroupRects[GroupIdx] = QRect(0, (int)GroupY, width(), mGroupRects[GroupIdx].height());
GroupY += mGroupRects[GroupIdx].height();
for (int ColorIdx = 0; ColorIdx < Group->Colors.GetSize(); ColorIdx++)
for (size_t ColorIdx = 0; ColorIdx < Group->Colors.size(); ColorIdx++)
{
const int Left = CellWidth * CurColumn - 1;
const int Right = (CurColumn + 1) * CellWidth - 1;