Moved pieces from a linked list to an array.

This commit is contained in:
leo 2014-04-10 04:46:48 +00:00
parent 4fb236d4c4
commit c5f006cd2c
8 changed files with 521 additions and 444 deletions

View file

@ -54,6 +54,11 @@ public:
return mData[Index]; return mData[Index];
} }
bool IsEmpty() const
{
return mLength == 0;
}
int GetSize() const int GetSize() const
{ {
return mLength; return mLength;

View file

@ -30,7 +30,6 @@ static LC_OBJECT_KEY_INFO piece_key_info[LC_PK_COUNT] =
Piece::Piece(PieceInfo* pPieceInfo) Piece::Piece(PieceInfo* pPieceInfo)
: Object (LC_OBJECT_PIECE) : Object (LC_OBJECT_PIECE)
{ {
m_pNext = NULL;
mPieceInfo = pPieceInfo; mPieceInfo = pPieceInfo;
m_nState = 0; m_nState = 0;
mColorIndex = 0; mColorIndex = 0;
@ -293,15 +292,19 @@ void Piece::Initialize(float x, float y, float z, unsigned char nStep)
UpdatePosition(1); UpdatePosition(1);
} }
void Piece::CreateName(Piece* pPiece) void Piece::CreateName(const lcArray<Piece*>& Pieces)
{ {
int i, max = 0; int i, max = 0;
for (; pPiece; pPiece = pPiece->m_pNext) for (int PieceIdx = 0; PieceIdx < Pieces.GetSize(); PieceIdx++)
if (strncmp (pPiece->m_strName, mPieceInfo->m_strDescription, strlen(mPieceInfo->m_strDescription)) == 0) {
if (sscanf(pPiece->m_strName + strlen(mPieceInfo->m_strDescription), " #%d", &i) == 1) Piece* Piece = Pieces[PieceIdx];
if (strncmp(Piece->m_strName, mPieceInfo->m_strDescription, strlen(mPieceInfo->m_strDescription)) == 0)
if (sscanf(Piece->m_strName + strlen(mPieceInfo->m_strDescription), " #%d", &i) == 1)
if (i > max) if (i > max)
max = i; max = i;
}
sprintf (m_strName, "%s #%.2d", mPieceInfo->m_strDescription, max+1); sprintf (m_strName, "%s #%.2d", mPieceInfo->m_strDescription, max+1);
} }

View file

@ -35,8 +35,6 @@ public:
Piece* m_pNext;
void Hide() void Hide()
{ m_nState = LC_PIECE_HIDDEN; } { m_nState = LC_PIECE_HIDDEN; }
void UnHide() void UnHide()
@ -54,7 +52,7 @@ public:
virtual void MinIntersectDist(lcClickLine* ClickLine); virtual void MinIntersectDist(lcClickLine* ClickLine);
bool IsVisible(unsigned short nTime); bool IsVisible(unsigned short nTime);
void Initialize(float x, float y, float z, unsigned char nStep); void Initialize(float x, float y, float z, unsigned char nStep);
void CreateName(Piece* pPiece); void CreateName(const lcArray<Piece*>& Pieces);
void CompareBoundingBox(float box[6]); void CompareBoundingBox(float box[6]);
void SetPieceInfo(PieceInfo* pPieceInfo); void SetPieceInfo(PieceInfo* pPieceInfo);
bool FileLoad(lcFile& file); bool FileLoad(lcFile& file);

File diff suppressed because it is too large Load diff

View file

@ -298,7 +298,7 @@ public:
} }
// Objects // Objects
Piece* m_pPieces; lcArray<Piece*> mPieces;
lcArray<Camera*> mCameras; lcArray<Camera*> mCameras;
lcArray<Light*> mLights; lcArray<Light*> mLights;
Group* m_pGroups; Group* m_pGroups;

View file

@ -105,15 +105,9 @@ void lcQEditGroupsDialog::updateParents(QTreeWidgetItem *parentItem, Group *pare
if (itemPiece) if (itemPiece)
{ {
int pieceIndex = 0; int pieceIndex = project->mPieces.FindIndex(itemPiece);
for (Piece *piece = project->m_pPieces; piece; piece = piece->m_pNext, pieceIndex++) if (pieceIndex != -1)
{ options->PieceParents[pieceIndex] = parentGroup;
if (itemPiece == piece)
{
options->PieceParents[pieceIndex] = parentGroup;
break;
}
}
} }
else else
{ {
@ -153,8 +147,10 @@ void lcQEditGroupsDialog::addChildren(QTreeWidgetItem *parentItem, Group *parent
addChildren(groupItem, group); addChildren(groupItem, group);
} }
for (Piece *piece = project->m_pPieces; piece; piece = piece->m_pNext) for (int pieceIndex = 0; pieceIndex < project->mPieces.GetSize(); pieceIndex++)
{ {
Piece *piece = project->mPieces[pieceIndex];
if (piece->GetGroup() != parentGroup) if (piece->GetGroup() != parentGroup)
continue; continue;

View file

@ -54,7 +54,7 @@ lcQMainWindow::lcQMainWindow(QWidget *parent)
GL_EnableVertexBufferObject(); GL_EnableVertexBufferObject();
if (lcGetActiveProject()->m_pPieces) if (!lcGetActiveProject()->mPieces.IsEmpty())
{ {
for (int PieceIdx = 0; PieceIdx < Library->mPieces.GetSize(); PieceIdx++) for (int PieceIdx = 0; PieceIdx < Library->mPieces.GetSize(); PieceIdx++)
{ {

View file

@ -162,8 +162,10 @@ void lcQSelectDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGrou
int numObjects = 0; int numObjects = 0;
for (Piece *piece = project->m_pPieces; piece; piece = piece->m_pNext, numObjects++) for (int pieceIdx = 0; pieceIdx < project->mPieces.GetSize(); pieceIdx++, numObjects++)
{ {
Piece *piece = project->mPieces[pieceIdx];
if (piece->GetGroup() != parentGroup) if (piece->GetGroup() != parentGroup)
continue; continue;