Skip to content

Commit

Permalink
CStarField: use std::vector for m_pStars
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Rusak <[email protected]>
  • Loading branch information
lrusak committed Apr 21, 2023
1 parent 0c5393a commit c6d7abf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
26 changes: 4 additions & 22 deletions src/StarField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,7 @@ int CStarField::Create(int iWidth, int iHeight)
m_Field.fMaxZ = 640.f;
m_Field.fLength = m_Field.fMaxZ - m_Field.fMinZ;

if (m_pStars)
{
delete[] m_pStars;
}

m_pStars = new ST_STAR[m_nStarCnt];

if (m_pStars == nullptr)
{
return -1;
}
m_pStars.resize(m_nStarCnt);

unsigned int n;

Expand All @@ -201,10 +191,10 @@ int CStarField::Create(int iWidth, int iHeight)
m_fBrightTable[n] = (float)(br * 255);
}

for (n = 0; n < m_nStarCnt; n++)
for (auto& star : m_pStars)
{
ResetStar(&m_pStars[n]);
m_pStars[n].z = RangeRand(m_Field.fMinZ, m_Field.fLength);
ResetStar(&star);
star.z = RangeRand(m_Field.fMinZ, m_Field.fLength);
}

for (n = 1; n < 256; n++)
Expand Down Expand Up @@ -249,9 +239,6 @@ char CStarField::GammaCorrect(unsigned char c, float g)

void CStarField::Destroy(void)
{
delete[] m_pStars;
m_pStars = nullptr;

m_pCurVertice = nullptr;
#ifndef WIN32
delete[] m_pVertices;
Expand All @@ -268,11 +255,6 @@ void CStarField::Destroy(void)

int CStarField::RenderFrame(void)
{
if (m_pStars == nullptr)
{
return -1;
}

m_Screen.fZoom = (float)m_Screen.iMidX * m_fZoom;
m_fVelocity += (m_fMaxVelocity - m_fVelocity) * .01f;

Expand Down
2 changes: 1 addition & 1 deletion src/StarField.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ATTR_DLL_LOCAL CStarField
ST_SCREEN m_Screen;
ST_FIELD m_Field;
ST_ROTATION m_Cam;
ST_STAR* m_pStars = nullptr;
std::vector<ST_STAR> m_pStars;
unsigned int m_nStarCnt;
unsigned int m_nDrawnStars;

Expand Down

0 comments on commit c6d7abf

Please sign in to comment.