fix: cppcheck (21 troballes)
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
// --- Includes ---
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint> // Para uint32_t, uint8_t
|
||||
#include <cstdio> // Para NULL, fseek, fclose, fopen, fread, ftell, FILE, SEEK_END, SEEK_SET
|
||||
#include <cstdlib> // Para free, malloc
|
||||
#include <iostream> // Para std::cout
|
||||
#include <memory> // Para std::unique_ptr
|
||||
#include <string> // Para std::string
|
||||
#include <vector> // Para std::vector
|
||||
#include <algorithm> // Para std::fill
|
||||
#include <cstdint> // Para uint32_t, uint8_t
|
||||
#include <cstdio> // Para NULL, fseek, fclose, fopen, fread, ftell, FILE, SEEK_END, SEEK_SET
|
||||
#include <cstdlib> // Para free, malloc
|
||||
#include <iostream> // Para std::cout
|
||||
#include <memory> // Para std::unique_ptr
|
||||
#include <string> // Para std::string
|
||||
#include <vector> // Para std::vector
|
||||
|
||||
#define STB_VORBIS_HEADER_ONLY
|
||||
#include "external/stb_vorbis.c" // NOLINT(bugprone-suspicious-include): stb header-only library
|
||||
@@ -270,9 +271,7 @@ inline void JA_Init(const int freq, const SDL_AudioFormat format, const int num_
|
||||
for (auto& channel : channels) {
|
||||
channel.state = JA_CHANNEL_FREE;
|
||||
}
|
||||
for (float& i : JA_soundVolume) {
|
||||
i = 0.5F;
|
||||
}
|
||||
std::fill(std::begin(JA_soundVolume), std::end(JA_soundVolume), 0.5F);
|
||||
}
|
||||
|
||||
inline void JA_Quit() {
|
||||
@@ -673,10 +672,10 @@ inline void JA_PauseChannel(const int channel) {
|
||||
}
|
||||
|
||||
if (channel == -1) {
|
||||
for (auto& channel : channels) {
|
||||
if (channel.state == JA_CHANNEL_PLAYING) {
|
||||
channel.state = JA_CHANNEL_PAUSED;
|
||||
SDL_UnbindAudioStream(channel.stream);
|
||||
for (auto& ch : channels) {
|
||||
if (ch.state == JA_CHANNEL_PLAYING) {
|
||||
ch.state = JA_CHANNEL_PAUSED;
|
||||
SDL_UnbindAudioStream(ch.stream);
|
||||
}
|
||||
}
|
||||
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||
@@ -693,10 +692,10 @@ inline void JA_ResumeChannel(const int channel) {
|
||||
}
|
||||
|
||||
if (channel == -1) {
|
||||
for (auto& channel : channels) {
|
||||
if (channel.state == JA_CHANNEL_PAUSED) {
|
||||
channel.state = JA_CHANNEL_PLAYING;
|
||||
SDL_BindAudioStream(sdlAudioDevice, channel.stream);
|
||||
for (auto& ch : channels) {
|
||||
if (ch.state == JA_CHANNEL_PAUSED) {
|
||||
ch.state = JA_CHANNEL_PLAYING;
|
||||
SDL_BindAudioStream(sdlAudioDevice, ch.stream);
|
||||
}
|
||||
}
|
||||
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||
@@ -709,15 +708,15 @@ inline void JA_ResumeChannel(const int channel) {
|
||||
|
||||
inline void JA_StopChannel(const int channel) {
|
||||
if (channel == -1) {
|
||||
for (auto& channel : channels) {
|
||||
if (channel.state != JA_CHANNEL_FREE) {
|
||||
if (channel.stream != nullptr) {
|
||||
SDL_DestroyAudioStream(channel.stream);
|
||||
for (auto& ch : channels) {
|
||||
if (ch.state != JA_CHANNEL_FREE) {
|
||||
if (ch.stream != nullptr) {
|
||||
SDL_DestroyAudioStream(ch.stream);
|
||||
}
|
||||
channel.stream = nullptr;
|
||||
channel.state = JA_CHANNEL_FREE;
|
||||
channel.pos = 0;
|
||||
channel.sound = nullptr;
|
||||
ch.stream = nullptr;
|
||||
ch.state = JA_CHANNEL_FREE;
|
||||
ch.pos = 0;
|
||||
ch.sound = nullptr;
|
||||
}
|
||||
}
|
||||
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
||||
@@ -748,9 +747,7 @@ inline auto JA_SetSoundVolume(float volume, const int group = -1) -> float {
|
||||
const float v = SDL_clamp(volume, 0.0F, 1.0F);
|
||||
|
||||
if (group == -1) {
|
||||
for (float& i : JA_soundVolume) {
|
||||
i = v;
|
||||
}
|
||||
std::fill(std::begin(JA_soundVolume), std::end(JA_soundVolume), v);
|
||||
} else if (group >= 0 && group < JA_MAX_GROUPS) {
|
||||
JA_soundVolume[group] = v;
|
||||
} else {
|
||||
|
||||
@@ -145,11 +145,11 @@ void JD8_FillRect(int x, int y, int w, int h, Uint8 color) {
|
||||
}
|
||||
}
|
||||
|
||||
void JD8_Blit(JD8_Surface surface) {
|
||||
void JD8_Blit(const Uint8* surface) {
|
||||
memcpy(screen, surface, 64000);
|
||||
}
|
||||
|
||||
void JD8_Blit(int x, int y, JD8_Surface surface, int sx, int sy, int sw, int sh) {
|
||||
void JD8_Blit(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh) {
|
||||
int src_pointer = sx + (sy * 320);
|
||||
int dst_pointer = x + (y * 320);
|
||||
for (int i = 0; i < sh; i++) {
|
||||
@@ -159,7 +159,7 @@ void JD8_Blit(int x, int y, JD8_Surface surface, int sx, int sy, int sw, int sh)
|
||||
}
|
||||
}
|
||||
|
||||
void JD8_BlitToSurface(int x, int y, JD8_Surface surface, int sx, int sy, int sw, int sh, JD8_Surface dest) {
|
||||
void JD8_BlitToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest) {
|
||||
int src_pointer = sx + (sy * 320);
|
||||
int dst_pointer = x + (y * 320);
|
||||
for (int i = 0; i < sh; i++) {
|
||||
@@ -305,7 +305,7 @@ void JD8_FadeStartOut() {
|
||||
fade_step = 0;
|
||||
}
|
||||
|
||||
void JD8_FadeStartToPal(JD8_Palette pal) {
|
||||
void JD8_FadeStartToPal(const Color* pal) {
|
||||
fade_type = FadeType::ToPal;
|
||||
memcpy(fade_target, pal, sizeof(Color) * 256);
|
||||
fade_step = 0;
|
||||
|
||||
@@ -30,11 +30,11 @@ void JD8_FillSquare(int ini, int height, Uint8 color);
|
||||
// Pensat per a UI senzilla (barra de progrés del BootLoader, etc.).
|
||||
void JD8_FillRect(int x, int y, int w, int h, Uint8 color);
|
||||
|
||||
void JD8_Blit(JD8_Surface surface);
|
||||
void JD8_Blit(const Uint8* surface);
|
||||
|
||||
void JD8_Blit(int x, int y, JD8_Surface surface, int sx, int sy, int sw, int sh);
|
||||
void JD8_Blit(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh);
|
||||
|
||||
void JD8_BlitToSurface(int x, int y, JD8_Surface surface, int sx, int sy, int sw, int sh, JD8_Surface dest);
|
||||
void JD8_BlitToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest);
|
||||
|
||||
void JD8_BlitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey);
|
||||
|
||||
@@ -69,7 +69,7 @@ void JD8_SetPaletteColor(Uint8 index, Uint8 r, Uint8 g, Uint8 b);
|
||||
// un fade en curs per a enllaçar-lo amb un altre subsistema.
|
||||
// L'embolcall `scenes::PaletteFade` ho fa més idiomàtic per a escenes.
|
||||
void JD8_FadeStartOut();
|
||||
void JD8_FadeStartToPal(JD8_Palette pal);
|
||||
void JD8_FadeStartToPal(const Color* pal);
|
||||
auto JD8_FadeTickStep() -> bool;
|
||||
auto JD8_FadeIsActive() -> bool;
|
||||
|
||||
|
||||
+13
-15
@@ -3,6 +3,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -90,11 +91,10 @@ void file_setconfigfolder(const char* foldername) {
|
||||
homedir = "/tmp";
|
||||
}
|
||||
config_folder = std::string(homedir) + "/.config/" + foldername;
|
||||
#else
|
||||
config_folder = std::string("/tmp/jailgames_config/") + foldername;
|
||||
#endif
|
||||
|
||||
if (config_folder.empty()) {
|
||||
config_folder = "/tmp/jailgames_config";
|
||||
}
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(config_folder, ec);
|
||||
// A emscripten/MEMFS create_directories pot fallar (p.ex. parent
|
||||
@@ -112,12 +112,11 @@ auto file_getconfigvalue(const char* key) -> const char* {
|
||||
if (config.empty()) {
|
||||
load_config_values();
|
||||
}
|
||||
for (const auto& pair : config) {
|
||||
if (pair.key == key) {
|
||||
thread_local std::string value_cache;
|
||||
value_cache = pair.value;
|
||||
return value_cache.c_str();
|
||||
}
|
||||
const auto it = std::find_if(config.begin(), config.end(), [key](const keyvalue& pair) { return pair.key == key; });
|
||||
if (it != config.end()) {
|
||||
thread_local std::string value_cache;
|
||||
value_cache = it->value;
|
||||
return value_cache.c_str();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -126,12 +125,11 @@ void file_setconfigvalue(const char* key, const char* value) {
|
||||
if (config.empty()) {
|
||||
load_config_values();
|
||||
}
|
||||
for (auto& pair : config) {
|
||||
if (pair.key == key) {
|
||||
pair.value = value;
|
||||
save_config_values();
|
||||
return;
|
||||
}
|
||||
const auto it = std::find_if(config.begin(), config.end(), [key](const keyvalue& pair) { return pair.key == key; });
|
||||
if (it != config.end()) {
|
||||
it->value = value;
|
||||
save_config_values();
|
||||
return;
|
||||
}
|
||||
config.push_back({std::string(key), std::string(value)});
|
||||
save_config_values();
|
||||
|
||||
@@ -365,12 +365,7 @@ namespace Menu {
|
||||
// body = (N-1) * ITEM_SPACING + charH — així BOTTOM_PAD és el buit real
|
||||
// sota el text del darrer ítem, no un buit extra per sobre d'un "slot" buit.
|
||||
static auto boxHeight(const Page& page) -> int {
|
||||
int n = 0;
|
||||
for (const auto& it : page.items) {
|
||||
if (isVisible(it)) {
|
||||
++n;
|
||||
}
|
||||
}
|
||||
const int n = static_cast<int>(std::count_if(page.items.begin(), page.items.end(), [](const auto& it) { return isVisible(it); }));
|
||||
int body = (n == 0) ? 8 : ((n - 1) * ITEM_SPACING) + 8;
|
||||
int header = HEADER_H + (page.subtitle.empty() ? 0 : SUBTITLE_H);
|
||||
return header + body + BOTTOM_PAD;
|
||||
@@ -557,12 +552,7 @@ namespace Menu {
|
||||
items_y += SUBTITLE_H;
|
||||
}
|
||||
// Compta visibles — si cap, dibuixa placeholder (caixa totalment col·lapsada però oberta)
|
||||
int visible_count = 0;
|
||||
for (const auto& it : page.items) {
|
||||
if (isVisible(it)) {
|
||||
++visible_count;
|
||||
}
|
||||
}
|
||||
const int visible_count = static_cast<int>(std::count_if(page.items.begin(), page.items.end(), [](const auto& it) { return isVisible(it); }));
|
||||
if (visible_count == 0) {
|
||||
const char* empty_text = Locale::get("menu.values.empty");
|
||||
int ew = font_->width(empty_text);
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace Overlay {
|
||||
|
||||
// Calcula amplada total interpolant cada segment per la seva anim
|
||||
float total_w = 0.0F;
|
||||
for (auto& seg : info_segments_) {
|
||||
for (const auto& seg : info_segments_) {
|
||||
if (seg.anim > 0.0F && !seg.text.empty()) {
|
||||
int w = seg.mono_digits
|
||||
? font_->widthMonoDigits(seg.text.c_str(), DIGIT_CELL)
|
||||
@@ -270,7 +270,7 @@ namespace Overlay {
|
||||
|
||||
// Dibuixa cada segment en la seva posició x acumulada
|
||||
float cur_x = (SCREEN_W - total_w) / 2.0F;
|
||||
for (auto& seg : info_segments_) {
|
||||
for (const auto& seg : info_segments_) {
|
||||
if (seg.anim > 0.01F && !seg.text.empty()) {
|
||||
int xi = static_cast<int>(cur_x);
|
||||
int seg_w = seg.mono_digits
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Resource {
|
||||
}
|
||||
|
||||
void Cache::calculateTotal() {
|
||||
auto* list = List::get();
|
||||
const auto* list = List::get();
|
||||
total_count_ = static_cast<int>(
|
||||
list->getListByType(List::Type::MUSIC).size() +
|
||||
list->getListByType(List::Type::SOUND).size() +
|
||||
@@ -110,7 +110,7 @@ namespace Resource {
|
||||
|
||||
const Uint64 start_ns = SDL_GetTicksNS();
|
||||
const Uint64 budget_ns = static_cast<Uint64>(budget_ms) * 1'000'000ULL;
|
||||
auto* list = List::get();
|
||||
const auto* list = List::get();
|
||||
|
||||
while (stage_ != LoadStage::DONE) {
|
||||
switch (stage_) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
const std::string ResourcePack::DEFAULT_ENCRYPT_KEY = "AEE_RESOURCES__2026";
|
||||
|
||||
@@ -21,11 +22,7 @@ ResourcePack::~ResourcePack() {
|
||||
|
||||
auto ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
|
||||
// djb2-like hash, seed 0x12345678 (idèntic a CCAE).
|
||||
uint32_t checksum = 0x12345678;
|
||||
for (unsigned char b : data) {
|
||||
checksum = ((checksum << 5) + checksum) + b;
|
||||
}
|
||||
return checksum;
|
||||
return std::accumulate(data.begin(), data.end(), uint32_t{0x12345678}, [](uint32_t acc, unsigned char b) { return ((acc << 5) + acc) + b; });
|
||||
}
|
||||
|
||||
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
|
||||
@@ -163,20 +160,18 @@ auto ResourcePack::addDirectory(const std::string& directory) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) {
|
||||
if (!entry.is_regular_file()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string filepath = entry.path().string();
|
||||
std::string filename = std::filesystem::relative(entry.path(), directory).string();
|
||||
std::ranges::replace(filename, '\\', '/');
|
||||
|
||||
if (!addFile(filename, filepath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
namespace fs = std::filesystem;
|
||||
return std::all_of(fs::recursive_directory_iterator(directory),
|
||||
fs::recursive_directory_iterator{},
|
||||
[&](const fs::directory_entry& entry) {
|
||||
if (!entry.is_regular_file()) {
|
||||
return true;
|
||||
}
|
||||
std::string filepath = entry.path().string();
|
||||
std::string filename = fs::relative(entry.path(), directory).string();
|
||||
std::ranges::replace(filename, '\\', '/');
|
||||
return addFile(filename, filepath);
|
||||
});
|
||||
}
|
||||
|
||||
auto ResourcePack::getResource(const std::string& filename) -> std::vector<uint8_t> {
|
||||
|
||||
Reference in New Issue
Block a user