neteja tidy a source/game (fixes d'arrel: BulletKind enum class, signatures, branches)

This commit is contained in:
2026-05-14 21:52:45 +02:00
parent 0ee117135c
commit 9a2da460cc
19 changed files with 643 additions and 693 deletions
+77 -73
View File
@@ -1,8 +1,8 @@
#include "game/scenes/title.h"
#include <SDL3/SDL.h>
#include <stdlib.h> // for rand
#include <cstdlib> // for rand
#include <iostream> // for basic_ostream, operator<<, basic_ostrea...
#include <string> // for basic_string, operator+, char_traits
@@ -147,10 +147,10 @@ void Title::init() {
coffeeBitmap->setPosY(11 - 200);
coffeeBitmap->setWidth(167);
coffeeBitmap->setHeight(46);
coffeeBitmap->setVelX(0.0f);
coffeeBitmap->setVelY(2.5f);
coffeeBitmap->setAccelX(0.0f);
coffeeBitmap->setAccelY(0.1f);
coffeeBitmap->setVelX(0.0F);
coffeeBitmap->setVelY(2.5F);
coffeeBitmap->setAccelX(0.0F);
coffeeBitmap->setAccelY(0.1F);
coffeeBitmap->setSpriteClip(0, 0, 167, 46);
coffeeBitmap->setEnabled(true);
coffeeBitmap->setEnabledCounter(0);
@@ -163,10 +163,10 @@ void Title::init() {
crisisBitmap->setPosY(57 + 200);
crisisBitmap->setWidth(137);
crisisBitmap->setHeight(46);
crisisBitmap->setVelX(0.0f);
crisisBitmap->setVelY(-2.5f);
crisisBitmap->setAccelX(0.0f);
crisisBitmap->setAccelY(-0.1f);
crisisBitmap->setVelX(0.0F);
crisisBitmap->setVelY(-2.5F);
crisisBitmap->setAccelX(0.0F);
crisisBitmap->setAccelY(-0.1F);
crisisBitmap->setSpriteClip(0, 0, 137, 46);
crisisBitmap->setEnabled(true);
crisisBitmap->setEnabledCounter(0);
@@ -202,7 +202,7 @@ void Title::init() {
// Inicializa los valores del vector con los valores del seno
for (int i = 0; i < 360; ++i) {
sin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
sin[i] = SDL_sinf((float)i * 3.14F / 180.0F);
}
// Actualiza los textos de los menus
@@ -313,8 +313,9 @@ void Title::update() {
if (demo) {
demoThenInstructions = true;
runDemoGame();
} else
} else {
section->name = SECTION_PROG_LOGO;
}
break;
default:
@@ -326,7 +327,7 @@ void Title::update() {
updateBG();
// Comprueba las entradas para el menu
if (menuVisible == true && !fade->isEnabled()) {
if (menuVisible && !fade->isEnabled()) {
menu.active->update();
}
@@ -393,12 +394,13 @@ void Title::update() {
if (menu.active->getName() == "OPTIONS") {
switch (menu.active->getItemSelected()) {
case 0: // Difficulty
if (Options::settings.difficulty == DIFFICULTY_EASY)
if (Options::settings.difficulty == DIFFICULTY_EASY) {
Options::settings.difficulty = DIFFICULTY_NORMAL;
else if (Options::settings.difficulty == DIFFICULTY_NORMAL)
} else if (Options::settings.difficulty == DIFFICULTY_NORMAL) {
Options::settings.difficulty = DIFFICULTY_HARD;
else
} else {
Options::settings.difficulty = DIFFICULTY_EASY;
}
updateMenuLabels();
break;
@@ -414,8 +416,9 @@ void Title::update() {
case 5: // Language
Options::settings.language++;
if (Options::settings.language == 3)
if (Options::settings.language == 3) {
Options::settings.language = 0;
}
updateMenuLabels();
break;
@@ -433,8 +436,9 @@ void Title::update() {
case 8: // Windows size
Options::window.zoom++;
if (Options::window.zoom > Options::window.max_zoom)
if (Options::window.zoom > Options::window.max_zoom) {
Options::window.zoom = 1;
}
updateMenuLabels();
break;
@@ -585,7 +589,7 @@ void Title::render() {
text2->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_HEIGHT - (BLOCK * 2), TEXT_COPYRIGHT, 1, noColor, 1, shdwTxtColor);
}
if (menuVisible == true) {
if (menuVisible) {
menu.active->render();
}
@@ -593,7 +597,7 @@ void Title::render() {
dustBitmapL->render();
// PRESS ANY KEY!
if ((counter % 50 > 14) && (menuVisible == false)) {
if ((counter % 50 > 14) && (!menuVisible)) {
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, PLAY_AREA_THIRD_QUARTER_Y + BLOCK, Lang::get()->getText(23), 1, noColor, 1, shdwTxtColor);
}
@@ -638,7 +642,7 @@ void Title::switchFullScreenModeVar() {
}
// Actualiza los elementos de los menus
void Title::updateMenuLabels() {
void Title::updateMenuLabels() const {
int i = 0;
// DIFFICULTY
switch (Options::settings.difficulty) {
@@ -673,9 +677,9 @@ void Title::updateMenuLabels() {
case INPUT_USE_GAMECONTROLLER:
menu.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
if (!Input::get()->gameControllerFound())
if (!Input::get()->gameControllerFound()) {
menu.options->setGreyed(i, true);
else {
} else {
menu.options->setGreyed(i, false);
menu.options->setItemCaption(i, Options::inputs[0].name);
}
@@ -700,9 +704,9 @@ void Title::updateMenuLabels() {
case INPUT_USE_GAMECONTROLLER:
menu.options->setItemCaption(i, Lang::get()->getText(70)); // GAME CONTROLLER
if (!Input::get()->gameControllerFound())
if (!Input::get()->gameControllerFound()) {
menu.options->setGreyed(i, true);
else {
} else {
menu.options->setGreyed(i, false);
menu.options->setItemCaption(i, Options::inputs[1].name);
}
@@ -725,11 +729,9 @@ void Title::updateMenuLabels() {
break;
case en_UK:
menu.options->setItemCaption(i, Lang::get()->getText(8) + ": " + Lang::get()->getText(26)); // ENGLISH
break;
default:
menu.options->setItemCaption(i, Lang::get()->getText(8) + ": " + Lang::get()->getText(26)); // ENGLISH
// ENGLISH (i fallback per a llengües no reconegudes)
menu.options->setItemCaption(i, Lang::get()->getText(8) + ": " + Lang::get()->getText(26));
break;
}
@@ -747,17 +749,19 @@ void Title::updateMenuLabels() {
i++;
// SCALE MODE
if (Options::video.scale_mode == SDL_SCALEMODE_LINEAR)
if (Options::video.scale_mode == SDL_SCALEMODE_LINEAR) {
menu.options->setItemCaption(i, Lang::get()->getText(60) + ": " + Lang::get()->getText(71)); // BILINEAL
else
} else {
menu.options->setItemCaption(i, Lang::get()->getText(60) + ": " + Lang::get()->getText(72)); // LINEAL
}
i++;
// VSYNC
if (Options::video.vsync)
if (Options::video.vsync) {
menu.options->setItemCaption(i, Lang::get()->getText(61) + ": " + Lang::get()->getText(73)); // ON
else
} else {
menu.options->setItemCaption(i, Lang::get()->getText(61) + ": " + Lang::get()->getText(74)); // OFF
}
i++;
// HOW TO PLAY
@@ -893,12 +897,12 @@ void Title::iterate() {
// Procesa un evento individual
void Title::handleEvent(const SDL_Event *event) {
// Si hay un sub-estado activo, delega el evento
if (instructionsActive && instructions) {
if (instructionsActive && (instructions != nullptr)) {
// SDL_EVENT_QUIT ya lo maneja Director
return;
}
if (demoGameActive && demoGame) {
if (demoGameActive && (demoGame != nullptr)) {
demoGame->handleEvent(event);
return;
}
@@ -944,7 +948,7 @@ void Title::runDemoGame() {
}
// Modifica las opciones para los controles de los jugadores
bool Title::updatePlayerInputs(int numPlayer) {
auto Title::updatePlayerInputs(int numPlayer) -> bool {
const int numDevices = availableInputDevices.size();
if (!Input::get()->gameControllerFound()) { // Si no hay mandos se deja todo de manera prefijada
@@ -960,37 +964,36 @@ bool Title::updatePlayerInputs(int numPlayer) {
Options::inputs[1].deviceType = INPUT_USE_GAMECONTROLLER;
return true;
} else { // Si hay mas de un dispositivo, se recorre el vector
if (Options::settings.console) {
std::cout << "numplayer:" << numPlayer << std::endl;
std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl;
}
// Incrementa el indice
if (deviceIndex[numPlayer] < numDevices - 1) {
deviceIndex[numPlayer]++;
} else {
deviceIndex[numPlayer] = 0;
}
if (Options::settings.console) {
std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl;
}
// Si coincide con el del otro jugador, se lo intercambian
if (deviceIndex[0] == deviceIndex[1]) {
const int theOtherPlayer = (numPlayer + 1) % 2;
deviceIndex[theOtherPlayer]--;
if (deviceIndex[theOtherPlayer] < 0) {
deviceIndex[theOtherPlayer] = numDevices - 1;
}
}
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador
Options::inputs[0] = availableInputDevices[deviceIndex[0]];
Options::inputs[1] = availableInputDevices[deviceIndex[1]];
return true;
} // Si hay mas de un dispositivo, se recorre el vector
if (Options::settings.console) {
std::cout << "numplayer:" << numPlayer << '\n';
std::cout << "deviceindex:" << deviceIndex[numPlayer] << '\n';
}
// Incrementa el indice
if (deviceIndex[numPlayer] < numDevices - 1) {
deviceIndex[numPlayer]++;
} else {
deviceIndex[numPlayer] = 0;
}
if (Options::settings.console) {
std::cout << "deviceindex:" << deviceIndex[numPlayer] << '\n';
}
// Si coincide con el del otro jugador, se lo intercambian
if (deviceIndex[0] == deviceIndex[1]) {
const int theOtherPlayer = (numPlayer + 1) % 2;
deviceIndex[theOtherPlayer]--;
if (deviceIndex[theOtherPlayer] < 0) {
deviceIndex[theOtherPlayer] = numDevices - 1;
}
}
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador
Options::inputs[0] = availableInputDevices[deviceIndex[0]];
Options::inputs[1] = availableInputDevices[deviceIndex[1]];
return true;
}
// Crea el mosaico de fondo del titulo
@@ -1002,13 +1005,13 @@ void Title::createTiledBackground() {
}
if (background == nullptr) {
if (Options::settings.console) {
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << '\n';
}
}
// Crea los objetos para pintar en la textura de fondo
Texture *bgTileTexture = new Texture(renderer, Asset::get()->get("title_bg_tile.png"));
Sprite *tile = new Sprite({0, 0, 64, 64}, bgTileTexture, renderer);
auto *bgTileTexture = new Texture(renderer, Asset::get()->get("title_bg_tile.png"));
auto *tile = new Sprite({0, 0, 64, 64}, bgTileTexture, renderer);
// Prepara para dibujar sobre la textura
SDL_SetRenderTarget(renderer, background);
@@ -1039,23 +1042,24 @@ void Title::createTiledBackground() {
// así que aquí solo leemos la lista actual sin reescanear.
void Title::checkInputDevices() {
if (Options::settings.console) {
std::cout << "Filling devices for options menu..." << std::endl;
std::cout << "Filling devices for options menu..." << '\n';
}
const int numControllers = Input::get()->getNumControllers();
availableInputDevices.clear();
input_t temp;
// Añade todos los mandos
if (numControllers > 0)
if (numControllers > 0) {
for (int i = 0; i < numControllers; ++i) {
temp.id = i;
temp.name = Input::get()->getControllerName(i);
temp.deviceType = INPUT_USE_GAMECONTROLLER;
availableInputDevices.push_back(temp);
if (Options::settings.console) {
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl;
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << '\n';
}
}
}
// Añade el teclado al final
temp.id = -1;
@@ -1063,8 +1067,8 @@ void Title::checkInputDevices() {
temp.deviceType = INPUT_USE_KEYBOARD;
availableInputDevices.push_back(temp);
if (Options::settings.console) {
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl;
std::cout << std::endl;
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << '\n';
std::cout << '\n';
}
}