From c6d7abfe5ba91ab969523c3f6dad8e981d92b062 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Fri, 21 Apr 2023 11:39:49 -0700 Subject: [PATCH] CStarField: use std::vector for m_pStars Signed-off-by: Lukas Rusak --- src/StarField.cpp | 26 ++++---------------------- src/StarField.h | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/StarField.cpp b/src/StarField.cpp index 24c582b..6cf3775 100644 --- a/src/StarField.cpp +++ b/src/StarField.cpp @@ -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; @@ -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++) @@ -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; @@ -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; diff --git a/src/StarField.h b/src/StarField.h index de9de97..a4df17d 100644 --- a/src/StarField.h +++ b/src/StarField.h @@ -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 m_pStars; unsigned int m_nStarCnt; unsigned int m_nDrawnStars;