Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernization #125

Open
wants to merge 20 commits into
base: Omega
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e2e586a
CCyclone: use std::vector for m_curves
lrusak Apr 20, 2023
f96c8d4
CCyclone: use std::vector and std::array for xyz
lrusak Apr 20, 2023
e705ccc
CScreensaverCyclone: use std::vector and unique_ptr for m_cyclones an…
lrusak Apr 20, 2023
94952da
CScreensaverColorFire: remove use of malloc and free
lrusak Apr 20, 2023
d252bb4
CScreensaverDrempels: use std::vector for m_fadeBuf
lrusak Apr 20, 2023
f5e0601
CScreensaverDrempels: use std::vector for m_cell
lrusak Apr 20, 2023
0211607
CScreensaverDrempels: use std::vector for m_buf
lrusak Apr 20, 2023
1b0e3a3
TexMgr: std::thread doesn't need to be a pointer
lrusak Apr 20, 2023
1aa8d42
CScreensaverEuphoria: use std::vector for m_wisps
lrusak Apr 20, 2023
9ddb480
CScreensaverEuphoria: use std::vector for m_vertices
lrusak Apr 20, 2023
1eefed8
CScreensaverFeedback: use std::vector for rsVec arrays
lrusak Apr 20, 2023
2818c18
CScreensaverFeedback: use std::vector for m_framedTextures
lrusak Apr 20, 2023
7b3c504
CScreensaverFeedback: use std::vector for pixels
lrusak Apr 20, 2023
0bccece
CScreensaverFeedback: remove duplicate macro
lrusak Apr 20, 2023
e75e1fb
CScreensaverFieldLines: use std::vector for m_packets
lrusak Apr 20, 2023
8b6d9f0
CBug: use std::vector for trails
lrusak Apr 20, 2023
b930342
CBug: use std::vector for m_trailLight
lrusak Apr 20, 2023
ce76b29
CParticle: use std::vector and std::array for m_vertices
lrusak Apr 20, 2023
151d37b
CFlux: use std::vector for m_particles
lrusak Apr 20, 2023
79ebdae
CScreensaverFlux: use std::vector for m_fluxes
lrusak Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/colorfire/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#include <gli/gli.hpp>
#include <bzlib.h>

#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
Expand Down Expand Up @@ -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<char*>(Texture.data()), &smokemap_size, const_cast<char*>(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<char*>(Texture.data()), &ripplemap_size, const_cast<char*>(ripplemap), ripplemap_compressedsize, 0, 0);

m_texture = kodi::gui::gl::Load(Texture);
FREE_TEXTURE(l_tex)
break;
}
case TYPE_SMOOTH:
Expand Down
72 changes: 29 additions & 43 deletions src/cyclone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "main.h"

#include <array>
#include <vector>
#include <chrono>
#include <algorithm>
#include <glm/glm.hpp>
Expand Down Expand Up @@ -96,9 +98,9 @@ int factorial(int x)
class CCyclone
{
public:
float **m_targetxyz;
float **m_xyz;
float **m_oldxyz;
std::vector<std::array<float, 3>> m_targetxyz;
std::vector<std::array<float, 3>> m_xyz;
std::vector<std::array<float, 3>> m_oldxyz;
float *m_targetWidth;
float *m_width;
float *m_oldWidth;
Expand All @@ -110,29 +112,24 @@ class CCyclone
float m_hslChange[2];

CCyclone();
~CCyclone();
~CCyclone() = default;
void Update(CScreensaverCyclone* base);

private:
sLight* m_curves = nullptr;
std::vector<sLight> m_curves;
};

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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -378,15 +359,15 @@ 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++)
{
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;
}
}
Expand Down Expand Up @@ -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<CCyclone>();

std::for_each(particles, particles + gCycloneSettings.dParticles, [&cyclone](auto& particle)
{
particle = std::make_unique<CParticle>(cyclone.get());
});

particles += gCycloneSettings.dParticles;
}

glGenBuffers(1, &m_vertexVBO);
Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions src/cyclone/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <kodi/gui/gl/Shader.h>
#include <glm/gtc/type_ptr.hpp>

#include <memory>
#include <vector>

struct sLight
{
glm::vec3 vertex;
Expand Down Expand Up @@ -93,8 +96,8 @@ class ATTR_DLL_LOCAL CScreensaverCyclone

GLuint m_vertexVBO = 0;

CCyclone **m_cyclones;
CParticle **m_particles;
std::vector<std::unique_ptr<CCyclone>> m_cyclones;
std::vector<std::unique_ptr<CParticle>> m_particles;

float m_frameTime = 0.0f;
bool m_startOK = false;
Expand Down
5 changes: 2 additions & 3 deletions src/drempels/TexMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ TexMgr::TexMgr()

TexMgr::~TexMgr()
{
delete m_imageThread;
delete [] m_curTex;
delete [] m_nextTex;
}
Expand All @@ -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()
Expand All @@ -63,7 +62,7 @@ void TexMgr::stop()
m_nextTexCond.notify_one();
}

m_imageThread->join();
m_imageThread.join();
}

bool TexMgr::getNext()
Expand Down
2 changes: 1 addition & 1 deletion src/drempels/TexMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 11 additions & 16 deletions src/drempels/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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];
Expand Down Expand Up @@ -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)
Expand All @@ -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++;
Expand All @@ -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));

Expand Down
6 changes: 3 additions & 3 deletions src/drempels/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ATTR_DLL_LOCAL CScreensaverDrempels
int m_cellResolution;

bool m_fadeComplete = false;
uint32_t *m_fadeBuf = nullptr;
std::vector<uint32_t> m_fadeBuf;

float m_animTime = 0;

Expand All @@ -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<td_cellcornerinfo> m_cell;
std::vector<unsigned short> m_buf;

glm::mat4 m_projMat;
glm::mat4 m_modelMat;
Expand Down
Loading