diff --git a/src/colorfire/main.cpp b/src/colorfire/main.cpp index 8725c6e20..23d94fde7 100644 --- a/src/colorfire/main.cpp +++ b/src/colorfire/main.cpp @@ -24,9 +24,6 @@ #include #include -#define LOAD_TEXTURE(dest, src, compressedSize, size) dest = (unsigned char *)malloc(size); BZ2_bzBuffToBuffDecompress((char *)dest, &size, (char *)src, compressedSize, 0, 0); -#define FREE_TEXTURE(tex) free(tex); - // Override GL_RED if not present with GL_LUMINANCE, e.g. on Android GLES #ifndef GL_RED #define GL_RED GL_LUMINANCE @@ -72,20 +69,20 @@ bool CScreensaverColorFire::Start() { case TYPE_SMOKE: { - LOAD_TEXTURE(l_tex, smokemap, smokemap_compressedsize, smokemap_size); gli::texture Texture(gli::TARGET_2D, gli::FORMAT_RGB8_UNORM_PACK8, gli::texture::extent_type(TEXSIZE, TEXSIZE, 1), 1, 1, 1); - std::memcpy(Texture.data(), l_tex, Texture.size()); + + BZ2_bzBuffToBuffDecompress(reinterpret_cast(Texture.data()), &smokemap_size, const_cast(smokemap), smokemap_compressedsize, 0, 0); + m_texture = kodi::gui::gl::Load(Texture); - FREE_TEXTURE(l_tex) break; } case TYPE_RIPPLES: { - LOAD_TEXTURE(l_tex, ripplemap, ripplemap_compressedsize, ripplemap_size); gli::texture Texture(gli::TARGET_2D, gli::FORMAT_RGB8_UNORM_PACK8, gli::texture::extent_type(TEXSIZE, TEXSIZE, 1), 1, 1, 1); - std::memcpy(Texture.data(), l_tex, Texture.size()); + + BZ2_bzBuffToBuffDecompress(reinterpret_cast(Texture.data()), &ripplemap_size, const_cast(ripplemap), ripplemap_compressedsize, 0, 0); + m_texture = kodi::gui::gl::Load(Texture); - FREE_TEXTURE(l_tex) break; } case TYPE_SMOOTH: diff --git a/src/cyclone/main.cpp b/src/cyclone/main.cpp index 64a9d56d1..f07ed37ae 100644 --- a/src/cyclone/main.cpp +++ b/src/cyclone/main.cpp @@ -16,6 +16,8 @@ #include "main.h" +#include +#include #include #include #include @@ -96,9 +98,9 @@ int factorial(int x) class CCyclone { public: - float **m_targetxyz; - float **m_xyz; - float **m_oldxyz; + std::vector> m_targetxyz; + std::vector> m_xyz; + std::vector> m_oldxyz; float *m_targetWidth; float *m_width; float *m_oldWidth; @@ -110,11 +112,11 @@ class CCyclone float m_hslChange[2]; CCyclone(); - ~CCyclone(); + ~CCyclone() = default; void Update(CScreensaverCyclone* base); private: - sLight* m_curves = nullptr; + std::vector m_curves; }; CCyclone::CCyclone() @@ -122,17 +124,12 @@ CCyclone::CCyclone() int i; // Initialize position stuff - m_curves = new sLight[std::max(gCycloneSettings.dComplexity + 3, 50)]; + m_curves.resize(std::max(gCycloneSettings.dComplexity + 3, 50)); + + m_targetxyz.resize(gCycloneSettings.dComplexity+3); + m_xyz.resize(gCycloneSettings.dComplexity+3); + m_oldxyz.resize(gCycloneSettings.dComplexity+3); - m_targetxyz = new float*[gCycloneSettings.dComplexity+3]; - m_xyz = new float*[gCycloneSettings.dComplexity+3]; - m_oldxyz = new float*[gCycloneSettings.dComplexity+3]; - for (i = 0; i < int(gCycloneSettings.dComplexity)+3; i++) - { - m_targetxyz[i] = new float[3]; - m_xyz[i] = new float[3]; - m_oldxyz[i] = new float[3]; - } m_xyz[gCycloneSettings.dComplexity+2][0] = rsRandf(float(WIDTH*2)) - float(WIDTH); m_xyz[gCycloneSettings.dComplexity+2][1] = float(HIGHT); m_xyz[gCycloneSettings.dComplexity+2][2] = rsRandf(float(WIDTH*2)) - float(WIDTH); @@ -184,22 +181,6 @@ CCyclone::CCyclone() m_hslChange[1] = 10.0f; } -CCyclone::~CCyclone() -{ - for (int i = 0; i < int(gCycloneSettings.dComplexity) + 3; i++) - { - delete[] m_targetxyz[i]; - delete[] m_xyz[i]; - delete[] m_oldxyz[i]; - } - - delete[] m_targetxyz; - delete[] m_xyz; - delete[] m_oldxyz; - - delete[] m_curves; -} - void CCyclone::Update(CScreensaverCyclone* base) { int i; @@ -378,7 +359,7 @@ void CCyclone::Update(CScreensaverCyclone* base) m_curves[ptr ].color = glm::vec4(0.0f, 1.0f, 0.0f, 1.0f); m_curves[ptr++].vertex = point; } - base->DrawEntry(GL_LINE_STRIP, m_curves, ptr); + base->DrawEntry(GL_LINE_STRIP, m_curves.data(), ptr); ptr = 0; for (i = 0; i < (gCycloneSettings.dComplexity+3); i++) @@ -386,7 +367,7 @@ void CCyclone::Update(CScreensaverCyclone* base) m_curves[ptr ].color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); m_curves[ptr++].vertex = glm::vec3(m_xyz[i][0], m_xyz[i][1], m_xyz[i][2]); } - base->DrawEntry(GL_LINE_STRIP, m_curves, ptr); + base->DrawEntry(GL_LINE_STRIP, m_curves.data(), ptr); base->m_lightingEnabled = 1; } } @@ -535,13 +516,22 @@ bool CScreensaverCyclone::Start() // Initialize cyclones and their particles for (i = 0; i < 13; i++) m_fact[i] = float(factorial(i)); - m_cyclones = new CCyclone*[gCycloneSettings.dCyclones]; - m_particles = new CParticle*[gCycloneSettings.dParticles * gCycloneSettings.dCyclones]; - for (i = 0; i < gCycloneSettings.dCyclones; i++) + + m_cyclones.resize(gCycloneSettings.dCyclones); + m_particles.resize(gCycloneSettings.dParticles * gCycloneSettings.dCyclones); + + auto particles = m_particles.begin(); + + for (auto& cyclone : m_cyclones) { - m_cyclones[i] = new CCyclone; - for (j=i*gCycloneSettings.dParticles; j<((i+1)*gCycloneSettings.dParticles); j++) - m_particles[j] = new CParticle(m_cyclones[i]); + cyclone = std::make_unique(); + + std::for_each(particles, particles + gCycloneSettings.dParticles, [&cyclone](auto& particle) + { + particle = std::make_unique(cyclone.get()); + }); + + particles += gCycloneSettings.dParticles; } glGenBuffers(1, &m_vertexVBO); @@ -565,10 +555,6 @@ void CScreensaverCyclone::Stop() glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); - - // Free memory - delete[] m_particles; - delete[] m_cyclones; } void CScreensaverCyclone::Render() diff --git a/src/cyclone/main.h b/src/cyclone/main.h index 455a50ebf..4f03d2a39 100644 --- a/src/cyclone/main.h +++ b/src/cyclone/main.h @@ -21,6 +21,9 @@ #include #include +#include +#include + struct sLight { glm::vec3 vertex; @@ -93,8 +96,8 @@ class ATTR_DLL_LOCAL CScreensaverCyclone GLuint m_vertexVBO = 0; - CCyclone **m_cyclones; - CParticle **m_particles; + std::vector> m_cyclones; + std::vector> m_particles; float m_frameTime = 0.0f; bool m_startOK = false; diff --git a/src/drempels/TexMgr.cpp b/src/drempels/TexMgr.cpp index 8769d6292..c6463ed22 100644 --- a/src/drempels/TexMgr.cpp +++ b/src/drempels/TexMgr.cpp @@ -39,7 +39,6 @@ TexMgr::TexMgr() TexMgr::~TexMgr() { - delete m_imageThread; delete [] m_curTex; delete [] m_nextTex; } @@ -51,7 +50,7 @@ void TexMgr::setImageDir(const std::string& newDirName) void TexMgr::start() { - m_imageThread = new std::thread(&TexMgr::imageThreadMain, this); + m_imageThread = std::thread(&TexMgr::imageThreadMain, this); } void TexMgr::stop() @@ -63,7 +62,7 @@ void TexMgr::stop() m_nextTexCond.notify_one(); } - m_imageThread->join(); + m_imageThread.join(); } bool TexMgr::getNext() diff --git a/src/drempels/TexMgr.h b/src/drempels/TexMgr.h index 9284ec73c..c980a55f7 100644 --- a/src/drempels/TexMgr.h +++ b/src/drempels/TexMgr.h @@ -52,7 +52,7 @@ class TexMgr std::string m_dirName; DIR* m_imageDir = nullptr; - std::thread* m_imageThread = nullptr; + std::thread m_imageThread; std::mutex m_nextTexMutex; std::condition_variable m_nextTexCond; volatile bool m_exiting = false; diff --git a/src/drempels/main.cpp b/src/drempels/main.cpp index 88e59b4c4..269773965 100644 --- a/src/drempels/main.cpp +++ b/src/drempels/main.cpp @@ -130,7 +130,7 @@ bool CScreensaverDrempels::Start() gSettings.dGenTexSize = 256; m_textureManager.setTexSize(256, 256); - m_fadeBuf = new uint32_t[256 * 256]; + m_fadeBuf.resize(256 * 256); m_textureManager.setGenTexSize(gSettings.dGenTexSize, gSettings.dGenTexSize); @@ -211,10 +211,6 @@ void CScreensaverDrempels::Stop() m_startOK = false; m_textureManager.stop(); - delete [] m_fadeBuf; - delete [] m_cell; - delete [] m_buf; - glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &m_vertexVBO); m_vertexVBO = 0; @@ -311,7 +307,7 @@ void CScreensaverDrempels::Render() glDisable (GL_BLEND); glBindTexture(GL_TEXTURE_2D, m_tex); - glReadPixels(0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, m_fadeBuf); + glReadPixels(0, 0, 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, m_fadeBuf.data()); } else if (!m_fadeComplete) { @@ -331,13 +327,11 @@ void CScreensaverDrempels::Render() const float scale = 0.45f + 0.1f*sinf(intframe2*0.01f); const float rot = m_animTime*gSettings.rotational_speed*6.28f; - if (m_cell == NULL) - m_cell = new td_cellcornerinfo[UVCELLSX * UVCELLSY]; + m_cell.clear(); + m_cell.resize(UVCELLSX * UVCELLSY); #define CELL(i,j) m_cell[((i) * UVCELLSX) + (j)] - memset(m_cell, 0, sizeof(td_cellcornerinfo)*(UVCELLSX)*(UVCELLSY)); - #define NUM_MODES 7 float t[NUM_MODES]; @@ -573,8 +567,9 @@ void CScreensaverDrempels::Render() CELL(i,j).dsdy = (CELL(i,j+1).s - CELL(i,j).s) / (v_delta*FXH); } - if (m_buf == nullptr) - m_buf = new unsigned short [FXW * FXH * 2]; + m_buf.clear(); + m_buf.resize(FXW * FXH * 2); + for (unsigned int jj = 0; jj < UVCELLSY - 2; jj += 2) { for (unsigned int ii = 0; ii < UVCELLSX - 2; ii += 2) @@ -601,9 +596,9 @@ void CScreensaverDrempels::Render() glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, m_tex); - unsigned short *uvbuf = m_buf; - uint32_t *texbuf = m_fadeComplete ? m_textureManager.getCurTex() : m_fadeBuf; - uint32_t *outbuf = (uint32_t *)m_buf; + unsigned short *uvbuf = m_buf.data(); + uint32_t *texbuf = m_fadeComplete ? m_textureManager.getCurTex() : m_fadeBuf.data(); + uint32_t *outbuf = (uint32_t *)m_buf.data(); for (unsigned int ii = 0; ii < FXW * FXH; ++ii) { const uint16_t u0 = *uvbuf++; @@ -622,7 +617,7 @@ void CScreensaverDrempels::Render() *outbuf++ = rgbLerp(l, r, u0); } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FXW, FXH, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_buf); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FXW, FXH, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_buf.data()); DrawQuads(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f - blurAmount)); diff --git a/src/drempels/main.h b/src/drempels/main.h index 78e111d2a..8aada0375 100644 --- a/src/drempels/main.h +++ b/src/drempels/main.h @@ -56,7 +56,7 @@ class ATTR_DLL_LOCAL CScreensaverDrempels int m_cellResolution; bool m_fadeComplete = false; - uint32_t *m_fadeBuf = nullptr; + std::vector m_fadeBuf; float m_animTime = 0; @@ -71,8 +71,8 @@ class ATTR_DLL_LOCAL CScreensaverDrempels double m_lastTexChange = 0; - td_cellcornerinfo *m_cell = nullptr; - unsigned short *m_buf = nullptr; + std::vector m_cell; + std::vector m_buf; glm::mat4 m_projMat; glm::mat4 m_modelMat; diff --git a/src/euphoria/main.cpp b/src/euphoria/main.cpp index 1b0c5389c..8778d85c1 100644 --- a/src/euphoria/main.cpp +++ b/src/euphoria/main.cpp @@ -285,7 +285,7 @@ class CWisp { public: CWisp(); - ~CWisp(); + ~CWisp() = default; void update(float frameTime); void draw(glm::mat4& modelMat, CScreensaverEuphoria* base); void drawAsBackground(glm::mat4& modelMat, CScreensaverEuphoria* base); @@ -295,7 +295,8 @@ class CWisp const float m_viscon1 = float(g_settings.dVisibility) * 0.01f; const float m_viscon2 = 1.0f / m_viscon1; - float ***m_vertices; + std::vector>> m_vertices; + float m_c[NUMCONSTS]; // constants float m_cr[NUMCONSTS]; // constants' radial position float m_cv[NUMCONSTS]; // constants' change velocities @@ -310,18 +311,17 @@ CWisp::CWisp() int i, j; float recHalfDens = 1.0f / (float(g_settings.dDensity) * 0.5f); - m_vertices = new float**[g_settings.dDensity+1]; - for (i = 0; i <= g_settings.dDensity; i++) + m_vertices.resize(g_settings.dDensity+1); + for (auto& x : m_vertices) { - m_vertices[i] = new float*[g_settings.dDensity+1]; - for (j = 0; j <= g_settings.dDensity; j++) + x.resize(g_settings.dDensity+1); + for (auto& y : x) { - m_vertices[i][j] = new float[7]; - m_vertices[i][j][3] = float(i) * recHalfDens - 1.0f; // x position on grid - m_vertices[i][j][4] = float(j) * recHalfDens - 1.0f; // y position on grid + y[3] = float(i) * recHalfDens - 1.0f; // x position on grid + y[4] = float(j) * recHalfDens - 1.0f; // y position on grid // distance squared from the center - m_vertices[i][j][5] = m_vertices[i][j][3] * m_vertices[i][j][3] + m_vertices[i][j][4] * m_vertices[i][j][4]; - m_vertices[i][j][6] = 0.0f; // intensity + y[5] = y[3] * y[3] + y[4] * y[4]; + y[6] = 0.0f; // intensity } } @@ -341,21 +341,6 @@ CWisp::CWisp() m_saturationSpeed = rsRandf(0.04f) + 0.001f; } -CWisp::~CWisp() -{ - int i, j; - - for (i = 0; i <= g_settings.dDensity; i++) - { - for (j = 0; j <= g_settings.dDensity; j++) - { - delete[] m_vertices[i][j]; - } - delete[] m_vertices[i]; - } - delete[] m_vertices; -} - void CWisp::update(float frameTime) { int i, j; @@ -618,8 +603,8 @@ bool CScreensaverEuphoria::Start() } // Initialize wisps - m_wisps = new CWisp[g_settings.dWisps]; - m_backwisps = new CWisp[g_settings.dBackground]; + m_wisps.resize(g_settings.dWisps); + m_backwisps.resize(g_settings.dBackground); glGenBuffers(1, &m_vertexVBO); glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO); @@ -656,10 +641,6 @@ void CScreensaverEuphoria::Stop() m_feedbackTex = 0; glDeleteTextures(1, &m_texture); m_texture = 0; - - // Free memory - delete[] m_wisps; - delete[] m_backwisps; } void CScreensaverEuphoria::Render() @@ -694,10 +675,11 @@ void CScreensaverEuphoria::Render() int i; // Update wisps - for (i = 0; i < g_settings.dWisps; i++) - m_wisps[i].update(frameTime); - for (i = 0; i < g_settings.dBackground; i++) - m_backwisps[i].update(frameTime); + for (auto& wisp : m_wisps) + wisp.update(frameTime); + + for (auto& wisp : m_backwisps) + wisp.update(frameTime); // Render feedback and copy to texture if necessary if (g_settings.dFeedback) @@ -750,10 +732,12 @@ void CScreensaverEuphoria::Render() m_modelMat = modelMat; BindTexture(GL_TEXTURE_2D, m_texture); - for (i = 0; i < g_settings.dBackground; i++) - m_backwisps[i].drawAsBackground(m_modelMat, this); - for (i = 0; i < g_settings.dWisps; i++) - m_wisps[i].draw(m_modelMat, this); + + for (auto& wisp : m_backwisps) + wisp.drawAsBackground(m_modelMat, this); + + for (auto& wisp : m_wisps) + wisp.draw(m_modelMat, this); // readback feedback texture glReadBuffer(GL_BACK); diff --git a/src/euphoria/main.h b/src/euphoria/main.h index 2e9885536..674901017 100644 --- a/src/euphoria/main.h +++ b/src/euphoria/main.h @@ -107,8 +107,8 @@ class ATTR_DLL_LOCAL CScreensaverEuphoria GLuint m_vertexVBO = 0; - CWisp *m_backwisps; - CWisp *m_wisps; + std::vector m_backwisps; + std::vector m_wisps; // GL stored variables to pop back during stop int m_glUnpackRowLength = 0; diff --git a/src/feedback/main.cpp b/src/feedback/main.cpp index f18ba395b..e620676bb 100644 --- a/src/feedback/main.cpp +++ b/src/feedback/main.cpp @@ -22,8 +22,6 @@ #include #include -#define BUFFER_OFFSET(i) ((char *)nullptr + (i)) - namespace { struct sFeedbackSettings @@ -82,7 +80,7 @@ bool CScreensaverFeedback::Start() gSettings.dTexSize = newTexSize; } - uint8_t *pixels = new uint8_t[m_width * m_height * 3]; + std::vector pixels(m_width * m_height * 3); for (int hh = 0, ii = 0; hh < m_height; ++hh) { for (int ww = 0; ww < m_width; ++ww) @@ -106,15 +104,13 @@ bool CScreensaverFeedback::Start() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); - - delete [] pixels; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels.data()); } - m_displacements = new rsVec[gSettings.cwidth * gSettings.cheight]; - m_velocities = new rsVec[gSettings.cwidth * gSettings.cheight]; - m_accelerations = new rsVec[gSettings.cwidth * gSettings.cheight]; - m_framedTextures = new sLight[gSettings.cwidth * gSettings.cheight * 10]; + m_displacements.resize(gSettings.cwidth * gSettings.cheight); + m_velocities.resize(gSettings.cwidth * gSettings.cheight); + m_accelerations.resize(gSettings.cwidth * gSettings.cheight); + m_framedTextures.resize(gSettings.cwidth * gSettings.cheight * 10); for (unsigned int hh = 0, ii = 0; hh < gSettings.cheight; ++hh) { @@ -166,11 +162,6 @@ void CScreensaverFeedback::Stop() m_indexVBO = 0; glDeleteTextures(1, &m_texture); m_texture = 0; - - delete[] m_displacements; - delete[] m_velocities; - delete[] m_accelerations; - delete[] m_framedTextures; } void CScreensaverFeedback::Render() @@ -359,7 +350,7 @@ void CScreensaverFeedback::Render() } EnableShader(); - glBufferData(GL_ARRAY_BUFFER, sizeof(sLight)*ptr, m_framedTextures, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(sLight)*ptr, m_framedTextures.data(), GL_DYNAMIC_DRAW); glDrawArrays(GL_LINES, 0, ptr); DisableShader(); } diff --git a/src/feedback/main.h b/src/feedback/main.h index 7c6ebf40e..b42f5e763 100644 --- a/src/feedback/main.h +++ b/src/feedback/main.h @@ -22,6 +22,8 @@ #include +#include + struct sLight { glm::vec3 vertex; @@ -53,7 +55,11 @@ class ATTR_DLL_LOCAL CScreensaverFeedback } int m_width = 256, m_height = 256; - rsVec *m_displacements, *m_velocities, *m_accelerations; + + std::vector m_displacements; + std::vector m_velocities; + std::vector m_accelerations; + rsVec m_totalV; glm::mat4 m_projMat; @@ -72,7 +78,7 @@ class ATTR_DLL_LOCAL CScreensaverFeedback GLuint m_texture; sLight m_rotatingColor[4]; - sLight* m_framedTextures = nullptr; + std::vector m_framedTextures; GLubyte m_rotatingColorIdx[4] = {0, 1, 3, 2}; bool m_textureUsed = false; diff --git a/src/fieldlines/main.cpp b/src/fieldlines/main.cpp index 5ca338a30..02ef567b5 100644 --- a/src/fieldlines/main.cpp +++ b/src/fieldlines/main.cpp @@ -69,7 +69,7 @@ bool CScreensaverFieldLines::Start() m_projMat = glm::mat4(1.0f); m_modelMat = glm::scale(glm::mat4(1.0f), glm::vec3(1.0f/m_usedDeep/m_reduction, 1.0f/m_usedDeep/m_reduction, 1.0f/m_usedDeep/m_reduction)); - m_packets = new PackedVertex[m_maxSteps * 4 + 2]; + m_packets.resize(m_maxSteps * 4 + 2); m_startOK = true; m_lastTime = std::chrono::duration(std::chrono::system_clock::now().time_since_epoch()).count(); @@ -90,8 +90,6 @@ void CScreensaverFieldLines::Stop() glDeleteBuffers(1, &m_vertexVBO); m_vertexVBO = 0; - - delete[] m_packets; } void CScreensaverFieldLines::Render() diff --git a/src/fieldlines/main.h b/src/fieldlines/main.h index b0e9f57c4..6fb286e7a 100644 --- a/src/fieldlines/main.h +++ b/src/fieldlines/main.h @@ -57,7 +57,7 @@ class ATTR_DLL_LOCAL CScreensaverFieldLines double m_lastTime; std::vector m_ions; - PackedVertex* m_packets = nullptr; + std::vector m_packets; unsigned int m_vertexVBO = 0; diff --git a/src/flocks/main.cpp b/src/flocks/main.cpp index 7c724fe6d..557030ee5 100644 --- a/src/flocks/main.cpp +++ b/src/flocks/main.cpp @@ -236,13 +236,13 @@ class CBug { public: CBug(); - ~CBug(); + ~CBug() = default; void initTrail(); void initLeader(int width, int height, int depth); void initFollower(int width, int height, int depth); void update(CBug* bugs, float colorFade, float elapsedTime); - void render(CBug* bugs, CScreensaverFlocks* base) const; + void render(CBug* bugs, CScreensaverFlocks* base); private: int m_width; @@ -264,19 +264,19 @@ class CBug int skipTrail; int trailEndPtr; - float *xtrail = nullptr; - float *ytrail = nullptr; - float *ztrail = nullptr; + std::vector xtrail; + std::vector ytrail; + std::vector ztrail; - float *rtrail = nullptr; - float *gtrail = nullptr; - float *btrail = nullptr; + std::vector rtrail; + std::vector gtrail; + std::vector btrail; float xdrift; float ydrift; float zdrift; - sLight* m_trailLight = nullptr; + std::vector m_trailLight; }; CBug::CBug() @@ -284,30 +284,18 @@ CBug::CBug() hcount = rand(); } -CBug::~CBug() -{ - delete[] xtrail; - delete[] ytrail; - delete[] ztrail; - delete[] rtrail; - delete[] gtrail; - delete[] btrail; - delete[] m_trailLight; - -} - void CBug::initTrail() { trailEndPtr = 0; skipTrail = 0; - xtrail = new float[gSettings.dTrail]; - ytrail = new float[gSettings.dTrail]; - ztrail = new float[gSettings.dTrail]; - rtrail = new float[gSettings.dTrail]; - gtrail = new float[gSettings.dTrail]; - btrail = new float[gSettings.dTrail]; - m_trailLight = new sLight[gSettings.dTrail]; + xtrail.resize(gSettings.dTrail); + ytrail.resize(gSettings.dTrail); + ztrail.resize(gSettings.dTrail); + rtrail.resize(gSettings.dTrail); + gtrail.resize(gSettings.dTrail); + btrail.resize(gSettings.dTrail); + m_trailLight.resize(gSettings.dTrail); for (int i = 0; i < gSettings.dTrail; i++) { @@ -555,7 +543,7 @@ void CBug::update(CBug* bugs, float colorFade, float elapsedTime) } } -void CBug::render(CBug* bugs, CScreensaverFlocks* base) const +void CBug::render(CBug* bugs, CScreensaverFlocks* base) { int i; float scale[4] = { 0.0f }; @@ -697,7 +685,7 @@ void CBug::render(CBug* bugs, CScreensaverFlocks* base) const } base->m_uniformColorUsed = 0; base->m_lightingEnabled = 0; - base->DrawEntry(GL_LINE_STRIP, m_trailLight, gSettings.dTrail); + base->DrawEntry(GL_LINE_STRIP, m_trailLight.data(), gSettings.dTrail); base->m_lightingEnabled = gSettings.dGeometry ? 1 : 0; for (i = 0; i < gSettings.dTrail; i++) diff --git a/src/flux/main.cpp b/src/flux/main.cpp index 8c1055cf5..3c2472dde 100644 --- a/src/flux/main.cpp +++ b/src/flux/main.cpp @@ -203,11 +203,11 @@ class CParticle { public: CParticle(); - ~CParticle(); + ~CParticle() = default; void update(float *c, CScreensaverFlux* base); private: - float **m_vertices; + std::vector> m_vertices; int m_counter; float m_offset[3]; @@ -227,26 +227,19 @@ CParticle::CParticle() gWhichparticle++; // Initialize memory and set initial positions out of view of the camera - m_vertices = new float*[gSettings.dTrail]; - for (int i = 0; i < gSettings.dTrail; i++){ - m_vertices[i] = new float[5]; // 0,1,2 = position, 3 = hue, 4 = saturation - m_vertices[i][0] = 0.0f; - m_vertices[i][1] = 3.0f; - m_vertices[i][2] = 0.0f; - m_vertices[i][3] = 0.0f; - m_vertices[i][4] = 0.0f; + m_vertices.resize(gSettings.dTrail); + for (auto& vertex : m_vertices) + { + vertex[0] = 0.0f; + vertex[1] = 3.0f; + vertex[2] = 0.0f; + vertex[3] = 0.0f; + vertex[4] = 0.0f; } m_counter = 0; } -CParticle::~CParticle() -{ - for (int i = 0; i < gSettings.dTrail; i++) - delete[] m_vertices[i]; - delete[] m_vertices; -} - void CParticle::update(float *c, CScreensaverFlux* base) { int i, p, growth; @@ -443,11 +436,11 @@ class CFlux { public: CFlux(); - ~CFlux(); + ~CFlux() = default; void update(CScreensaverFlux* base); private: - CParticle *m_particles; + std::vector m_particles; int m_randomize; float m_c[NUMCONSTS]; // constants float m_cv[NUMCONSTS]; // constants' change velocities @@ -459,7 +452,7 @@ CFlux::CFlux() gWhichparticle = 0; - m_particles = new CParticle[gSettings.dParticles]; + m_particles.resize(gSettings.dParticles); m_randomize = 1; for (i = 0; i < NUMCONSTS; i++) { @@ -469,11 +462,6 @@ CFlux::CFlux() } } -CFlux::~CFlux() -{ - delete[] m_particles; -} - void CFlux::update(CScreensaverFlux* base) { // randomize constants @@ -614,7 +602,7 @@ bool CScreensaverFlux::Start() m_lumdiff = 1.0f / float(gSettings.dTrail); // Initialize flux fields - m_fluxes = new CFlux[gSettings.dFluxes]; + m_fluxes.resize(gSettings.dFluxes); glGenBuffers(1, &m_vertexVBO); glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO); @@ -650,9 +638,6 @@ void CScreensaverFlux::Stop() #if defined(HAS_GL) || (defined(HAS_GLES) && HAS_GLES == 3) glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); #endif - - // Free memory - delete[] m_fluxes; } void CScreensaverFlux::Render() diff --git a/src/flux/main.h b/src/flux/main.h index 540a758a6..7e4b0efbf 100644 --- a/src/flux/main.h +++ b/src/flux/main.h @@ -107,7 +107,7 @@ class ATTR_DLL_LOCAL CScreensaverFlux GLuint m_lightingEnabled = 0; - CFlux *m_fluxes; + std::vector m_fluxes; std::vector m_sphereTriangleFan1; std::vector m_sphereTriangleFan2;