refactor: partir defaults.hpp en source/core/defaults/*.hpp (umbrella)
defaults.hpp tenia 527 línies amb 17 namespaces de dominis distints (Window, Game, Zones, Entities, Palette, Ship, Physics, Math, Brightness, Rendering, Audio, Music, Sound, Controls, Enemies, Title, FloatingScore). 22 .cpp/.hpp l'incloïen, així que tocar una constant forçava recompilar pràcticament tot. Es divideix en 15 subfitxers (un per namespace, fusionant Music/Sound a audio.hpp i unificant els dos blocs Game duplicats en un sol): defaults/window.hpp defaults/audio.hpp defaults/game.hpp defaults/controls.hpp defaults/zones.hpp defaults/enemies.hpp defaults/entities.hpp defaults/title.hpp defaults/palette.hpp defaults/floating_score.hpp defaults/ship.hpp defaults/math.hpp defaults/physics.hpp defaults/brightness.hpp defaults/rendering.hpp Cross-deps explícites (#include en lloc d'order-of-declaration): zones.hpp -> game.hpp (per Game::WIDTH/HEIGHT) enemies.hpp -> entities.hpp (per SHIP_RADIUS) title.hpp -> game.hpp, math.hpp + <cmath> defaults.hpp queda com a umbrella que inclou els 15 subfitxers. Els 22 includers existents no requereixen cap canvi. Codi nou pot incloure el subfitxer concret per millorar la compilació incremental. Hallazgos #22 i #30 de CODE_REVIEW.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f777017460
commit
aa0abd9ae1
16 files changed
+641
-525
No files matched your search
@@ -0,0 +1,81 @@
|
||||
// zones.hpp - Zones de l'àrea de joc (SDL_FRect amb càlculs automàtics per percentatges)
|
||||
// © 2026 JailDesigner
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "core/defaults/game.hpp"
|
||||
|
||||
namespace Defaults::Zones {
|
||||
|
||||
// --- CONFIGURACIÓ DE PORCENTATGES ---
|
||||
// Todas las zones definides como a porcentajes de Game::WIDTH (640) i Game::HEIGHT (480)
|
||||
|
||||
// Percentatges de height (divisió vertical)
|
||||
constexpr float SCOREBOARD_TOP_HEIGHT_PERCENT = 0.02F; // 10% superior
|
||||
constexpr float MAIN_PLAYAREA_HEIGHT_PERCENT = 0.88F; // 80% central
|
||||
constexpr float SCOREBOARD_BOTTOM_HEIGHT_PERCENT = 0.10F; // 10% inferior
|
||||
|
||||
// Padding horizontal para PLAYAREA (dentro de MAIN_PLAYAREA)
|
||||
constexpr float PLAYAREA_PADDING_HORIZONTAL_PERCENT = 0.015F; // 5% a cada costat
|
||||
|
||||
// --- CÀLCULS AUTOMÀTICS DE PÍXELS ---
|
||||
// Cálculos automáticos a partir dels porcentajes
|
||||
|
||||
// Alçades
|
||||
constexpr float SCOREBOARD_TOP_H = Game::HEIGHT * SCOREBOARD_TOP_HEIGHT_PERCENT;
|
||||
constexpr float MAIN_PLAYAREA_H = Game::HEIGHT * MAIN_PLAYAREA_HEIGHT_PERCENT;
|
||||
constexpr float SCOREBOARD_BOTTOM_H = Game::HEIGHT * SCOREBOARD_BOTTOM_HEIGHT_PERCENT;
|
||||
|
||||
// Posicions Y
|
||||
constexpr float SCOREBOARD_TOP_Y = 0.0F;
|
||||
constexpr float MAIN_PLAYAREA_Y = SCOREBOARD_TOP_H;
|
||||
constexpr float SCOREBOARD_BOTTOM_Y = MAIN_PLAYAREA_Y + MAIN_PLAYAREA_H;
|
||||
|
||||
// Padding horizontal de PLAYAREA
|
||||
constexpr float PLAYAREA_PADDING_H = Game::WIDTH * PLAYAREA_PADDING_HORIZONTAL_PERCENT;
|
||||
|
||||
// --- ZONES FINALS (SDL_FRect) ---
|
||||
|
||||
// Marcador superior (reservado para futuro uso)
|
||||
// Ocupa el 2% superior
|
||||
constexpr SDL_FRect SCOREBOARD_TOP = {
|
||||
0.0F, // x = 0.0
|
||||
SCOREBOARD_TOP_Y, // y = 0.0
|
||||
static_cast<float>(Game::WIDTH), // ancho completo
|
||||
SCOREBOARD_TOP_H // alto
|
||||
};
|
||||
|
||||
// Área de juego principal (contenedor del 80% central, sin padding)
|
||||
// Ocupa el 88% central, ancho completo
|
||||
constexpr SDL_FRect MAIN_PLAYAREA = {
|
||||
0.0F, // x = 0.0
|
||||
MAIN_PLAYAREA_Y, // debajo del scoreboard superior
|
||||
static_cast<float>(Game::WIDTH), // ancho completo
|
||||
MAIN_PLAYAREA_H // alto
|
||||
};
|
||||
|
||||
// Zona de juego real (con padding horizontal del 5%)
|
||||
// Ocupa: dentro de MAIN_PLAYAREA, con márgenes laterales
|
||||
// Se utiliza para límites del juego, colisiones, spawn
|
||||
constexpr SDL_FRect PLAYAREA = {
|
||||
PLAYAREA_PADDING_H, // padding horizontal
|
||||
MAIN_PLAYAREA_Y, // debajo del scoreboard superior (igual que MAIN_PLAYAREA)
|
||||
Game::WIDTH - (2.0F * PLAYAREA_PADDING_H), // ancho con padding
|
||||
MAIN_PLAYAREA_H // alto (igual que MAIN_PLAYAREA)
|
||||
};
|
||||
|
||||
// Marcador inferior (marcador actual)
|
||||
// Ocupa el 10% inferior
|
||||
constexpr SDL_FRect SCOREBOARD = {
|
||||
0.0F, // x = 0.0
|
||||
SCOREBOARD_BOTTOM_Y, // fondo
|
||||
static_cast<float>(Game::WIDTH), // ancho completo
|
||||
SCOREBOARD_BOTTOM_H // alto
|
||||
};
|
||||
|
||||
// Padding horizontal del marcador (para alinear zonas izquierda/derecha con PLAYAREA)
|
||||
constexpr float SCOREBOARD_PADDING_H = 0.0F; // Game::WIDTH * 0.015f;
|
||||
|
||||
} // namespace Defaults::Zones
|
||||
Reference in new issue
Block a user