manuals tidy tier 1: suffixes, params, switches, equals-default

This commit is contained in:
2026-05-14 18:58:29 +02:00
parent b7a551c158
commit 8676c0e773
15 changed files with 47 additions and 36 deletions
+3 -3
View File
@@ -260,7 +260,7 @@ inline void JA_Update() {
inline void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) { inline void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channels) {
JA_audioSpec = {.format = format, .channels = num_channels, .freq = freq}; JA_audioSpec = {.format = format, .channels = num_channels, .freq = freq};
if (sdlAudioDevice != 0u) { if (sdlAudioDevice != 0U) {
SDL_CloseAudioDevice(sdlAudioDevice); SDL_CloseAudioDevice(sdlAudioDevice);
} }
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec); sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
@@ -280,7 +280,7 @@ inline void JA_Quit() {
SDL_DestroyAudioStream(outgoing_music.stream); SDL_DestroyAudioStream(outgoing_music.stream);
outgoing_music.stream = nullptr; outgoing_music.stream = nullptr;
} }
if (sdlAudioDevice != 0u) { if (sdlAudioDevice != 0U) {
SDL_CloseAudioDevice(sdlAudioDevice); SDL_CloseAudioDevice(sdlAudioDevice);
} }
sdlAudioDevice = 0; sdlAudioDevice = 0;
@@ -586,7 +586,7 @@ inline void JA_EnableMusic(const bool value) {
inline auto JA_LoadSound(uint8_t* buffer, uint32_t size) -> JA_Sound_t* { inline auto JA_LoadSound(uint8_t* buffer, uint32_t size) -> JA_Sound_t* {
auto sound = std::make_unique<JA_Sound_t>(); auto sound = std::make_unique<JA_Sound_t>();
Uint8* raw = nullptr; Uint8* raw = nullptr;
if (!SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &raw, &sound->length)) { if (!SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), true, &sound->spec, &raw, &sound->length)) {
std::cout << "Failed to load WAV from memory: " << SDL_GetError() << '\n'; std::cout << "Failed to load WAV from memory: " << SDL_GetError() << '\n';
return nullptr; return nullptr;
} }
+7 -7
View File
@@ -87,7 +87,7 @@ auto JD8_LoadPalette(const char* file) -> JD8_Palette {
// Sempre retorna un buffer de 256 colors reservat amb `new Color[256]` // Sempre retorna un buffer de 256 colors reservat amb `new Color[256]`
// — el caller és responsable d'alliberar-lo amb `delete[]` (o lliurar-ne // — el caller és responsable d'alliberar-lo amb `delete[]` (o lliurar-ne
// l'ownership a `JD8_SetScreenPalette`). // l'ownership a `JD8_SetScreenPalette`).
auto palette = new Color[256]; auto* palette = new Color[256];
if (Resource::Cache::get() != nullptr) { if (Resource::Cache::get() != nullptr) {
try { try {
@@ -167,7 +167,7 @@ void JD8_BlitToSurface(int x, int y, JD8_Surface surface, int sx, int sy, int sw
} }
} }
void JD8_BlitCK(int x, int y, const JD8_Surface surface, int sx, int sy, int sw, int sh, Uint8 colorkey) { void JD8_BlitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey) {
int src_pointer = sx + (sy * 320); int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320); int dst_pointer = x + (y * 320);
for (int j = 0; j < sh; j++) { for (int j = 0; j < sh; j++) {
@@ -181,7 +181,7 @@ void JD8_BlitCK(int x, int y, const JD8_Surface surface, int sx, int sy, int sw,
} }
} }
void JD8_BlitCKCut(int x, int y, const JD8_Surface surface, int sx, int sy, int sw, int sh, Uint8 colorkey) { void JD8_BlitCKCut(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey) {
int src_pointer = sx + (sy * 320); int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320); int dst_pointer = x + (y * 320);
for (int j = 0; j < sh; j++) { for (int j = 0; j < sh; j++) {
@@ -195,7 +195,7 @@ void JD8_BlitCKCut(int x, int y, const JD8_Surface surface, int sx, int sy, int
} }
} }
void JD8_BlitCKScroll(int y, const JD8_Surface surface, int sx, int sy, int sh, Uint8 colorkey) { void JD8_BlitCKScroll(int y, const Uint8* surface, int sx, int sy, int sh, Uint8 colorkey) {
int dst_pointer = y * 320; int dst_pointer = y * 320;
for (int j = sy; j < sy + sh; j++) { for (int j = sy; j < sy + sh; j++) {
for (int i = 0; i < 320; i++) { for (int i = 0; i < 320; i++) {
@@ -208,7 +208,7 @@ void JD8_BlitCKScroll(int y, const JD8_Surface surface, int sx, int sy, int sh,
} }
} }
void JD8_BlitCKToSurface(int x, int y, const JD8_Surface surface, int sx, int sy, int sw, int sh, JD8_Surface dest, Uint8 colorkey) { void JD8_BlitCKToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest, Uint8 colorkey) {
int src_pointer = sx + (sy * 320); int src_pointer = sx + (sy * 320);
int dst_pointer = x + (y * 320); int dst_pointer = x + (y * 320);
for (int j = 0; j < sh; j++) { for (int j = 0; j < sh; j++) {
@@ -239,11 +239,11 @@ auto JD8_GetFramebuffer() -> Uint32* {
return pixel_data; return pixel_data;
} }
void JD8_FreeSurface(const JD8_Surface surface) { void JD8_FreeSurface(JD8_Surface surface) { // NOLINT(readability-non-const-parameter): allibera memòria, no pot ser const
delete[] surface; delete[] surface;
} }
auto JD8_GetPixel(JD8_Surface surface, int x, int y) -> Uint8 { auto JD8_GetPixel(const Uint8* surface, int x, int y) -> Uint8 {
return surface[x + (y * 320)]; return surface[x + (y * 320)];
} }
+6 -6
View File
@@ -36,13 +36,13 @@ 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, JD8_Surface surface, int sx, int sy, int sw, int sh, JD8_Surface dest);
void JD8_BlitCK(int x, int y, const JD8_Surface surface, int sx, int sy, int sw, int sh, Uint8 colorkey); void JD8_BlitCK(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey);
void JD8_BlitCKCut(int x, int y, const JD8_Surface surface, int sx, int sy, int sw, int sh, Uint8 colorkey); void JD8_BlitCKCut(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, Uint8 colorkey);
void JD8_BlitCKScroll(int y, const JD8_Surface surface, int sx, int sy, int sh, Uint8 colorkey); void JD8_BlitCKScroll(int y, const Uint8* surface, int sx, int sy, int sh, Uint8 colorkey);
void JD8_BlitCKToSurface(int x, int y, const JD8_Surface surface, int sx, int sy, int sw, int sh, JD8_Surface dest, Uint8 colorkey); void JD8_BlitCKToSurface(int x, int y, const Uint8* surface, int sx, int sy, int sw, int sh, JD8_Surface dest, Uint8 colorkey);
// Converteix la pantalla indexada a ARGB. El Director crida aquesta // Converteix la pantalla indexada a ARGB. El Director crida aquesta
// funció al final de cada tick i després llegeix el framebuffer via // funció al final de cada tick i després llegeix el framebuffer via
@@ -53,9 +53,9 @@ void JD8_Flip();
// JD8_Flip(). Propietat de jdraw8 — el caller no ha de lliberar-lo. // JD8_Flip(). Propietat de jdraw8 — el caller no ha de lliberar-lo.
auto JD8_GetFramebuffer() -> Uint32*; auto JD8_GetFramebuffer() -> Uint32*;
void JD8_FreeSurface(const JD8_Surface surface); void JD8_FreeSurface(JD8_Surface surface);
auto JD8_GetPixel(JD8_Surface surface, int x, int y) -> Uint8; auto JD8_GetPixel(const Uint8* surface, int x, int y) -> Uint8;
void JD8_PutPixel(JD8_Surface surface, int x, int y, Uint8 pixel); void JD8_PutPixel(JD8_Surface surface, int x, int y, Uint8 pixel);
+1 -1
View File
@@ -81,7 +81,7 @@ void JI_Update() {
if (wait_ms > 0.0F) { if (wait_ms > 0.0F) {
wait_ms -= delta_ms; wait_ms -= delta_ms;
wait_ms = std::max(wait_ms, 0.0f); wait_ms = std::max(wait_ms, 0.0F);
} }
// Consumim el flag de "alguna tecla no-GUI polsada" del director // Consumim el flag de "alguna tecla no-GUI polsada" del director
+1 -1
View File
@@ -228,7 +228,7 @@ namespace Menu {
pct = std::min(pct, 100); pct = std::min(pct, 100);
char buf[8]; char buf[8];
std::snprintf(buf, sizeof(buf), "%d%%", pct); std::snprintf(buf, sizeof(buf), "%d%%", pct);
return std::string(buf); return {buf};
} }
// Canvi +/- d'un volum en steps de 0.05 (5%) amb clamping // Canvi +/- d'un volum en steps de 0.05 (5%) amb clamping
+1 -1
View File
@@ -418,7 +418,7 @@ namespace Overlay {
void setRenderInfoSegments(const char* s0, const char* s1, const char* s2, const char* s3, unsigned int mono_mask) { void setRenderInfoSegments(const char* s0, const char* s1, const char* s2, const char* s3, unsigned int mono_mask) {
const char* segs[INFO_SEGMENT_COUNT] = {s0, s1, s2, s3}; const char* segs[INFO_SEGMENT_COUNT] = {s0, s1, s2, s3};
for (int i = 0; i < INFO_SEGMENT_COUNT; i++) { for (int i = 0; i < INFO_SEGMENT_COUNT; i++) {
info_segments_[i].mono_digits = (((mono_mask >> i) & 1U) != 0u); info_segments_[i].mono_digits = (((mono_mask >> i) & 1U) != 0U);
if (segs[i] != nullptr && *segs[i] != '\0') { if (segs[i] != nullptr && *segs[i] != '\0') {
info_segments_[i].text = segs[i]; info_segments_[i].text = segs[i];
info_segments_[i].visible = true; info_segments_[i].visible = true;
+1 -1
View File
@@ -66,7 +66,7 @@ class Director {
static void initGameContext(); static void initGameContext();
// Construeix l'escena apropiada segons game_state_ i info::ctx. // Construeix l'escena apropiada segons game_state_ i info::ctx.
// Retorna nullptr si l'state actual no té escena registrada (bug). // Retorna nullptr si l'state actual no té escena registrada (bug).
auto createNextScene() const -> std::unique_ptr<scenes::Scene>; [[nodiscard]] auto createNextScene() const -> std::unique_ptr<scenes::Scene>;
// Buffers persistents entre iteracions. Abans eren locals a run(), // Buffers persistents entre iteracions. Abans eren locals a run(),
// ara són membres perquè iterate() els pot reutilitzar sense tornar-los // ara són membres perquè iterate() els pot reutilitzar sense tornar-los
+6
View File
@@ -40,6 +40,8 @@ void Mapa::draw() {
case 3: // Left case 3: // Left
JD8_BlitCKToSurface(sam->x + 8, sam->y, this->gfx, 45 + (14 - sam->frame_pejades), 125, 1, 15, this->fondo, 255); JD8_BlitCKToSurface(sam->x + 8, sam->y, this->gfx, 45 + (14 - sam->frame_pejades), 125, 1, 15, this->fondo, 255);
break; break;
default:
break;
} }
} }
@@ -124,6 +126,8 @@ void Mapa::preparaFondoEstatic() {
case 6: case 6:
JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 145, 80, 15, 15, this->fondo); JD8_BlitToSurface(20 + (x * 15), 30 + (y * 15), this->gfx, 145, 80, 15, 15, this->fondo);
break; break;
default:
break;
} }
} }
} }
@@ -284,6 +288,8 @@ void Mapa::comprovaCaixa(Uint8 num) {
this->farao = this->clau = true; this->farao = this->clau = true;
} }
break; break;
default:
break;
} }
this->comprovaPorta(); this->comprovaPorta();
+2
View File
@@ -59,5 +59,7 @@ void Marcador::pintaNumero(Uint16 x, Uint16 y, Uint8 num) {
case 9: case 9:
JD8_BlitCK(x, y, this->gfx, 131, 193, 10, 7, 255); JD8_BlitCK(x, y, this->gfx, 131, 193, 10, 7, 255);
break; break;
default:
break;
} }
} }
+2
View File
@@ -143,6 +143,8 @@ auto Momia::update() -> bool {
this->x--; this->x--;
} }
break; break;
default:
break;
} }
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
+3 -1
View File
@@ -150,6 +150,8 @@ auto Prota::update() -> Uint8 {
this->x--; this->x--;
} }
break; break;
default:
break;
} }
if (dir == 4) { if (dir == 4) {
@@ -166,7 +168,7 @@ auto Prota::update() -> Uint8 {
} }
} }
} }
eixir = 0u; eixir = 0U;
} else { } else {
if (JG_GetCycleCounter() % this->cycles_per_frame == 0) { if (JG_GetCycleCounter() % this->cycles_per_frame == 0) {
this->cur_frame++; this->cur_frame++;
+2 -3
View File
@@ -36,9 +36,8 @@ namespace {
namespace scenes { namespace scenes {
CreditsScene::~CreditsScene() { // No toquem la paleta activa: SetScreenPalette n'ha pres ownership.
// No toquem la paleta activa: SetScreenPalette n'ha pres ownership. CreditsScene::~CreditsScene() = default;
}
void CreditsScene::onEnter() { void CreditsScene::onEnter() {
// El vell doCredits no tocava música — heretava la del doSlides // El vell doCredits no tocava música — heretava la del doSlides
+4 -5
View File
@@ -41,11 +41,10 @@ namespace scenes {
IntroNewLogoScene::IntroNewLogoScene() = default; IntroNewLogoScene::IntroNewLogoScene() = default;
IntroNewLogoScene::~IntroNewLogoScene() { // No alliberem `pal_`: JD8_SetScreenPalette n'ha pres ownership i el
// No alliberem `pal_`: JD8_SetScreenPalette n'ha pres ownership i // proper SetScreenPalette / FadeToPal el lliurarà. Alliberar-lo ací
// el proper SetScreenPalette / FadeToPal el lliurarà. Alliberar-lo // provocaria double free.
// ací provocaria double free. IntroNewLogoScene::~IntroNewLogoScene() = default;
}
void IntroNewLogoScene::onEnter() { void IntroNewLogoScene::onEnter() {
playMusic("music/menu.ogg"); playMusic("music/menu.ogg");
+4 -5
View File
@@ -59,11 +59,10 @@ namespace scenes {
IntroScene::IntroScene() = default; IntroScene::IntroScene() = default;
IntroScene::~IntroScene() { // No alliberem `pal_`: JD8_SetScreenPalette n'ha pres ownership i el
// No alliberem `pal_`: JD8_SetScreenPalette n'ha pres ownership i el // proper SetScreenPalette / FadeToPal la lliurarà. Alliberar-la ací
// proper SetScreenPalette / FadeToPal la lliurarà. Alliberar-la ací // provocaria double free.
// provocaria double free. IntroScene::~IntroScene() = default;
}
void IntroScene::onEnter() { void IntroScene::onEnter() {
playMusic("music/menu.ogg"); playMusic("music/menu.ogg");
+4 -2
View File
@@ -286,8 +286,9 @@ namespace {
return variant_1; return variant_1;
case 2: case 2:
return variant_2; return variant_2;
default:
return variant_0;
} }
return variant_0;
} }
auto variant_length(int variant) -> int { auto variant_length(int variant) -> int {
@@ -298,8 +299,9 @@ namespace {
return sizeof(variant_1) / sizeof(variant_1[0]); return sizeof(variant_1) / sizeof(variant_1[0]);
case 2: case 2:
return sizeof(variant_2) / sizeof(variant_2[0]); return sizeof(variant_2) / sizeof(variant_2[0]);
default:
return 0;
} }
return 0;
} }
auto phase_step_count(const SpritePhase& p) -> int { auto phase_step_count(const SpritePhase& p) -> int {