mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 05:12:25 +08:00
chore: make use of auto where it made sense
This commit is contained in:
parent
d0752b8659
commit
eb1f7e47ce
@ -17,9 +17,8 @@ const ITexture* CContainer::readTexture (const std::filesystem::path& filename)
|
||||
// get the texture's filename (usually .tex)
|
||||
std::filesystem::path texture = "materials" / std::filesystem::path (filename.string ().append (".tex"));
|
||||
|
||||
const uint8_t* textureContents = this->readFile (texture, nullptr);
|
||||
|
||||
const ITexture* result = new CTexture (textureContents);
|
||||
const auto* textureContents = this->readFile (texture, nullptr);
|
||||
const auto* result = new CTexture (textureContents);
|
||||
|
||||
#if !NDEBUG
|
||||
glObjectLabel (GL_TEXTURE, result->getTextureID (0), -1, texture.c_str ());
|
||||
@ -76,8 +75,8 @@ std::string CContainer::readFileAsString (const std::filesystem::path& filename)
|
||||
uint32_t length = 0;
|
||||
|
||||
// read file contents and allocate a buffer for a string
|
||||
const uint8_t* contents = this->readFile (filename, &length);
|
||||
char* buffer = new char [length + 1];
|
||||
const auto* contents = this->readFile (filename, &length);
|
||||
auto* buffer = new char [length + 1];
|
||||
|
||||
// ensure there's a 0 at the end
|
||||
memset (buffer, 0, length + 1);
|
||||
|
@ -62,14 +62,16 @@ CTexture::CTexture (const void* fileData) : m_resolution () {
|
||||
case GL_RGBA8:
|
||||
case GL_RG8:
|
||||
case GL_R8:
|
||||
glTexImage2D (GL_TEXTURE_2D, level, internalFormat, width, height, 0, textureFormat,
|
||||
GL_UNSIGNED_BYTE, dataptr);
|
||||
glTexImage2D (
|
||||
GL_TEXTURE_2D, level, internalFormat, width, height, 0, textureFormat,
|
||||
GL_UNSIGNED_BYTE, dataptr);
|
||||
break;
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
||||
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
||||
glCompressedTexImage2D (GL_TEXTURE_2D, level, internalFormat, width, height, 0, bufferSize,
|
||||
dataptr);
|
||||
glCompressedTexImage2D (
|
||||
GL_TEXTURE_2D, level, internalFormat, width, height, 0, bufferSize,
|
||||
dataptr);
|
||||
break;
|
||||
default: sLog.exception ("Cannot load texture, unknown format", this->m_header->format);
|
||||
}
|
||||
@ -259,7 +261,8 @@ CTexture::TextureHeader::TextureHeader () :
|
||||
gifHeight (0),
|
||||
format (TextureFormat::UNKNOWN),
|
||||
imageCount (0),
|
||||
mipmapCount (0) {}
|
||||
mipmapCount (0),
|
||||
isVideoMp4 (false) {}
|
||||
|
||||
CTexture::TextureHeader::~TextureHeader () {
|
||||
for (const auto& [index, mipmaps] : this->images)
|
||||
@ -311,7 +314,7 @@ CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) {
|
||||
header->freeImageFormat = FIF_MP4;
|
||||
}
|
||||
|
||||
// default to TEXB0003 behaviour if no mp4 video is there
|
||||
// default to TEXB0003 behavior if no mp4 video is there
|
||||
if (header->freeImageFormat != FIF_MP4) {
|
||||
header->containerVersion = ContainerVersion::TEXB0003;
|
||||
}
|
||||
@ -344,7 +347,7 @@ CTexture::TextureHeader* CTexture::parseHeader (const char* fileData) {
|
||||
}
|
||||
|
||||
// gifs have extra information after the mipmaps
|
||||
if (header->isAnimated () == true) {
|
||||
if (header->isAnimated ()) {
|
||||
if (strncmp (fileData, "TEXS0002", 9) == 0) {
|
||||
header->animatedVersion = AnimatedVersion::TEXS0002;
|
||||
} else if (strncmp (fileData, "TEXS0003", 9) == 0) {
|
||||
|
@ -140,7 +140,7 @@ class CTexture final : public ITexture {
|
||||
/** Free Image format */
|
||||
FreeImageFormat freeImageFormat = FreeImageFormat::FIF_UNKNOWN;
|
||||
/** Indicates if we have an MP4 video */
|
||||
bool isVideoMp4;
|
||||
bool isVideoMp4{};
|
||||
/** The amount of images in the texture file */
|
||||
uint32_t imageCount;
|
||||
/** Number of mipmap levels on the texture */
|
||||
|
@ -53,8 +53,9 @@ void audio_callback (void* userdata, uint8_t* streamData, int length) {
|
||||
len1 = streamLength;
|
||||
|
||||
// mix the audio
|
||||
SDL_MixAudioFormat (streamDataPointer, &buffer->audio_buf [buffer->audio_buf_index],
|
||||
driver->getSpec ().format, len1, driver->getApplicationContext ().state.audio.volume);
|
||||
SDL_MixAudioFormat (
|
||||
streamDataPointer, &buffer->audio_buf [buffer->audio_buf_index], driver->getSpec ().format,
|
||||
len1, driver->getApplicationContext ().state.audio.volume);
|
||||
|
||||
streamLength -= len1;
|
||||
streamDataPointer += len1;
|
||||
@ -75,12 +76,14 @@ CSDLAudioDriver::CSDLAudioDriver (Application::CApplicationContext& applicationC
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_AudioSpec requestedSpec = {.freq = 48000,
|
||||
.format = AUDIO_F32,
|
||||
.channels = 2,
|
||||
.samples = SDL_AUDIO_BUFFER_SIZE,
|
||||
.callback = audio_callback,
|
||||
.userdata = this};
|
||||
const SDL_AudioSpec requestedSpec = {
|
||||
.freq = 48000,
|
||||
.format = AUDIO_F32,
|
||||
.channels = 2,
|
||||
.samples = SDL_AUDIO_BUFFER_SIZE,
|
||||
.callback = audio_callback,
|
||||
.userdata = this
|
||||
};
|
||||
|
||||
this->m_deviceID =
|
||||
SDL_OpenAudioDevice (nullptr, false, &requestedSpec, &this->m_audioSpec, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
|
@ -16,7 +16,7 @@ void sinkInputInfoCallback (pa_context* context, const pa_sink_input_info* info,
|
||||
// get processid
|
||||
const char* value = pa_proplist_gets (info->proplist, PA_PROP_APPLICATION_PROCESS_ID);
|
||||
|
||||
if (value && atoi (value) != getpid () && pa_cvolume_avg (&info->volume) != PA_VOLUME_MUTED)
|
||||
if (value && strtol (value, nullptr, 10) != getpid () && pa_cvolume_avg (&info->volume) != PA_VOLUME_MUTED)
|
||||
detector->setIsPlaying (true);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ static int backgroundId = -1;
|
||||
|
||||
CProject::CProject (
|
||||
std::string title, std::string type, std::string workshopid, const CContainer* container,
|
||||
const std::map<std::string, Projects::CProperty*> properties
|
||||
const std::map<std::string, Projects::CProperty*>& properties
|
||||
) :
|
||||
m_workshopid(std::move(workshopid)),
|
||||
m_title (std::move(title)),
|
||||
|
@ -35,7 +35,7 @@ class CProject {
|
||||
protected:
|
||||
CProject (
|
||||
std::string title, std::string type, std::string workshopid, const CContainer* container,
|
||||
std::map<std::string, Projects::CProperty*> properties);
|
||||
const std::map<std::string, Projects::CProperty*>& properties);
|
||||
|
||||
void setWallpaper (const CWallpaper* wallpaper);
|
||||
|
||||
|
@ -321,7 +321,7 @@ template const glm::ivec4 Core::jsonFindRequired (const nlohmann::json& data, co
|
||||
template const glm::ivec3 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
||||
template const glm::ivec2 Core::jsonFindRequired (const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
||||
|
||||
const nlohmann::json::const_iterator Core::jsonFindRequired (
|
||||
nlohmann::json::const_iterator Core::jsonFindRequired (
|
||||
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg
|
||||
) {
|
||||
auto value = data->find (key);
|
||||
@ -332,7 +332,7 @@ const nlohmann::json::const_iterator Core::jsonFindRequired (
|
||||
return value;
|
||||
}
|
||||
|
||||
const nlohmann::json::const_iterator Core::jsonFindRequired (
|
||||
nlohmann::json::const_iterator Core::jsonFindRequired (
|
||||
const nlohmann::json& data, const char* key, const char* notFoundMsg
|
||||
) {
|
||||
auto value = data.find (key);
|
||||
|
@ -36,9 +36,9 @@ template <typename T> const T jsonFindRequired (
|
||||
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
||||
template <typename T> const T jsonFindRequired (
|
||||
const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
||||
const nlohmann::json::const_iterator jsonFindRequired (
|
||||
nlohmann::json::const_iterator jsonFindRequired (
|
||||
const nlohmann::json::const_iterator& data, const char* key, const char* notFoundMsg);
|
||||
const nlohmann::json::const_iterator jsonFindRequired (
|
||||
nlohmann::json::const_iterator jsonFindRequired (
|
||||
const nlohmann::json& data, const char* key, const char* notFoundMsg);
|
||||
template <typename T> const T jsonFindDefault (
|
||||
const nlohmann::json::const_iterator& data, const char* key, const T defaultValue);
|
||||
|
@ -76,7 +76,7 @@ std::map<std::string, int> CEffect::combosFromJSON (const json::const_iterator&
|
||||
std::map<std::string, int> combos;
|
||||
|
||||
for (const auto& cur : combos_it->items ()) {
|
||||
std::string uppercase = std::string (cur.key ());
|
||||
auto uppercase = std::string (cur.key ());
|
||||
|
||||
std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
|
||||
combos.insert (std::pair (uppercase, cur.value ()));
|
||||
|
@ -13,8 +13,9 @@ void CustomGLFWErrorHandler (int errorCode, const char* reason) {
|
||||
sLog.error ("GLFW error ", errorCode, ": ", reason);
|
||||
}
|
||||
|
||||
CGLFWOpenGLDriver::CGLFWOpenGLDriver (const char* windowTitle, CApplicationContext& context,
|
||||
CWallpaperApplication& app) :
|
||||
CGLFWOpenGLDriver::CGLFWOpenGLDriver (
|
||||
const char* windowTitle, CApplicationContext& context, CWallpaperApplication& app
|
||||
) :
|
||||
CVideoDriver (app),
|
||||
m_context (context),
|
||||
m_frameCounter (0) {
|
||||
|
@ -149,7 +149,7 @@ void CWaylandOpenGLDriver::initEGL () {
|
||||
sLog.exception ("eglInitialize failed!");
|
||||
}
|
||||
|
||||
const std::string CLIENTEXTENSIONSPOSTINIT = std::string (eglQueryString (m_eglContext.display, EGL_EXTENSIONS));
|
||||
const auto CLIENTEXTENSIONSPOSTINIT = std::string (eglQueryString (m_eglContext.display, EGL_EXTENSIONS));
|
||||
|
||||
if (CLIENTEXTENSIONSPOSTINIT.find ("EGL_KHR_create_context") == std::string::npos) {
|
||||
this->finishEGL ();
|
||||
|
Loading…
Reference in New Issue
Block a user