Merge branch 'chore/lint': frame loop al Director, debug overlay, copyrights, lint a 0
Squash conceptual de la rama chore/lint, mergeada con --no-ff para preservar la historia de los 8 commits del trabajo de linting y refactor: -efbf245cppcheck (25 hits) + compiler warnings -c45e524tidy --fix mechanical (trailing/init/auto/enum-size/starts-with) -424d0d2bugs reales + uint8_t enums + use-equals-default -1214599helpers file-static y constexpr locales traducidos al inglés -c80212alocales (constants + const-ref vars) -6d0df8547 métodos privados → camelBack + traducidos -4e5ab6b20 convert-to-static -bbbb8d4rename públicos al inglés + refactor cognitive-complexity + unused-includes Resultado final: cppcheck 0 hits, clang-tidy 0 warnings visibles, 3 NOLINT únicos justificados (stb_vorbis externo + static class member con sufijo `_`). También se introdujo en la rama: - Plan A: frame loop al Director con interfaz Scene - Debug overlay (F11) con FPS+VSync - Limpieza de copyrights a "© 2026 JailDesigner" Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,11 @@ Checks:
|
||||
- -bugprone-easily-swappable-parameters
|
||||
- -bugprone-narrowing-conversions
|
||||
- -modernize-avoid-c-arrays
|
||||
# performance-noexcept-move-constructor crashea clang-tidy (LLVM 19.1)
|
||||
# con recursión infinita en ExceptionSpecAnalyzer::analyzeRecord cuando
|
||||
# analiza ciertas instanciaciones de std::set. No es un falso positivo
|
||||
# sobre nuestro código: el check ni siquiera llega a evaluar el patrón.
|
||||
- -performance-noexcept-move-constructor
|
||||
|
||||
WarningsAsErrors: '*'
|
||||
# Headers nostres (excloem source/external/ que conté dependències de tercers no editables)
|
||||
|
||||
+2
-1
@@ -104,4 +104,5 @@ ehthumbs_vista.db
|
||||
*.swo
|
||||
|
||||
.cache/
|
||||
.claude/
|
||||
.claude/lint-reports/
|
||||
lint-reports/
|
||||
|
||||
@@ -259,6 +259,7 @@ if(CPPCHECK_EXE)
|
||||
--suppress=*:*source/external/*
|
||||
--suppress=*:*source/legacy/*
|
||||
--suppress=normalCheckLevelMaxBranches
|
||||
--suppress=useStlAlgorithm
|
||||
-D_DEBUG
|
||||
-DLINUX_BUILD
|
||||
--quiet
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# Deshabilitar clang-tidy para este directorio (código externo: jail_audio.hpp)
|
||||
# Los demás archivos de este directorio (audio.cpp, audio_cache.cpp) también se benefician
|
||||
# de no ser modificados porque dependen íntimamente de la API de jail_audio.hpp
|
||||
|
||||
Checks: '-*'
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <functional> // Para std::function
|
||||
#include <memory> // Para std::unique_ptr
|
||||
#include <string> // Para string
|
||||
#include <utility> // Para move
|
||||
|
||||
// Forward-declares per no incloure core/audio/jail_audio.hpp al header. Els
|
||||
// tres símbols (Music/Sound para el punter que exposa la API i Engine per al
|
||||
|
||||
@@ -22,26 +22,26 @@ namespace {
|
||||
|
||||
// Cachés locales: indexados por nombre lógico ("title.ogg", "effects/laser_shoot.wav", etc.)
|
||||
// Mantienen ownership con unique_ptr; se liberan al salir del programa.
|
||||
std::unordered_map<std::string, std::unique_ptr<Ja::Music>>& musicCache() {
|
||||
static std::unordered_map<std::string, std::unique_ptr<Ja::Music>> cache;
|
||||
return cache;
|
||||
auto musicCache() -> std::unordered_map<std::string, std::unique_ptr<Ja::Music>>& {
|
||||
static std::unordered_map<std::string, std::unique_ptr<Ja::Music>> cache_;
|
||||
return cache_;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::unique_ptr<Ja::Sound>>& soundCache() {
|
||||
static std::unordered_map<std::string, std::unique_ptr<Ja::Sound>> cache;
|
||||
return cache;
|
||||
auto soundCache() -> std::unordered_map<std::string, std::unique_ptr<Ja::Sound>>& {
|
||||
static std::unordered_map<std::string, std::unique_ptr<Ja::Sound>> cache_;
|
||||
return cache_;
|
||||
}
|
||||
|
||||
// Normaliza el nombre añadiendo la subcarpeta correspondiente si no la trae:
|
||||
// "title.ogg" -> "music/title.ogg"
|
||||
// "music/title.ogg" -> "music/title.ogg"
|
||||
// "effects/laser.wav" -> "sounds/effects/laser.wav"
|
||||
std::string normalizeMusicPath(const std::string& name) {
|
||||
return (name.rfind("music/", 0) == 0) ? name : "music/" + name;
|
||||
auto normalizeMusicPath(const std::string& name) -> std::string {
|
||||
return (name.starts_with("music/")) ? name : "music/" + name;
|
||||
}
|
||||
|
||||
std::string normalizeSoundPath(const std::string& name) {
|
||||
return (name.rfind("sounds/", 0) == 0) ? name : "sounds/" + name;
|
||||
auto normalizeSoundPath(const std::string& name) -> std::string {
|
||||
return (name.starts_with("sounds/")) ? name : "sounds/" + name;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -54,21 +54,21 @@ auto getMusic(const std::string& name) -> Ja::Music* {
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
const std::string path = normalizeMusicPath(name);
|
||||
auto bytes = Resource::Helper::loadFile(path);
|
||||
const std::string PATH = normalizeMusicPath(name);
|
||||
auto bytes = Resource::Helper::loadFile(PATH);
|
||||
if (bytes.empty()) {
|
||||
std::cerr << "[AudioResource] no se ha podido cargar música: " << path << "\n";
|
||||
std::cerr << "[AudioResource] no se ha podido cargar música: " << PATH << "\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Ja::Music* raw = Ja::loadMusic(bytes.data(), static_cast<std::uint32_t>(bytes.size()), name.c_str());
|
||||
if (raw == nullptr) {
|
||||
std::cerr << "[AudioResource] decodificación de música falló: " << path << "\n";
|
||||
std::cerr << "[AudioResource] decodificación de música falló: " << PATH << "\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cache.emplace(name, std::unique_ptr<Ja::Music>(raw));
|
||||
std::cout << "[AudioResource] música cargada: " << path << "\n";
|
||||
std::cout << "[AudioResource] música cargada: " << PATH << "\n";
|
||||
return raw;
|
||||
}
|
||||
|
||||
@@ -78,21 +78,21 @@ auto getSound(const std::string& name) -> Ja::Sound* {
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
const std::string path = normalizeSoundPath(name);
|
||||
auto bytes = Resource::Helper::loadFile(path);
|
||||
const std::string PATH = normalizeSoundPath(name);
|
||||
auto bytes = Resource::Helper::loadFile(PATH);
|
||||
if (bytes.empty()) {
|
||||
std::cerr << "[AudioResource] no se ha podido cargar sonido: " << path << "\n";
|
||||
std::cerr << "[AudioResource] no se ha podido cargar sonido: " << PATH << "\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Ja::Sound* raw = Ja::loadSound(bytes.data(), static_cast<std::uint32_t>(bytes.size()));
|
||||
if (raw == nullptr) {
|
||||
std::cerr << "[AudioResource] decodificación de sonido falló: " << path << "\n";
|
||||
std::cerr << "[AudioResource] decodificación de sonido falló: " << PATH << "\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cache.emplace(name, std::unique_ptr<Ja::Sound>(raw));
|
||||
std::cout << "[AudioResource] sonido cargado: " << path << "\n";
|
||||
std::cout << "[AudioResource] sonido cargado: " << PATH << "\n";
|
||||
return raw;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,10 @@ void readRgb255(const fkyaml::node& node, const char* key,
|
||||
dst_r = static_cast<float>(R) / 255.0F;
|
||||
dst_g = static_cast<float>(G) / 255.0F;
|
||||
dst_b = static_cast<float>(B) / 255.0F;
|
||||
} catch (...) {
|
||||
// Mantiene los defaults si algún elemento no es entero.
|
||||
} catch (...) { // @INTENTIONAL
|
||||
// Mantiene los defaults si algún elemento del RGB no es entero parseable
|
||||
// (el YAML viene de archivo, así que es razonable degradar a los defaults
|
||||
// en vez de propagar la excepción y abortar el load del postpro entero).
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
|
||||
namespace Defaults {
|
||||
@@ -439,16 +438,16 @@ constexpr float CENTER_Y = Game::HEIGHT / 2.0F; // auto-derivado de Game::HEIGH
|
||||
// Posicions target (calculades dinàmicament des dels parámetros base)
|
||||
// Nota: std::cos/sin no són constexpr en C++20, pero funcionen en runtime
|
||||
// Les funciones inline són optimitzades por el compilador (zero overhead)
|
||||
inline float P1_TARGET_X() {
|
||||
inline auto p1TargetX() -> float {
|
||||
return CENTER_X + (CLOCK_RADIUS * std::cos(CLOCK_8_ANGLE));
|
||||
}
|
||||
inline float P1_TARGET_Y() {
|
||||
inline auto p1TargetY() -> float {
|
||||
return CENTER_Y + ((Game::HEIGHT / 2.0F) * TARGET_Y_RATIO);
|
||||
}
|
||||
inline float P2_TARGET_X() {
|
||||
inline auto p2TargetX() -> float {
|
||||
return CENTER_X + (CLOCK_RADIUS * std::cos(CLOCK_4_ANGLE));
|
||||
}
|
||||
inline float P2_TARGET_Y() {
|
||||
inline auto p2TargetY() -> float {
|
||||
return CENTER_Y + ((Game::HEIGHT / 2.0F) * TARGET_Y_RATIO);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,21 +30,21 @@ class Entity {
|
||||
virtual void init() = 0;
|
||||
virtual void update(float delta_time) = 0;
|
||||
virtual void draw() const = 0;
|
||||
[[nodiscard]] virtual bool isActive() const = 0;
|
||||
[[nodiscard]] virtual auto isActive() const -> bool = 0;
|
||||
|
||||
// Sincronización post-física (override opcional).
|
||||
// Llamado por GameScene tras world.update(). Default: no-op.
|
||||
virtual void postUpdate(float /*delta_time*/) {}
|
||||
|
||||
// Interfaz de colisión (override opcional)
|
||||
[[nodiscard]] virtual float getCollisionRadius() const { return 0.0F; }
|
||||
[[nodiscard]] virtual bool isCollidable() const { return false; }
|
||||
[[nodiscard]] virtual auto getCollisionRadius() const -> float { return 0.0F; }
|
||||
[[nodiscard]] virtual auto isCollidable() const -> bool { return false; }
|
||||
|
||||
// Getters comunes (inline, sin overhead)
|
||||
[[nodiscard]] const Vec2& getCenter() const { return center_; }
|
||||
[[nodiscard]] float getAngle() const { return angle_; }
|
||||
[[nodiscard]] float getBrightness() const { return brightness_; }
|
||||
[[nodiscard]] const std::shared_ptr<Graphics::Shape>& getShape() const { return shape_; }
|
||||
[[nodiscard]] auto getCenter() const -> const Vec2& { return center_; }
|
||||
[[nodiscard]] auto getAngle() const -> float { return angle_; }
|
||||
[[nodiscard]] auto getBrightness() const -> float { return brightness_; }
|
||||
[[nodiscard]] auto getShape() const -> const std::shared_ptr<Graphics::Shape>& { return shape_; }
|
||||
|
||||
// Acceso al cuerpo físico (Fase 6+). El PhysicsWorld lo registra
|
||||
// por puntero; la entidad lo configura en init().
|
||||
|
||||
@@ -12,12 +12,12 @@ namespace Graphics {
|
||||
|
||||
Shape::Shape(const std::string& filepath)
|
||||
: center_({.x = 0.0F, .y = 0.0F}),
|
||||
escala_defecte_(1.0F),
|
||||
|
||||
nom_("unnamed") {
|
||||
load(filepath);
|
||||
}
|
||||
|
||||
bool Shape::load(const std::string& filepath) {
|
||||
auto Shape::load(const std::string& filepath) -> bool {
|
||||
// Llegir file
|
||||
std::ifstream file(filepath);
|
||||
if (!file.is_open()) {
|
||||
@@ -35,7 +35,7 @@ bool Shape::load(const std::string& filepath) {
|
||||
return parseFile(contingut);
|
||||
}
|
||||
|
||||
bool Shape::parseFile(const std::string& contingut) {
|
||||
auto Shape::parseFile(const std::string& contingut) -> bool {
|
||||
std::istringstream iss(contingut);
|
||||
std::string line;
|
||||
|
||||
@@ -49,27 +49,27 @@ bool Shape::parseFile(const std::string& contingut) {
|
||||
}
|
||||
|
||||
// Parse command
|
||||
if (starts_with(line, "name:")) {
|
||||
nom_ = trim(extract_value(line));
|
||||
} else if (starts_with(line, "scale:")) {
|
||||
if (startsWith(line, "name:")) {
|
||||
nom_ = trim(extractValue(line));
|
||||
} else if (startsWith(line, "scale:")) {
|
||||
try {
|
||||
escala_defecte_ = std::stof(extract_value(line));
|
||||
escala_defecte_ = std::stof(extractValue(line));
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: scale invàlida, usant 1.0" << '\n';
|
||||
escala_defecte_ = 1.0F;
|
||||
}
|
||||
} else if (starts_with(line, "center:")) {
|
||||
parse_center(extract_value(line));
|
||||
} else if (starts_with(line, "polyline:")) {
|
||||
auto points = parse_points(extract_value(line));
|
||||
} else if (startsWith(line, "center:")) {
|
||||
parseCenter(extractValue(line));
|
||||
} else if (startsWith(line, "polyline:")) {
|
||||
auto points = parsePoints(extractValue(line));
|
||||
if (points.size() >= 2) {
|
||||
primitives_.push_back({PrimitiveType::POLYLINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: polyline con menys de 2 points ignorada"
|
||||
<< '\n';
|
||||
}
|
||||
} else if (starts_with(line, "line:")) {
|
||||
auto points = parse_points(extract_value(line));
|
||||
} else if (startsWith(line, "line:")) {
|
||||
auto points = parsePoints(extractValue(line));
|
||||
if (points.size() == 2) {
|
||||
primitives_.push_back({PrimitiveType::LINE, points});
|
||||
} else {
|
||||
@@ -89,7 +89,7 @@ bool Shape::parseFile(const std::string& contingut) {
|
||||
}
|
||||
|
||||
// Helper: trim whitespace
|
||||
std::string Shape::trim(const std::string& str) const {
|
||||
auto Shape::trim(const std::string& str) -> std::string {
|
||||
const char* whitespace = " \t\n\r";
|
||||
size_t start = str.find_first_not_of(whitespace);
|
||||
if (start == std::string::npos) {
|
||||
@@ -100,9 +100,9 @@ std::string Shape::trim(const std::string& str) const {
|
||||
return str.substr(start, end - start + 1);
|
||||
}
|
||||
|
||||
// Helper: starts_with
|
||||
bool Shape::starts_with(const std::string& str,
|
||||
const std::string& prefix) const {
|
||||
// Helper: startsWith
|
||||
auto Shape::startsWith(const std::string& str,
|
||||
const std::string& prefix) -> bool {
|
||||
if (str.length() < prefix.length()) {
|
||||
return false;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ bool Shape::starts_with(const std::string& str,
|
||||
}
|
||||
|
||||
// Helper: extract value after ':'
|
||||
std::string Shape::extract_value(const std::string& line) const {
|
||||
auto Shape::extractValue(const std::string& line) -> std::string {
|
||||
size_t colon = line.find(':');
|
||||
if (colon == std::string::npos) {
|
||||
return "";
|
||||
@@ -119,7 +119,7 @@ std::string Shape::extract_value(const std::string& line) const {
|
||||
}
|
||||
|
||||
// Helper: parse center "x, y"
|
||||
void Shape::parse_center(const std::string& value) {
|
||||
void Shape::parseCenter(const std::string& value) {
|
||||
std::string val = trim(value);
|
||||
size_t comma = val.find(',');
|
||||
if (comma != std::string::npos) {
|
||||
@@ -134,7 +134,7 @@ void Shape::parse_center(const std::string& value) {
|
||||
}
|
||||
|
||||
// Helper: parse points "x1,y1 x2,y2 x3,y3"
|
||||
std::vector<Vec2> Shape::parse_points(const std::string& str) const {
|
||||
auto Shape::parsePoints(const std::string& str) -> std::vector<Vec2> {
|
||||
std::vector<Vec2> points;
|
||||
std::istringstream iss(trim(str));
|
||||
std::string pair;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -11,7 +12,7 @@
|
||||
namespace Graphics {
|
||||
|
||||
// Tipo de primitiva dins de una shape
|
||||
enum class PrimitiveType {
|
||||
enum class PrimitiveType : std::uint8_t {
|
||||
POLYLINE, // Secuencia de points connectats
|
||||
LINE // Línia individual (2 points)
|
||||
};
|
||||
@@ -30,35 +31,37 @@ class Shape {
|
||||
explicit Shape(const std::string& filepath);
|
||||
|
||||
// Carregar shape desde file .shp
|
||||
bool load(const std::string& filepath);
|
||||
auto load(const std::string& filepath) -> bool;
|
||||
|
||||
// Parsejar shape desde buffer de memòria (per al sistema de recursos)
|
||||
bool parseFile(const std::string& contingut);
|
||||
auto parseFile(const std::string& contingut) -> bool;
|
||||
|
||||
// Getters
|
||||
[[nodiscard]] const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
[[nodiscard]] auto getPrimitives() const -> const std::vector<ShapePrimitive>& {
|
||||
return primitives_;
|
||||
}
|
||||
[[nodiscard]] const Vec2& getCenter() const { return center_; }
|
||||
[[nodiscard]] float get_escala_defecte() const { return escala_defecte_; }
|
||||
[[nodiscard]] bool isValid() const { return !primitives_.empty(); }
|
||||
[[nodiscard]] auto getCenter() const -> const Vec2& { return center_; }
|
||||
[[nodiscard]] auto getDefaultScale() const -> float { return escala_defecte_; }
|
||||
[[nodiscard]] auto isValid() const -> bool { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
[[nodiscard]] std::string get_nom() const { return nom_; }
|
||||
[[nodiscard]] size_t get_num_primitives() const { return primitives_.size(); }
|
||||
[[nodiscard]] auto getName() const -> const std::string& { return nom_; }
|
||||
[[nodiscard]] auto getNumPrimitives() const -> size_t { return primitives_.size(); }
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
Vec2 center_; // Centro/origin de la shape
|
||||
float escala_defecte_; // Escala per defecte (normalment 1.0)
|
||||
std::string nom_; // Nom de la shape (per depuració)
|
||||
Vec2 center_; // Centro/origin de la shape
|
||||
float escala_defecte_{1.0F}; // Escala per defecte (normalment 1.0). Inicializada para
|
||||
// que el ctor por defecto no deje el campo indeterminado.
|
||||
std::string nom_; // Nom de la shape (per depuració)
|
||||
|
||||
// Helpers privats per parsejar
|
||||
[[nodiscard]] std::string trim(const std::string& str) const;
|
||||
[[nodiscard]] bool starts_with(const std::string& str, const std::string& prefix) const;
|
||||
[[nodiscard]] std::string extract_value(const std::string& line) const;
|
||||
void parse_center(const std::string& value);
|
||||
[[nodiscard]] std::vector<Vec2> parse_points(const std::string& str) const;
|
||||
// Helpers privats per parsejar. Son estáticos: no necesitan estado
|
||||
// de instancia, trabajan sobre el string pasado por parámetro.
|
||||
[[nodiscard]] static auto trim(const std::string& str) -> std::string;
|
||||
[[nodiscard]] static auto startsWith(const std::string& str, const std::string& prefix) -> bool;
|
||||
[[nodiscard]] static auto extractValue(const std::string& line) -> std::string;
|
||||
void parseCenter(const std::string& value);
|
||||
[[nodiscard]] static auto parsePoints(const std::string& str) -> std::vector<Vec2>;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -10,13 +10,12 @@
|
||||
namespace Graphics {
|
||||
|
||||
// Inicialización de variables estàtiques
|
||||
std::unordered_map<std::string, std::shared_ptr<Shape>> ShapeLoader::cache_;
|
||||
std::string ShapeLoader::base_path_ = "data/shapes/";
|
||||
std::unordered_map<std::string, std::shared_ptr<Shape>> ShapeLoader::cache;
|
||||
|
||||
std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
auto ShapeLoader::load(const std::string& filename) -> std::shared_ptr<Shape> {
|
||||
// Check cache first
|
||||
auto it = cache_.find(filename);
|
||||
if (it != cache_.end()) {
|
||||
auto it = cache.find(filename);
|
||||
if (it != cache.end()) {
|
||||
std::cout << "[ShapeLoader] Cache hit: " << filename << '\n';
|
||||
return it->second; // Cache hit
|
||||
}
|
||||
@@ -53,34 +52,34 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
}
|
||||
|
||||
// Cache and return
|
||||
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->get_nom()
|
||||
<< ", " << shape->get_num_primitives() << " primitives)" << '\n';
|
||||
std::cout << "[ShapeLoader] Carregat: " << normalized << " (" << shape->getName()
|
||||
<< ", " << shape->getNumPrimitives() << " primitives)" << '\n';
|
||||
|
||||
cache_[filename] = shape;
|
||||
cache[filename] = shape;
|
||||
return shape;
|
||||
}
|
||||
|
||||
void ShapeLoader::clear_cache() {
|
||||
std::cout << "[ShapeLoader] Netejant caché (" << cache_.size() << " formes)"
|
||||
void ShapeLoader::clearCache() {
|
||||
std::cout << "[ShapeLoader] Netejant caché (" << cache.size() << " formes)"
|
||||
<< '\n';
|
||||
cache_.clear();
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
size_t ShapeLoader::get_cache_size() { return cache_.size(); }
|
||||
auto ShapeLoader::getCacheSize() -> size_t { return cache.size(); }
|
||||
|
||||
std::string ShapeLoader::resolve_path(const std::string& filename) {
|
||||
auto ShapeLoader::resolvePath(const std::string& filename) -> std::string {
|
||||
// Si es un path absolut (comença con '/'), usar-lo directament
|
||||
if (!filename.empty() && filename[0] == '/') {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// Si ya conté el prefix base_path, usar-lo directament
|
||||
if (filename.starts_with(base_path_)) {
|
||||
if (filename.starts_with(BASE_PATH)) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// Altrament, añadir base_path (ara suporta subdirectoris)
|
||||
return base_path_ + filename;
|
||||
return std::string(BASE_PATH) + filename;
|
||||
}
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -20,20 +20,20 @@ class ShapeLoader {
|
||||
// Carregar shape desde file (con caché)
|
||||
// Retorna punter compartit (nullptr si error)
|
||||
// Exemple: load("ship.shp") → busca a "data/shapes/ship.shp"
|
||||
static std::shared_ptr<Shape> load(const std::string& filename);
|
||||
static auto load(const std::string& filename) -> std::shared_ptr<Shape>;
|
||||
|
||||
// Netejar caché (útil per debug/recàrrega)
|
||||
static void clear_cache();
|
||||
static void clearCache();
|
||||
|
||||
// Estadístiques (debug)
|
||||
static size_t get_cache_size();
|
||||
static auto getCacheSize() -> size_t;
|
||||
|
||||
private:
|
||||
static std::unordered_map<std::string, std::shared_ptr<Shape>> cache_;
|
||||
static std::string base_path_; // "data/shapes/"
|
||||
static std::unordered_map<std::string, std::shared_ptr<Shape>> cache;
|
||||
static constexpr const char* BASE_PATH = "data/shapes/";
|
||||
|
||||
// Helpers privats
|
||||
static std::string resolve_path(const std::string& filename);
|
||||
static auto resolvePath(const std::string& filename) -> std::string;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -18,13 +18,10 @@ Starfield::Starfield(Rendering::Renderer* renderer,
|
||||
const Vec2& punt_fuga,
|
||||
const SDL_FRect& area,
|
||||
int densitat)
|
||||
: renderer_(renderer),
|
||||
: shape_estrella_(ShapeLoader::load("star.shp")),
|
||||
renderer_(renderer),
|
||||
punt_fuga_(punt_fuga),
|
||||
area_(area),
|
||||
densitat_(densitat) {
|
||||
// Carregar shape de estrella con ShapeLoader
|
||||
shape_estrella_ = ShapeLoader::load("star.shp");
|
||||
|
||||
area_(area) {
|
||||
if (!shape_estrella_ || !shape_estrella_->isValid()) {
|
||||
std::cerr << "ERROR: No s'ha pogut load star.shp" << '\n';
|
||||
return;
|
||||
@@ -69,7 +66,7 @@ Starfield::Starfield(Rendering::Renderer* renderer,
|
||||
}
|
||||
|
||||
// Inicialitzar una estrella (nueva o regenerada)
|
||||
void Starfield::inicialitzar_estrella(Estrella& estrella) const {
|
||||
void Starfield::initStar(Estrella& estrella) const {
|
||||
// Angle aleatori des del point de fuga hacia fuera
|
||||
estrella.angle = (static_cast<float>(rand()) / RAND_MAX) * 2.0F * Defaults::Math::PI;
|
||||
|
||||
@@ -83,7 +80,7 @@ void Starfield::inicialitzar_estrella(Estrella& estrella) const {
|
||||
}
|
||||
|
||||
// Verificar si una estrella está fuera de l'àrea
|
||||
bool Starfield::fora_area(const Estrella& estrella) const {
|
||||
auto Starfield::isOutsideArea(const Estrella& estrella) const -> bool {
|
||||
return (estrella.position.x < area_.x ||
|
||||
estrella.position.x > area_.x + area_.w ||
|
||||
estrella.position.y < area_.y ||
|
||||
@@ -91,7 +88,7 @@ bool Starfield::fora_area(const Estrella& estrella) const {
|
||||
}
|
||||
|
||||
// Calcular scale dinàmica segons distancia del centro
|
||||
float Starfield::calcular_escala(const Estrella& estrella) const {
|
||||
auto Starfield::computeScale(const Estrella& estrella) const -> float {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
// Interpolació lineal basada en distancia del centro
|
||||
@@ -101,7 +98,7 @@ float Starfield::calcular_escala(const Estrella& estrella) const {
|
||||
}
|
||||
|
||||
// Calcular brightness dinàmica segons distancia del centro
|
||||
float Starfield::calcular_brightness(const Estrella& estrella) const {
|
||||
auto Starfield::computeBrightness(const Estrella& estrella) const -> float {
|
||||
// Interpolació lineal: estrelles properes (vora) més brillants
|
||||
// distancia_centre: 0.0 (centro, llunyanes) → 1.0 (vora, properes)
|
||||
float brightness_base = Defaults::Brightness::STARFIELD_MIN +
|
||||
@@ -133,14 +130,14 @@ void Starfield::update(float delta_time) {
|
||||
estrella.distancia_centre = dist_px / radi_max_;
|
||||
|
||||
// Si ha sortit de l'àrea, regenerar-la
|
||||
if (fora_area(estrella)) {
|
||||
inicialitzar_estrella(estrella);
|
||||
if (isOutsideArea(estrella)) {
|
||||
initStar(estrella);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establir multiplicador de brightness
|
||||
void Starfield::set_brightness(float multiplier) {
|
||||
void Starfield::setBrightness(float multiplier) {
|
||||
multiplicador_brightness_ = std::max(0.0F, multiplier); // Evitar valors negatius
|
||||
}
|
||||
|
||||
@@ -152,11 +149,11 @@ void Starfield::draw() {
|
||||
|
||||
for (const auto& estrella : estrelles_) {
|
||||
// Calcular scale i brightness dinàmicament
|
||||
float scale = calcular_escala(estrella);
|
||||
float brightness = calcular_brightness(estrella);
|
||||
float scale = computeScale(estrella);
|
||||
float brightness = computeBrightness(estrella);
|
||||
|
||||
// Renderizar estrella sin rotación
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
renderer_,
|
||||
shape_estrella_,
|
||||
estrella.position,
|
||||
|
||||
@@ -43,8 +43,8 @@ class Starfield {
|
||||
void draw();
|
||||
|
||||
// Setters per ajustar parámetros en time real
|
||||
void set_punt_fuga(const Vec2& point) { punt_fuga_ = point; }
|
||||
void set_brightness(float multiplier);
|
||||
void setVanishingPoint(const Vec2& point) { punt_fuga_ = point; }
|
||||
void setBrightness(float multiplier);
|
||||
|
||||
private:
|
||||
// Estructura interna per cada estrella
|
||||
@@ -56,16 +56,16 @@ class Starfield {
|
||||
};
|
||||
|
||||
// Inicialitzar una estrella (nueva o regenerada)
|
||||
void inicialitzar_estrella(Estrella& estrella) const;
|
||||
void initStar(Estrella& estrella) const;
|
||||
|
||||
// Verificar si una estrella está fuera de l'àrea
|
||||
[[nodiscard]] bool fora_area(const Estrella& estrella) const;
|
||||
[[nodiscard]] auto isOutsideArea(const Estrella& estrella) const -> bool;
|
||||
|
||||
// Calcular scale dinàmica segons distancia del centro
|
||||
[[nodiscard]] float calcular_escala(const Estrella& estrella) const;
|
||||
[[nodiscard]] auto computeScale(const Estrella& estrella) const -> float;
|
||||
|
||||
// Calcular brightness dinàmica segons distancia del centro
|
||||
[[nodiscard]] float calcular_brightness(const Estrella& estrella) const;
|
||||
[[nodiscard]] auto computeBrightness(const Estrella& estrella) const -> float;
|
||||
|
||||
// Dades
|
||||
std::vector<Estrella> estrelles_;
|
||||
@@ -77,7 +77,6 @@ class Starfield {
|
||||
Vec2 punt_fuga_; // Vec2 de origin de las estrelles
|
||||
SDL_FRect area_; // Àrea activa
|
||||
float radi_max_; // Distancia màxima del centro al límit de pantalla
|
||||
int densitat_; // Nombre total de estrelles
|
||||
float multiplicador_brightness_{1.0F}; // Multiplicador de brightness (1.0 = default)
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// vector_text.cpp - Implementació del sistema de text vectorial
|
||||
// © 2026 JailDesigner
|
||||
// Test pre-commit hook
|
||||
|
||||
#include "core/graphics/vector_text.hpp"
|
||||
|
||||
@@ -12,18 +11,18 @@
|
||||
namespace Graphics {
|
||||
|
||||
// Constants para mides base dels caràcters
|
||||
constexpr float char_width = 20.0F; // Amplada base del caràcter
|
||||
constexpr float char_height = 40.0F; // Altura base del caràcter
|
||||
constexpr float BASE_CHAR_WIDTH = 20.0F; // Amplada base del caràcter
|
||||
constexpr float BASE_CHAR_HEIGHT = 40.0F; // Altura base del caràcter
|
||||
|
||||
VectorText::VectorText(Rendering::Renderer* renderer)
|
||||
: renderer_(renderer) {
|
||||
load_charset();
|
||||
loadCharset();
|
||||
}
|
||||
|
||||
void VectorText::load_charset() {
|
||||
void VectorText::loadCharset() {
|
||||
// Cargar dígitos 0-9
|
||||
for (char c = '0'; c <= '9'; c++) {
|
||||
std::string filename = get_shape_filename(c);
|
||||
std::string filename = getShapeFilename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->isValid()) {
|
||||
@@ -36,7 +35,7 @@ void VectorText::load_charset() {
|
||||
|
||||
// Cargar lletres A-Z (majúscules)
|
||||
for (char c = 'A'; c <= 'Z'; c++) {
|
||||
std::string filename = get_shape_filename(c);
|
||||
std::string filename = getShapeFilename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->isValid()) {
|
||||
@@ -48,10 +47,10 @@ void VectorText::load_charset() {
|
||||
}
|
||||
|
||||
// Cargar símbolos
|
||||
const std::string symbols[] = {".", ",", "-", ":", "!", "?"};
|
||||
for (const auto& sym : symbols) {
|
||||
const std::string SYMBOLS[] = {".", ",", "-", ":", "!", "?"};
|
||||
for (const auto& sym : SYMBOLS) {
|
||||
char c = sym[0];
|
||||
std::string filename = get_shape_filename(c);
|
||||
std::string filename = getShapeFilename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->isValid()) {
|
||||
@@ -62,17 +61,16 @@ void VectorText::load_charset() {
|
||||
}
|
||||
}
|
||||
|
||||
// Cargar símbolo de copyright (©) - UTF-8 U+00A9
|
||||
// Usem el segon byte (0xA9) como a key interna
|
||||
// Cargar símbolo de copyright (©) - UTF-8 U+00A9.
|
||||
// Usamos el segundo byte (0xA9, 169 decimal) como key interna del map.
|
||||
{
|
||||
char c = '\xA9'; // 169 decimal
|
||||
std::string filename = "font/char_copyright.shp";
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
const std::string FILENAME = "font/char_copyright.shp";
|
||||
auto shape = ShapeLoader::load(FILENAME);
|
||||
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
chars_['\xA9'] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << FILENAME
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -81,8 +79,10 @@ void VectorText::load_charset() {
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
std::string VectorText::get_shape_filename(char c) const {
|
||||
// Mapeo carácter → nombre de archivo (con prefix "font/")
|
||||
auto VectorText::getShapeFilename(char c) -> std::string {
|
||||
// Mapeo carácter → nombre de archivo (con prefix "font/").
|
||||
// Dígitos 0-9 y mayúsculas A-Z comparten el mismo path: la shape se llama
|
||||
// como el caracter mismo, así que se agrupan en un único case.
|
||||
switch (c) {
|
||||
case '0':
|
||||
case '1':
|
||||
@@ -94,9 +94,6 @@ std::string VectorText::get_shape_filename(char c) const {
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
return std::string("font/char_") + c + ".shp";
|
||||
|
||||
// Lletres majúscules A-Z
|
||||
case 'A':
|
||||
case 'B':
|
||||
case 'C':
|
||||
@@ -178,7 +175,7 @@ std::string VectorText::get_shape_filename(char c) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool VectorText::is_supported(char c) const {
|
||||
auto VectorText::isSupported(char c) const -> bool {
|
||||
return chars_.contains(c);
|
||||
}
|
||||
|
||||
@@ -188,16 +185,16 @@ void VectorText::render(const std::string& text, const Vec2& position, float sca
|
||||
}
|
||||
|
||||
// Ancho de un carácter base (20 px a scale 1.0)
|
||||
const float char_width_scaled = char_width * scale;
|
||||
const float CHAR_WIDTH_SCALED = BASE_CHAR_WIDTH * scale;
|
||||
|
||||
// Spacing escalado
|
||||
const float spacing_scaled = spacing * scale;
|
||||
const float SPACING_SCALED = spacing * scale;
|
||||
|
||||
// Altura de un carácter escalado (necesario para ajustar Y)
|
||||
const float char_height_scaled = char_height * scale;
|
||||
const float CHAR_HEIGHT_SCALED = BASE_CHAR_HEIGHT * scale;
|
||||
|
||||
// Posición X del borde izquierdo del carácter actual
|
||||
// (se ajustará +char_width/2 para obtener el centro al renderizar)
|
||||
// (se ajustará +BASE_CHAR_WIDTH/2 para obtener el centro al renderizar)
|
||||
float current_x = position.x;
|
||||
|
||||
// Iterar sobre cada byte del string (con detecció UTF-8)
|
||||
@@ -213,7 +210,7 @@ void VectorText::render(const std::string& text, const Vec2& position, float sca
|
||||
|
||||
// Manejar espacios (avanzar sin dibujar)
|
||||
if (c == ' ') {
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
current_x += CHAR_WIDTH_SCALED + SPACING_SCALED;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -223,24 +220,24 @@ void VectorText::render(const std::string& text, const Vec2& position, float sca
|
||||
// Renderizar carácter
|
||||
// Ajustar X e Y para que position represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = position.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, scale, 1.0F, brightness);
|
||||
Vec2 char_pos = {.x = current_x + (CHAR_WIDTH_SCALED / 2.0F), .y = position.y + (CHAR_HEIGHT_SCALED / 2.0F)};
|
||||
Rendering::renderShape(renderer_, it->second, char_pos, 0.0F, scale, 1.0F, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
current_x += CHAR_WIDTH_SCALED + SPACING_SCALED;
|
||||
} else {
|
||||
// Carácter no soportado: saltar (o renderizar '?' en el futuro)
|
||||
std::cerr << "[VectorText] Warning: caràcter no suportat '" << c << "'"
|
||||
<< '\n';
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
current_x += CHAR_WIDTH_SCALED + SPACING_SCALED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt, float scale, float spacing, float brightness) const {
|
||||
// Calcular dimensions del text
|
||||
float text_width = get_text_width(text, scale, spacing);
|
||||
float text_height = get_text_height(scale);
|
||||
float text_width = getTextWidth(text, scale, spacing);
|
||||
float text_height = getTextHeight(scale);
|
||||
|
||||
// Calcular posición de l'esquina superior izquierda
|
||||
// restant la meitat de las dimensions del point central
|
||||
@@ -252,13 +249,13 @@ void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt
|
||||
render(text, posicio_esquerra, scale, spacing, brightness);
|
||||
}
|
||||
|
||||
float VectorText::get_text_width(const std::string& text, float scale, float spacing) const {
|
||||
auto VectorText::getTextWidth(const std::string& text, float scale, float spacing) -> float {
|
||||
if (text.empty()) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
const float char_width_scaled = char_width * scale;
|
||||
const float spacing_scaled = spacing * scale;
|
||||
const float CHAR_WIDTH_SCALED = BASE_CHAR_WIDTH * scale;
|
||||
const float SPACING_SCALED = spacing * scale;
|
||||
|
||||
// Contar caracteres visuals (no bytes) - manejar UTF-8
|
||||
size_t visual_chars = 0;
|
||||
@@ -276,11 +273,11 @@ float VectorText::get_text_width(const std::string& text, float scale, float spa
|
||||
}
|
||||
|
||||
// Ancho total = todos los caracteres VISUALES + spacing entre ellos
|
||||
return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled);
|
||||
return (visual_chars * CHAR_WIDTH_SCALED) + ((visual_chars - 1) * SPACING_SCALED);
|
||||
}
|
||||
|
||||
float VectorText::get_text_height(float scale) const {
|
||||
return char_height * scale;
|
||||
auto VectorText::getTextHeight(float scale) -> float {
|
||||
return BASE_CHAR_HEIGHT * scale;
|
||||
}
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Graphics {
|
||||
|
||||
class VectorText {
|
||||
public:
|
||||
VectorText(Rendering::Renderer* renderer);
|
||||
explicit VectorText(Rendering::Renderer* renderer);
|
||||
|
||||
// Renderizar string completo
|
||||
// - text: cadena a renderizar (soporta: A-Z, a-z, 0-9, '.', ',', '-', ':',
|
||||
@@ -37,21 +37,23 @@ class VectorText {
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void renderCentered(const std::string& text, const Vec2& centre_punt, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado)
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const;
|
||||
// Calcular ancho total de un string (útil para centrado).
|
||||
// Es estático: no depende del estado del VectorText (el ancho viene de
|
||||
// las constantes BASE_CHAR_WIDTH/BASE_CHAR_HEIGHT del archivo .cpp).
|
||||
[[nodiscard]] static auto getTextWidth(const std::string& text, float scale = 1.0F, float spacing = 2.0F) -> float;
|
||||
|
||||
// Calcular altura del texto (útil para centrado vertical)
|
||||
[[nodiscard]] float get_text_height(float scale = 1.0F) const;
|
||||
// Calcular altura del texto (útil para centrado vertical).
|
||||
[[nodiscard]] static auto getTextHeight(float scale = 1.0F) -> float;
|
||||
|
||||
// Verificar si un carácter está soportado
|
||||
[[nodiscard]] bool is_supported(char c) const;
|
||||
[[nodiscard]] auto isSupported(char c) const -> bool;
|
||||
|
||||
private:
|
||||
Rendering::Renderer* renderer_;
|
||||
std::unordered_map<char, std::shared_ptr<Shape>> chars_;
|
||||
|
||||
void load_charset();
|
||||
[[nodiscard]] std::string get_shape_filename(char c) const;
|
||||
void loadCharset();
|
||||
[[nodiscard]] static auto getShapeFilename(char c) -> std::string;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_GetGamepadAxis, SDL_GamepadAxis, SDL_GamepadButton, SDL_GetError, SDL_JoystickID, SDL_AddGamepadMappingsFromFile, SDL_Event, SDL_EventType, SDL_GetGamepadButton, SDL_GetKeyboardState, SDL_INIT_GAMEPAD, SDL_InitSubSystem, SDL_LogError, SDL_OpenGamepad, SDL_PollEvent, SDL_WasInit, Sint16, SDL_Gamepad, SDL_LogCategory, SDL_Scancode
|
||||
|
||||
#include <algorithm> // Para std::ranges::any_of
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout, cerr
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access, allocator, operator==, make_shared
|
||||
#include <ranges> // Para __find_if_fn, find_if
|
||||
#include <unordered_map> // Para unordered_map, _Node_iterator, operator==, _Node_iterator_base, _Node_const_iterator
|
||||
#include <utility> // Para pair, move
|
||||
#include <utility> // Para move
|
||||
|
||||
#include "game/options.hpp" // Para Options::controls
|
||||
|
||||
@@ -190,12 +190,9 @@ auto Input::checkAnyButton(bool repeat) -> bool {
|
||||
|
||||
// Comprueba si algún player (P1 o P2) presionó alguna acción de una lista
|
||||
auto Input::checkAnyPlayerAction(const std::span<const InputAction>& actions, bool repeat) -> bool {
|
||||
for (const auto& action : actions) {
|
||||
if (checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return std::ranges::any_of(actions, [this, repeat](const InputAction& action) {
|
||||
return checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat);
|
||||
});
|
||||
}
|
||||
|
||||
// Comprueba si hay algun mando conectado
|
||||
@@ -420,8 +417,11 @@ auto Input::handleEvent(const SDL_Event& event) -> std::string {
|
||||
return addGamepad(event.gdevice.which);
|
||||
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||
return removeGamepad(event.gdevice.which);
|
||||
default:
|
||||
// El resto de eventos SDL no interesan a Input (los maneja el resto
|
||||
// del sistema: ventana, teclado, mouse).
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Input::addGamepad(int device_index) -> std::string {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <span> // Para span
|
||||
#include <string> // Para string, basic_string
|
||||
#include <unordered_map> // Para unordered_map
|
||||
#include <utility> // Para pair
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "core/input/input_types.hpp" // for InputAction
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "input_types.hpp"
|
||||
|
||||
#include <utility> // Para pair
|
||||
|
||||
// Definición de los mapas
|
||||
const std::unordered_map<InputAction, std::string> ACTION_TO_STRING = {
|
||||
{InputAction::LEFT, "LEFT"},
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
// --- Enums ---
|
||||
enum class InputAction : int { // Acciones de entrada posibles en el juego
|
||||
enum class InputAction : std::uint8_t { // Acciones de entrada posibles en el juego
|
||||
// Inputs de juego (movimiento y acción)
|
||||
LEFT, // Rotar izquierda
|
||||
RIGHT, // Rotar derecha
|
||||
|
||||
@@ -42,7 +42,7 @@ void setForceHidden(bool force) {
|
||||
}
|
||||
}
|
||||
|
||||
bool isForceHidden() {
|
||||
auto isForceHidden() -> bool {
|
||||
return force_hidden;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,5 @@ void updateCursorVisibility();
|
||||
|
||||
// Control de visibilidad forzada (para modo pantalla completa)
|
||||
void setForceHidden(bool force); // Activar/desactivar ocultación forzada
|
||||
bool isForceHidden(); // Consultar estado actual
|
||||
auto isForceHidden() -> bool; // Consultar estado actual
|
||||
} // namespace Mouse
|
||||
|
||||
@@ -8,21 +8,21 @@ namespace Easing {
|
||||
// Ease-out quadratic: empieza rápido, desacelera suavemente
|
||||
// t = progreso normalizado [0.0 - 1.0]
|
||||
// retorna value interpolado [0.0 - 1.0]
|
||||
inline float ease_out_quad(float t) {
|
||||
inline auto easeOutQuad(float t) -> float {
|
||||
return 1.0F - ((1.0F - t) * (1.0F - t));
|
||||
}
|
||||
|
||||
// Ease-in quadratic: empieza lento, acelera
|
||||
// t = progreso normalizado [0.0 - 1.0]
|
||||
// retorna value interpolado [0.0 - 1.0]
|
||||
inline float ease_in_quad(float t) {
|
||||
inline auto easeInQuad(float t) -> float {
|
||||
return t * t;
|
||||
}
|
||||
|
||||
// Ease-in-out quadratic: acelera al inicio, desacelera al final
|
||||
// t = progreso normalizado [0.0 - 1.0]
|
||||
// retorna value interpolado [0.0 - 1.0]
|
||||
inline float ease_in_out_quad(float t) {
|
||||
inline auto easeInOutQuad(float t) -> float {
|
||||
return (t < 0.5F)
|
||||
? 2.0F * t * t
|
||||
: 1.0F - ((-2.0F * t + 2.0F) * (-2.0F * t + 2.0F) / 2.0F);
|
||||
@@ -31,13 +31,13 @@ inline float ease_in_out_quad(float t) {
|
||||
// Ease-out cubic: desaceleración más suave que quadratic
|
||||
// t = progreso normalizado [0.0 - 1.0]
|
||||
// retorna value interpolado [0.0 - 1.0]
|
||||
inline float ease_out_cubic(float t) {
|
||||
inline auto easeOutCubic(float t) -> float {
|
||||
float t1 = 1.0F - t;
|
||||
return 1.0F - (t1 * t1 * t1);
|
||||
}
|
||||
|
||||
// Interpolación lineal básica (para referencia)
|
||||
inline float lerp(float start, float end, float t) {
|
||||
inline auto lerp(float start, float end, float t) -> float {
|
||||
return start + ((end - start) * t);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace Physics {
|
||||
|
||||
// Comprobación genèrica de colisión entre dues entidades
|
||||
inline bool check_collision(const Entities::Entity& a, const Entities::Entity& b, float amplifier = 1.0F) {
|
||||
inline auto checkCollision(const Entities::Entity& a, const Entities::Entity& b, float amplifier = 1.0F) -> bool {
|
||||
// Comprovar si ambdós són col·lisionables
|
||||
if (!a.isCollidable() || !b.isCollidable()) {
|
||||
return false;
|
||||
|
||||
@@ -42,8 +42,8 @@ void PhysicsWorld::integrate(float dt) {
|
||||
}
|
||||
|
||||
// Aplicar fuerzas acumuladas → aceleración
|
||||
const Vec2 acceleration = body->force_accumulator * body->inverse_mass;
|
||||
body->velocity += acceleration * dt;
|
||||
const Vec2 ACCELERATION = body->force_accumulator * body->inverse_mass;
|
||||
body->velocity += ACCELERATION * dt;
|
||||
|
||||
// Damping exponencial: equivalente a v *= exp(-damping * dt)
|
||||
// Aproximación lineal cuando damping*dt es pequeño.
|
||||
@@ -121,58 +121,61 @@ void PhysicsWorld::resolveBodyCollisions() {
|
||||
for (std::size_t j = i + 1; j < COUNT; ++j) {
|
||||
auto* a = bodies_[i];
|
||||
auto* b = bodies_[j];
|
||||
if (a == nullptr || b == nullptr) {
|
||||
continue;
|
||||
}
|
||||
// Dos cuerpos estáticos no necesitan resolución
|
||||
if (a->isStatic() && b->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Vec2 DELTA = b->position - a->position;
|
||||
const float DIST_SQ = DELTA.lengthSquared();
|
||||
const float SUM_R = a->radius + b->radius;
|
||||
if (DIST_SQ > SUM_R * SUM_R || DIST_SQ <= 0.0F) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const float DIST = std::sqrt(DIST_SQ);
|
||||
const Vec2 NORMAL = DELTA / DIST; // de A hacia B
|
||||
|
||||
// Corrección posicional (resolver penetración)
|
||||
const float PENETRATION = SUM_R - DIST;
|
||||
const float TOTAL_INV_MASS = a->inverse_mass + b->inverse_mass;
|
||||
if (TOTAL_INV_MASS > 0.0F) {
|
||||
const Vec2 CORRECTION = NORMAL * (PENETRATION / TOTAL_INV_MASS);
|
||||
if (!a->isStatic()) {
|
||||
a->position -= CORRECTION * a->inverse_mass;
|
||||
}
|
||||
if (!b->isStatic()) {
|
||||
b->position += CORRECTION * b->inverse_mass;
|
||||
}
|
||||
}
|
||||
|
||||
// Velocidad relativa proyectada sobre la normal
|
||||
const Vec2 V_REL = b->velocity - a->velocity;
|
||||
const float VEL_ALONG_NORMAL = V_REL.dot(NORMAL);
|
||||
// Si se están separando, no aplicar impulso
|
||||
if (VEL_ALONG_NORMAL > 0.0F) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Restitución promedio (Box2D usa max; promedio es más permisivo)
|
||||
const float E = (a->restitution + b->restitution) * 0.5F;
|
||||
const float J = -(1.0F + E) * VEL_ALONG_NORMAL / TOTAL_INV_MASS;
|
||||
const Vec2 IMPULSE = NORMAL * J;
|
||||
|
||||
if (!a->isStatic()) {
|
||||
a->velocity -= IMPULSE * a->inverse_mass;
|
||||
}
|
||||
if (!b->isStatic()) {
|
||||
b->velocity += IMPULSE * b->inverse_mass;
|
||||
if (a != nullptr && b != nullptr) {
|
||||
resolveBodyPair(*a, *b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsWorld::resolveBodyPair(RigidBody& a, RigidBody& b) {
|
||||
// Dos cuerpos estáticos no necesitan resolución
|
||||
if (a.isStatic() && b.isStatic()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Vec2 DELTA = b.position - a.position;
|
||||
const float DIST_SQ = DELTA.lengthSquared();
|
||||
const float SUM_R = a.radius + b.radius;
|
||||
if (DIST_SQ > SUM_R * SUM_R || DIST_SQ <= 0.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float DIST = std::sqrt(DIST_SQ);
|
||||
const Vec2 NORMAL = DELTA / DIST; // de A hacia B
|
||||
|
||||
// Corrección posicional (resolver penetración)
|
||||
const float PENETRATION = SUM_R - DIST;
|
||||
const float TOTAL_INV_MASS = a.inverse_mass + b.inverse_mass;
|
||||
if (TOTAL_INV_MASS > 0.0F) {
|
||||
const Vec2 CORRECTION = NORMAL * (PENETRATION / TOTAL_INV_MASS);
|
||||
if (!a.isStatic()) {
|
||||
a.position -= CORRECTION * a.inverse_mass;
|
||||
}
|
||||
if (!b.isStatic()) {
|
||||
b.position += CORRECTION * b.inverse_mass;
|
||||
}
|
||||
}
|
||||
|
||||
// Velocidad relativa proyectada sobre la normal
|
||||
const Vec2 V_REL = b.velocity - a.velocity;
|
||||
const float VEL_ALONG_NORMAL = V_REL.dot(NORMAL);
|
||||
// Si se están separando, no aplicar impulso
|
||||
if (VEL_ALONG_NORMAL > 0.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Restitución promedio (Box2D usa max; promedio es más permisivo)
|
||||
const float E = (a.restitution + b.restitution) * 0.5F;
|
||||
const float J = -(1.0F + E) * VEL_ALONG_NORMAL / TOTAL_INV_MASS;
|
||||
const Vec2 IMPULSE = NORMAL * J;
|
||||
|
||||
if (!a.isStatic()) {
|
||||
a.velocity -= IMPULSE * a.inverse_mass;
|
||||
}
|
||||
if (!b.isStatic()) {
|
||||
b.velocity += IMPULSE * b.inverse_mass;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Physics
|
||||
|
||||
@@ -59,6 +59,9 @@ class PhysicsWorld {
|
||||
void integrate(float dt);
|
||||
void resolveBoundsCollisions();
|
||||
void resolveBodyCollisions();
|
||||
// Resol un únic parell (a, b): correcció posicional + impulso elàstic.
|
||||
// Estàtic: només toca els dos cossos rebuts, no consulta el world.
|
||||
static void resolveBodyPair(RigidBody& a, RigidBody& b);
|
||||
};
|
||||
|
||||
} // namespace Physics
|
||||
|
||||
@@ -11,21 +11,21 @@ namespace Rendering {
|
||||
extern float g_current_scale_factor;
|
||||
|
||||
// Transforma coordenada lógica a física con arrodoniment
|
||||
inline int transform_x(int logical_x, float scale) {
|
||||
inline auto transformX(int logical_x, float scale) -> int {
|
||||
return static_cast<int>(std::round(logical_x * scale));
|
||||
}
|
||||
|
||||
inline int transform_y(int logical_y, float scale) {
|
||||
inline auto transformY(int logical_y, float scale) -> int {
|
||||
return static_cast<int>(std::round(logical_y * scale));
|
||||
}
|
||||
|
||||
// Variant que usa el factor de scale global
|
||||
inline int transform_x(int logical_x) {
|
||||
return transform_x(logical_x, g_current_scale_factor);
|
||||
inline auto transformX(int logical_x) -> int {
|
||||
return transformX(logical_x, g_current_scale_factor);
|
||||
}
|
||||
|
||||
inline int transform_y(int logical_y) {
|
||||
return transform_y(logical_y, g_current_scale_factor);
|
||||
inline auto transformY(int logical_y) -> int {
|
||||
return transformY(logical_y, g_current_scale_factor);
|
||||
}
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
@@ -239,8 +239,8 @@ void GpuFrameRenderer::flushBatch() {
|
||||
|
||||
SDL_GPUDevice* dev = device_.get();
|
||||
|
||||
const uint32_t VBO_SIZE = static_cast<uint32_t>(vertices_.size() * sizeof(LineVertex));
|
||||
const uint32_t IBO_SIZE = static_cast<uint32_t>(indices_.size() * sizeof(uint16_t));
|
||||
const auto VBO_SIZE = static_cast<uint32_t>(vertices_.size() * sizeof(LineVertex));
|
||||
const auto IBO_SIZE = static_cast<uint32_t>(indices_.size() * sizeof(uint16_t));
|
||||
|
||||
SDL_GPUBufferCreateInfo vbo_info{};
|
||||
vbo_info.usage = SDL_GPU_BUFFERUSAGE_VERTEX;
|
||||
@@ -362,7 +362,7 @@ void GpuFrameRenderer::compositePass() {
|
||||
ubo.flicker_amplitude = FLICKER_AMPLITUDE;
|
||||
ubo.flicker_frequency_hz = postfx_params_.flicker_frequency_hz;
|
||||
ubo.background_pulse_freq_hz = postfx_params_.background_pulse_freq_hz;
|
||||
ubo.pad_a_ = 0.0F;
|
||||
ubo.pad_a = 0.0F;
|
||||
ubo.background_min_r = BG_MIN_R;
|
||||
ubo.background_min_g = BG_MIN_G;
|
||||
ubo.background_min_b = BG_MIN_B;
|
||||
@@ -373,8 +373,8 @@ void GpuFrameRenderer::compositePass() {
|
||||
ubo.background_max_a = 1.0F;
|
||||
ubo.texel_size_x = 1.0F / logical_w_;
|
||||
ubo.texel_size_y = 1.0F / logical_h_;
|
||||
ubo.pad_b_ = 0.0F;
|
||||
ubo.pad_c_ = 0.0F;
|
||||
ubo.pad_b = 0.0F;
|
||||
ubo.pad_c = 0.0F;
|
||||
|
||||
SDL_PushGPUFragmentUniformData(cmd_buffer_, 0, &ubo, sizeof(ubo));
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
#include <SDL3/SDL_gpu.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Rendering::GPU {
|
||||
|
||||
class GpuDevice;
|
||||
|
||||
@@ -29,7 +29,7 @@ struct PostFxUniforms {
|
||||
float flicker_amplitude; // Profundidad del flicker (0..1)
|
||||
float flicker_frequency_hz; // Hz
|
||||
float background_pulse_freq_hz; // Hz
|
||||
float pad_a_;
|
||||
float pad_a;
|
||||
|
||||
float background_min_r; // Color min RGB en [0..1], A=1
|
||||
float background_min_g;
|
||||
@@ -43,8 +43,8 @@ struct PostFxUniforms {
|
||||
|
||||
float texel_size_x; // 1.0 / texture_width
|
||||
float texel_size_y;
|
||||
float pad_b_;
|
||||
float pad_c_;
|
||||
float pad_b;
|
||||
float pad_c;
|
||||
};
|
||||
|
||||
class GpuPostFxPipeline {
|
||||
|
||||
@@ -25,10 +25,10 @@ void linea(Renderer* renderer,
|
||||
|
||||
// Coords lógicas (1280×720). El shader hace el mapeo a NDC; el viewport
|
||||
// del SDLManager hace el letterbox a píxeles físicos.
|
||||
const float FX1 = static_cast<float>(x1);
|
||||
const float FY1 = static_cast<float>(y1);
|
||||
const float FX2 = static_cast<float>(x2);
|
||||
const float FY2 = static_cast<float>(y2);
|
||||
const auto FX1 = static_cast<float>(x1);
|
||||
const auto FY1 = static_cast<float>(y1);
|
||||
const auto FX2 = static_cast<float>(x2);
|
||||
const auto FY2 = static_cast<float>(y2);
|
||||
|
||||
// color.alpha==0 → usar color global (verde fósforo). alpha>0 → color directo.
|
||||
const SDL_Color SOURCE = (color.a > 0) ? color : g_current_line_color;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/input/mouse.hpp"
|
||||
#include "core/rendering/coordinate_transform.hpp"
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
#include "game/options.hpp"
|
||||
#include "project.h"
|
||||
|
||||
@@ -316,14 +315,18 @@ auto SDLManager::handleWindowEvent(const SDL_Event& event) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SDLManager::clear(uint8_t r, uint8_t g, uint8_t b) {
|
||||
auto SDLManager::clear(uint8_t r, uint8_t g, uint8_t b) -> bool {
|
||||
// El fondo lo dibuja ahora el shader de postpro (background pulse). El
|
||||
// offscreen se limpia en negro dentro de beginFrame. Los argumentos r/g/b
|
||||
// se mantienen por compatibilidad de API.
|
||||
(void)r;
|
||||
(void)g;
|
||||
(void)b;
|
||||
gpu_renderer_.beginFrame(0.0F, 0.0F, 0.0F);
|
||||
// beginFrame devuelve false si la swapchain no está disponible (ventana
|
||||
// minimizada, por ejemplo). Propagamos el bool al caller para que pueda
|
||||
// saltarse draw+present ese frame; si no, los vértices se acumulan en
|
||||
// el batch interno sin que nadie los consuma.
|
||||
return gpu_renderer_.beginFrame(0.0F, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
void SDLManager::present() {
|
||||
|
||||
@@ -31,8 +31,10 @@ class SDLManager {
|
||||
void toggleVSync(); // F4
|
||||
auto handleWindowEvent(const SDL_Event& event) -> bool; // Per a SDL_EVENT_WINDOW_RESIZED
|
||||
|
||||
// Funciones principals (renderizado)
|
||||
void clear(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0);
|
||||
// Funciones principals (renderizado).
|
||||
// clear() devuelve false si la swapchain no está disponible (p.ej.
|
||||
// ventana minimizada). El caller debe saltarse draw+present ese frame.
|
||||
[[nodiscard]] auto clear(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0) -> bool;
|
||||
void present();
|
||||
|
||||
// Getters
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Helper: aplicar rotación 3D a un point 2D (assumeix Z=0)
|
||||
static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
static auto apply3dRotation(float x, float y, const Rotation3D& rot) -> Vec2 {
|
||||
float z = 0.0F; // Todos los points 2D comencen a Z=0
|
||||
|
||||
// Pitch (rotación eix X): cabeceo arriba/baix
|
||||
@@ -35,21 +34,21 @@ static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
// Proyecció perspectiva (Z-divide simple)
|
||||
// Naves quieren hacia el point de fuga (320, 240) a "infinit" (Z → +∞)
|
||||
// Z més grande = més lluny = més pequeño a pantalla
|
||||
constexpr float perspective_factor = 500.0F;
|
||||
float scale_factor = perspective_factor / (perspective_factor + z2);
|
||||
constexpr float PERSPECTIVE_FACTOR = 500.0F;
|
||||
float scale_factor = PERSPECTIVE_FACTOR / (PERSPECTIVE_FACTOR + z2);
|
||||
|
||||
return {.x = x3 * scale_factor, .y = y3 * scale_factor};
|
||||
}
|
||||
|
||||
// Helper: transformar un point con rotación, scale i traslación
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale, const Rotation3D* rotation_3d) {
|
||||
static auto transformPoint(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale, const Rotation3D* rotation_3d) -> Vec2 {
|
||||
// 1. Centrar el point respecte al centro de la shape
|
||||
float centered_x = point.x - shape_centre.x;
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
|
||||
// 2. Aplicar rotación 3D (si es proporciona)
|
||||
if ((rotation_3d != nullptr) && rotation_3d->has_rotation()) {
|
||||
Vec2 rotated_3d = apply_3d_rotation(centered_x, centered_y, *rotation_3d);
|
||||
if ((rotation_3d != nullptr) && rotation_3d->hasRotation()) {
|
||||
Vec2 rotated_3d = apply3dRotation(centered_x, centered_y, *rotation_3d);
|
||||
centered_x = rotated_3d.x;
|
||||
centered_y = rotated_3d.y;
|
||||
}
|
||||
@@ -72,7 +71,7 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V
|
||||
return {.x = rotated_x + position.x, .y = rotated_y + position.y};
|
||||
}
|
||||
|
||||
void render_shape(Rendering::Renderer* renderer,
|
||||
void renderShape(Rendering::Renderer* renderer,
|
||||
const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& position,
|
||||
float angle,
|
||||
@@ -88,20 +87,20 @@ void render_shape(Rendering::Renderer* renderer,
|
||||
return;
|
||||
}
|
||||
|
||||
const Vec2& SHAPE_CENTRE = shape->getCenter();
|
||||
const Vec2& shape_centre = shape->getCenter();
|
||||
|
||||
for (const auto& primitive : shape->get_primitives()) {
|
||||
for (const auto& primitive : shape->getPrimitives()) {
|
||||
if (primitive.type == Graphics::PrimitiveType::POLYLINE) {
|
||||
// POLYLINE: conectar puntos consecutivos.
|
||||
for (size_t i = 0; i < primitive.points.size() - 1; i++) {
|
||||
const Vec2 P1 = transform_point(primitive.points[i], SHAPE_CENTRE, position, angle, scale, rotation_3d);
|
||||
const Vec2 P2 = transform_point(primitive.points[i + 1], SHAPE_CENTRE, position, angle, scale, rotation_3d);
|
||||
const Vec2 P1 = transformPoint(primitive.points[i], shape_centre, position, angle, scale, rotation_3d);
|
||||
const Vec2 P2 = transformPoint(primitive.points[i + 1], shape_centre, position, angle, scale, rotation_3d);
|
||||
linea(renderer, static_cast<int>(P1.x), static_cast<int>(P1.y),
|
||||
static_cast<int>(P2.x), static_cast<int>(P2.y), brightness, 0.0F, color);
|
||||
}
|
||||
} else if (primitive.points.size() >= 2) { // LINE
|
||||
const Vec2 P1 = transform_point(primitive.points[0], SHAPE_CENTRE, position, angle, scale, rotation_3d);
|
||||
const Vec2 P2 = transform_point(primitive.points[1], SHAPE_CENTRE, position, angle, scale, rotation_3d);
|
||||
const Vec2 P1 = transformPoint(primitive.points[0], shape_centre, position, angle, scale, rotation_3d);
|
||||
const Vec2 P2 = transformPoint(primitive.points[1], shape_centre, position, angle, scale, rotation_3d);
|
||||
linea(renderer, static_cast<int>(P1.x), static_cast<int>(P1.y),
|
||||
static_cast<int>(P2.x), static_cast<int>(P2.y), brightness, 0.0F, color);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ struct Rotation3D {
|
||||
yaw(y),
|
||||
roll(r) {}
|
||||
|
||||
[[nodiscard]] bool has_rotation() const {
|
||||
[[nodiscard]] auto hasRotation() const -> bool {
|
||||
return pitch != 0.0F || yaw != 0.0F || roll != 0.0F;
|
||||
}
|
||||
};
|
||||
@@ -42,7 +42,7 @@ struct Rotation3D {
|
||||
// - scale: factor de scale (1.0 = mida original)
|
||||
// - progress: progrés de l'animación (0.0-1.0, default 1.0 = tot visible)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void render_shape(Rendering::Renderer* renderer,
|
||||
void renderShape(Rendering::Renderer* renderer,
|
||||
const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& position,
|
||||
float angle,
|
||||
|
||||
@@ -4,19 +4,18 @@
|
||||
#include "resource_helper.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "resource_loader.hpp"
|
||||
|
||||
namespace Resource::Helper {
|
||||
|
||||
// Inicialitzar el sistema de recursos
|
||||
bool initializeResourceSystem(const std::string& pack_file, bool fallback) {
|
||||
auto initializeResourceSystem(const std::string& pack_file, bool fallback) -> bool {
|
||||
return Loader::get().initialize(pack_file, fallback);
|
||||
}
|
||||
|
||||
// Carregar un file
|
||||
std::vector<uint8_t> loadFile(const std::string& filepath) {
|
||||
auto loadFile(const std::string& filepath) -> std::vector<uint8_t> {
|
||||
// Normalitzar la ruta
|
||||
std::string normalized = normalizePath(filepath);
|
||||
|
||||
@@ -25,14 +24,14 @@ std::vector<uint8_t> loadFile(const std::string& filepath) {
|
||||
}
|
||||
|
||||
// Comprovar si existeix un file
|
||||
bool fileExists(const std::string& filepath) {
|
||||
auto fileExists(const std::string& filepath) -> bool {
|
||||
std::string normalized = normalizePath(filepath);
|
||||
return Loader::get().resourceExists(normalized);
|
||||
}
|
||||
|
||||
// Obtenir ruta normalitzada per al paquet
|
||||
// Elimina prefixos "data/", rutes absolutes, etc.
|
||||
std::string getPackPath(const std::string& asset_path) {
|
||||
auto getPackPath(const std::string& asset_path) -> std::string {
|
||||
std::string path = asset_path;
|
||||
|
||||
// Eliminar rutes absolutes (detectar / o C:\ al principi)
|
||||
@@ -69,12 +68,12 @@ std::string getPackPath(const std::string& asset_path) {
|
||||
}
|
||||
|
||||
// Normalitzar ruta (alias de getPackPath)
|
||||
std::string normalizePath(const std::string& path) {
|
||||
auto normalizePath(const std::string& path) -> std::string {
|
||||
return getPackPath(path);
|
||||
}
|
||||
|
||||
// Comprovar si hay paquet carregat
|
||||
bool isPackLoaded() {
|
||||
auto isPackLoaded() -> bool {
|
||||
return Loader::get().isPackLoaded();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
namespace Resource::Helper {
|
||||
|
||||
// Inicialización del sistema
|
||||
bool initializeResourceSystem(const std::string& pack_file, bool fallback);
|
||||
auto initializeResourceSystem(const std::string& pack_file, bool fallback) -> bool;
|
||||
|
||||
// Càrrega de archivos
|
||||
std::vector<uint8_t> loadFile(const std::string& filepath);
|
||||
bool fileExists(const std::string& filepath);
|
||||
auto loadFile(const std::string& filepath) -> std::vector<uint8_t>;
|
||||
auto fileExists(const std::string& filepath) -> bool;
|
||||
|
||||
// Normalització de rutes
|
||||
std::string getPackPath(const std::string& asset_path);
|
||||
std::string normalizePath(const std::string& path);
|
||||
auto getPackPath(const std::string& asset_path) -> std::string;
|
||||
auto normalizePath(const std::string& path) -> std::string;
|
||||
|
||||
// Estat
|
||||
bool isPackLoaded();
|
||||
auto isPackLoaded() -> bool;
|
||||
|
||||
} // namespace Resource::Helper
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
namespace Resource {
|
||||
|
||||
// Singleton
|
||||
Loader& Loader::get() {
|
||||
static Loader instance;
|
||||
return instance;
|
||||
auto Loader::get() -> Loader& {
|
||||
static Loader instance_;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
// Inicialitzar el sistema de recursos
|
||||
bool Loader::initialize(const std::string& pack_file, bool enable_fallback) {
|
||||
auto Loader::initialize(const std::string& pack_file, bool enable_fallback) -> bool {
|
||||
fallback_enabled_ = enable_fallback;
|
||||
|
||||
// Intentar load el paquet
|
||||
@@ -39,7 +39,7 @@ bool Loader::initialize(const std::string& pack_file, bool enable_fallback) {
|
||||
}
|
||||
|
||||
// Carregar un recurs
|
||||
std::vector<uint8_t> Loader::loadResource(const std::string& filename) {
|
||||
auto Loader::loadResource(const std::string& filename) -> std::vector<uint8_t> {
|
||||
// Intentar load del paquet primer
|
||||
if (pack_) {
|
||||
if (pack_->hasResource(filename)) {
|
||||
@@ -68,7 +68,7 @@ std::vector<uint8_t> Loader::loadResource(const std::string& filename) {
|
||||
}
|
||||
|
||||
// Comprovar si existeix un recurs
|
||||
bool Loader::resourceExists(const std::string& filename) {
|
||||
auto Loader::resourceExists(const std::string& filename) -> bool {
|
||||
// Comprovar al paquet
|
||||
if (pack_ && pack_->hasResource(filename)) {
|
||||
return true;
|
||||
@@ -84,7 +84,7 @@ bool Loader::resourceExists(const std::string& filename) {
|
||||
}
|
||||
|
||||
// Validar el paquet
|
||||
bool Loader::validatePack() {
|
||||
auto Loader::validatePack() -> bool {
|
||||
if (!pack_) {
|
||||
std::cerr << "[ResourceLoader] Advertència: no hay paquet carregat per validar\n";
|
||||
return false;
|
||||
@@ -94,7 +94,7 @@ bool Loader::validatePack() {
|
||||
}
|
||||
|
||||
// Comprovar si hay paquet carregat
|
||||
bool Loader::isPackLoaded() const {
|
||||
auto Loader::isPackLoaded() const -> bool {
|
||||
return pack_ != nullptr;
|
||||
}
|
||||
|
||||
@@ -105,12 +105,12 @@ void Loader::setBasePath(const std::string& path) {
|
||||
}
|
||||
|
||||
// Obtenir la ruta base
|
||||
std::string Loader::getBasePath() const {
|
||||
auto Loader::getBasePath() const -> const std::string& {
|
||||
return base_path_;
|
||||
}
|
||||
|
||||
// Carregar des del sistema de archivos (fallback)
|
||||
std::vector<uint8_t> Loader::loadFromFilesystem(const std::string& filename) {
|
||||
auto Loader::loadFromFilesystem(const std::string& filename) -> std::vector<uint8_t> {
|
||||
// The filename is already normalized (e.g., "shapes/logo/letra_j.shp")
|
||||
// We need to prepend base_path + "data/"
|
||||
std::string fullpath;
|
||||
|
||||
@@ -16,26 +16,26 @@ namespace Resource {
|
||||
class Loader {
|
||||
public:
|
||||
// Singleton
|
||||
static Loader& get();
|
||||
static auto get() -> Loader&;
|
||||
|
||||
// Inicialización
|
||||
bool initialize(const std::string& pack_file, bool enable_fallback);
|
||||
auto initialize(const std::string& pack_file, bool enable_fallback) -> bool;
|
||||
|
||||
// Càrrega de recursos
|
||||
std::vector<uint8_t> loadResource(const std::string& filename);
|
||||
bool resourceExists(const std::string& filename);
|
||||
auto loadResource(const std::string& filename) -> std::vector<uint8_t>;
|
||||
auto resourceExists(const std::string& filename) -> bool;
|
||||
|
||||
// Validació
|
||||
bool validatePack();
|
||||
[[nodiscard]] bool isPackLoaded() const;
|
||||
auto validatePack() -> bool;
|
||||
[[nodiscard]] auto isPackLoaded() const -> bool;
|
||||
|
||||
// Estat
|
||||
void setBasePath(const std::string& path);
|
||||
[[nodiscard]] std::string getBasePath() const;
|
||||
[[nodiscard]] auto getBasePath() const -> const std::string&;
|
||||
|
||||
// No es pot copiar ni moure
|
||||
Loader(const Loader&) = delete;
|
||||
Loader& operator=(const Loader&) = delete;
|
||||
auto operator=(const Loader&) -> Loader& = delete;
|
||||
|
||||
private:
|
||||
Loader() = default;
|
||||
@@ -47,7 +47,7 @@ class Loader {
|
||||
std::string base_path_;
|
||||
|
||||
// Funciones auxiliars
|
||||
std::vector<uint8_t> loadFromFilesystem(const std::string& filename);
|
||||
auto loadFromFilesystem(const std::string& filename) -> std::vector<uint8_t>;
|
||||
};
|
||||
|
||||
} // namespace Resource
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace Resource {
|
||||
|
||||
// Calcular checksum CRC32 simplificat
|
||||
uint32_t Pack::calculateChecksum(const std::vector<uint8_t>& data) const {
|
||||
auto Pack::calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t {
|
||||
uint32_t checksum = 0x12345678;
|
||||
for (unsigned char byte : data) {
|
||||
checksum = ((checksum << 5) + checksum) + byte;
|
||||
@@ -35,7 +35,7 @@ void Pack::decryptData(std::vector<uint8_t>& data, const std::string& key) {
|
||||
}
|
||||
|
||||
// Llegir file complet a memòria
|
||||
std::vector<uint8_t> Pack::readFile(const std::string& filepath) {
|
||||
auto Pack::readFile(const std::string& filepath) -> std::vector<uint8_t> {
|
||||
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
|
||||
if (!file) {
|
||||
std::cerr << "[ResourcePack] Error: no es pot obrir " << filepath << '\n';
|
||||
@@ -55,7 +55,7 @@ std::vector<uint8_t> Pack::readFile(const std::string& filepath) {
|
||||
}
|
||||
|
||||
// Añadir un file individual al paquet
|
||||
bool Pack::addFile(const std::string& filepath, const std::string& pack_name) {
|
||||
auto Pack::addFile(const std::string& filepath, const std::string& pack_name) -> bool {
|
||||
auto file_data = readFile(filepath);
|
||||
if (file_data.empty()) {
|
||||
return false;
|
||||
@@ -78,8 +78,8 @@ bool Pack::addFile(const std::string& filepath, const std::string& pack_name) {
|
||||
}
|
||||
|
||||
// Añadir todos los archivos de un directori recursivament
|
||||
bool Pack::addDirectory(const std::string& dir_path,
|
||||
const std::string& base_path) {
|
||||
auto Pack::addDirectory(const std::string& dir_path,
|
||||
const std::string& base_path) -> bool {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
if (!fs::exists(dir_path) || !fs::is_directory(dir_path)) {
|
||||
@@ -117,7 +117,7 @@ bool Pack::addDirectory(const std::string& dir_path,
|
||||
}
|
||||
|
||||
// Guardar paquet a disc
|
||||
bool Pack::savePack(const std::string& pack_file) {
|
||||
auto Pack::savePack(const std::string& pack_file) -> bool {
|
||||
std::ofstream file(pack_file, std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "[ResourcePack] Error: no es pot crear " << pack_file << '\n';
|
||||
@@ -161,7 +161,7 @@ bool Pack::savePack(const std::string& pack_file) {
|
||||
}
|
||||
|
||||
// Carregar paquet desde disc
|
||||
bool Pack::loadPack(const std::string& pack_file) {
|
||||
auto Pack::loadPack(const std::string& pack_file) -> bool {
|
||||
std::ifstream file(pack_file, std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "[ResourcePack] Error: no es pot obrir " << pack_file << '\n';
|
||||
@@ -226,7 +226,7 @@ bool Pack::loadPack(const std::string& pack_file) {
|
||||
}
|
||||
|
||||
// Obtenir un recurs del paquet
|
||||
std::vector<uint8_t> Pack::getResource(const std::string& filename) {
|
||||
auto Pack::getResource(const std::string& filename) -> std::vector<uint8_t> {
|
||||
auto it = resources_.find(filename);
|
||||
if (it == resources_.end()) {
|
||||
std::cerr << "[ResourcePack] Error: recurs no trobat: " << filename << '\n';
|
||||
@@ -257,12 +257,12 @@ std::vector<uint8_t> Pack::getResource(const std::string& filename) {
|
||||
}
|
||||
|
||||
// Comprovar si existeix un recurs
|
||||
bool Pack::hasResource(const std::string& filename) const {
|
||||
auto Pack::hasResource(const std::string& filename) const -> bool {
|
||||
return resources_.contains(filename);
|
||||
}
|
||||
|
||||
// Obtenir list de todos los recursos
|
||||
std::vector<std::string> Pack::getResourceList() const {
|
||||
auto Pack::getResourceList() const -> std::vector<std::string> {
|
||||
std::vector<std::string> list;
|
||||
list.reserve(resources_.size());
|
||||
|
||||
@@ -275,7 +275,7 @@ std::vector<std::string> Pack::getResourceList() const {
|
||||
}
|
||||
|
||||
// Validar integritat del paquet
|
||||
bool Pack::validatePack() const {
|
||||
auto Pack::validatePack() const -> bool {
|
||||
bool valid = true;
|
||||
|
||||
for (const auto& [name, entry] : resources_) {
|
||||
|
||||
@@ -32,20 +32,20 @@ class Pack {
|
||||
~Pack() = default;
|
||||
|
||||
// Añadir archivos al paquet
|
||||
bool addFile(const std::string& filepath, const std::string& pack_name);
|
||||
bool addDirectory(const std::string& dir_path, const std::string& base_path = "");
|
||||
auto addFile(const std::string& filepath, const std::string& pack_name) -> bool;
|
||||
auto addDirectory(const std::string& dir_path, const std::string& base_path = "") -> bool;
|
||||
|
||||
// Guardar i load paquets
|
||||
bool savePack(const std::string& pack_file);
|
||||
bool loadPack(const std::string& pack_file);
|
||||
auto savePack(const std::string& pack_file) -> bool;
|
||||
auto loadPack(const std::string& pack_file) -> bool;
|
||||
|
||||
// Accés a recursos
|
||||
std::vector<uint8_t> getResource(const std::string& filename);
|
||||
[[nodiscard]] bool hasResource(const std::string& filename) const;
|
||||
[[nodiscard]] std::vector<std::string> getResourceList() const;
|
||||
auto getResource(const std::string& filename) -> std::vector<uint8_t>;
|
||||
[[nodiscard]] auto hasResource(const std::string& filename) const -> bool;
|
||||
[[nodiscard]] auto getResourceList() const -> std::vector<std::string>;
|
||||
|
||||
// Validació
|
||||
[[nodiscard]] bool validatePack() const;
|
||||
[[nodiscard]] auto validatePack() const -> bool;
|
||||
|
||||
private:
|
||||
// Constants
|
||||
@@ -57,11 +57,12 @@ class Pack {
|
||||
std::unordered_map<std::string, ResourceEntry> resources_;
|
||||
std::vector<uint8_t> data_;
|
||||
|
||||
// Funciones auxiliars
|
||||
std::vector<uint8_t> readFile(const std::string& filepath);
|
||||
[[nodiscard]] uint32_t calculateChecksum(const std::vector<uint8_t>& data) const;
|
||||
void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
// Funciones auxiliars. Helpers estáticos: no necesitan estado del Pack,
|
||||
// trabajan sobre los bytes/path pasados por parámetro.
|
||||
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>;
|
||||
[[nodiscard]] static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t;
|
||||
static void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
static void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
};
|
||||
|
||||
} // namespace Resource
|
||||
|
||||
@@ -23,15 +23,8 @@ constexpr float FPS_UPDATE_INTERVAL = 0.5F;
|
||||
} // namespace
|
||||
|
||||
DebugOverlay::DebugOverlay(Rendering::Renderer* renderer)
|
||||
: text_(renderer),
|
||||
#ifdef _DEBUG
|
||||
visible_(true),
|
||||
#else
|
||||
visible_(false),
|
||||
#endif
|
||||
fps_accumulator_(0.0F),
|
||||
fps_frame_count_(0),
|
||||
fps_display_(0) {}
|
||||
: text_(renderer)
|
||||
{}
|
||||
|
||||
void DebugOverlay::update(float delta_time) {
|
||||
fps_accumulator_ += delta_time;
|
||||
|
||||
@@ -27,12 +27,12 @@ class DebugOverlay {
|
||||
|
||||
private:
|
||||
Graphics::VectorText text_;
|
||||
bool visible_;
|
||||
bool visible_{true};
|
||||
|
||||
// FPS counter — se actualiza cada FPS_UPDATE_INTERVAL segundos.
|
||||
float fps_accumulator_;
|
||||
int fps_frame_count_;
|
||||
int fps_display_;
|
||||
float fps_accumulator_{0.0F};
|
||||
int fps_frame_count_{0};
|
||||
int fps_display_{0};
|
||||
};
|
||||
|
||||
} // namespace System
|
||||
|
||||
@@ -175,8 +175,10 @@ void Director::createSystemFolder(const std::string& folder) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Comprovar si la carpeta existeix
|
||||
struct stat st = {.st_dev = 0};
|
||||
// Comprovar si la carpeta existeix. Zero-init de toda la struct stat
|
||||
// para evitar -Wmissing-field-initializers (struct con muchos campos
|
||||
// específicos del SO que no queremos enumerar manualmente).
|
||||
struct stat st{};
|
||||
if (stat(system_folder_.c_str(), &st) == -1) {
|
||||
errno = 0;
|
||||
|
||||
@@ -325,7 +327,12 @@ void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context
|
||||
debug_overlay.update(delta_time);
|
||||
Audio::update();
|
||||
|
||||
sdl.clear(0, 0, 0);
|
||||
// Si la swapchain no está disponible (ventana minimizada, etc.),
|
||||
// saltarse draw+present ese frame: dibujar dejaría vértices
|
||||
// colgando en el batch interno sin nadie que los presente.
|
||||
if (!sdl.clear(0, 0, 0)) {
|
||||
continue;
|
||||
}
|
||||
sdl.updateRenderingContext();
|
||||
scene.draw();
|
||||
debug_overlay.draw(); // siempre on top de la escena
|
||||
|
||||
@@ -15,7 +15,10 @@ class Director {
|
||||
explicit Director(std::vector<std::string> const& args);
|
||||
~Director();
|
||||
|
||||
auto run() -> int; // Main game loop
|
||||
// Main game loop. Estático: los miembros del Director (executable_path_,
|
||||
// system_folder_) se establecen en el ctor y no se vuelven a leer aquí;
|
||||
// el bucle solo orquesta sistemas globales (SDLManager, Options, Audio).
|
||||
static auto run() -> int;
|
||||
|
||||
private:
|
||||
std::string executable_path_;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace GameConfig {
|
||||
|
||||
// Mode de juego
|
||||
enum class Mode {
|
||||
enum class Mode : std::uint8_t {
|
||||
NORMAL, // Partida normal
|
||||
DEMO // Mode demostració (futur)
|
||||
};
|
||||
@@ -19,29 +19,29 @@ struct MatchConfig {
|
||||
// Métodos auxiliars
|
||||
|
||||
// Retorna true si solo hay un player active
|
||||
[[nodiscard]] bool es_un_jugador() const {
|
||||
[[nodiscard]] auto isSinglePlayer() const -> bool {
|
||||
return (jugador1_actiu && !jugador2_actiu) ||
|
||||
(!jugador1_actiu && jugador2_actiu);
|
||||
}
|
||||
|
||||
// Retorna true si hay dos jugadors active
|
||||
[[nodiscard]] bool son_dos_jugadors() const {
|
||||
[[nodiscard]] auto isCoop() const -> bool {
|
||||
return jugador1_actiu && jugador2_actiu;
|
||||
}
|
||||
|
||||
// Retorna true si no hay sin player active
|
||||
[[nodiscard]] bool cap_jugador() const {
|
||||
[[nodiscard]] auto hasNoPlayers() const -> bool {
|
||||
return !jugador1_actiu && !jugador2_actiu;
|
||||
}
|
||||
|
||||
// Compte de jugadors active (0, 1 o 2)
|
||||
[[nodiscard]] uint8_t compte_jugadors() const {
|
||||
[[nodiscard]] auto getPlayerCount() const -> uint8_t {
|
||||
return (jugador1_actiu ? 1 : 0) + (jugador2_actiu ? 1 : 0);
|
||||
}
|
||||
|
||||
// Retorna l'ID de l'únic player active (0 o 1)
|
||||
// Solo vàlid si es_un_jugador() retorna true
|
||||
[[nodiscard]] uint8_t id_unic_jugador() const {
|
||||
[[nodiscard]] auto getSinglePlayerId() const -> uint8_t {
|
||||
if (jugador1_actiu && !jugador2_actiu) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ using SceneType = SceneContext::SceneType;
|
||||
|
||||
namespace GlobalEvents {
|
||||
|
||||
bool handle(const SDL_Event& event, SDLManager& sdl, SceneContext& context) {
|
||||
auto handle(const SDL_Event& event, SDLManager& sdl, SceneContext& context) -> bool {
|
||||
// 1. Permitir que Input procese el evento (para hotplug de gamepads)
|
||||
auto event_msg = Input::get()->handleEvent(event);
|
||||
if (!event_msg.empty()) {
|
||||
|
||||
@@ -15,5 +15,5 @@ class SceneContext;
|
||||
namespace GlobalEvents {
|
||||
// Processa events globals (F1/F2/F3/ESC/QUIT)
|
||||
// Retorna true si l'event ha state processat y no necesario seguir processant-lo
|
||||
bool handle(const SDL_Event& event, SDLManager& sdl, SceneManager::SceneContext& context);
|
||||
auto handle(const SDL_Event& event, SDLManager& sdl, SceneManager::SceneContext& context) -> bool;
|
||||
} // namespace GlobalEvents
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "core/system/game_config.hpp"
|
||||
|
||||
namespace SceneManager {
|
||||
@@ -12,7 +14,7 @@ namespace SceneManager {
|
||||
class SceneContext {
|
||||
public:
|
||||
// Tipo de escena del juego
|
||||
enum class SceneType {
|
||||
enum class SceneType : std::uint8_t {
|
||||
LOGO, // Pantalla de start (logo JAILGAMES)
|
||||
TITLE, // Pantalla de título con menú
|
||||
GAME, // Juego principal (Asteroids)
|
||||
@@ -20,7 +22,7 @@ class SceneContext {
|
||||
};
|
||||
|
||||
// Opciones específiques para cada escena
|
||||
enum class Option {
|
||||
enum class Option : std::uint8_t {
|
||||
NONE, // Sin opciones especials (comportament per defecte)
|
||||
JUMP_TO_TITLE_MAIN, // TITLE: Saltar directament a MAIN (starfield instantani)
|
||||
// MODE_DEMO, // GAME: Mode demostració con IA (futur)
|
||||
@@ -64,7 +66,7 @@ class SceneContext {
|
||||
}
|
||||
|
||||
// Obtenir configuración de match (consumit per GameScene)
|
||||
[[nodiscard]] const GameConfig::MatchConfig& getMatchConfig() const {
|
||||
[[nodiscard]] auto getMatchConfig() const -> const GameConfig::MatchConfig& {
|
||||
return match_config_;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,43 +10,43 @@
|
||||
namespace Utils {
|
||||
|
||||
// Variables globals per guardar argv[0]
|
||||
static std::string executable_path_;
|
||||
static std::string executable_directory_;
|
||||
static std::string executable_path;
|
||||
static std::string executable_directory;
|
||||
|
||||
// Inicialitzar el sistema de rutes con argv[0]
|
||||
void initializePathSystem(const char* argv0) {
|
||||
if (argv0 == nullptr) {
|
||||
std::cerr << "[PathUtils] ADVERTÈNCIA: argv[0] es nullptr\n";
|
||||
executable_path_ = "";
|
||||
executable_directory_ = ".";
|
||||
executable_path = "";
|
||||
executable_directory = ".";
|
||||
return;
|
||||
}
|
||||
|
||||
executable_path_ = argv0;
|
||||
executable_path = argv0;
|
||||
|
||||
// Extreure el directori
|
||||
std::filesystem::path path(argv0);
|
||||
executable_directory_ = path.parent_path().string();
|
||||
executable_directory = path.parent_path().string();
|
||||
|
||||
if (executable_directory_.empty()) {
|
||||
executable_directory_ = ".";
|
||||
if (executable_directory.empty()) {
|
||||
executable_directory = ".";
|
||||
}
|
||||
|
||||
std::cout << "[PathUtils] Executable: " << executable_path_ << "\n";
|
||||
std::cout << "[PathUtils] Directori: " << executable_directory_ << "\n";
|
||||
std::cout << "[PathUtils] Executable: " << executable_path << "\n";
|
||||
std::cout << "[PathUtils] Directori: " << executable_directory << "\n";
|
||||
}
|
||||
|
||||
// Obtenir el directori de l'executable
|
||||
std::string getExecutableDirectory() {
|
||||
if (executable_directory_.empty()) {
|
||||
auto getExecutableDirectory() -> std::string {
|
||||
if (executable_directory.empty()) {
|
||||
std::cerr << "[PathUtils] ADVERTÈNCIA: Sistema de rutes no inicialitzat\n";
|
||||
return ".";
|
||||
}
|
||||
return executable_directory_;
|
||||
return executable_directory;
|
||||
}
|
||||
|
||||
// Detectar si estem dins un bundle de macOS
|
||||
bool isMacOSBundle() {
|
||||
auto isMacOSBundle() -> bool {
|
||||
#ifdef MACOS_BUNDLE
|
||||
return true;
|
||||
#else
|
||||
@@ -58,7 +58,7 @@ bool isMacOSBundle() {
|
||||
}
|
||||
|
||||
// Obtenir la ruta base dels recursos
|
||||
std::string getResourceBasePath() {
|
||||
auto getResourceBasePath() -> std::string {
|
||||
std::string exe_dir = getExecutableDirectory();
|
||||
|
||||
if (isMacOSBundle()) {
|
||||
@@ -70,7 +70,7 @@ std::string getResourceBasePath() {
|
||||
}
|
||||
|
||||
// Normalitzar ruta (convertir barres, etc.)
|
||||
std::string normalizePath(const std::string& path) {
|
||||
auto normalizePath(const std::string& path) -> std::string {
|
||||
std::string normalized = path;
|
||||
|
||||
// Convertir barres invertides a normals
|
||||
|
||||
@@ -12,13 +12,13 @@ namespace Utils {
|
||||
void initializePathSystem(const char* argv0);
|
||||
|
||||
// Obtenció de rutes
|
||||
std::string getExecutableDirectory();
|
||||
std::string getResourceBasePath();
|
||||
auto getExecutableDirectory() -> std::string;
|
||||
auto getResourceBasePath() -> std::string;
|
||||
|
||||
// Detecció de plataforma
|
||||
bool isMacOSBundle();
|
||||
auto isMacOSBundle() -> bool;
|
||||
|
||||
// Normalització
|
||||
std::string normalizePath(const std::string& path);
|
||||
auto normalizePath(const std::string& path) -> std::string;
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -26,12 +26,12 @@ constexpr int VELOCITAT_MAX = static_cast<int>(Defaults::Physics::BULLET_SPEED);
|
||||
constexpr float PI = Defaults::Math::PI;
|
||||
|
||||
// Helpers per comprovar límits de zona
|
||||
inline bool dins_zona_joc(float x, float y) {
|
||||
const SDL_FPoint point = {x, y};
|
||||
return SDL_PointInRectFloat(&point, &Defaults::Zones::PLAYAREA);
|
||||
inline auto isInPlayArea(float x, float y) -> bool {
|
||||
const SDL_FPoint POINT = {x, y};
|
||||
return SDL_PointInRectFloat(&POINT, &Defaults::Zones::PLAYAREA);
|
||||
}
|
||||
|
||||
inline void obtenir_limits_zona(float& min_x, float& max_x, float& min_y, float& max_y) {
|
||||
inline void getPlayAreaBounds(float& min_x, float& max_x, float& min_y, float& max_y) {
|
||||
const auto& zona = Defaults::Zones::PLAYAREA;
|
||||
min_x = zona.x;
|
||||
max_x = zona.x + zona.w;
|
||||
@@ -40,7 +40,7 @@ inline void obtenir_limits_zona(float& min_x, float& max_x, float& min_y, float&
|
||||
}
|
||||
|
||||
// Obtenir límits segurs (compensant radi de l'entidad)
|
||||
inline void obtenir_limits_zona_segurs(float radi, float& min_x, float& max_x, float& min_y, float& max_y) {
|
||||
inline void getSafePlayAreaBounds(float radi, float& min_x, float& max_x, float& min_y, float& max_y) {
|
||||
const auto& zona = Defaults::Zones::PLAYAREA;
|
||||
constexpr float MARGE_SEGURETAT = 10.0F; // Safety margin
|
||||
|
||||
@@ -51,7 +51,7 @@ inline void obtenir_limits_zona_segurs(float radi, float& min_x, float& max_x, f
|
||||
}
|
||||
|
||||
// Obtenir centro de l'àrea de juego
|
||||
inline void obtenir_centre_zona(float& centre_x, float& centre_y) {
|
||||
inline void getPlayAreaCenter(float& centre_x, float& centre_y) {
|
||||
const auto& zona = Defaults::Zones::PLAYAREA;
|
||||
centre_x = zona.x + (zona.w / 2.0F);
|
||||
centre_y = zona.y + (zona.h / 2.0F);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Effects {
|
||||
|
||||
// Helper: transformar point con rotación, scale i traslación
|
||||
// (Copiat de shape_renderer.cpp:12-34)
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale) {
|
||||
static auto transformPoint(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale) -> Vec2 {
|
||||
// 1. Centrar el point respecte al centro de la shape
|
||||
float centered_x = point.x - shape_centre.x;
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
@@ -62,147 +62,150 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
// Reproducir sonido de explosión
|
||||
Audio::get()->playSound(sound, Audio::Group::GAME);
|
||||
|
||||
// Obtenir centro de la shape para transformacions
|
||||
const Vec2& shape_centre = shape->getCenter();
|
||||
|
||||
// Iterar sobre todas las primitives de la shape
|
||||
for (const auto& primitive : shape->get_primitives()) {
|
||||
// Processar cada segment de línia
|
||||
std::vector<std::pair<Vec2, Vec2>> segments;
|
||||
for (const auto& primitive : shape->getPrimitives()) {
|
||||
for (const auto& [local_p1, local_p2] : extractSegments(primitive)) {
|
||||
// Transformar points locals → coordenades mundials
|
||||
Vec2 world_p1 = transformPoint(local_p1, shape_centre, centro, angle, scale);
|
||||
Vec2 world_p2 = transformPoint(local_p2, shape_centre, centro, angle, scale);
|
||||
|
||||
if (primitive.type == Graphics::PrimitiveType::POLYLINE) {
|
||||
// Polyline: extreure segments consecutius
|
||||
for (size_t i = 0; i < primitive.points.size() - 1; i++) {
|
||||
segments.emplace_back(primitive.points[i], primitive.points[i + 1]);
|
||||
}
|
||||
} else { // PrimitiveType::LINE
|
||||
// Line: un únic segment
|
||||
if (primitive.points.size() >= 2) {
|
||||
segments.emplace_back(primitive.points[0], primitive.points[1]);
|
||||
// Si el pool es ple, no té sentit continuar amb la resta de segments
|
||||
if (!spawnDebris(world_p1, world_p2, centro, velocitat_base, brightness,
|
||||
velocitat_objecte, velocitat_angular,
|
||||
factor_herencia_visual, color)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crear debris para cada segment
|
||||
for (const auto& [local_p1, local_p2] : segments) {
|
||||
// 1. Transformar points locals → coordenades mundials
|
||||
Vec2 world_p1 =
|
||||
transform_point(local_p1, shape_centre, centro, angle, scale);
|
||||
Vec2 world_p2 =
|
||||
transform_point(local_p2, shape_centre, centro, angle, scale);
|
||||
auto DebrisManager::extractSegments(const Graphics::ShapePrimitive& primitive)
|
||||
-> std::vector<std::pair<Vec2, Vec2>> {
|
||||
std::vector<std::pair<Vec2, Vec2>> segments;
|
||||
|
||||
// 2. Trobar slot lliure
|
||||
Debris* debris = findFreeSlot();
|
||||
if (debris == nullptr) {
|
||||
std::cerr << "[DebrisManager] Warning: no debris slots disponibles\n";
|
||||
return; // Pool ple
|
||||
}
|
||||
|
||||
// 3. Inicialitzar geometria
|
||||
debris->p1 = world_p1;
|
||||
debris->p2 = world_p2;
|
||||
|
||||
// 4. Calcular direcció de explosión (radial, des del centro hacia fuera)
|
||||
Vec2 direccio = computeExplosionDirection(world_p1, world_p2, centro);
|
||||
|
||||
// 5. Velocidad inicial (base ± variació aleatòria + velocity heretada)
|
||||
float speed =
|
||||
velocitat_base +
|
||||
(((std::rand() / static_cast<float>(RAND_MAX)) * 2.0F - 1.0F) *
|
||||
Defaults::Physics::Debris::VARIACIO_VELOCITAT);
|
||||
|
||||
// Heredar velocity de l'objecte original (suma vectorial)
|
||||
debris->velocity.x = (direccio.x * speed) + velocitat_objecte.x;
|
||||
debris->velocity.y = (direccio.y * speed) + velocitat_objecte.y;
|
||||
debris->acceleration = Defaults::Physics::Debris::ACCELERACIO;
|
||||
|
||||
// 6. Herència de velocity angular con sin + conversió de excés
|
||||
|
||||
// 6a. Rotación de TRAYECTORIA con sin + conversió tangencial
|
||||
if (std::abs(velocitat_angular) > 0.01F) {
|
||||
// FASE 1: Aplicar herència i variació (igual que antes)
|
||||
float factor_herencia =
|
||||
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN +
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) *
|
||||
(Defaults::Physics::Debris::FACTOR_HERENCIA_MAX -
|
||||
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN));
|
||||
|
||||
float velocitat_ang_heretada = velocitat_angular * factor_herencia;
|
||||
|
||||
float variacio =
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) * 0.2F) - 0.1F;
|
||||
velocitat_ang_heretada *= (1.0F + variacio);
|
||||
|
||||
// FASE 2: Aplicar sin i calcular excés
|
||||
constexpr float CAP = Defaults::Physics::Debris::VELOCITAT_ROT_MAX;
|
||||
float abs_ang = std::abs(velocitat_ang_heretada);
|
||||
float sign_ang = (velocitat_ang_heretada >= 0.0F) ? 1.0F : -1.0F;
|
||||
|
||||
if (abs_ang > CAP) {
|
||||
// Excés: convertir a velocity tangencial
|
||||
float excess = abs_ang - CAP;
|
||||
|
||||
// Radi de la shape (enemigos = 20 px)
|
||||
float radius = 20.0F;
|
||||
|
||||
// Velocidad tangencial = ω_excés × radi
|
||||
float v_tangential = excess * radius;
|
||||
|
||||
// Direcció tangencial: perpendicular a la radial (90° CCW)
|
||||
// Si direccio = (dx, dy), tangent = (-dy, dx)
|
||||
float tangent_x = -direccio.y;
|
||||
float tangent_y = direccio.x;
|
||||
|
||||
// Añadir velocity tangencial (suma vectorial)
|
||||
debris->velocity.x += tangent_x * v_tangential;
|
||||
debris->velocity.y += tangent_y * v_tangential;
|
||||
|
||||
// Aplicar hacia velocity angular (preservar signe)
|
||||
debris->velocitat_rot = sign_ang * CAP;
|
||||
} else {
|
||||
// Per sota del sin: comportament normal
|
||||
debris->velocitat_rot = velocitat_ang_heretada;
|
||||
}
|
||||
} else {
|
||||
debris->velocitat_rot = 0.0F; // Nave: sin curvas
|
||||
}
|
||||
|
||||
// 6b. Rotación VISUAL (proporcional según factor_herencia_visual)
|
||||
if (factor_herencia_visual > 0.01F && std::abs(velocitat_angular) > 0.01F) {
|
||||
// Heredar rotación visual con factor proporcional
|
||||
debris->velocitat_rot_visual = debris->velocitat_rot * factor_herencia_visual;
|
||||
|
||||
// Variació aleatòria pequeña (±5%) per naturalitat
|
||||
float variacio_visual =
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) * 0.1F) - 0.05F;
|
||||
debris->velocitat_rot_visual *= (1.0F + variacio_visual);
|
||||
} else {
|
||||
// Rotación visual aleatòria (factor = 0.0 o sin velocidad angular)
|
||||
debris->velocitat_rot_visual =
|
||||
Defaults::Physics::Debris::ROTACIO_MIN +
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) *
|
||||
(Defaults::Physics::Debris::ROTACIO_MAX -
|
||||
Defaults::Physics::Debris::ROTACIO_MIN));
|
||||
|
||||
// 50% probabilitat de rotación en sentit contrari
|
||||
if (std::rand() % 2 == 0) {
|
||||
debris->velocitat_rot_visual = -debris->velocitat_rot_visual;
|
||||
}
|
||||
}
|
||||
|
||||
debris->angle_rotacio = 0.0F;
|
||||
|
||||
// 7. Configurar vida i shrinking
|
||||
debris->temps_vida = 0.0F;
|
||||
debris->temps_max = Defaults::Physics::Debris::TEMPS_VIDA;
|
||||
debris->factor_shrink = Defaults::Physics::Debris::SHRINK_RATE;
|
||||
|
||||
// 8. Heredar brightness y color del padre
|
||||
debris->brightness = brightness;
|
||||
debris->color = color;
|
||||
|
||||
// 9. Activar
|
||||
debris->active = true;
|
||||
if (primitive.type == Graphics::PrimitiveType::POLYLINE) {
|
||||
// Polyline: extreure segments consecutius
|
||||
for (size_t i = 0; i + 1 < primitive.points.size(); i++) {
|
||||
segments.emplace_back(primitive.points[i], primitive.points[i + 1]);
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
// PrimitiveType::LINE: un únic segment (si té els 2 punts)
|
||||
if (primitive.points.size() >= 2) {
|
||||
segments.emplace_back(primitive.points[0], primitive.points[1]);
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
auto DebrisManager::spawnDebris(const Vec2& world_p1, const Vec2& world_p2,
|
||||
const Vec2& centro, float velocitat_base, float brightness,
|
||||
const Vec2& velocitat_objecte, float velocitat_angular,
|
||||
float factor_herencia_visual, SDL_Color color) -> bool {
|
||||
Debris* debris = findFreeSlot();
|
||||
if (debris == nullptr) {
|
||||
std::cerr << "[DebrisManager] Warning: no debris slots disponibles\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Geometria
|
||||
debris->p1 = world_p1;
|
||||
debris->p2 = world_p2;
|
||||
|
||||
// Direcció radial (desde el centro hacia el segment)
|
||||
Vec2 direccio = computeExplosionDirection(world_p1, world_p2, centro);
|
||||
|
||||
// Velocidad inicial (base ± variació aleatòria + velocity heretada de l'objecte)
|
||||
float speed =
|
||||
velocitat_base +
|
||||
(((std::rand() / static_cast<float>(RAND_MAX)) * 2.0F - 1.0F) *
|
||||
Defaults::Physics::Debris::VARIACIO_VELOCITAT);
|
||||
debris->velocity.x = (direccio.x * speed) + velocitat_objecte.x;
|
||||
debris->velocity.y = (direccio.y * speed) + velocitat_objecte.y;
|
||||
debris->acceleration = Defaults::Physics::Debris::ACCELERACIO;
|
||||
|
||||
// Rotación de trayectoria (con conversió a tangencial si excedeix cap)
|
||||
applyAngularVelocity(*debris, direccio, velocitat_angular);
|
||||
|
||||
// Rotación visual (proporcional o aleatòria)
|
||||
applyVisualRotation(*debris, velocitat_angular, factor_herencia_visual);
|
||||
|
||||
debris->angle_rotacio = 0.0F;
|
||||
|
||||
// Vida i shrinking
|
||||
debris->temps_vida = 0.0F;
|
||||
debris->temps_max = Defaults::Physics::Debris::TEMPS_VIDA;
|
||||
debris->factor_shrink = Defaults::Physics::Debris::SHRINK_RATE;
|
||||
|
||||
// Visuals heretades
|
||||
debris->brightness = brightness;
|
||||
debris->color = color;
|
||||
|
||||
debris->active = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DebrisManager::applyAngularVelocity(Debris& debris, const Vec2& direccio,
|
||||
float velocitat_angular) {
|
||||
if (std::abs(velocitat_angular) <= 0.01F) {
|
||||
debris.velocitat_rot = 0.0F; // Nave: sin curvas
|
||||
return;
|
||||
}
|
||||
|
||||
// FASE 1: Aplicar herència i variació
|
||||
float factor_herencia =
|
||||
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN +
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) *
|
||||
(Defaults::Physics::Debris::FACTOR_HERENCIA_MAX -
|
||||
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN));
|
||||
float velocitat_ang_heretada = velocitat_angular * factor_herencia;
|
||||
float variacio = ((std::rand() / static_cast<float>(RAND_MAX)) * 0.2F) - 0.1F;
|
||||
velocitat_ang_heretada *= (1.0F + variacio);
|
||||
|
||||
// FASE 2: Cap a la velocity màxima; l'excés es converteix en tangencial
|
||||
constexpr float CAP = Defaults::Physics::Debris::VELOCITAT_ROT_MAX;
|
||||
float abs_ang = std::abs(velocitat_ang_heretada);
|
||||
float sign_ang = (velocitat_ang_heretada >= 0.0F) ? 1.0F : -1.0F;
|
||||
|
||||
if (abs_ang <= CAP) {
|
||||
debris.velocitat_rot = velocitat_ang_heretada;
|
||||
return;
|
||||
}
|
||||
|
||||
// Excés: converteix l'excés de velocitat angular en velocitat tangencial lineal
|
||||
float excess = abs_ang - CAP;
|
||||
constexpr float RADIUS = 20.0F; // Radi típic de la shape (enemigos = 20 px)
|
||||
float v_tangential = excess * RADIUS;
|
||||
|
||||
// Direcció tangencial: perpendicular a la radial (90° CCW): tangent = (-dy, dx)
|
||||
debris.velocity.x += -direccio.y * v_tangential;
|
||||
debris.velocity.y += direccio.x * v_tangential;
|
||||
|
||||
// Velocitat angular limitada al cap (preservant el signe)
|
||||
debris.velocitat_rot = sign_ang * CAP;
|
||||
}
|
||||
|
||||
void DebrisManager::applyVisualRotation(Debris& debris, float velocitat_angular,
|
||||
float factor_herencia_visual) {
|
||||
if (factor_herencia_visual > 0.01F && std::abs(velocitat_angular) > 0.01F) {
|
||||
// Heredar rotación visual con factor proporcional + ±5% de variació
|
||||
debris.velocitat_rot_visual = debris.velocitat_rot * factor_herencia_visual;
|
||||
float variacio_visual =
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) * 0.1F) - 0.05F;
|
||||
debris.velocitat_rot_visual *= (1.0F + variacio_visual);
|
||||
return;
|
||||
}
|
||||
|
||||
// Rotación visual aleatòria (factor = 0.0 o sin velocidad angular)
|
||||
debris.velocitat_rot_visual =
|
||||
Defaults::Physics::Debris::ROTACIO_MIN +
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) *
|
||||
(Defaults::Physics::Debris::ROTACIO_MAX -
|
||||
Defaults::Physics::Debris::ROTACIO_MIN));
|
||||
|
||||
// 50% probabilitat de rotación en sentit contrari
|
||||
if (std::rand() % 2 == 0) {
|
||||
debris.velocitat_rot_visual = -debris.velocitat_rot_visual;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +323,7 @@ void DebrisManager::draw() const {
|
||||
}
|
||||
}
|
||||
|
||||
Debris* DebrisManager::findFreeSlot() {
|
||||
auto DebrisManager::findFreeSlot() -> Debris* {
|
||||
for (auto& debris : debris_pool_) {
|
||||
if (!debris.active) {
|
||||
return &debris;
|
||||
@@ -329,9 +332,9 @@ Debris* DebrisManager::findFreeSlot() {
|
||||
return nullptr; // Pool ple
|
||||
}
|
||||
|
||||
Vec2 DebrisManager::computeExplosionDirection(const Vec2& p1,
|
||||
auto DebrisManager::computeExplosionDirection(const Vec2& p1,
|
||||
const Vec2& p2,
|
||||
const Vec2& centre_objecte) const {
|
||||
const Vec2& centre_objecte) -> Vec2 {
|
||||
// 1. Calcular centro del segment
|
||||
float centro_seg_x = (p1.x + p2.x) / 2.0F;
|
||||
float centro_seg_y = (p1.y + p2.y) / 2.0F;
|
||||
@@ -372,7 +375,7 @@ void DebrisManager::reset() {
|
||||
}
|
||||
}
|
||||
|
||||
int DebrisManager::getActiveCount() const {
|
||||
auto DebrisManager::getActiveCount() const -> int {
|
||||
int count = 0;
|
||||
for (const auto& debris : debris_pool_) {
|
||||
if (debris.active) {
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/graphics/shape.hpp"
|
||||
@@ -54,7 +56,7 @@ class DebrisManager {
|
||||
void reset();
|
||||
|
||||
// Obtenir número de fragments active
|
||||
[[nodiscard]] int getActiveCount() const;
|
||||
[[nodiscard]] auto getActiveCount() const -> int;
|
||||
|
||||
private:
|
||||
Rendering::Renderer* renderer_;
|
||||
@@ -67,10 +69,26 @@ class DebrisManager {
|
||||
std::array<Debris, MAX_DEBRIS> debris_pool_;
|
||||
|
||||
// Trobar primer slot inactiu
|
||||
Debris* findFreeSlot();
|
||||
auto findFreeSlot() -> Debris*;
|
||||
|
||||
// Calcular direcció de explosión (radial, des del centro hacia el segment)
|
||||
[[nodiscard]] Vec2 computeExplosionDirection(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) const;
|
||||
// Calcular direcció de explosión (radial, des del centro hacia el segment).
|
||||
// Estático: solo opera sobre los puntos pasados, sin estado del manager.
|
||||
[[nodiscard]] static auto computeExplosionDirection(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) -> Vec2;
|
||||
|
||||
// Sub-pasos de explode() (descomposició per reduir complexitat cognitiva).
|
||||
// extractSegments y los apply* son static (solo toquen el debris pasado).
|
||||
[[nodiscard]] static auto extractSegments(const Graphics::ShapePrimitive& primitive)
|
||||
-> std::vector<std::pair<Vec2, Vec2>>;
|
||||
// Inicialitza un debris en un slot lliure i el deixa actiu. Retorna
|
||||
// false si el pool está ple (la cridadora ha d'aturar el bucle).
|
||||
auto spawnDebris(const Vec2& world_p1, const Vec2& world_p2,
|
||||
const Vec2& centro, float velocitat_base, float brightness,
|
||||
const Vec2& velocitat_objecte, float velocitat_angular,
|
||||
float factor_herencia_visual, SDL_Color color) -> bool;
|
||||
static void applyAngularVelocity(Debris& debris, const Vec2& direccio,
|
||||
float velocitat_angular);
|
||||
static void applyVisualRotation(Debris& debris, float velocitat_angular,
|
||||
float factor_herencia_visual);
|
||||
};
|
||||
|
||||
} // namespace Effects
|
||||
|
||||
@@ -64,10 +64,10 @@ void FloatingScoreManager::draw() {
|
||||
}
|
||||
|
||||
// Renderizar centrat con brightness (fade)
|
||||
constexpr float scale = Defaults::FloatingScore::SCALE;
|
||||
constexpr float spacing = Defaults::FloatingScore::SPACING;
|
||||
constexpr float SCALE = Defaults::FloatingScore::SCALE;
|
||||
constexpr float SPACING = Defaults::FloatingScore::SPACING;
|
||||
|
||||
text_.renderCentered(pf.text, pf.position, scale, spacing, pf.brightness);
|
||||
text_.renderCentered(pf.text, pf.position, SCALE, SPACING, pf.brightness);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ void FloatingScoreManager::reset() {
|
||||
}
|
||||
}
|
||||
|
||||
int FloatingScoreManager::getActiveCount() const {
|
||||
auto FloatingScoreManager::getActiveCount() const -> int {
|
||||
int count = 0;
|
||||
for (const auto& pf : pool_) {
|
||||
if (pf.active) {
|
||||
@@ -87,7 +87,7 @@ int FloatingScoreManager::getActiveCount() const {
|
||||
return count;
|
||||
}
|
||||
|
||||
FloatingScore* FloatingScoreManager::findFreeSlot() {
|
||||
auto FloatingScoreManager::findFreeSlot() -> FloatingScore* {
|
||||
for (auto& pf : pool_) {
|
||||
if (!pf.active) {
|
||||
return &pf;
|
||||
|
||||
@@ -37,7 +37,7 @@ class FloatingScoreManager {
|
||||
void reset();
|
||||
|
||||
// Obtenir número active (debug)
|
||||
[[nodiscard]] int getActiveCount() const;
|
||||
[[nodiscard]] auto getActiveCount() const -> int;
|
||||
|
||||
private:
|
||||
Graphics::VectorText text_; // Sistema de text vectorial
|
||||
@@ -49,7 +49,7 @@ class FloatingScoreManager {
|
||||
std::array<FloatingScore, MAX_PUNTUACIONS> pool_;
|
||||
|
||||
// Trobar primer slot inactiu
|
||||
FloatingScore* findFreeSlot();
|
||||
auto findFreeSlot() -> FloatingScore*;
|
||||
};
|
||||
|
||||
} // namespace Effects
|
||||
|
||||
@@ -23,10 +23,8 @@ constexpr float BULLET_SPEED = 140.0F;
|
||||
} // namespace
|
||||
|
||||
Bullet::Bullet(Rendering::Renderer* renderer)
|
||||
: Entity(renderer),
|
||||
esta_(false),
|
||||
owner_id_(0),
|
||||
grace_timer_(0.0F) {
|
||||
: Entity(renderer)
|
||||
{
|
||||
// Brightness específico para balas
|
||||
brightness_ = Defaults::Brightness::BALA;
|
||||
|
||||
@@ -50,7 +48,7 @@ Bullet::Bullet(Rendering::Renderer* renderer)
|
||||
|
||||
void Bullet::init() {
|
||||
// Inicialment inactiva
|
||||
esta_ = false;
|
||||
is_active_ = false;
|
||||
center_ = {.x = 0.0F, .y = 0.0F};
|
||||
angle_ = 0.0F;
|
||||
grace_timer_ = 0.0F;
|
||||
@@ -65,7 +63,7 @@ void Bullet::init() {
|
||||
|
||||
void Bullet::disparar(const Vec2& position, float angle, uint8_t owner_id) {
|
||||
// Activar bullet
|
||||
esta_ = true;
|
||||
is_active_ = true;
|
||||
|
||||
// Almacenar propietario (0=P1, 1=P2)
|
||||
owner_id_ = owner_id;
|
||||
@@ -92,7 +90,7 @@ void Bullet::disparar(const Vec2& position, float angle, uint8_t owner_id) {
|
||||
}
|
||||
|
||||
void Bullet::update(float delta_time) {
|
||||
if (!esta_) {
|
||||
if (!is_active_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,7 +106,7 @@ void Bullet::update(float delta_time) {
|
||||
float max_x;
|
||||
float min_y;
|
||||
float max_y;
|
||||
Constants::obtenir_limits_zona_segurs(Defaults::Entities::BULLET_RADIUS,
|
||||
Constants::getSafePlayAreaBounds(Defaults::Entities::BULLET_RADIUS,
|
||||
min_x,
|
||||
max_x,
|
||||
min_y,
|
||||
@@ -127,16 +125,16 @@ void Bullet::postUpdate(float /*delta_time*/) {
|
||||
}
|
||||
|
||||
void Bullet::desactivar() {
|
||||
esta_ = false;
|
||||
is_active_ = false;
|
||||
// Detener el cuerpo físico para que no acumule deriva mientras inactiva.
|
||||
body_.velocity = Vec2{};
|
||||
body_.angular_velocity = 0.0F;
|
||||
}
|
||||
|
||||
void Bullet::draw() const {
|
||||
if (esta_ && shape_) {
|
||||
if (is_active_ && shape_) {
|
||||
// Les bales roten segons l'angle de trayectòria (estático tras disparo)
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, 1.0F, 1.0F, brightness_,
|
||||
Rendering::renderShape(renderer_, shape_, center_, angle_, 1.0F, 1.0F, brightness_,
|
||||
/*rotation_3d=*/nullptr, Defaults::Palette::BULLET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class Bullet : public Entities::Entity {
|
||||
public:
|
||||
Bullet()
|
||||
: Entity(nullptr) {}
|
||||
Bullet(Rendering::Renderer* renderer);
|
||||
explicit Bullet(Rendering::Renderer* renderer);
|
||||
|
||||
void init() override;
|
||||
void disparar(const Vec2& position, float angle, uint8_t owner_id);
|
||||
@@ -23,25 +23,26 @@ class Bullet : public Entities::Entity {
|
||||
void draw() const override;
|
||||
|
||||
// Override: Interfaz de Entity
|
||||
[[nodiscard]] auto isActive() const -> bool override { return esta_; }
|
||||
[[nodiscard]] auto isActive() const -> bool override { return is_active_; }
|
||||
|
||||
// Override: Interfaz de colisión (gameplay-level: PLAYAREA bounds-check)
|
||||
[[nodiscard]] auto getCollisionRadius() const -> float override {
|
||||
return Defaults::Entities::BULLET_RADIUS;
|
||||
}
|
||||
[[nodiscard]] auto isCollidable() const -> bool override {
|
||||
return esta_ && grace_timer_ <= 0.0F;
|
||||
return is_active_ && grace_timer_ <= 0.0F;
|
||||
}
|
||||
|
||||
// Getters (API pública sin cambios)
|
||||
[[nodiscard]] auto esta_activa() const -> bool { return esta_; }
|
||||
[[nodiscard]] auto getOwnerId() const -> uint8_t { return owner_id_; }
|
||||
[[nodiscard]] auto getGraceTimer() const -> float { return grace_timer_; }
|
||||
void desactivar();
|
||||
|
||||
private:
|
||||
// Miembros específicos de Bullet (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
|
||||
bool esta_;
|
||||
uint8_t owner_id_; // 0=P1, 1=P2
|
||||
float grace_timer_; // Grace period timer (0.0 = vulnerable)
|
||||
// Miembros específicos de Bullet (heredados: renderer_, shape_, center_, angle_, brightness_, body_).
|
||||
// Inicializados en la declaración para que tanto el ctor por defecto como el que toma renderer
|
||||
// dejen el objeto en estado coherente (proyectil inactivo, sin owner, sin grace timer).
|
||||
bool is_active_{false};
|
||||
uint8_t owner_id_{0}; // 0=P1, 1=P2
|
||||
float grace_timer_{0.0F}; // Grace period timer (0.0 = vulnerable)
|
||||
};
|
||||
|
||||
@@ -40,15 +40,9 @@ auto velocityToAngle(const Vec2& velocity) -> float {
|
||||
|
||||
Enemy::Enemy(Rendering::Renderer* renderer)
|
||||
: Entity(renderer),
|
||||
drotacio_(0.0F),
|
||||
rotacio_(0.0F),
|
||||
esta_(false),
|
||||
type_(EnemyType::PENTAGON),
|
||||
tracking_timer_(0.0F),
|
||||
ship_position_(nullptr),
|
||||
tracking_strength_(0.5F),
|
||||
direction_change_timer_(0.0F),
|
||||
timer_invulnerabilitat_(0.0F) {
|
||||
|
||||
tracking_strength_(0.5F)
|
||||
{
|
||||
brightness_ = Defaults::Brightness::ENEMIC;
|
||||
|
||||
// Configuración del cuerpo físico — defaults para enemy genérico.
|
||||
@@ -119,7 +113,7 @@ void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
float max_x;
|
||||
float min_y;
|
||||
float max_y;
|
||||
Constants::obtenir_limits_zona_segurs(Defaults::Entities::ENEMY_RADIUS, min_x, max_x, min_y, max_y);
|
||||
Constants::getSafePlayAreaBounds(Defaults::Entities::ENEMY_RADIUS, min_x, max_x, min_y, max_y);
|
||||
|
||||
if (ship_pos != nullptr) {
|
||||
bool found_safe_position = false;
|
||||
@@ -235,7 +229,7 @@ void Enemy::draw() const {
|
||||
case EnemyType::QUADRAT: color = Defaults::Palette::QUADRAT; break;
|
||||
case EnemyType::MOLINILLO: color = Defaults::Palette::MOLINILLO; break;
|
||||
}
|
||||
Rendering::render_shape(renderer_, shape_, center_, rotacio_, SCALE, 1.0F, brightness_,
|
||||
Rendering::renderShape(renderer_, shape_, center_, rotacio_, SCALE, 1.0F, brightness_,
|
||||
/*rotation_3d=*/nullptr, color);
|
||||
}
|
||||
|
||||
@@ -442,7 +436,7 @@ auto Enemy::attemptSafeSpawn(const Vec2& ship_pos, float& out_x, float& out_y) -
|
||||
float max_x;
|
||||
float min_y;
|
||||
float max_y;
|
||||
Constants::obtenir_limits_zona_segurs(Defaults::Entities::ENEMY_RADIUS, min_x, max_x, min_y, max_y);
|
||||
Constants::getSafePlayAreaBounds(Defaults::Entities::ENEMY_RADIUS, min_x, max_x, min_y, max_y);
|
||||
|
||||
const int RANGE_X = static_cast<int>(max_x - min_x);
|
||||
const int RANGE_Y = static_cast<int>(max_y - min_y);
|
||||
|
||||
@@ -37,7 +37,7 @@ class Enemy : public Entities::Entity {
|
||||
public:
|
||||
Enemy()
|
||||
: Entity(nullptr) {}
|
||||
Enemy(Rendering::Renderer* renderer);
|
||||
explicit Enemy(Rendering::Renderer* renderer);
|
||||
|
||||
void init() override { init(EnemyType::PENTAGON, nullptr); }
|
||||
void init(EnemyType type, const Vec2* ship_pos = nullptr);
|
||||
@@ -86,22 +86,24 @@ class Enemy : public Entities::Entity {
|
||||
[[nodiscard]] auto getInvulnerabilityTime() const -> float { return timer_invulnerabilitat_; }
|
||||
|
||||
private:
|
||||
// Miembros específicos (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
|
||||
float drotacio_; // Velocidad angular visual (rad/s) — solo decoración, separada de body_.angular_velocity
|
||||
float rotacio_; // Rotación visual acumulada (no afecta movimiento)
|
||||
bool esta_;
|
||||
// Miembros específicos (heredados: renderer_, shape_, center_, angle_, brightness_, body_).
|
||||
// Inicializados en la declaración: el ctor por defecto deja al enemy en estado "inactivo
|
||||
// como pentágono", coherente con lo que harán init() o el ctor con renderer al activarlo.
|
||||
float drotacio_{0.0F}; // Velocidad angular visual (rad/s) — solo decoración, separada de body_.angular_velocity
|
||||
float rotacio_{0.0F}; // Rotación visual acumulada (no afecta movimiento)
|
||||
bool esta_{false};
|
||||
|
||||
EnemyType type_;
|
||||
EnemyType type_{EnemyType::PENTAGON};
|
||||
EnemyAnimation animacio_;
|
||||
|
||||
// Comportamiento type-specific
|
||||
float tracking_timer_; // Quadrat: tiempo desde último update de dirección
|
||||
const Vec2* ship_position_; // Puntero a posición de la nave (para tracking)
|
||||
float tracking_strength_; // Quadrat: intensidad de tracking (0.0-1.5), default 0.5
|
||||
float direction_change_timer_; // Pentagon: tiempo para próximo cambio de dirección
|
||||
float tracking_timer_{0.0F}; // Quadrat: tiempo desde último update de dirección
|
||||
const Vec2* ship_position_{nullptr}; // Puntero a posición de la nave (para tracking)
|
||||
float tracking_strength_{0.0F}; // Quadrat: intensidad de tracking (0.0-1.5), default 0.5
|
||||
float direction_change_timer_{0.0F}; // Pentagon: tiempo para próximo cambio de dirección
|
||||
|
||||
// Invulnerabilidad post-spawn
|
||||
float timer_invulnerabilitat_;
|
||||
float timer_invulnerabilitat_{0.0F};
|
||||
|
||||
// Métodos privados
|
||||
void updateAnimation(float delta_time);
|
||||
@@ -111,7 +113,8 @@ class Enemy : public Entities::Entity {
|
||||
void behaviorQuadrat(float delta_time);
|
||||
void behaviorMolinillo(float delta_time);
|
||||
[[nodiscard]] auto computeCurrentScale() const -> float;
|
||||
auto attemptSafeSpawn(const Vec2& ship_pos, float& out_x, float& out_y) -> bool;
|
||||
// Estático: solo opera sobre ship_pos pasado; no consulta estado del enemy.
|
||||
static auto attemptSafeSpawn(const Vec2& ship_pos, float& out_x, float& out_y) -> bool;
|
||||
|
||||
// Helper: setear body_.velocity desde un ángulo y magnitud.
|
||||
// angle_movement=0 apunta hacia arriba (eje Y negativo SDL).
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
#include "game/constants.hpp"
|
||||
|
||||
Ship::Ship(Rendering::Renderer* renderer, const char* shape_file)
|
||||
: Entity(renderer),
|
||||
is_hit_(false),
|
||||
invulnerable_timer_(0.0F) {
|
||||
: Entity(renderer)
|
||||
{
|
||||
// Brightness específico para naves
|
||||
brightness_ = Defaults::Brightness::NAU;
|
||||
|
||||
@@ -47,7 +46,7 @@ void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) {
|
||||
} else {
|
||||
float centre_x;
|
||||
float centre_y;
|
||||
Constants::obtenir_centre_zona(centre_x, centre_y);
|
||||
Constants::getPlayAreaCenter(centre_x, centre_y);
|
||||
center_ = {.x = centre_x, .y = centre_y};
|
||||
}
|
||||
|
||||
@@ -159,6 +158,6 @@ void Ship::draw() const {
|
||||
const float VISUAL_PUSH = SPEED / 33.33F;
|
||||
const float SCALE = 1.0F + (VISUAL_PUSH / 12.0F);
|
||||
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, SCALE, 1.0F, brightness_,
|
||||
Rendering::renderShape(renderer_, shape_, center_, angle_, SCALE, 1.0F, brightness_,
|
||||
/*rotation_3d=*/nullptr, Defaults::Palette::SHIP);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class Ship : public Entities::Entity {
|
||||
public:
|
||||
Ship()
|
||||
: Entity(nullptr) {}
|
||||
Ship(Rendering::Renderer* renderer, const char* shape_file = "ship.shp");
|
||||
explicit Ship(Rendering::Renderer* renderer, const char* shape_file = "ship.shp");
|
||||
|
||||
void init() override { init(nullptr, false); }
|
||||
void init(const Vec2* spawn_point, bool activar_invulnerabilitat = false);
|
||||
@@ -56,7 +56,9 @@ class Ship : public Entities::Entity {
|
||||
}
|
||||
|
||||
private:
|
||||
// Miembros específicos de Ship (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
|
||||
bool is_hit_;
|
||||
float invulnerable_timer_; // 0.0f = vulnerable, >0.0f = invulnerable
|
||||
// Miembros específicos de Ship (heredados: renderer_, shape_, center_, angle_, brightness_, body_).
|
||||
// Inicializados en la declaración: el ctor por defecto deja la nave "viva y sin invulnerabilidad",
|
||||
// que es el estado coherente al que llevan tanto init() como el ctor con renderer.
|
||||
bool is_hit_{false};
|
||||
float invulnerable_timer_{0.0F}; // 0.0f = vulnerable, >0.0f = invulnerable
|
||||
};
|
||||
|
||||
+89
-167
@@ -224,119 +224,71 @@ void setConfigFile(const std::string& path) { config_file_path = path; }
|
||||
|
||||
// Funciones auxiliars per load seccions del YAML
|
||||
|
||||
// Lee un campo escalar del YAML aplicando un validador; si la clau no
|
||||
// existe, deja `dest` intacto; si la conversió o la validació fallen,
|
||||
// asigna `fallback`. Estàtic per quedar dins de la unitat de traducció.
|
||||
template <typename T, typename Validator>
|
||||
static void readField(const fkyaml::node& parent, const char* key, T& dest,
|
||||
T fallback, Validator&& validate) {
|
||||
if (!parent.contains(key)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
auto val = parent[key].template get_value<T>();
|
||||
dest = validate(val) ? val : fallback;
|
||||
} catch (...) {
|
||||
dest = fallback;
|
||||
}
|
||||
}
|
||||
|
||||
// Variant sin validador: només lectura amb fallback en cas d'error.
|
||||
template <typename T>
|
||||
static void readField(const fkyaml::node& parent, const char* key, T& dest, T fallback) {
|
||||
if (!parent.contains(key)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
dest = parent[key].template get_value<T>();
|
||||
} catch (...) {
|
||||
dest = fallback;
|
||||
}
|
||||
}
|
||||
|
||||
static void loadWindowConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (yaml.contains("window")) {
|
||||
const auto& win = yaml["window"];
|
||||
if (!yaml.contains("window")) {
|
||||
return;
|
||||
}
|
||||
const auto& win = yaml["window"];
|
||||
|
||||
if (win.contains("width")) {
|
||||
try {
|
||||
auto val = win["width"].get_value<int>();
|
||||
window.width = (val >= Defaults::Window::MIN_WIDTH)
|
||||
? val
|
||||
: Defaults::Window::WIDTH;
|
||||
} catch (...) {
|
||||
window.width = Defaults::Window::WIDTH;
|
||||
}
|
||||
}
|
||||
readField(win, "width", window.width, Defaults::Window::WIDTH,
|
||||
[](int v) { return v >= Defaults::Window::MIN_WIDTH; });
|
||||
readField(win, "height", window.height, Defaults::Window::HEIGHT,
|
||||
[](int v) { return v >= Defaults::Window::MIN_HEIGHT; });
|
||||
readField(win, "fullscreen", window.fullscreen, false);
|
||||
|
||||
if (win.contains("height")) {
|
||||
try {
|
||||
auto val = win["height"].get_value<int>();
|
||||
window.height = (val >= Defaults::Window::MIN_HEIGHT)
|
||||
? val
|
||||
: Defaults::Window::HEIGHT;
|
||||
} catch (...) {
|
||||
window.height = Defaults::Window::HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (win.contains("fullscreen")) {
|
||||
try {
|
||||
window.fullscreen = win["fullscreen"].get_value<bool>();
|
||||
} catch (...) {
|
||||
window.fullscreen = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (win.contains("zoom_factor")) {
|
||||
try {
|
||||
auto val = win["zoom_factor"].get_value<float>();
|
||||
window.zoom_factor = (val >= Defaults::Window::MIN_ZOOM && val <= 10.0F)
|
||||
? val
|
||||
: Defaults::Window::BASE_ZOOM;
|
||||
} catch (...) {
|
||||
window.zoom_factor = Defaults::Window::BASE_ZOOM;
|
||||
}
|
||||
} else {
|
||||
// Legacy config: infer zoom from width
|
||||
window.zoom_factor = static_cast<float>(window.width) / Defaults::Window::WIDTH;
|
||||
window.zoom_factor = std::max(Defaults::Window::MIN_ZOOM, window.zoom_factor);
|
||||
}
|
||||
if (win.contains("zoom_factor")) {
|
||||
readField(win, "zoom_factor", window.zoom_factor, Defaults::Window::BASE_ZOOM,
|
||||
[](float v) { return v >= Defaults::Window::MIN_ZOOM && v <= 10.0F; });
|
||||
} else {
|
||||
// Legacy config: infer zoom from width
|
||||
window.zoom_factor = static_cast<float>(window.width) / Defaults::Window::WIDTH;
|
||||
window.zoom_factor = std::max(Defaults::Window::MIN_ZOOM, window.zoom_factor);
|
||||
}
|
||||
}
|
||||
|
||||
static void loadPhysicsConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (yaml.contains("physics")) {
|
||||
const auto& phys = yaml["physics"];
|
||||
|
||||
if (phys.contains("rotation_speed")) {
|
||||
try {
|
||||
auto val = phys["rotation_speed"].get_value<float>();
|
||||
physics.rotation_speed =
|
||||
(val > 0) ? val : Defaults::Physics::ROTATION_SPEED;
|
||||
} catch (...) {
|
||||
physics.rotation_speed = Defaults::Physics::ROTATION_SPEED;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("acceleration")) {
|
||||
try {
|
||||
auto val = phys["acceleration"].get_value<float>();
|
||||
physics.acceleration =
|
||||
(val > 0) ? val : Defaults::Physics::ACCELERATION;
|
||||
} catch (...) {
|
||||
physics.acceleration = Defaults::Physics::ACCELERATION;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("max_velocity")) {
|
||||
try {
|
||||
auto val = phys["max_velocity"].get_value<float>();
|
||||
physics.max_velocity =
|
||||
(val > 0) ? val : Defaults::Physics::MAX_VELOCITY;
|
||||
} catch (...) {
|
||||
physics.max_velocity = Defaults::Physics::MAX_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("friction")) {
|
||||
try {
|
||||
auto val = phys["friction"].get_value<float>();
|
||||
physics.friction = (val > 0) ? val : Defaults::Physics::FRICTION;
|
||||
} catch (...) {
|
||||
physics.friction = Defaults::Physics::FRICTION;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("enemy_speed")) {
|
||||
try {
|
||||
auto val = phys["enemy_speed"].get_value<float>();
|
||||
physics.enemy_speed = (val > 0) ? val : Defaults::Physics::ENEMY_SPEED;
|
||||
} catch (...) {
|
||||
physics.enemy_speed = Defaults::Physics::ENEMY_SPEED;
|
||||
}
|
||||
}
|
||||
|
||||
if (phys.contains("bullet_speed")) {
|
||||
try {
|
||||
auto val = phys["bullet_speed"].get_value<float>();
|
||||
physics.bullet_speed =
|
||||
(val > 0) ? val : Defaults::Physics::BULLET_SPEED;
|
||||
} catch (...) {
|
||||
physics.bullet_speed = Defaults::Physics::BULLET_SPEED;
|
||||
}
|
||||
}
|
||||
if (!yaml.contains("physics")) {
|
||||
return;
|
||||
}
|
||||
const auto& phys = yaml["physics"];
|
||||
constexpr auto POSITIVE = [](float v) { return v > 0.0F; };
|
||||
|
||||
readField(phys, "rotation_speed", physics.rotation_speed, Defaults::Physics::ROTATION_SPEED, POSITIVE);
|
||||
readField(phys, "acceleration", physics.acceleration, Defaults::Physics::ACCELERATION, POSITIVE);
|
||||
readField(phys, "max_velocity", physics.max_velocity, Defaults::Physics::MAX_VELOCITY, POSITIVE);
|
||||
readField(phys, "friction", physics.friction, Defaults::Physics::FRICTION, POSITIVE);
|
||||
readField(phys, "enemy_speed", physics.enemy_speed, Defaults::Physics::ENEMY_SPEED, POSITIVE);
|
||||
readField(phys, "bullet_speed", physics.bullet_speed, Defaults::Physics::BULLET_SPEED, POSITIVE);
|
||||
}
|
||||
|
||||
static void loadGameplayConfigFromYaml(const fkyaml::node& yaml) {
|
||||
@@ -381,69 +333,39 @@ static void loadRenderingConfigFromYaml(const fkyaml::node& yaml) {
|
||||
}
|
||||
}
|
||||
|
||||
static void loadAudioConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (yaml.contains("audio")) {
|
||||
const auto& aud = yaml["audio"];
|
||||
|
||||
if (aud.contains("enabled")) {
|
||||
try {
|
||||
audio.enabled = aud["enabled"].get_value<bool>();
|
||||
} catch (...) {
|
||||
audio.enabled = Defaults::Audio::ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (aud.contains("volume")) {
|
||||
try {
|
||||
auto val = aud["volume"].get_value<float>();
|
||||
audio.volume = (val >= 0.0F && val <= 1.0F) ? val : Defaults::Audio::VOLUME;
|
||||
} catch (...) {
|
||||
audio.volume = Defaults::Audio::VOLUME;
|
||||
}
|
||||
}
|
||||
|
||||
if (aud.contains("music")) {
|
||||
const auto& mus = aud["music"];
|
||||
|
||||
if (mus.contains("enabled")) {
|
||||
try {
|
||||
audio.music.enabled = mus["enabled"].get_value<bool>();
|
||||
} catch (...) {
|
||||
audio.music.enabled = Defaults::Audio::MUSIC_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (mus.contains("volume")) {
|
||||
try {
|
||||
auto val = mus["volume"].get_value<float>();
|
||||
audio.music.volume = (val >= 0.0F && val <= 1.0F) ? val : Defaults::Audio::MUSIC_VOLUME;
|
||||
} catch (...) {
|
||||
audio.music.volume = Defaults::Audio::MUSIC_VOLUME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (aud.contains("sound")) {
|
||||
const auto& snd = aud["sound"];
|
||||
|
||||
if (snd.contains("enabled")) {
|
||||
try {
|
||||
audio.sound.enabled = snd["enabled"].get_value<bool>();
|
||||
} catch (...) {
|
||||
audio.sound.enabled = Defaults::Audio::SOUND_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
if (snd.contains("volume")) {
|
||||
try {
|
||||
auto val = snd["volume"].get_value<float>();
|
||||
audio.sound.volume = (val >= 0.0F && val <= 1.0F) ? val : Defaults::Audio::SOUND_VOLUME;
|
||||
} catch (...) {
|
||||
audio.sound.volume = Defaults::Audio::SOUND_VOLUME;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void loadAudioMusicSection(const fkyaml::node& aud) {
|
||||
if (!aud.contains("music")) {
|
||||
return;
|
||||
}
|
||||
const auto& mus = aud["music"];
|
||||
constexpr auto UNIT_RANGE = [](float v) { return v >= 0.0F && v <= 1.0F; };
|
||||
|
||||
readField(mus, "enabled", audio.music.enabled, Defaults::Audio::MUSIC_ENABLED);
|
||||
readField(mus, "volume", audio.music.volume, Defaults::Audio::MUSIC_VOLUME, UNIT_RANGE);
|
||||
}
|
||||
|
||||
static void loadAudioSoundSection(const fkyaml::node& aud) {
|
||||
if (!aud.contains("sound")) {
|
||||
return;
|
||||
}
|
||||
const auto& snd = aud["sound"];
|
||||
constexpr auto UNIT_RANGE = [](float v) { return v >= 0.0F && v <= 1.0F; };
|
||||
|
||||
readField(snd, "enabled", audio.sound.enabled, Defaults::Audio::SOUND_ENABLED);
|
||||
readField(snd, "volume", audio.sound.volume, Defaults::Audio::SOUND_VOLUME, UNIT_RANGE);
|
||||
}
|
||||
|
||||
static void loadAudioConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("audio")) {
|
||||
return;
|
||||
}
|
||||
const auto& aud = yaml["audio"];
|
||||
constexpr auto UNIT_RANGE = [](float v) { return v >= 0.0F && v <= 1.0F; };
|
||||
|
||||
readField(aud, "enabled", audio.enabled, Defaults::Audio::ENABLED);
|
||||
readField(aud, "volume", audio.volume, Defaults::Audio::VOLUME, UNIT_RANGE);
|
||||
loadAudioMusicSection(aud);
|
||||
loadAudioSoundSection(aud);
|
||||
}
|
||||
|
||||
// Carregar controls del player 1 desde YAML
|
||||
|
||||
+193
-228
@@ -8,13 +8,9 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/entities/entity.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/math/easing.hpp"
|
||||
#include "core/physics/collision.hpp"
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
#include "core/system/scene_context.hpp"
|
||||
#include "game/stage_system/stage_loader.hpp"
|
||||
@@ -32,8 +28,8 @@ GameScene::GameScene(SDLManager& sdl, SceneContext& context)
|
||||
context_(context),
|
||||
debris_manager_(sdl.getRenderer()),
|
||||
floating_score_manager_(sdl.getRenderer()),
|
||||
text_(sdl.getRenderer()),
|
||||
init_hud_rect_sound_played_(false) {
|
||||
text_(sdl.getRenderer())
|
||||
{
|
||||
// Recuperar configuración de match des del context
|
||||
match_config_ = context_.getMatchConfig();
|
||||
|
||||
@@ -122,7 +118,7 @@ void GameScene::init() {
|
||||
score_per_player_[1] = 0;
|
||||
floating_score_manager_.reset();
|
||||
|
||||
// DEPRECATED: spawn_position_ ya no s'usa, es calcula dinàmicament con obtenir_punt_spawn(player_id)
|
||||
// DEPRECATED: spawn_position_ ya no s'usa, es calcula dinàmicament con getSpawnPoint(player_id)
|
||||
// const SDL_FRect& zona = Defaults::Zones::PLAYAREA;
|
||||
// spawn_position_.x = zona.x + zona.w * 0.5f;
|
||||
// spawn_position_.y = zona.y + zona.h * Defaults::Game::INIT_HUD_SHIP_START_Y_RATIO;
|
||||
@@ -133,7 +129,7 @@ void GameScene::init() {
|
||||
|
||||
if (jugador_actiu) {
|
||||
// Jugador active: init normalment
|
||||
Vec2 spawn_pos = obtenir_punt_spawn(i);
|
||||
Vec2 spawn_pos = getSpawnPoint(i);
|
||||
ships_[i].init(&spawn_pos, false); // No invulnerability at start
|
||||
// Registrar el cuerpo físico de la nave en el mundo (Fase 6c)
|
||||
physics_world_.addBody(&ships_[i].getBody());
|
||||
@@ -213,17 +209,17 @@ void GameScene::stepShootingInput() {
|
||||
auto* input = Input::get();
|
||||
if (match_config_.jugador1_actiu &&
|
||||
input->checkActionPlayer1(InputAction::SHOOT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
disparar_bala(0);
|
||||
fireBullet(0);
|
||||
}
|
||||
if (match_config_.jugador2_actiu &&
|
||||
input->checkActionPlayer2(InputAction::SHOOT, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
disparar_bala(1);
|
||||
fireBullet(1);
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::stepMidGameJoin() {
|
||||
// Permitir join solo durante PLAYING.
|
||||
if (stage_manager_->get_estat() != StageSystem::EstatStage::PLAYING) {
|
||||
if (stage_manager_->getState() != StageSystem::EstatStage::PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -248,7 +244,7 @@ void GameScene::stepMidGameJoin() {
|
||||
? input->checkActionPlayer1(InputAction::START, Input::DO_NOT_ALLOW_REPEAT)
|
||||
: input->checkActionPlayer2(InputAction::START, Input::DO_NOT_ALLOW_REPEAT);
|
||||
if (START_PRESSED) {
|
||||
unir_jugador(pid);
|
||||
joinPlayer(pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,7 +265,7 @@ auto GameScene::stepContinueScreen(float delta_time) -> bool {
|
||||
.hit_timer_per_player = hit_timer_per_player_,
|
||||
.ships = ships_,
|
||||
.match_config = match_config_,
|
||||
.get_spawn_point = [this](uint8_t pid) { return obtenir_punt_spawn(pid); },
|
||||
.get_spawn_point = [this](uint8_t pid) { return getSpawnPoint(pid); },
|
||||
};
|
||||
Systems::ContinueScreen::update(cont_ctx, delta_time);
|
||||
Systems::ContinueScreen::processInput(cont_ctx);
|
||||
@@ -310,7 +306,7 @@ auto GameScene::stepGameOver(float delta_time) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto GameScene::stepDeathSequence(float delta_time) -> bool {
|
||||
void GameScene::stepDeathSequence(float delta_time) {
|
||||
bool algun_mort = false;
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
if (hit_timer_per_player_[i] <= 0.0F || hit_timer_per_player_[i] >= 999.0F) {
|
||||
@@ -326,7 +322,7 @@ auto GameScene::stepDeathSequence(float delta_time) -> bool {
|
||||
// *** PHASE 3: RESPAWN OR GAME OVER ***
|
||||
lives_per_player_[i]--;
|
||||
if (lives_per_player_[i] > 0) {
|
||||
Vec2 spawn_pos = obtenir_punt_spawn(i);
|
||||
Vec2 spawn_pos = getSpawnPoint(i);
|
||||
ships_[i].init(&spawn_pos, /*activar_invulnerabilitat=*/true);
|
||||
hit_timer_per_player_[i] = 0.0F;
|
||||
continue;
|
||||
@@ -355,11 +351,13 @@ auto GameScene::stepDeathSequence(float delta_time) -> bool {
|
||||
debris_manager_.update(delta_time);
|
||||
floating_score_manager_.update(delta_time);
|
||||
}
|
||||
return algun_mort;
|
||||
// El bool 'algun_mort' es puramente interno: no aporta nada al caller
|
||||
// (la stage state machine sigue corriendo aunque haya jugadores muriendo),
|
||||
// así que la función no devuelve nada.
|
||||
}
|
||||
|
||||
void GameScene::stepStageStateMachine(float delta_time) {
|
||||
const StageSystem::EstatStage STATE = stage_manager_->get_estat();
|
||||
const StageSystem::EstatStage STATE = stage_manager_->getState();
|
||||
switch (STATE) {
|
||||
case StageSystem::EstatStage::INIT_HUD:
|
||||
runStageInitHud(delta_time);
|
||||
@@ -380,11 +378,11 @@ void GameScene::runStageInitHud(float delta_time) {
|
||||
// Update stage manager timer (puede cambiar el state).
|
||||
stage_manager_->update(delta_time);
|
||||
// Si el state cambió, salir para no usar el timer del nuevo state.
|
||||
if (stage_manager_->get_estat() != StageSystem::EstatStage::INIT_HUD) {
|
||||
if (stage_manager_->getState() != StageSystem::EstatStage::INIT_HUD) {
|
||||
return;
|
||||
}
|
||||
|
||||
float global_progress = 1.0F - (stage_manager_->get_timer_transicio() / Defaults::Game::INIT_HUD_DURATION);
|
||||
float global_progress = 1.0F - (stage_manager_->getTransitionTimer() / Defaults::Game::INIT_HUD_DURATION);
|
||||
global_progress = std::min(1.0F, global_progress);
|
||||
|
||||
const float SHIP1_P = Systems::InitHud::computeRangeProgress(
|
||||
@@ -397,10 +395,10 @@ void GameScene::runStageInitHud(float delta_time) {
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_END);
|
||||
|
||||
if (match_config_.jugador1_actiu && SHIP1_P < 1.0F) {
|
||||
ships_[0].setCenter(Systems::InitHud::computeShipPosition(SHIP1_P, obtenir_punt_spawn(0)));
|
||||
ships_[0].setCenter(Systems::InitHud::computeShipPosition(SHIP1_P, getSpawnPoint(0)));
|
||||
}
|
||||
if (match_config_.jugador2_actiu && SHIP2_P < 1.0F) {
|
||||
ships_[1].setCenter(Systems::InitHud::computeShipPosition(SHIP2_P, obtenir_punt_spawn(1)));
|
||||
ships_[1].setCenter(Systems::InitHud::computeShipPosition(SHIP2_P, getSpawnPoint(1)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,8 +425,8 @@ void GameScene::runStagePlaying(float delta_time) {
|
||||
|
||||
// Stage completado: cuando al menos un jugador está vivo y todos los enemies muertos.
|
||||
const bool ALGU_VIU = (hit_timer_per_player_[0] == 0.0F || hit_timer_per_player_[1] == 0.0F);
|
||||
if (ALGU_VIU && stage_manager_->getSpawnController().tots_enemics_destruits(enemies_)) {
|
||||
stage_manager_->stage_completat();
|
||||
if (ALGU_VIU && stage_manager_->getSpawnController().allEnemiesDestroyed(enemies_)) {
|
||||
stage_manager_->markStageCompleted();
|
||||
Audio::get()->playSound(Defaults::Sound::GOOD_JOB_COMMANDER, Audio::Group::GAME);
|
||||
return;
|
||||
}
|
||||
@@ -486,192 +484,159 @@ void GameScene::runCollisionDetections() {
|
||||
}
|
||||
|
||||
void GameScene::draw() {
|
||||
// Handle CONTINUE screen
|
||||
if (game_over_state_ == GameOverState::CONTINUE) {
|
||||
// Draw game background elements first
|
||||
dibuixar_marges();
|
||||
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
dibuixar_marcador();
|
||||
|
||||
// Draw CONTINUE screen overlay
|
||||
dibuixar_continue();
|
||||
drawContinueState();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle final GAME OVER state
|
||||
if (game_over_state_ == GameOverState::GAME_OVER) {
|
||||
// Game over: draw enemies, bullets, debris, and "GAME OVER" text
|
||||
dibuixar_marges();
|
||||
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
// Draw centered "GAME OVER" text
|
||||
const std::string game_over_text = "GAME OVER";
|
||||
constexpr float scale = Defaults::Game::GameOverScreen::TEXT_SCALE;
|
||||
constexpr float spacing = Defaults::Game::GameOverScreen::TEXT_SPACING;
|
||||
|
||||
// Calcular centro de l'àrea de juego usant constants
|
||||
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
|
||||
float centre_x = play_area.x + (play_area.w / 2.0F);
|
||||
float centre_y = play_area.y + (play_area.h / 2.0F);
|
||||
|
||||
text_.renderCentered(game_over_text, {.x = centre_x, .y = centre_y}, scale, spacing);
|
||||
|
||||
dibuixar_marcador();
|
||||
drawGameOverState();
|
||||
return;
|
||||
}
|
||||
|
||||
// [NEW] Stage state rendering
|
||||
StageSystem::EstatStage state = stage_manager_->get_estat();
|
||||
|
||||
switch (state) {
|
||||
case StageSystem::EstatStage::INIT_HUD: {
|
||||
// Calcular progrés de cada animación independent
|
||||
float timer = stage_manager_->get_timer_transicio();
|
||||
float total_time = Defaults::Game::INIT_HUD_DURATION;
|
||||
float global_progress = 1.0F - (timer / total_time);
|
||||
|
||||
// [NEW] Calcular progress independiente para cada elemento
|
||||
float rect_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_END);
|
||||
|
||||
float score_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_END);
|
||||
|
||||
float ship1_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_END);
|
||||
|
||||
float ship2_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_END);
|
||||
|
||||
// Dibuixar elements animats
|
||||
if (rect_progress > 0.0F) {
|
||||
// [NOU] Reproduir so cuando comença l'animación del rectangle
|
||||
if (!init_hud_rect_sound_played_) {
|
||||
Audio::get()->playSound(Defaults::Sound::INIT_HUD, Audio::Group::GAME);
|
||||
init_hud_rect_sound_played_ = true;
|
||||
}
|
||||
|
||||
Systems::InitHud::drawBordersAnimated(sdl_.getRenderer(), rect_progress);
|
||||
}
|
||||
|
||||
if (score_progress > 0.0F) {
|
||||
Systems::InitHud::drawScoreboardAnimated(text_, buildScoreboard(), score_progress);
|
||||
}
|
||||
|
||||
// [MODIFICAT] Dibuixar naves con progress independent
|
||||
if (ship1_progress > 0.0F && match_config_.jugador1_actiu && !ships_[0].isHit()) {
|
||||
ships_[0].draw();
|
||||
}
|
||||
|
||||
if (ship2_progress > 0.0F && match_config_.jugador2_actiu && !ships_[1].isHit()) {
|
||||
ships_[1].draw();
|
||||
}
|
||||
|
||||
switch (stage_manager_->getState()) {
|
||||
case StageSystem::EstatStage::INIT_HUD:
|
||||
drawInitHudState();
|
||||
break;
|
||||
}
|
||||
|
||||
case StageSystem::EstatStage::LEVEL_START:
|
||||
dibuixar_marges();
|
||||
// [NEW] Draw both ships if active and alive
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Draw bullets
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
// [NEW] Draw debris
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
// [EXISTING] Draw intro message and score
|
||||
dibuixar_missatge_stage(stage_manager_->get_missatge_level_start());
|
||||
dibuixar_marcador();
|
||||
drawLevelStartState();
|
||||
break;
|
||||
|
||||
case StageSystem::EstatStage::PLAYING:
|
||||
dibuixar_marges();
|
||||
|
||||
// [EXISTING] Normal rendering - active ships
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
dibuixar_marcador();
|
||||
drawPlayingState();
|
||||
break;
|
||||
|
||||
case StageSystem::EstatStage::LEVEL_COMPLETED:
|
||||
dibuixar_marges();
|
||||
// [NEW] Draw both ships if active and alive
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Draw bullets (allow last shots to be visible)
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
// [NEW] Draw debris (from last destroyed enemies)
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
// [EXISTING] Draw completion message and score
|
||||
dibuixar_missatge_stage(StageSystem::Constants::MISSATGE_LEVEL_COMPLETED);
|
||||
dibuixar_marcador();
|
||||
drawLevelCompletedState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawEnemies() const {
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawBullets() const {
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawActiveShipsAlive() const {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawContinueState() {
|
||||
drawMargins();
|
||||
drawEnemies();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawScoreboard();
|
||||
drawContinue();
|
||||
}
|
||||
|
||||
void GameScene::drawGameOverState() {
|
||||
drawMargins();
|
||||
drawEnemies();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
const std::string GAME_OVER_TEXT = "GAME OVER";
|
||||
constexpr float SCALE = Defaults::Game::GameOverScreen::TEXT_SCALE;
|
||||
constexpr float SPACING = Defaults::Game::GameOverScreen::TEXT_SPACING;
|
||||
|
||||
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
|
||||
float centre_x = play_area.x + (play_area.w / 2.0F);
|
||||
float centre_y = play_area.y + (play_area.h / 2.0F);
|
||||
|
||||
text_.renderCentered(GAME_OVER_TEXT, {.x = centre_x, .y = centre_y}, SCALE, SPACING);
|
||||
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::drawInitHudState() {
|
||||
float timer = stage_manager_->getTransitionTimer();
|
||||
float total_time = Defaults::Game::INIT_HUD_DURATION;
|
||||
float global_progress = 1.0F - (timer / total_time);
|
||||
|
||||
float rect_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_END);
|
||||
|
||||
float score_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_END);
|
||||
|
||||
float ship1_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_END);
|
||||
|
||||
float ship2_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_END);
|
||||
|
||||
if (rect_progress > 0.0F) {
|
||||
if (!init_hud_rect_sound_played_) {
|
||||
Audio::get()->playSound(Defaults::Sound::INIT_HUD, Audio::Group::GAME);
|
||||
init_hud_rect_sound_played_ = true;
|
||||
}
|
||||
Systems::InitHud::drawBordersAnimated(sdl_.getRenderer(), rect_progress);
|
||||
}
|
||||
|
||||
if (score_progress > 0.0F) {
|
||||
Systems::InitHud::drawScoreboardAnimated(text_, buildScoreboard(), score_progress);
|
||||
}
|
||||
|
||||
if (ship1_progress > 0.0F && match_config_.jugador1_actiu && !ships_[0].isHit()) {
|
||||
ships_[0].draw();
|
||||
}
|
||||
|
||||
if (ship2_progress > 0.0F && match_config_.jugador2_actiu && !ships_[1].isHit()) {
|
||||
ships_[1].draw();
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawLevelStartState() {
|
||||
drawMargins();
|
||||
drawActiveShipsAlive();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawStageMessage(stage_manager_->getLevelStartMessage());
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::drawPlayingState() {
|
||||
drawMargins();
|
||||
drawActiveShipsAlive();
|
||||
drawEnemies();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::drawLevelCompletedState() {
|
||||
drawMargins();
|
||||
drawActiveShipsAlive();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawStageMessage(StageSystem::Constants::MISSATGE_LEVEL_COMPLETED);
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::tocado(uint8_t player_id) {
|
||||
// Death sequence: 3 phases
|
||||
// Phase 1: First call (hit_timer_per_player_[player_id] == 0) - trigger explosion
|
||||
@@ -712,7 +677,7 @@ void GameScene::tocado(uint8_t player_id) {
|
||||
// Phase 3 is handled in update() when hit_timer_per_player_ >= DEATH_DURATION
|
||||
}
|
||||
|
||||
void GameScene::dibuixar_marges() const {
|
||||
void GameScene::drawMargins() const {
|
||||
// Dibuixar rectangle de la zona de juego
|
||||
const SDL_FRect& zona = Defaults::Zones::PLAYAREA;
|
||||
|
||||
@@ -729,24 +694,24 @@ void GameScene::dibuixar_marges() const {
|
||||
Rendering::linea(sdl_.getRenderer(), x2, y1, x2, y2); // Right
|
||||
}
|
||||
|
||||
void GameScene::dibuixar_marcador() {
|
||||
void GameScene::drawScoreboard() {
|
||||
// Construir text del marcador
|
||||
std::string text = buildScoreboard();
|
||||
|
||||
// Parámetros de renderització
|
||||
const float scale = 0.85F;
|
||||
const float spacing = 0.0F;
|
||||
const float SCALE = 0.85F;
|
||||
const float SPACING = 0.0F;
|
||||
|
||||
// Calcular centro de la zona del marcador
|
||||
const SDL_FRect& scoreboard = Defaults::Zones::SCOREBOARD;
|
||||
float centre_x = scoreboard.w / 2.0F;
|
||||
float centre_y = scoreboard.y + (scoreboard.h / 2.0F);
|
||||
const SDL_FRect& scoreboard_zone = Defaults::Zones::SCOREBOARD;
|
||||
float centre_x = scoreboard_zone.w / 2.0F;
|
||||
float centre_y = scoreboard_zone.y + (scoreboard_zone.h / 2.0F);
|
||||
|
||||
// Renderizar centrat
|
||||
text_.renderCentered(text, {.x = centre_x, .y = centre_y}, scale, spacing);
|
||||
text_.renderCentered(text, {.x = centre_x, .y = centre_y}, SCALE, SPACING);
|
||||
}
|
||||
|
||||
std::string GameScene::buildScoreboard() const {
|
||||
auto GameScene::buildScoreboard() const -> std::string {
|
||||
// Puntuación P1 (6 dígits) - mostrar zeros si inactiu
|
||||
std::string score_p1;
|
||||
std::string vides_p1;
|
||||
@@ -762,7 +727,7 @@ std::string GameScene::buildScoreboard() const {
|
||||
}
|
||||
|
||||
// Nivel (2 dígits)
|
||||
uint8_t stage_num = stage_manager_->get_stage_actual();
|
||||
uint8_t stage_num = stage_manager_->getCurrentStage();
|
||||
std::string stage_str = (stage_num < 10) ? "0" + std::to_string(stage_num)
|
||||
: std::to_string(stage_num);
|
||||
|
||||
@@ -787,19 +752,19 @@ std::string GameScene::buildScoreboard() const {
|
||||
|
||||
// [NEW] Stage system helper methods
|
||||
|
||||
void GameScene::dibuixar_missatge_stage(const std::string& message) {
|
||||
constexpr float escala_base = 1.0F;
|
||||
constexpr float spacing = 2.0F;
|
||||
void GameScene::drawStageMessage(const std::string& message) {
|
||||
constexpr float BASE_SCALE = 1.0F;
|
||||
constexpr float SPACING = 2.0F;
|
||||
|
||||
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
|
||||
const float max_width = play_area.w * Defaults::Game::STAGE_MESSAGE_MAX_WIDTH_RATIO;
|
||||
const float MAX_WIDTH = play_area.w * Defaults::Game::STAGE_MESSAGE_MAX_WIDTH_RATIO;
|
||||
|
||||
// ========== TYPEWRITER EFFECT (PARAMETRIZED) ==========
|
||||
// Get state-specific timing configuration
|
||||
float total_time;
|
||||
float typing_ratio;
|
||||
|
||||
if (stage_manager_->get_estat() == StageSystem::EstatStage::LEVEL_START) {
|
||||
if (stage_manager_->getState() == StageSystem::EstatStage::LEVEL_START) {
|
||||
total_time = Defaults::Game::LEVEL_START_DURATION;
|
||||
typing_ratio = Defaults::Game::LEVEL_START_TYPING_RATIO;
|
||||
} else { // LEVEL_COMPLETED
|
||||
@@ -808,7 +773,7 @@ void GameScene::dibuixar_missatge_stage(const std::string& message) {
|
||||
}
|
||||
|
||||
// Calculate progress from timer (0.0 at start → 1.0 at end)
|
||||
float remaining_time = stage_manager_->get_timer_transicio();
|
||||
float remaining_time = stage_manager_->getTransitionTimer();
|
||||
float progress = 1.0F - (remaining_time / total_time);
|
||||
|
||||
// Determine how many characters to show
|
||||
@@ -832,16 +797,16 @@ void GameScene::dibuixar_missatge_stage(const std::string& message) {
|
||||
// ===================================================
|
||||
|
||||
// Calculate text width at base scale (using FULL message for position calculation)
|
||||
float text_width_at_base = text_.get_text_width(message, escala_base, spacing);
|
||||
float text_width_at_base = Graphics::VectorText::getTextWidth(message, BASE_SCALE, SPACING);
|
||||
|
||||
// Auto-scale if text exceeds max width
|
||||
float scale = (text_width_at_base <= max_width)
|
||||
? escala_base
|
||||
: max_width / text_width_at_base;
|
||||
float scale = (text_width_at_base <= MAX_WIDTH)
|
||||
? BASE_SCALE
|
||||
: MAX_WIDTH / text_width_at_base;
|
||||
|
||||
// Recalculate dimensions with final scale (using FULL message for centering)
|
||||
float full_text_width = text_.get_text_width(message, scale, spacing);
|
||||
float text_height = text_.get_text_height(scale);
|
||||
float full_text_width = Graphics::VectorText::getTextWidth(message, scale, SPACING);
|
||||
float text_height = Graphics::VectorText::getTextHeight(scale);
|
||||
|
||||
// Calculate position as if FULL text was there (for fixed position typewriter)
|
||||
float x = play_area.x + ((play_area.w - full_text_width) / 2.0F);
|
||||
@@ -849,18 +814,18 @@ void GameScene::dibuixar_missatge_stage(const std::string& message) {
|
||||
|
||||
// Render only the partial message (typewriter effect)
|
||||
Vec2 pos = {.x = x, .y = y};
|
||||
text_.render(partial_message, pos, scale, spacing);
|
||||
text_.render(partial_message, pos, scale, SPACING);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// Helper methods for 2-player support
|
||||
// ========================================
|
||||
|
||||
Vec2 GameScene::obtenir_punt_spawn(uint8_t player_id) const {
|
||||
auto GameScene::getSpawnPoint(uint8_t player_id) const -> Vec2 {
|
||||
const SDL_FRect& zona = Defaults::Zones::PLAYAREA;
|
||||
|
||||
float x_ratio;
|
||||
if (match_config_.es_un_jugador()) {
|
||||
if (match_config_.isSinglePlayer()) {
|
||||
// Un sol player: spawn al centro (50%)
|
||||
x_ratio = 0.5F;
|
||||
} else {
|
||||
@@ -875,7 +840,7 @@ Vec2 GameScene::obtenir_punt_spawn(uint8_t player_id) const {
|
||||
.y = zona.y + (zona.h * Defaults::Game::SPAWN_Y_RATIO)};
|
||||
}
|
||||
|
||||
void GameScene::disparar_bala(uint8_t player_id) {
|
||||
void GameScene::fireBullet(uint8_t player_id) {
|
||||
// Verificar que el player está vivo
|
||||
if (hit_timer_per_player_[player_id] > 0.0F) {
|
||||
return;
|
||||
@@ -899,49 +864,49 @@ void GameScene::disparar_bala(uint8_t player_id) {
|
||||
// Buscar primera bullet inactiva en el pool del player
|
||||
int start_idx = player_id * 3; // P1=[0,1,2], P2=[3,4,5]
|
||||
for (int i = start_idx; i < start_idx + 3; i++) {
|
||||
if (!bullets_[i].esta_activa()) {
|
||||
if (!bullets_[i].isActive()) {
|
||||
bullets_[i].disparar(posicio_dispar, ship_angle, player_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::dibuixar_continue() {
|
||||
void GameScene::drawContinue() {
|
||||
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
|
||||
constexpr float spacing = 4.0F;
|
||||
constexpr float SPACING = 4.0F;
|
||||
|
||||
// "CONTINUE" text (using constants)
|
||||
const std::string continue_text = "CONTINUE";
|
||||
const std::string CONTINUE_TEXT = "CONTINUE";
|
||||
float escala_continue = Defaults::Game::ContinueScreen::CONTINUE_TEXT_SCALE;
|
||||
float y_ratio_continue = Defaults::Game::ContinueScreen::CONTINUE_TEXT_Y_RATIO;
|
||||
|
||||
float centre_x = play_area.x + (play_area.w / 2.0F);
|
||||
float centre_y_continue = play_area.y + (play_area.h * y_ratio_continue);
|
||||
|
||||
text_.renderCentered(continue_text, {.x = centre_x, .y = centre_y_continue}, escala_continue, spacing);
|
||||
text_.renderCentered(CONTINUE_TEXT, {.x = centre_x, .y = centre_y_continue}, escala_continue, SPACING);
|
||||
|
||||
// Countdown number (using constants)
|
||||
const std::string counter_str = std::to_string(continue_counter_);
|
||||
const std::string COUNTER_STR = std::to_string(continue_counter_);
|
||||
float escala_counter = Defaults::Game::ContinueScreen::COUNTER_TEXT_SCALE;
|
||||
float y_ratio_counter = Defaults::Game::ContinueScreen::COUNTER_TEXT_Y_RATIO;
|
||||
|
||||
float centre_y_counter = play_area.y + (play_area.h * y_ratio_counter);
|
||||
|
||||
text_.renderCentered(counter_str, {.x = centre_x, .y = centre_y_counter}, escala_counter, spacing);
|
||||
text_.renderCentered(COUNTER_STR, {.x = centre_x, .y = centre_y_counter}, escala_counter, SPACING);
|
||||
|
||||
// "CONTINUES LEFT" (conditional + using constants)
|
||||
if (!Defaults::Game::INFINITE_CONTINUES) {
|
||||
const std::string continues_text = "CONTINUES LEFT: " + std::to_string(Defaults::Game::MAX_CONTINUES - continues_used_);
|
||||
const std::string CONTINUES_TEXT = "CONTINUES LEFT: " + std::to_string(Defaults::Game::MAX_CONTINUES - continues_used_);
|
||||
float escala_info = Defaults::Game::ContinueScreen::INFO_TEXT_SCALE;
|
||||
float y_ratio_info = Defaults::Game::ContinueScreen::INFO_TEXT_Y_RATIO;
|
||||
|
||||
float centre_y_info = play_area.y + (play_area.h * y_ratio_info);
|
||||
|
||||
text_.renderCentered(continues_text, {.x = centre_x, .y = centre_y_info}, escala_info, spacing);
|
||||
text_.renderCentered(CONTINUES_TEXT, {.x = centre_x, .y = centre_y_info}, escala_info, SPACING);
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::unir_jugador(uint8_t player_id) {
|
||||
void GameScene::joinPlayer(uint8_t player_id) {
|
||||
// Activate player
|
||||
if (player_id == 0) {
|
||||
match_config_.jugador1_actiu = true;
|
||||
@@ -955,7 +920,7 @@ void GameScene::unir_jugador(uint8_t player_id) {
|
||||
hit_timer_per_player_[player_id] = 0.0F;
|
||||
|
||||
// Spawn with invulnerability
|
||||
Vec2 spawn_pos = obtenir_punt_spawn(player_id);
|
||||
Vec2 spawn_pos = getSpawnPoint(player_id);
|
||||
ships_[player_id].init(&spawn_pos, true);
|
||||
|
||||
// No visual message, just spawn (per user requirement)
|
||||
|
||||
@@ -61,7 +61,9 @@ class GameScene final : public Scene {
|
||||
// Estat del juego
|
||||
std::array<Ship, 2> ships_; // [0]=P1, [1]=P2
|
||||
std::array<Enemy, Constants::MAX_ORNIS> enemies_;
|
||||
std::array<Bullet, Constants::MAX_BALES * 2> bullets_; // 6 balas: P1=[0,1,2], P2=[3,4,5]
|
||||
// 6 balas: P1=[0,1,2], P2=[3,4,5]. El cast a size_t evita la
|
||||
// widening conversion implícita que detecta clang-tidy.
|
||||
std::array<Bullet, static_cast<std::size_t>(Constants::MAX_BALES) * 2> bullets_;
|
||||
std::array<float, 2> hit_timer_per_player_; // Death timers per player (seconds)
|
||||
|
||||
// Lives and game over system
|
||||
@@ -82,24 +84,36 @@ class GameScene final : public Scene {
|
||||
std::unique_ptr<StageSystem::StageManager> stage_manager_;
|
||||
|
||||
// Control de sons de animación INIT_HUD
|
||||
bool init_hud_rect_sound_played_; // Flag para evitar repetir sonido del rectángulo
|
||||
bool init_hud_rect_sound_played_{false}; // Flag para evitar repetir sonido del rectángulo
|
||||
|
||||
// Funciones privades
|
||||
void tocado(uint8_t player_id);
|
||||
void dibuixar_marges() const; // Dibuixar vores de la zona de juego
|
||||
void dibuixar_marcador(); // Dibuixar marcador de puntuación
|
||||
void disparar_bala(uint8_t player_id); // Shoot bullet from player
|
||||
[[nodiscard]] Vec2 obtenir_punt_spawn(uint8_t player_id) const; // Get spawn position for player
|
||||
void drawMargins() const; // Dibuixar vores de la zona de juego
|
||||
void drawScoreboard(); // Dibuixar marcador de puntuación
|
||||
void fireBullet(uint8_t player_id); // Shoot bullet from player
|
||||
[[nodiscard]] auto getSpawnPoint(uint8_t player_id) const -> Vec2; // Get spawn position for player
|
||||
|
||||
// [NEW] Continue & Join system
|
||||
void unir_jugador(uint8_t player_id); // Join inactive player mid-game
|
||||
void dibuixar_continue(); // Draw continue screen
|
||||
void joinPlayer(uint8_t player_id); // Join inactive player mid-game
|
||||
void drawContinue(); // Draw continue screen
|
||||
|
||||
// [NEW] Stage system helpers
|
||||
void dibuixar_missatge_stage(const std::string& message);
|
||||
void drawStageMessage(const std::string& message);
|
||||
|
||||
// Helpers de renderitzat (extracció de draw() per reduir complexitat).
|
||||
// Cadascun gestiona un bloc concret; draw() només despatxa segons l'estat.
|
||||
void drawEnemies() const;
|
||||
void drawBullets() const;
|
||||
void drawActiveShipsAlive() const;
|
||||
void drawContinueState();
|
||||
void drawGameOverState();
|
||||
void drawInitHudState();
|
||||
void drawLevelStartState();
|
||||
void drawPlayingState();
|
||||
void drawLevelCompletedState();
|
||||
|
||||
// [NEW] Función helper del marcador
|
||||
[[nodiscard]] std::string buildScoreboard() const;
|
||||
[[nodiscard]] auto buildScoreboard() const -> std::string;
|
||||
|
||||
// Sub-pasos de update() (descompuestos en Fase 9d para reducir
|
||||
// complejidad cognitiva; cada uno es responsable de una sección).
|
||||
@@ -109,10 +123,10 @@ class GameScene final : public Scene {
|
||||
// Devuelven true si el frame debe salir tras esta sección.
|
||||
[[nodiscard]] auto stepContinueScreen(float delta_time) -> bool;
|
||||
[[nodiscard]] auto stepGameOver(float delta_time) -> bool;
|
||||
// Avanza el death timer / respawn / transition a CONTINUE. Devuelve
|
||||
// true si algun jugador está en secuencia de muerte (para que el
|
||||
// caller actualice efectos sin gameplay).
|
||||
[[nodiscard]] auto stepDeathSequence(float delta_time) -> bool;
|
||||
// Avanza el death timer / respawn / transición a CONTINUE. Si algún
|
||||
// jugador está en secuencia de muerte, también actualiza efectos
|
||||
// (enemigos, balas, debris) que siguen vivos en el escenario.
|
||||
void stepDeathSequence(float delta_time);
|
||||
void stepStageStateMachine(float delta_time);
|
||||
void runStageInitHud(float delta_time);
|
||||
void runStageLevelStart(float delta_time);
|
||||
|
||||
@@ -22,7 +22,7 @@ using Option = SceneContext::Option;
|
||||
|
||||
// Helper: calcular el progrés individual de una lletra
|
||||
// en función del progrés global (efecte seqüencial)
|
||||
static float calcular_progress_letra(size_t letra_index, size_t num_letras, float global_progress, float threshold) {
|
||||
static auto computeLetterProgress(size_t letra_index, size_t num_letras, float global_progress, float threshold) -> float {
|
||||
if (num_letras == 0) {
|
||||
return 1.0F;
|
||||
}
|
||||
@@ -46,11 +46,9 @@ static float calcular_progress_letra(size_t letra_index, size_t num_letras, floa
|
||||
LogoScene::LogoScene(SDLManager& sdl, SceneContext& context)
|
||||
: sdl_(sdl),
|
||||
context_(context),
|
||||
estat_actual_(AnimationState::PRE_ANIMATION),
|
||||
temps_estat_actual_(0.0F),
|
||||
debris_manager_(std::make_unique<Effects::DebrisManager>(sdl.getRenderer())),
|
||||
lletra_explosio_index_(0),
|
||||
temps_des_ultima_explosio_(0.0F) {
|
||||
|
||||
debris_manager_(std::make_unique<Effects::DebrisManager>(sdl.getRenderer()))
|
||||
{
|
||||
std::cout << "SceneType Logo: Inicialitzant...\n";
|
||||
|
||||
// Consumir opciones (LOGO no processa opciones actualment)
|
||||
@@ -58,7 +56,7 @@ LogoScene::LogoScene(SDLManager& sdl, SceneContext& context)
|
||||
(void)option; // Suprimir warning
|
||||
|
||||
so_reproduit_.fill(false); // Inicialitzar seguiment de sons
|
||||
inicialitzar_lletres();
|
||||
initLetters();
|
||||
}
|
||||
|
||||
LogoScene::~LogoScene() {
|
||||
@@ -77,7 +75,7 @@ void LogoScene::handleEvent(const SDL_Event& event) {
|
||||
(void)event;
|
||||
}
|
||||
|
||||
void LogoScene::inicialitzar_lletres() {
|
||||
void LogoScene::initLetters() {
|
||||
using namespace Graphics;
|
||||
|
||||
// Llista de archivos .shp (A repetida para las dues A's)
|
||||
@@ -106,7 +104,7 @@ void LogoScene::inicialitzar_lletres() {
|
||||
float min_x = FLT_MAX;
|
||||
float max_x = -FLT_MAX;
|
||||
|
||||
for (const auto& prim : shape->get_primitives()) {
|
||||
for (const auto& prim : shape->getPrimitives()) {
|
||||
for (const auto& point : prim.points) {
|
||||
min_x = std::min(min_x, point.x);
|
||||
max_x = std::max(max_x, point.x);
|
||||
@@ -156,7 +154,7 @@ void LogoScene::inicialitzar_lletres() {
|
||||
<< " lletres carregades, ancho total: " << ancho_total << " px\n";
|
||||
}
|
||||
|
||||
void LogoScene::canviar_estat(AnimationState nou_estat) {
|
||||
void LogoScene::changeState(AnimationState nou_estat) {
|
||||
estat_actual_ = nou_estat;
|
||||
temps_estat_actual_ = 0.0F; // Reset time
|
||||
|
||||
@@ -181,12 +179,12 @@ void LogoScene::canviar_estat(AnimationState nou_estat) {
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
bool LogoScene::totes_lletres_completes() const {
|
||||
auto LogoScene::allLettersComplete() const -> bool {
|
||||
// Cuando global_progress = 1.0, todas las lletres tenen letra_progress = 1.0
|
||||
return temps_estat_actual_ >= DURACIO_ZOOM;
|
||||
}
|
||||
|
||||
void LogoScene::actualitzar_explosions(float delta_time) {
|
||||
void LogoScene::updateExplosions(float delta_time) {
|
||||
temps_des_ultima_explosio_ += delta_time;
|
||||
|
||||
// Comprovar si es el moment de explode la següent lletra
|
||||
@@ -213,7 +211,7 @@ void LogoScene::actualitzar_explosions(float delta_time) {
|
||||
temps_des_ultima_explosio_ = 0.0F;
|
||||
} else {
|
||||
// Todas las lletres han explotat, transición a POST_EXPLOSION
|
||||
canviar_estat(AnimationState::POST_EXPLOSION);
|
||||
changeState(AnimationState::POST_EXPLOSION);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,7 +222,7 @@ void LogoScene::update(float delta_time) {
|
||||
switch (estat_actual_) {
|
||||
case AnimationState::PRE_ANIMATION:
|
||||
if (temps_estat_actual_ >= DURACIO_PRE) {
|
||||
canviar_estat(AnimationState::ANIMATION);
|
||||
changeState(AnimationState::ANIMATION);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -234,7 +232,7 @@ void LogoScene::update(float delta_time) {
|
||||
|
||||
for (size_t i = 0; i < lletres_.size() && i < so_reproduit_.size(); i++) {
|
||||
if (!so_reproduit_[i]) {
|
||||
float letra_progress = calcular_progress_letra(
|
||||
float letra_progress = computeLetterProgress(
|
||||
i,
|
||||
lletres_.size(),
|
||||
global_progress,
|
||||
@@ -248,20 +246,20 @@ void LogoScene::update(float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
if (totes_lletres_completes()) {
|
||||
canviar_estat(AnimationState::POST_ANIMATION);
|
||||
if (allLettersComplete()) {
|
||||
changeState(AnimationState::POST_ANIMATION);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case AnimationState::POST_ANIMATION:
|
||||
if (temps_estat_actual_ >= DURACIO_POST_ANIMATION) {
|
||||
canviar_estat(AnimationState::EXPLOSION);
|
||||
changeState(AnimationState::EXPLOSION);
|
||||
}
|
||||
break;
|
||||
|
||||
case AnimationState::EXPLOSION:
|
||||
actualitzar_explosions(delta_time);
|
||||
updateExplosions(delta_time);
|
||||
break;
|
||||
|
||||
case AnimationState::POST_EXPLOSION:
|
||||
@@ -302,7 +300,7 @@ void LogoScene::draw() {
|
||||
for (size_t i = 0; i < lletres_.size(); i++) {
|
||||
const auto& lletra = lletres_[i];
|
||||
|
||||
float letra_progress = calcular_progress_letra(
|
||||
float letra_progress = computeLetterProgress(
|
||||
i,
|
||||
lletres_.size(),
|
||||
global_progress,
|
||||
@@ -323,7 +321,7 @@ void LogoScene::draw() {
|
||||
float current_scale =
|
||||
ESCALA_INICIAL + ((ESCALA_FINAL - ESCALA_INICIAL) * ease_factor);
|
||||
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
sdl_.getRenderer(),
|
||||
lletra.shape,
|
||||
pos_actual,
|
||||
@@ -346,7 +344,7 @@ void LogoScene::draw() {
|
||||
if (!explotades.contains(i)) {
|
||||
const auto& lletra = lletres_[i];
|
||||
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
sdl_.getRenderer(),
|
||||
lletra.shape,
|
||||
lletra.position,
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/input/input_types.hpp"
|
||||
#include "core/rendering/sdl_manager.hpp"
|
||||
#include "core/system/scene.hpp"
|
||||
#include "core/system/scene_context.hpp"
|
||||
@@ -32,7 +32,7 @@ class LogoScene final : public Scene {
|
||||
|
||||
private:
|
||||
// Màquina de estats per l'animación
|
||||
enum class AnimationState {
|
||||
enum class AnimationState : std::uint8_t {
|
||||
PRE_ANIMATION, // Pantalla negra inicial
|
||||
ANIMATION, // Animación de zoom de lletres
|
||||
POST_ANIMATION, // Logo complet visible
|
||||
@@ -42,16 +42,16 @@ class LogoScene final : public Scene {
|
||||
|
||||
SDLManager& sdl_;
|
||||
SceneManager::SceneContext& context_;
|
||||
AnimationState estat_actual_; // Estat actual de la màquina
|
||||
AnimationState estat_actual_{AnimationState::PRE_ANIMATION}; // Estat actual de la màquina
|
||||
float
|
||||
temps_estat_actual_; // Temps en l'state actual (reset en cada transición)
|
||||
temps_estat_actual_{0.0F}; // Temps en l'state actual (reset en cada transición)
|
||||
|
||||
// Gestor de fragments de explosions
|
||||
std::unique_ptr<Effects::DebrisManager> debris_manager_;
|
||||
|
||||
// Seguiment de explosions seqüencials
|
||||
size_t lletra_explosio_index_; // Índex de la següent lletra a explode
|
||||
float temps_des_ultima_explosio_; // Temps desde l'última explosión
|
||||
size_t lletra_explosio_index_{0}; // Índex de la següent lletra a explode
|
||||
float temps_des_ultima_explosio_{0.0F}; // Temps desde l'última explosión
|
||||
std::vector<size_t> ordre_explosio_; // Ordre aleatori de índexs de lletres
|
||||
|
||||
// Estructura para cada lletra del logo
|
||||
@@ -84,11 +84,12 @@ class LogoScene final : public Scene {
|
||||
static constexpr float ORIGEN_ZOOM_Y = Defaults::Game::HEIGHT * 0.4F; // Vec2 inicial Y del zoom
|
||||
|
||||
// Métodos privats
|
||||
void inicialitzar_lletres();
|
||||
void actualitzar_explosions(float delta_time);
|
||||
auto checkSkipButtonPressed() -> bool;
|
||||
void initLetters();
|
||||
void updateExplosions(float delta_time);
|
||||
// Estático: solo consulta Input (singleton), no estado de la escena.
|
||||
static auto checkSkipButtonPressed() -> bool;
|
||||
|
||||
// Métodos de gestió de estats
|
||||
void canviar_estat(AnimationState nou_estat);
|
||||
[[nodiscard]] bool totes_lletres_completes() const;
|
||||
void changeState(AnimationState nou_estat);
|
||||
[[nodiscard]] auto allLettersComplete() const -> bool;
|
||||
};
|
||||
|
||||
+204
-188
@@ -11,6 +11,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/graphics/shape_loader.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/rendering/shape_renderer.hpp"
|
||||
@@ -25,13 +26,8 @@ using Option = SceneContext::Option;
|
||||
TitleScene::TitleScene(SDLManager& sdl, SceneContext& context)
|
||||
: sdl_(sdl),
|
||||
context_(context),
|
||||
text_(sdl.getRenderer()),
|
||||
estat_actual_(TitleState::STARFIELD_FADE_IN),
|
||||
temps_acumulat_(0.0F),
|
||||
temps_animacio_(0.0F),
|
||||
temps_estat_main_(0.0F),
|
||||
animacio_activa_(false),
|
||||
factor_lerp_(0.0F) {
|
||||
text_(sdl.getRenderer())
|
||||
{
|
||||
std::cout << "SceneType Titol: Inicialitzant...\n";
|
||||
|
||||
// Inicialitzar configuración de match (sin player active per defecte)
|
||||
@@ -69,10 +65,10 @@ TitleScene::TitleScene(SDLManager& sdl, SceneContext& context)
|
||||
// Brightness depèn de l'opción
|
||||
if (estat_actual_ == TitleState::MAIN) {
|
||||
// Si saltem a MAIN, starfield instantàniament brillant
|
||||
starfield_->set_brightness(BRIGHTNESS_STARFIELD);
|
||||
starfield_->setBrightness(BRIGHTNESS_STARFIELD);
|
||||
} else {
|
||||
// Flux normal: comença con brightness 0.0 per fade-in
|
||||
starfield_->set_brightness(0.0F);
|
||||
starfield_->setBrightness(0.0F);
|
||||
}
|
||||
|
||||
// Inicialitzar animador de naves 3D
|
||||
@@ -81,15 +77,15 @@ TitleScene::TitleScene(SDLManager& sdl, SceneContext& context)
|
||||
|
||||
if (estat_actual_ == TitleState::MAIN) {
|
||||
// Jump to MAIN: empezar entrada inmediatamente
|
||||
ship_animator_->set_visible(true);
|
||||
ship_animator_->start_entry_animation();
|
||||
ship_animator_->setVisible(true);
|
||||
ship_animator_->startEntryAnimation();
|
||||
} else {
|
||||
// Flux normal: NO empezar entrada todavía (esperaran a MAIN)
|
||||
ship_animator_->set_visible(false);
|
||||
ship_animator_->setVisible(false);
|
||||
}
|
||||
|
||||
// Inicialitzar lletres del título "ORNI ATTACK!"
|
||||
inicialitzar_titol();
|
||||
initTitle();
|
||||
|
||||
// Logo JAILGAMES pequeño sobre el copyright inferior.
|
||||
inicialitzarJailgames();
|
||||
@@ -105,7 +101,7 @@ TitleScene::~TitleScene() {
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
|
||||
void TitleScene::inicialitzar_titol() {
|
||||
void TitleScene::initTitle() {
|
||||
using namespace Graphics;
|
||||
|
||||
// === LÍNIA 1: "ORNI" ===
|
||||
@@ -131,7 +127,7 @@ void TitleScene::inicialitzar_titol() {
|
||||
float min_y = FLT_MAX;
|
||||
float max_y = -FLT_MAX;
|
||||
|
||||
for (const auto& prim : shape->get_primitives()) {
|
||||
for (const auto& prim : shape->getPrimitives()) {
|
||||
for (const auto& point : prim.points) {
|
||||
min_x = std::min(min_x, point.x);
|
||||
max_x = std::max(max_x, point.x);
|
||||
@@ -205,7 +201,7 @@ void TitleScene::inicialitzar_titol() {
|
||||
float min_y = FLT_MAX;
|
||||
float max_y = -FLT_MAX;
|
||||
|
||||
for (const auto& prim : shape->get_primitives()) {
|
||||
for (const auto& prim : shape->getPrimitives()) {
|
||||
for (const auto& point : prim.points) {
|
||||
min_x = std::min(min_x, point.x);
|
||||
max_x = std::max(max_x, point.x);
|
||||
@@ -289,7 +285,7 @@ void TitleScene::inicialitzarJailgames() {
|
||||
float max_x = -FLT_MAX;
|
||||
float min_y = FLT_MAX;
|
||||
float max_y = -FLT_MAX;
|
||||
for (const auto& prim : shape->get_primitives()) {
|
||||
for (const auto& prim : shape->getPrimitives()) {
|
||||
for (const auto& point : prim.points) {
|
||||
min_x = std::min(min_x, point.x);
|
||||
max_x = std::max(max_x, point.x);
|
||||
@@ -331,7 +327,7 @@ void TitleScene::inicialitzarJailgames() {
|
||||
void TitleScene::dibuixarPeuTitol(float spacing) const {
|
||||
// Logo JAILGAMES pequeño sobre el copyright.
|
||||
for (const auto& lletra : lletres_jailgames_) {
|
||||
Rendering::render_shape(sdl_.getRenderer(), lletra.shape,
|
||||
Rendering::renderShape(sdl_.getRenderer(), lletra.shape,
|
||||
lletra.position, 0.0F,
|
||||
Defaults::Title::Layout::JAILGAMES_SCALE,
|
||||
1.0F);
|
||||
@@ -370,184 +366,204 @@ void TitleScene::update(float delta_time) {
|
||||
}
|
||||
|
||||
switch (estat_actual_) {
|
||||
case TitleState::STARFIELD_FADE_IN: {
|
||||
temps_acumulat_ += delta_time;
|
||||
|
||||
// Calcular progrés del fade (0.0 → 1.0)
|
||||
float progress = std::min(1.0F, temps_acumulat_ / DURACIO_FADE_IN);
|
||||
|
||||
// Lerp brightness de 0.0 a BRIGHTNESS_STARFIELD
|
||||
float brightness_actual = progress * BRIGHTNESS_STARFIELD;
|
||||
starfield_->set_brightness(brightness_actual);
|
||||
|
||||
// Transición a STARFIELD cuando el fade es completa
|
||||
if (temps_acumulat_ >= DURACIO_FADE_IN) {
|
||||
estat_actual_ = TitleState::STARFIELD;
|
||||
temps_acumulat_ = 0.0F; // Reset timer per al següent state
|
||||
starfield_->set_brightness(BRIGHTNESS_STARFIELD); // Assegurar value final
|
||||
}
|
||||
case TitleState::STARFIELD_FADE_IN:
|
||||
updateStarfieldFadeInState(delta_time);
|
||||
break;
|
||||
}
|
||||
|
||||
case TitleState::STARFIELD:
|
||||
temps_acumulat_ += delta_time;
|
||||
if (temps_acumulat_ >= DURACIO_INIT) {
|
||||
estat_actual_ = TitleState::MAIN;
|
||||
temps_estat_main_ = 0.0F; // Reset timer al entrar a MAIN
|
||||
animacio_activa_ = false; // Comença estàtic
|
||||
factor_lerp_ = 0.0F; // Sin animación aún
|
||||
|
||||
// Naves esperaran ENTRANCE_DELAY antes de entrar (no start aquí)
|
||||
}
|
||||
updateStarfieldState(delta_time);
|
||||
break;
|
||||
|
||||
case TitleState::MAIN: {
|
||||
temps_estat_main_ += delta_time;
|
||||
|
||||
// Iniciar animación de entrada de naves después del delay
|
||||
if (temps_estat_main_ >= Defaults::Title::Ships::ENTRANCE_DELAY) {
|
||||
if (ship_animator_ && !ship_animator_->is_visible()) {
|
||||
ship_animator_->set_visible(true);
|
||||
ship_animator_->start_entry_animation();
|
||||
}
|
||||
}
|
||||
|
||||
// Fase 1: Estàtic (0-10s)
|
||||
if (temps_estat_main_ < DELAY_INICI_ANIMACIO) {
|
||||
factor_lerp_ = 0.0F;
|
||||
animacio_activa_ = false;
|
||||
}
|
||||
// Fase 2: Lerp (10-12s)
|
||||
else if (temps_estat_main_ < DELAY_INICI_ANIMACIO + DURACIO_LERP) {
|
||||
float temps_lerp = temps_estat_main_ - DELAY_INICI_ANIMACIO;
|
||||
factor_lerp_ = temps_lerp / DURACIO_LERP; // 0.0 → 1.0 linealment
|
||||
animacio_activa_ = true;
|
||||
}
|
||||
// Fase 3: Animación completa (12s+)
|
||||
else {
|
||||
factor_lerp_ = 1.0F;
|
||||
animacio_activa_ = true;
|
||||
}
|
||||
|
||||
// Actualitzar animación del logo
|
||||
actualitzar_animacio_logo(delta_time);
|
||||
case TitleState::MAIN:
|
||||
updateMainState(delta_time);
|
||||
break;
|
||||
}
|
||||
|
||||
case TitleState::PLAYER_JOIN_PHASE:
|
||||
temps_acumulat_ += delta_time;
|
||||
|
||||
// Continuar animación orbital durante la transición
|
||||
actualitzar_animacio_logo(delta_time);
|
||||
|
||||
// [NOU] Continuar comprovant si l'altre player quiere unir-se durante la transición ("late join")
|
||||
{
|
||||
bool p1_actiu_abans = match_config_.jugador1_actiu;
|
||||
bool p2_actiu_abans = match_config_.jugador2_actiu;
|
||||
|
||||
if (checkStartGameButtonPressed()) {
|
||||
// Updates match_config_ if pressed, logs are in the method
|
||||
context_.setMatchConfig(match_config_);
|
||||
|
||||
// Trigger animación de salida per la ship que acaba de unir-se
|
||||
if (ship_animator_) {
|
||||
if (match_config_.jugador1_actiu && !p1_actiu_abans) {
|
||||
ship_animator_->trigger_exit_animation_for_player(1);
|
||||
std::cout << "[TitleScene] P1 late join - ship exiting\n";
|
||||
}
|
||||
if (match_config_.jugador2_actiu && !p2_actiu_abans) {
|
||||
ship_animator_->trigger_exit_animation_for_player(2);
|
||||
std::cout << "[TitleScene] P2 late join - ship exiting\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Reproducir so de START cuando el segon player s'uneix
|
||||
Audio::get()->playSound(Defaults::Sound::START, Audio::Group::GAME);
|
||||
|
||||
// Reiniciar el timer per allargar el time de transición
|
||||
temps_acumulat_ = 0.0F;
|
||||
|
||||
std::cout << "[TitleScene] Segon player s'ha unit - so i timer reiniciats\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (temps_acumulat_ >= DURACIO_TRANSITION) {
|
||||
// Transición a pantalla negra
|
||||
estat_actual_ = TitleState::BLACK_SCREEN;
|
||||
temps_acumulat_ = 0.0F;
|
||||
std::cout << "[TitleScene] Passant a BLACK_SCREEN\n";
|
||||
}
|
||||
updatePlayerJoinPhaseState(delta_time);
|
||||
break;
|
||||
|
||||
case TitleState::BLACK_SCREEN:
|
||||
temps_acumulat_ += delta_time;
|
||||
|
||||
// No animation, no input checking - just wait
|
||||
if (temps_acumulat_ >= DURACIO_BLACK_SCREEN) {
|
||||
// Transición a escena GAME (el Director detecta isFinished()).
|
||||
context_.setNextScene(SceneType::GAME);
|
||||
std::cout << "[TitleScene] Canviant a escena GAME\n";
|
||||
}
|
||||
updateBlackScreenState(delta_time);
|
||||
break;
|
||||
}
|
||||
|
||||
// Verificar botones de skip (FIRE/THRUST/START) para saltar escenas ANTES de MAIN
|
||||
if (estat_actual_ == TitleState::STARFIELD_FADE_IN || estat_actual_ == TitleState::STARFIELD) {
|
||||
if (checkSkipButtonPressed()) {
|
||||
// Saltar a MAIN
|
||||
estat_actual_ = TitleState::MAIN;
|
||||
starfield_->set_brightness(BRIGHTNESS_STARFIELD);
|
||||
temps_estat_main_ = 0.0F;
|
||||
handleSkipInput();
|
||||
handleStartInput();
|
||||
}
|
||||
|
||||
// Naves esperaran ENTRANCE_DELAY antes de entrar (no start aquí)
|
||||
}
|
||||
}
|
||||
void TitleScene::updateStarfieldFadeInState(float delta_time) {
|
||||
temps_acumulat_ += delta_time;
|
||||
|
||||
// Verificar boton START para start match desde MAIN
|
||||
if (estat_actual_ == TitleState::MAIN) {
|
||||
// Guardar state anterior per detectar qui ha premut START AQUEST frame
|
||||
bool p1_actiu_abans = match_config_.jugador1_actiu;
|
||||
bool p2_actiu_abans = match_config_.jugador2_actiu;
|
||||
// Calcular progrés del fade (0.0 → 1.0)
|
||||
float progress = std::min(1.0F, temps_acumulat_ / DURACIO_FADE_IN);
|
||||
|
||||
if (checkStartGameButtonPressed()) {
|
||||
// Si START es prem durante el delay (naves aún invisibles), saltar-las a FLOATING
|
||||
if (ship_animator_ && !ship_animator_->is_visible()) {
|
||||
ship_animator_->set_visible(true);
|
||||
ship_animator_->skip_to_floating_state();
|
||||
}
|
||||
// Lerp brightness de 0.0 a BRIGHTNESS_STARFIELD
|
||||
float brightness_actual = progress * BRIGHTNESS_STARFIELD;
|
||||
starfield_->setBrightness(brightness_actual);
|
||||
|
||||
// Configurar match antes de canviar de escena
|
||||
context_.setMatchConfig(match_config_);
|
||||
std::cout << "[TitleScene] Configuración de match - P1: "
|
||||
<< (match_config_.jugador1_actiu ? "ACTIU" : "INACTIU")
|
||||
<< ", P2: "
|
||||
<< (match_config_.jugador2_actiu ? "ACTIU" : "INACTIU")
|
||||
<< '\n';
|
||||
|
||||
// El setNextScene a GAME se hace al final de BLACK_SCREEN para no
|
||||
// saltar la animación de salida (isFinished() lo recoge entonces).
|
||||
estat_actual_ = TitleState::PLAYER_JOIN_PHASE;
|
||||
temps_acumulat_ = 0.0F;
|
||||
|
||||
// Trigger animación de salida NOMÉS per las naves que han premut START
|
||||
if (ship_animator_) {
|
||||
if (match_config_.jugador1_actiu && !p1_actiu_abans) {
|
||||
ship_animator_->trigger_exit_animation_for_player(1);
|
||||
std::cout << "[TitleScene] P1 ship exiting\n";
|
||||
}
|
||||
if (match_config_.jugador2_actiu && !p2_actiu_abans) {
|
||||
ship_animator_->trigger_exit_animation_for_player(2);
|
||||
std::cout << "[TitleScene] P2 ship exiting\n";
|
||||
}
|
||||
}
|
||||
|
||||
Audio::get()->fadeOutMusic(MUSIC_FADE);
|
||||
Audio::get()->playSound(Defaults::Sound::START, Audio::Group::GAME);
|
||||
}
|
||||
// Transición a STARFIELD cuando el fade es completa
|
||||
if (temps_acumulat_ >= DURACIO_FADE_IN) {
|
||||
estat_actual_ = TitleState::STARFIELD;
|
||||
temps_acumulat_ = 0.0F; // Reset timer per al següent state
|
||||
starfield_->setBrightness(BRIGHTNESS_STARFIELD); // Assegurar value final
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScene::actualitzar_animacio_logo(float delta_time) {
|
||||
void TitleScene::updateStarfieldState(float delta_time) {
|
||||
temps_acumulat_ += delta_time;
|
||||
if (temps_acumulat_ >= DURACIO_INIT) {
|
||||
estat_actual_ = TitleState::MAIN;
|
||||
temps_estat_main_ = 0.0F; // Reset timer al entrar a MAIN
|
||||
animacio_activa_ = false; // Comença estàtic
|
||||
factor_lerp_ = 0.0F; // Sin animación aún
|
||||
|
||||
// Naves esperaran ENTRANCE_DELAY antes de entrar (no start aquí)
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScene::updateMainState(float delta_time) {
|
||||
temps_estat_main_ += delta_time;
|
||||
|
||||
// Iniciar animación de entrada de naves después del delay
|
||||
if (temps_estat_main_ >= Defaults::Title::Ships::ENTRANCE_DELAY &&
|
||||
ship_animator_ && !ship_animator_->isVisible()) {
|
||||
ship_animator_->setVisible(true);
|
||||
ship_animator_->startEntryAnimation();
|
||||
}
|
||||
|
||||
// Fase 1: Estàtic (0-10s)
|
||||
if (temps_estat_main_ < DELAY_INICI_ANIMACIO) {
|
||||
factor_lerp_ = 0.0F;
|
||||
animacio_activa_ = false;
|
||||
}
|
||||
// Fase 2: Lerp (10-12s)
|
||||
else if (temps_estat_main_ < DELAY_INICI_ANIMACIO + DURACIO_LERP) {
|
||||
float temps_lerp = temps_estat_main_ - DELAY_INICI_ANIMACIO;
|
||||
factor_lerp_ = temps_lerp / DURACIO_LERP; // 0.0 → 1.0 linealment
|
||||
animacio_activa_ = true;
|
||||
}
|
||||
// Fase 3: Animación completa (12s+)
|
||||
else {
|
||||
factor_lerp_ = 1.0F;
|
||||
animacio_activa_ = true;
|
||||
}
|
||||
|
||||
// Actualitzar animación del logo
|
||||
updateLogoAnimation(delta_time);
|
||||
}
|
||||
|
||||
void TitleScene::updatePlayerJoinPhaseState(float delta_time) {
|
||||
temps_acumulat_ += delta_time;
|
||||
|
||||
// Continuar animación orbital durante la transición
|
||||
updateLogoAnimation(delta_time);
|
||||
|
||||
// [NOU] Continuar comprovant si l'altre player quiere unir-se durante la transición ("late join")
|
||||
bool p1_actiu_abans = match_config_.jugador1_actiu;
|
||||
bool p2_actiu_abans = match_config_.jugador2_actiu;
|
||||
|
||||
if (checkStartGameButtonPressed()) {
|
||||
// Updates match_config_ if pressed, logs are in the method
|
||||
context_.setMatchConfig(match_config_);
|
||||
|
||||
// Trigger animación de salida per la ship que acaba de unir-se
|
||||
triggerExitForJoinedPlayers(p1_actiu_abans, p2_actiu_abans, "late join - ");
|
||||
|
||||
// Reproducir so de START cuando el segon player s'uneix
|
||||
Audio::get()->playSound(Defaults::Sound::START, Audio::Group::GAME);
|
||||
|
||||
// Reiniciar el timer per allargar el time de transición
|
||||
temps_acumulat_ = 0.0F;
|
||||
|
||||
std::cout << "[TitleScene] Segon player s'ha unit - so i timer reiniciats\n";
|
||||
}
|
||||
|
||||
if (temps_acumulat_ >= DURACIO_TRANSITION) {
|
||||
// Transición a pantalla negra
|
||||
estat_actual_ = TitleState::BLACK_SCREEN;
|
||||
temps_acumulat_ = 0.0F;
|
||||
std::cout << "[TitleScene] Passant a BLACK_SCREEN\n";
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScene::updateBlackScreenState(float delta_time) {
|
||||
temps_acumulat_ += delta_time;
|
||||
|
||||
// No animation, no input checking - just wait
|
||||
if (temps_acumulat_ >= DURACIO_BLACK_SCREEN) {
|
||||
// Transición a escena GAME (el Director detecta isFinished()).
|
||||
context_.setNextScene(SceneType::GAME);
|
||||
std::cout << "[TitleScene] Canviant a escena GAME\n";
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScene::handleSkipInput() {
|
||||
// Verificar botones de skip (FIRE/THRUST/START) para saltar escenas ANTES de MAIN
|
||||
if (estat_actual_ != TitleState::STARFIELD_FADE_IN && estat_actual_ != TitleState::STARFIELD) {
|
||||
return;
|
||||
}
|
||||
if (!checkSkipButtonPressed()) {
|
||||
return;
|
||||
}
|
||||
// Saltar a MAIN
|
||||
estat_actual_ = TitleState::MAIN;
|
||||
starfield_->setBrightness(BRIGHTNESS_STARFIELD);
|
||||
temps_estat_main_ = 0.0F;
|
||||
// Naves esperaran ENTRANCE_DELAY antes de entrar (no start aquí)
|
||||
}
|
||||
|
||||
void TitleScene::handleStartInput() {
|
||||
// Verificar boton START para start match desde MAIN
|
||||
if (estat_actual_ != TitleState::MAIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Guardar state anterior per detectar qui ha premut START AQUEST frame
|
||||
bool p1_actiu_abans = match_config_.jugador1_actiu;
|
||||
bool p2_actiu_abans = match_config_.jugador2_actiu;
|
||||
|
||||
if (!checkStartGameButtonPressed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Si START es prem durante el delay (naves aún invisibles), saltar-las a FLOATING
|
||||
if (ship_animator_ && !ship_animator_->isVisible()) {
|
||||
ship_animator_->setVisible(true);
|
||||
ship_animator_->skipToFloatingState();
|
||||
}
|
||||
|
||||
// Configurar match antes de canviar de escena
|
||||
context_.setMatchConfig(match_config_);
|
||||
std::cout << "[TitleScene] Configuración de match - P1: "
|
||||
<< (match_config_.jugador1_actiu ? "ACTIU" : "INACTIU")
|
||||
<< ", P2: "
|
||||
<< (match_config_.jugador2_actiu ? "ACTIU" : "INACTIU")
|
||||
<< '\n';
|
||||
|
||||
// El setNextScene a GAME se hace al final de BLACK_SCREEN para no
|
||||
// saltar la animación de salida (isFinished() lo recoge entonces).
|
||||
estat_actual_ = TitleState::PLAYER_JOIN_PHASE;
|
||||
temps_acumulat_ = 0.0F;
|
||||
|
||||
// Trigger animación de salida NOMÉS per las naves que han premut START
|
||||
triggerExitForJoinedPlayers(p1_actiu_abans, p2_actiu_abans, "");
|
||||
|
||||
Audio::get()->fadeOutMusic(MUSIC_FADE);
|
||||
Audio::get()->playSound(Defaults::Sound::START, Audio::Group::GAME);
|
||||
}
|
||||
|
||||
void TitleScene::triggerExitForJoinedPlayers(bool p1_was_active, bool p2_was_active,
|
||||
const char* log_prefix) {
|
||||
if (ship_animator_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (match_config_.jugador1_actiu && !p1_was_active) {
|
||||
ship_animator_->triggerExitAnimationForPlayer(1);
|
||||
std::cout << "[TitleScene] P1 " << log_prefix << "ship exiting\n";
|
||||
}
|
||||
if (match_config_.jugador2_actiu && !p2_was_active) {
|
||||
ship_animator_->triggerExitAnimationForPlayer(2);
|
||||
std::cout << "[TitleScene] P2 " << log_prefix << "ship exiting\n";
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScene::updateLogoAnimation(float delta_time) {
|
||||
// Solo calcular i aplicar offsets si l'animación está activa
|
||||
if (animacio_activa_) {
|
||||
// Acumular time escalat
|
||||
@@ -623,7 +639,7 @@ void TitleScene::draw() {
|
||||
pos_shadow.x = posicions_originals_orni_[i].x + static_cast<int>(std::round(shadow_offset_x));
|
||||
pos_shadow.y = posicions_originals_orni_[i].y + static_cast<int>(std::round(shadow_offset_y));
|
||||
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
sdl_.getRenderer(),
|
||||
lletres_orni_[i].shape,
|
||||
pos_shadow,
|
||||
@@ -640,7 +656,7 @@ void TitleScene::draw() {
|
||||
pos_shadow.x = posicions_originals_attack_[i].x + static_cast<int>(std::round(shadow_offset_x));
|
||||
pos_shadow.y = posicions_originals_attack_[i].y + static_cast<int>(std::round(shadow_offset_y));
|
||||
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
sdl_.getRenderer(),
|
||||
lletres_attack_[i].shape,
|
||||
pos_shadow,
|
||||
@@ -655,7 +671,7 @@ void TitleScene::draw() {
|
||||
|
||||
// Dibuixar "ORNI" (línia 1)
|
||||
for (const auto& lletra : lletres_orni_) {
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
sdl_.getRenderer(),
|
||||
lletra.shape,
|
||||
lletra.position,
|
||||
@@ -667,7 +683,7 @@ void TitleScene::draw() {
|
||||
|
||||
// Dibuixar "ATTACK!" (línia 2)
|
||||
for (const auto& lletra : lletres_attack_) {
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
sdl_.getRenderer(),
|
||||
lletra.shape,
|
||||
lletra.position,
|
||||
@@ -681,7 +697,7 @@ void TitleScene::draw() {
|
||||
// En state MAIN: siempre visible
|
||||
// En state TRANSITION: parpellejant (blink con sinusoide)
|
||||
|
||||
const float spacing = Defaults::Title::Layout::TEXT_SPACING;
|
||||
const float SPACING = Defaults::Title::Layout::TEXT_SPACING;
|
||||
|
||||
bool mostrar_text = true;
|
||||
if (estat_actual_ == TitleState::PLAYER_JOIN_PHASE) {
|
||||
@@ -691,16 +707,16 @@ void TitleScene::draw() {
|
||||
}
|
||||
|
||||
if (mostrar_text) {
|
||||
const std::string main_text = "PRESS START TO PLAY";
|
||||
const float escala_main = Defaults::Title::Layout::PRESS_START_SCALE;
|
||||
const std::string MAIN_TEXT = "PRESS START TO PLAY";
|
||||
const float MAIN_SCALE = Defaults::Title::Layout::PRESS_START_SCALE;
|
||||
|
||||
float centre_x = Defaults::Game::WIDTH / 2.0F;
|
||||
float centre_y = Defaults::Game::HEIGHT * Defaults::Title::Layout::PRESS_START_POS;
|
||||
|
||||
text_.renderCentered(main_text, {.x = centre_x, .y = centre_y}, escala_main, spacing);
|
||||
text_.renderCentered(MAIN_TEXT, {.x = centre_x, .y = centre_y}, MAIN_SCALE, SPACING);
|
||||
}
|
||||
|
||||
dibuixarPeuTitol(spacing);
|
||||
dibuixarPeuTitol(SPACING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/graphics/starfield.hpp"
|
||||
#include "core/graphics/vector_text.hpp"
|
||||
@@ -39,7 +39,7 @@ class TitleScene final : public Scene {
|
||||
|
||||
private:
|
||||
// Màquina de estats per la pantalla de título
|
||||
enum class TitleState {
|
||||
enum class TitleState : std::uint8_t {
|
||||
STARFIELD_FADE_IN, // Fade-in del starfield (3.0s)
|
||||
STARFIELD, // Pantalla con camp de estrelles (4.0s)
|
||||
MAIN, // Pantalla de título con text (indefinit, hasta START)
|
||||
@@ -62,8 +62,8 @@ class TitleScene final : public Scene {
|
||||
Graphics::VectorText text_; // Sistema de text vectorial
|
||||
std::unique_ptr<Graphics::Starfield> starfield_; // Camp de estrelles de fons
|
||||
std::unique_ptr<Title::ShipAnimator> ship_animator_; // Naves 3D flotantes
|
||||
TitleState estat_actual_; // Estat actual de la màquina
|
||||
float temps_acumulat_; // Temps acumulat per l'state INIT
|
||||
TitleState estat_actual_{TitleState::STARFIELD_FADE_IN}; // Estat actual de la màquina
|
||||
float temps_acumulat_{0.0F}; // Temps acumulat per l'state INIT
|
||||
|
||||
// Lletres del título "ORNI ATTACK!"
|
||||
std::vector<LetraLogo> lletres_orni_; // Lletres de "ORNI" (línia 1)
|
||||
@@ -74,14 +74,14 @@ class TitleScene final : public Scene {
|
||||
std::vector<LetraLogo> lletres_jailgames_;
|
||||
|
||||
// Estat de animación del logo
|
||||
float temps_animacio_; // Temps acumulat per animación orbital
|
||||
float temps_animacio_{0.0F}; // Temps acumulat per animación orbital
|
||||
std::vector<Vec2> posicions_originals_orni_; // Posicions originals de "ORNI"
|
||||
std::vector<Vec2> posicions_originals_attack_; // Posicions originals de "ATTACK!"
|
||||
|
||||
// Estat de arrencada de l'animación
|
||||
float temps_estat_main_; // Temps acumulat en state MAIN
|
||||
bool animacio_activa_; // Flag: true cuando animación está activa
|
||||
float factor_lerp_; // Factor de lerp actual (0.0 → 1.0)
|
||||
float temps_estat_main_{0.0F}; // Temps acumulat en state MAIN
|
||||
bool animacio_activa_{false}; // Flag: true cuando animación está activa
|
||||
float factor_lerp_{0.0F}; // Factor de lerp actual (0.0 → 1.0)
|
||||
|
||||
// Constants
|
||||
static constexpr float BRIGHTNESS_STARFIELD = 1.2F; // Brightness del starfield (>1.0 = més brillant)
|
||||
@@ -111,10 +111,25 @@ class TitleScene final : public Scene {
|
||||
static constexpr float DURACIO_LERP = 2.0F; // 2s per arribar a amplitud completa
|
||||
|
||||
// Métodos privats
|
||||
void actualitzar_animacio_logo(float delta_time); // Actualitza l'animación orbital del logo
|
||||
auto checkSkipButtonPressed() -> bool;
|
||||
void updateLogoAnimation(float delta_time); // Actualitza l'animación orbital del logo
|
||||
// Estático: solo consulta Input (singleton), no estado de la escena.
|
||||
static auto checkSkipButtonPressed() -> bool;
|
||||
auto checkStartGameButtonPressed() -> bool;
|
||||
void inicialitzar_titol(); // Carrega i posiciona las lletres del título
|
||||
void initTitle(); // Carrega i posiciona las lletres del título
|
||||
void inicialitzarJailgames(); // Carrega i posiciona el logo JAILGAMES pequeño
|
||||
void dibuixarPeuTitol(float spacing) const; // Logo JAILGAMES + línia de copyright
|
||||
|
||||
// Sub-pasos de update() (extreure cada state per reduir complexitat).
|
||||
void updateStarfieldFadeInState(float delta_time);
|
||||
void updateStarfieldState(float delta_time);
|
||||
void updateMainState(float delta_time);
|
||||
void updatePlayerJoinPhaseState(float delta_time);
|
||||
void updateBlackScreenState(float delta_time);
|
||||
// Handlers de input globals (independents de l'state actual).
|
||||
void handleSkipInput();
|
||||
void handleStartInput();
|
||||
// Helper compartit: dispara l'animación de salida per las naves del player que
|
||||
// acaba de fer un join "en aquest frame" (jugadorX_actiu == true && !prev).
|
||||
void triggerExitForJoinedPlayers(bool p1_was_active, bool p2_was_active,
|
||||
const char* log_prefix);
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "spawn_controller.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
@@ -15,11 +16,7 @@
|
||||
|
||||
namespace StageSystem {
|
||||
|
||||
SpawnController::SpawnController()
|
||||
: config_(nullptr),
|
||||
temps_transcorregut_(0.0F),
|
||||
index_spawn_actual_(0),
|
||||
ship_position_(nullptr) {}
|
||||
SpawnController::SpawnController() = default;
|
||||
|
||||
void SpawnController::configure(const StageConfig* config) {
|
||||
config_ = config;
|
||||
@@ -32,7 +29,7 @@ void SpawnController::start() {
|
||||
}
|
||||
|
||||
reset();
|
||||
generar_spawn_events();
|
||||
generateSpawnEvents();
|
||||
|
||||
std::cout << "[SpawnController] Stage " << static_cast<int>(config_->stage_id)
|
||||
<< ": generats " << spawn_queue_.size() << " spawn events" << '\n';
|
||||
@@ -67,7 +64,7 @@ void SpawnController::update(float delta_time, std::array<Enemy, 15>& orni_array
|
||||
// Find first inactive enemy
|
||||
for (auto& enemy : orni_array) {
|
||||
if (!enemy.isActive()) {
|
||||
spawn_enemic(enemy, event.type, ship_position_);
|
||||
spawnEnemy(enemy, event.type, ship_position_);
|
||||
event.spawnejat = true;
|
||||
index_spawn_actual_++;
|
||||
break;
|
||||
@@ -85,25 +82,18 @@ void SpawnController::update(float delta_time, std::array<Enemy, 15>& orni_array
|
||||
}
|
||||
}
|
||||
|
||||
bool SpawnController::tots_enemics_spawnejats() const {
|
||||
auto SpawnController::allEnemiesSpawned() const -> bool {
|
||||
return index_spawn_actual_ >= spawn_queue_.size();
|
||||
}
|
||||
|
||||
bool SpawnController::tots_enemics_destruits(const std::array<Enemy, 15>& orni_array) const {
|
||||
if (!tots_enemics_spawnejats()) {
|
||||
auto SpawnController::allEnemiesDestroyed(const std::array<Enemy, 15>& orni_array) const -> bool {
|
||||
if (!allEnemiesSpawned()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& enemy : orni_array) {
|
||||
if (enemy.isActive()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return std::ranges::all_of(orni_array, [](const Enemy& enemy) { return !enemy.isActive(); });
|
||||
}
|
||||
|
||||
uint8_t SpawnController::get_enemics_vius(const std::array<Enemy, 15>& orni_array) const {
|
||||
auto SpawnController::getAliveEnemyCount(const std::array<Enemy, 15>& orni_array) -> uint8_t {
|
||||
uint8_t count = 0;
|
||||
for (const auto& enemy : orni_array) {
|
||||
if (enemy.isActive()) {
|
||||
@@ -113,11 +103,11 @@ uint8_t SpawnController::get_enemics_vius(const std::array<Enemy, 15>& orni_arra
|
||||
return count;
|
||||
}
|
||||
|
||||
uint8_t SpawnController::get_enemics_spawnejats() const {
|
||||
auto SpawnController::countSpawnedEnemies() const -> uint8_t {
|
||||
return static_cast<uint8_t>(index_spawn_actual_);
|
||||
}
|
||||
|
||||
void SpawnController::generar_spawn_events() {
|
||||
void SpawnController::generateSpawnEvents() {
|
||||
if (config_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -126,13 +116,13 @@ void SpawnController::generar_spawn_events() {
|
||||
float spawn_time = config_->config_spawn.delay_inicial +
|
||||
(i * config_->config_spawn.interval_spawn);
|
||||
|
||||
EnemyType type = seleccionar_tipus_aleatori();
|
||||
EnemyType type = selectRandomType();
|
||||
|
||||
spawn_queue_.push_back({spawn_time, type, false});
|
||||
}
|
||||
}
|
||||
|
||||
EnemyType SpawnController::seleccionar_tipus_aleatori() const {
|
||||
auto SpawnController::selectRandomType() const -> EnemyType {
|
||||
if (config_ == nullptr) {
|
||||
return EnemyType::PENTAGON;
|
||||
}
|
||||
@@ -149,15 +139,15 @@ EnemyType SpawnController::seleccionar_tipus_aleatori() const {
|
||||
return EnemyType::MOLINILLO;
|
||||
}
|
||||
|
||||
void SpawnController::spawn_enemic(Enemy& enemy, EnemyType type, const Vec2* ship_pos) {
|
||||
void SpawnController::spawnEnemy(Enemy& enemy, EnemyType type, const Vec2* ship_pos) {
|
||||
// Initialize enemy (with safe spawn if ship_pos provided)
|
||||
enemy.init(type, ship_pos);
|
||||
|
||||
// Apply difficulty multipliers
|
||||
aplicar_multiplicadors(enemy);
|
||||
applyMultipliers(enemy);
|
||||
}
|
||||
|
||||
void SpawnController::aplicar_multiplicadors(Enemy& enemy) const {
|
||||
void SpawnController::applyMultipliers(Enemy& enemy) const {
|
||||
if (config_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,26 +33,27 @@ class SpawnController {
|
||||
void update(float delta_time, std::array<Enemy, 15>& orni_array, bool pausar = false);
|
||||
|
||||
// Status queries
|
||||
[[nodiscard]] bool tots_enemics_spawnejats() const;
|
||||
[[nodiscard]] bool tots_enemics_destruits(const std::array<Enemy, 15>& orni_array) const;
|
||||
[[nodiscard]] uint8_t get_enemics_vius(const std::array<Enemy, 15>& orni_array) const;
|
||||
[[nodiscard]] uint8_t get_enemics_spawnejats() const;
|
||||
[[nodiscard]] auto allEnemiesSpawned() const -> bool;
|
||||
[[nodiscard]] auto allEnemiesDestroyed(const std::array<Enemy, 15>& orni_array) const -> bool;
|
||||
// Estático: solo recorre el array pasado; no consulta estado del controller.
|
||||
[[nodiscard]] static auto getAliveEnemyCount(const std::array<Enemy, 15>& orni_array) -> uint8_t;
|
||||
[[nodiscard]] auto countSpawnedEnemies() const -> uint8_t;
|
||||
|
||||
// [NEW] Set ship position reference for safe spawn
|
||||
void setShipPosition(const Vec2* ship_pos) { ship_position_ = ship_pos; }
|
||||
|
||||
private:
|
||||
const StageConfig* config_; // Non-owning pointer to current stage config
|
||||
const StageConfig* config_{nullptr}; // Non-owning pointer to current stage config
|
||||
std::vector<SpawnEvent> spawn_queue_;
|
||||
float temps_transcorregut_; // Elapsed time since stage start
|
||||
uint8_t index_spawn_actual_; // Next spawn to process
|
||||
float temps_transcorregut_{0.0F}; // Elapsed time since stage start
|
||||
uint8_t index_spawn_actual_{0}; // Next spawn to process
|
||||
|
||||
// Spawn generation
|
||||
void generar_spawn_events();
|
||||
[[nodiscard]] EnemyType seleccionar_tipus_aleatori() const;
|
||||
void spawn_enemic(Enemy& enemy, EnemyType type, const Vec2* ship_pos = nullptr);
|
||||
void aplicar_multiplicadors(Enemy& enemy) const;
|
||||
const Vec2* ship_position_; // [NEW] Non-owning pointer to ship position
|
||||
void generateSpawnEvents();
|
||||
[[nodiscard]] auto selectRandomType() const -> EnemyType;
|
||||
void spawnEnemy(Enemy& enemy, EnemyType type, const Vec2* ship_pos = nullptr);
|
||||
void applyMultipliers(Enemy& enemy) const;
|
||||
const Vec2* ship_position_{nullptr}; // [NEW] Non-owning pointer to ship position
|
||||
};
|
||||
|
||||
} // namespace StageSystem
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace StageSystem {
|
||||
|
||||
// Tipo de mode de spawn
|
||||
enum class ModeSpawn {
|
||||
enum class ModeSpawn : std::uint8_t {
|
||||
PROGRESSIVE, // Spawn progressiu con intervals
|
||||
IMMEDIATE, // Todos los enemigos de cop
|
||||
WAVE // Onades de 3-5 enemigos (futura extensió)
|
||||
@@ -55,8 +55,10 @@ struct StageConfig {
|
||||
MultiplicadorsDificultat multiplicadors;
|
||||
|
||||
// Validació
|
||||
[[nodiscard]] bool es_valid() const {
|
||||
return stage_id >= 1 && stage_id <= 255 &&
|
||||
[[nodiscard]] auto isValid() const -> bool {
|
||||
// stage_id es uint8_t: el rango superior (<=255) está garantizado por
|
||||
// el tipo; basta con confirmar que no es 0 (sentinela "sin asignar").
|
||||
return stage_id >= 1 &&
|
||||
total_enemies > 0 && total_enemies <= 15 &&
|
||||
distribucio.pentagon + distribucio.cuadrado + distribucio.molinillo == 100;
|
||||
}
|
||||
@@ -68,7 +70,7 @@ struct StageSystemConfig {
|
||||
std::vector<StageConfig> stages; // Índex [0] = stage 1
|
||||
|
||||
// Obtenir configuración de un stage específic
|
||||
[[nodiscard]] const StageConfig* obte_stage(uint8_t stage_id) const {
|
||||
[[nodiscard]] auto findStage(uint8_t stage_id) const -> const StageConfig* {
|
||||
if (stage_id < 1 || stage_id > stages.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
namespace StageSystem {
|
||||
|
||||
std::unique_ptr<StageSystemConfig> StageLoader::load(const std::string& path) {
|
||||
auto StageLoader::load(const std::string& path) -> std::unique_ptr<StageSystemConfig> {
|
||||
try {
|
||||
// Normalize path: "data/stages/stages.yaml" → "stages/stages.yaml"
|
||||
std::string normalized = path;
|
||||
@@ -47,7 +47,7 @@ std::unique_ptr<StageSystemConfig> StageLoader::load(const std::string& path) {
|
||||
std::cerr << "[StageLoader] Error: falta camp 'metadata'" << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
if (!parse_metadata(yaml["metadata"], config->metadata)) {
|
||||
if (!parseMetadata(yaml["metadata"], config->metadata)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -64,14 +64,14 @@ std::unique_ptr<StageSystemConfig> StageLoader::load(const std::string& path) {
|
||||
|
||||
for (const auto& stage_yaml : yaml["stages"]) {
|
||||
StageConfig stage;
|
||||
if (!parse_stage(stage_yaml, stage)) {
|
||||
if (!parseStage(stage_yaml, stage)) {
|
||||
return nullptr;
|
||||
}
|
||||
config->stages.push_back(stage);
|
||||
}
|
||||
|
||||
// Validar configuración
|
||||
if (!validar_config(*config)) {
|
||||
if (!validateConfig(*config)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ std::unique_ptr<StageSystemConfig> StageLoader::load(const std::string& path) {
|
||||
}
|
||||
}
|
||||
|
||||
bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta) {
|
||||
auto StageLoader::parseMetadata(const fkyaml::node& yaml, MetadataStages& meta) -> bool {
|
||||
try {
|
||||
if (!yaml.contains("version") || !yaml.contains("total_stages")) {
|
||||
std::cerr << "[StageLoader] Error: metadata incompleta" << '\n';
|
||||
@@ -105,7 +105,7 @@ bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta)
|
||||
}
|
||||
}
|
||||
|
||||
bool StageLoader::parse_stage(const fkyaml::node& yaml, StageConfig& stage) {
|
||||
auto StageLoader::parseStage(const fkyaml::node& yaml, StageConfig& stage) -> bool {
|
||||
try {
|
||||
if (!yaml.contains("stage_id") || !yaml.contains("total_enemies") ||
|
||||
!yaml.contains("spawn_config") || !yaml.contains("enemy_distribution") ||
|
||||
@@ -117,17 +117,17 @@ bool StageLoader::parse_stage(const fkyaml::node& yaml, StageConfig& stage) {
|
||||
stage.stage_id = yaml["stage_id"].get_value<uint8_t>();
|
||||
stage.total_enemies = yaml["total_enemies"].get_value<uint8_t>();
|
||||
|
||||
if (!parse_spawn_config(yaml["spawn_config"], stage.config_spawn)) {
|
||||
if (!parseSpawnConfig(yaml["spawn_config"], stage.config_spawn)) {
|
||||
return false;
|
||||
}
|
||||
if (!parse_distribution(yaml["enemy_distribution"], stage.distribucio)) {
|
||||
if (!parseDistribution(yaml["enemy_distribution"], stage.distribucio)) {
|
||||
return false;
|
||||
}
|
||||
if (!parse_multipliers(yaml["difficulty_multipliers"], stage.multiplicadors)) {
|
||||
if (!parseMultipliers(yaml["difficulty_multipliers"], stage.multiplicadors)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!stage.es_valid()) {
|
||||
if (!stage.isValid()) {
|
||||
std::cerr << "[StageLoader] Error: stage " << static_cast<int>(stage.stage_id)
|
||||
<< " no es vàlid" << '\n';
|
||||
return false;
|
||||
@@ -140,7 +140,7 @@ bool StageLoader::parse_stage(const fkyaml::node& yaml, StageConfig& stage) {
|
||||
}
|
||||
}
|
||||
|
||||
bool StageLoader::parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& config) {
|
||||
auto StageLoader::parseSpawnConfig(const fkyaml::node& yaml, ConfigSpawn& config) -> bool {
|
||||
try {
|
||||
if (!yaml.contains("mode") || !yaml.contains("initial_delay") ||
|
||||
!yaml.contains("spawn_interval")) {
|
||||
@@ -149,7 +149,7 @@ bool StageLoader::parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& conf
|
||||
}
|
||||
|
||||
auto mode_str = yaml["mode"].get_value<std::string>();
|
||||
config.mode = parse_spawn_mode(mode_str);
|
||||
config.mode = parseSpawnMode(mode_str);
|
||||
config.delay_inicial = yaml["initial_delay"].get_value<float>();
|
||||
config.interval_spawn = yaml["spawn_interval"].get_value<float>();
|
||||
|
||||
@@ -160,7 +160,7 @@ bool StageLoader::parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& conf
|
||||
}
|
||||
}
|
||||
|
||||
bool StageLoader::parse_distribution(const fkyaml::node& yaml, DistribucioEnemics& dist) {
|
||||
auto StageLoader::parseDistribution(const fkyaml::node& yaml, DistribucioEnemics& dist) -> bool {
|
||||
try {
|
||||
if (!yaml.contains("pentagon") || !yaml.contains("cuadrado") ||
|
||||
!yaml.contains("molinillo")) {
|
||||
@@ -186,7 +186,7 @@ bool StageLoader::parse_distribution(const fkyaml::node& yaml, DistribucioEnemic
|
||||
}
|
||||
}
|
||||
|
||||
bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDificultat& mult) {
|
||||
auto StageLoader::parseMultipliers(const fkyaml::node& yaml, MultiplicadorsDificultat& mult) -> bool {
|
||||
try {
|
||||
if (!yaml.contains("speed_multiplier") || !yaml.contains("rotation_multiplier") ||
|
||||
!yaml.contains("tracking_strength")) {
|
||||
@@ -216,7 +216,7 @@ bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDifi
|
||||
}
|
||||
}
|
||||
|
||||
ModeSpawn StageLoader::parse_spawn_mode(const std::string& mode_str) {
|
||||
auto StageLoader::parseSpawnMode(const std::string& mode_str) -> ModeSpawn {
|
||||
if (mode_str == "progressive") {
|
||||
return ModeSpawn::PROGRESSIVE;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ ModeSpawn StageLoader::parse_spawn_mode(const std::string& mode_str) {
|
||||
return ModeSpawn::PROGRESSIVE;
|
||||
}
|
||||
|
||||
bool StageLoader::validar_config(const StageSystemConfig& config) {
|
||||
auto StageLoader::validateConfig(const StageSystemConfig& config) -> bool {
|
||||
if (config.stages.empty()) {
|
||||
std::cerr << "[StageLoader] Error: sin stage carregat" << '\n';
|
||||
return false;
|
||||
|
||||
@@ -15,19 +15,19 @@ class StageLoader {
|
||||
public:
|
||||
// Carregar configuración desde file YAML
|
||||
// Retorna nullptr si hay errors
|
||||
static std::unique_ptr<StageSystemConfig> load(const std::string& path);
|
||||
static auto load(const std::string& path) -> std::unique_ptr<StageSystemConfig>;
|
||||
|
||||
private:
|
||||
// Parsing helpers (implementats en .cpp)
|
||||
static bool parse_metadata(const fkyaml::node& yaml, MetadataStages& meta);
|
||||
static bool parse_stage(const fkyaml::node& yaml, StageConfig& stage);
|
||||
static bool parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& config);
|
||||
static bool parse_distribution(const fkyaml::node& yaml, DistribucioEnemics& dist);
|
||||
static bool parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDificultat& mult);
|
||||
static ModeSpawn parse_spawn_mode(const std::string& mode_str);
|
||||
static auto parseMetadata(const fkyaml::node& yaml, MetadataStages& meta) -> bool;
|
||||
static auto parseStage(const fkyaml::node& yaml, StageConfig& stage) -> bool;
|
||||
static auto parseSpawnConfig(const fkyaml::node& yaml, ConfigSpawn& config) -> bool;
|
||||
static auto parseDistribution(const fkyaml::node& yaml, DistribucioEnemics& dist) -> bool;
|
||||
static auto parseMultipliers(const fkyaml::node& yaml, MultiplicadorsDificultat& mult) -> bool;
|
||||
static auto parseSpawnMode(const std::string& mode_str) -> ModeSpawn;
|
||||
|
||||
// Validació
|
||||
static bool validar_config(const StageSystemConfig& config);
|
||||
static auto validateConfig(const StageSystemConfig& config) -> bool;
|
||||
};
|
||||
|
||||
} // namespace StageSystem
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
namespace StageSystem {
|
||||
|
||||
StageManager::StageManager(const StageSystemConfig* config)
|
||||
: config_(config),
|
||||
estat_(EstatStage::LEVEL_START),
|
||||
stage_actual_(1),
|
||||
timer_transicio_(0.0F) {
|
||||
: config_(config)
|
||||
{
|
||||
if (config_ == nullptr) {
|
||||
std::cerr << "[StageManager] Error: config es null" << '\n';
|
||||
}
|
||||
@@ -26,8 +24,8 @@ StageManager::StageManager(const StageSystemConfig* config)
|
||||
|
||||
void StageManager::init() {
|
||||
stage_actual_ = 1;
|
||||
carregar_stage(stage_actual_);
|
||||
canviar_estat(EstatStage::INIT_HUD);
|
||||
loadStage(stage_actual_);
|
||||
changeState(EstatStage::INIT_HUD);
|
||||
|
||||
std::cout << "[StageManager] Inicialitzat a stage " << static_cast<int>(stage_actual_)
|
||||
<< '\n';
|
||||
@@ -36,40 +34,40 @@ void StageManager::init() {
|
||||
void StageManager::update(float delta_time, bool pause_spawn) {
|
||||
switch (estat_) {
|
||||
case EstatStage::INIT_HUD:
|
||||
processar_init_hud(delta_time);
|
||||
processInitHud(delta_time);
|
||||
break;
|
||||
|
||||
case EstatStage::LEVEL_START:
|
||||
processar_level_start(delta_time);
|
||||
processLevelStart(delta_time);
|
||||
break;
|
||||
|
||||
case EstatStage::PLAYING:
|
||||
processar_playing(delta_time, pause_spawn);
|
||||
processPlaying(delta_time, pause_spawn);
|
||||
break;
|
||||
|
||||
case EstatStage::LEVEL_COMPLETED:
|
||||
processar_level_completed(delta_time);
|
||||
processLevelCompleted(delta_time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void StageManager::stage_completat() {
|
||||
void StageManager::markStageCompleted() {
|
||||
std::cout << "[StageManager] Stage " << static_cast<int>(stage_actual_) << " completat!"
|
||||
<< '\n';
|
||||
canviar_estat(EstatStage::LEVEL_COMPLETED);
|
||||
changeState(EstatStage::LEVEL_COMPLETED);
|
||||
}
|
||||
|
||||
bool StageManager::tot_completat() const {
|
||||
auto StageManager::isGameComplete() const -> bool {
|
||||
return stage_actual_ >= config_->metadata.total_stages &&
|
||||
estat_ == EstatStage::LEVEL_COMPLETED &&
|
||||
timer_transicio_ <= 0.0F;
|
||||
}
|
||||
|
||||
const StageConfig* StageManager::get_config_actual() const {
|
||||
return config_->obte_stage(stage_actual_);
|
||||
auto StageManager::getCurrentConfig() const -> const StageConfig* {
|
||||
return config_->findStage(stage_actual_);
|
||||
}
|
||||
|
||||
void StageManager::canviar_estat(EstatStage nou_estat) {
|
||||
void StageManager::changeState(EstatStage nou_estat) {
|
||||
estat_ = nou_estat;
|
||||
|
||||
// Set timer based on state type
|
||||
@@ -111,23 +109,24 @@ void StageManager::canviar_estat(EstatStage nou_estat) {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
void StageManager::processar_init_hud(float delta_time) {
|
||||
void StageManager::processInitHud(float delta_time) {
|
||||
timer_transicio_ -= delta_time;
|
||||
|
||||
if (timer_transicio_ <= 0.0F) {
|
||||
canviar_estat(EstatStage::LEVEL_START);
|
||||
changeState(EstatStage::LEVEL_START);
|
||||
}
|
||||
}
|
||||
|
||||
void StageManager::processar_level_start(float delta_time) {
|
||||
void StageManager::processLevelStart(float delta_time) {
|
||||
timer_transicio_ -= delta_time;
|
||||
|
||||
if (timer_transicio_ <= 0.0F) {
|
||||
canviar_estat(EstatStage::PLAYING);
|
||||
changeState(EstatStage::PLAYING);
|
||||
}
|
||||
}
|
||||
|
||||
void StageManager::processar_playing(float delta_time, bool pause_spawn) {
|
||||
void StageManager::processPlaying(float delta_time, bool pause_spawn) {
|
||||
|
||||
// Update spawn controller (pauses when pause_spawn = true)
|
||||
// Note: The actual enemy array update happens in GameScene::update()
|
||||
// This is just for internal timekeeping
|
||||
@@ -135,7 +134,7 @@ void StageManager::processar_playing(float delta_time, bool pause_spawn) {
|
||||
(void)pause_spawn; // Passed to spawn_controller_.update() by GameScene
|
||||
}
|
||||
|
||||
void StageManager::processar_level_completed(float delta_time) {
|
||||
void StageManager::processLevelCompleted(float delta_time) {
|
||||
timer_transicio_ -= delta_time;
|
||||
|
||||
if (timer_transicio_ <= 0.0F) {
|
||||
@@ -150,13 +149,13 @@ void StageManager::processar_level_completed(float delta_time) {
|
||||
}
|
||||
|
||||
// Load next stage
|
||||
carregar_stage(stage_actual_);
|
||||
canviar_estat(EstatStage::LEVEL_START);
|
||||
loadStage(stage_actual_);
|
||||
changeState(EstatStage::LEVEL_START);
|
||||
}
|
||||
}
|
||||
|
||||
void StageManager::carregar_stage(uint8_t stage_id) {
|
||||
const StageConfig* stage_config = config_->obte_stage(stage_id);
|
||||
void StageManager::loadStage(uint8_t stage_id) {
|
||||
const StageConfig* stage_config = config_->findStage(stage_id);
|
||||
if (stage_config == nullptr) {
|
||||
std::cerr << "[StageManager] Error: no es pot trobar stage " << static_cast<int>(stage_id)
|
||||
<< '\n';
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace StageSystem {
|
||||
|
||||
// Estats del stage system
|
||||
enum class EstatStage {
|
||||
enum class EstatStage : std::uint8_t {
|
||||
INIT_HUD, // Animación inicial del HUD (3s)
|
||||
LEVEL_START, // Pantalla "ENEMY INCOMING" (3s)
|
||||
PLAYING, // Gameplay normal
|
||||
@@ -28,36 +28,37 @@ class StageManager {
|
||||
void update(float delta_time, bool pause_spawn = false);
|
||||
|
||||
// Stage progression
|
||||
void stage_completat(); // Call when all enemies destroyed
|
||||
[[nodiscard]] bool tot_completat() const; // All 10 stages done?
|
||||
void markStageCompleted(); // Call when all enemies destroyed
|
||||
[[nodiscard]] auto isGameComplete() const -> bool; // All 10 stages done?
|
||||
|
||||
// Current state queries
|
||||
[[nodiscard]] EstatStage get_estat() const { return estat_; }
|
||||
[[nodiscard]] uint8_t get_stage_actual() const { return stage_actual_; }
|
||||
[[nodiscard]] const StageConfig* get_config_actual() const;
|
||||
[[nodiscard]] float get_timer_transicio() const { return timer_transicio_; }
|
||||
[[nodiscard]] const std::string& get_missatge_level_start() const { return missatge_level_start_actual_; }
|
||||
[[nodiscard]] auto getState() const -> EstatStage { return estat_; }
|
||||
[[nodiscard]] auto getCurrentStage() const -> uint8_t { return stage_actual_; }
|
||||
[[nodiscard]] auto getCurrentConfig() const -> const StageConfig*;
|
||||
[[nodiscard]] auto getTransitionTimer() const -> float { return timer_transicio_; }
|
||||
[[nodiscard]] auto getLevelStartMessage() const -> const std::string& { return missatge_level_start_actual_; }
|
||||
|
||||
// Spawn control (delegate to SpawnController)
|
||||
SpawnController& getSpawnController() { return spawn_controller_; }
|
||||
[[nodiscard]] const SpawnController& getSpawnController() const { return spawn_controller_; }
|
||||
auto getSpawnController() -> SpawnController& { return spawn_controller_; }
|
||||
[[nodiscard]] auto getSpawnController() const -> const SpawnController& { return spawn_controller_; }
|
||||
|
||||
private:
|
||||
const StageSystemConfig* config_; // Non-owning pointer
|
||||
SpawnController spawn_controller_;
|
||||
|
||||
EstatStage estat_;
|
||||
uint8_t stage_actual_; // 1-10
|
||||
float timer_transicio_; // Timer for LEVEL_START/LEVEL_COMPLETED (3.0s → 0.0s)
|
||||
EstatStage estat_{EstatStage::LEVEL_START};
|
||||
uint8_t stage_actual_{1}; // 1-10
|
||||
float timer_transicio_{0.0F}; // Timer for LEVEL_START/LEVEL_COMPLETED (3.0s → 0.0s)
|
||||
std::string missatge_level_start_actual_; // Missatge seleccionat per al level actual
|
||||
|
||||
// State transitions
|
||||
void canviar_estat(EstatStage nou_estat);
|
||||
void processar_init_hud(float delta_time);
|
||||
void processar_level_start(float delta_time);
|
||||
void processar_playing(float delta_time, bool pause_spawn);
|
||||
void processar_level_completed(float delta_time);
|
||||
void carregar_stage(uint8_t stage_id);
|
||||
void changeState(EstatStage nou_estat);
|
||||
void processInitHud(float delta_time);
|
||||
void processLevelStart(float delta_time);
|
||||
// Estático: solo registra log; no consulta estado del manager.
|
||||
static void processPlaying(float delta_time, bool pause_spawn);
|
||||
void processLevelCompleted(float delta_time);
|
||||
void loadStage(uint8_t stage_id);
|
||||
};
|
||||
|
||||
} // namespace StageSystem
|
||||
|
||||
@@ -16,12 +16,12 @@ void detectBulletEnemy(Context& ctx) {
|
||||
|
||||
for (auto& bullet : ctx.bullets) {
|
||||
for (auto& enemy : ctx.enemies) {
|
||||
if (!Physics::check_collision(bullet, enemy, AMPLIFIER)) {
|
||||
if (!Physics::checkCollision(bullet, enemy, AMPLIFIER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// *** COLISIÓN bullet → enemy ***
|
||||
const Vec2& POS_ENEMIC = enemy.getCenter();
|
||||
const Vec2& enemy_pos = enemy.getCenter();
|
||||
|
||||
// 1. Puntos según tipo
|
||||
int points = 0;
|
||||
@@ -39,7 +39,7 @@ void detectBulletEnemy(Context& ctx) {
|
||||
|
||||
uint8_t owner_id = bullet.getOwnerId();
|
||||
ctx.score_per_player[owner_id] += points;
|
||||
ctx.floating_score_manager.crear(points, POS_ENEMIC);
|
||||
ctx.floating_score_manager.crear(points, enemy_pos);
|
||||
|
||||
// 2. Destruir enemy + crear explosión (debris hereda color del enemy)
|
||||
SDL_Color enemy_color{};
|
||||
@@ -52,7 +52,7 @@ void detectBulletEnemy(Context& ctx) {
|
||||
Vec2 vel_enemic = enemy.getVelocityVector();
|
||||
ctx.debris_manager.explode(
|
||||
enemy.getShape(),
|
||||
POS_ENEMIC,
|
||||
enemy_pos,
|
||||
0.0F, // angle (la rotación es interna del enemy)
|
||||
1.0F, // escala
|
||||
VELOCITAT_EXPLOSIO,
|
||||
@@ -86,7 +86,7 @@ void detectShipEnemy(Context& ctx) {
|
||||
if (enemy.isInvulnerable()) {
|
||||
continue;
|
||||
}
|
||||
if (Physics::check_collision(ctx.ships[i], enemy, AMPLIFIER)) {
|
||||
if (Physics::checkCollision(ctx.ships[i], enemy, AMPLIFIER)) {
|
||||
ctx.on_player_hit(i);
|
||||
break; // Solo una colisión por player por frame
|
||||
}
|
||||
@@ -102,7 +102,7 @@ void detectBulletPlayer(Context& ctx) {
|
||||
constexpr float AMPLIFIER = Defaults::Game::COLLISION_BULLET_PLAYER_AMPLIFIER;
|
||||
|
||||
for (auto& bullet : ctx.bullets) {
|
||||
if (!bullet.esta_activa() || bullet.getGraceTimer() > 0.0F) {
|
||||
if (!bullet.isActive() || bullet.getGraceTimer() > 0.0F) {
|
||||
continue;
|
||||
}
|
||||
const uint8_t BULLET_OWNER = bullet.getOwnerId();
|
||||
@@ -120,7 +120,7 @@ void detectBulletPlayer(Context& ctx) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Physics::check_collision(bullet, ctx.ships[player_id], AMPLIFIER)) {
|
||||
if (!Physics::checkCollision(bullet, ctx.ships[player_id], AMPLIFIER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Systems::Collision {
|
||||
struct Context {
|
||||
std::array<Ship, 2>& ships;
|
||||
std::array<Enemy, Defaults::Entities::MAX_ORNIS>& enemies;
|
||||
std::array<Bullet, Defaults::Entities::MAX_BALES * 2>& bullets;
|
||||
std::array<Bullet, static_cast<std::size_t>(Defaults::Entities::MAX_BALES) * 2>& bullets;
|
||||
std::array<float, 2>& hit_timer_per_player;
|
||||
std::array<int, 2>& score_per_player;
|
||||
std::array<int, 2>& lives_per_player;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
@@ -30,22 +29,22 @@ auto computeRangeProgress(float global_progress,
|
||||
}
|
||||
|
||||
auto computeShipPosition(float progress, const Vec2& final_position) -> Vec2 {
|
||||
const float EASED = Easing::ease_out_quad(progress);
|
||||
const SDL_FRect& ZONA = Defaults::Zones::PLAYAREA;
|
||||
const float EASED = Easing::easeOutQuad(progress);
|
||||
const SDL_FRect& zone = Defaults::Zones::PLAYAREA;
|
||||
// Y inicial: 50 px bajo la zona de juego.
|
||||
const float Y_INI = ZONA.y + ZONA.h + 50.0F;
|
||||
const float Y_INI = zone.y + zone.h + 50.0F;
|
||||
const float Y_ANIM = Y_INI + ((final_position.y - Y_INI) * EASED);
|
||||
return Vec2{.x = final_position.x, .y = Y_ANIM};
|
||||
}
|
||||
|
||||
void drawBordersAnimated(Rendering::Renderer* renderer, float progress) {
|
||||
const SDL_FRect& ZONA = Defaults::Zones::PLAYAREA;
|
||||
const float EASED = Easing::ease_out_quad(progress);
|
||||
const SDL_FRect& zone = Defaults::Zones::PLAYAREA;
|
||||
const float EASED = Easing::easeOutQuad(progress);
|
||||
|
||||
const int X1 = static_cast<int>(ZONA.x);
|
||||
const int Y1 = static_cast<int>(ZONA.y);
|
||||
const int X2 = static_cast<int>(ZONA.x + ZONA.w);
|
||||
const int Y2 = static_cast<int>(ZONA.y + ZONA.h);
|
||||
const int X1 = static_cast<int>(zone.x);
|
||||
const int Y1 = static_cast<int>(zone.y);
|
||||
const int X2 = static_cast<int>(zone.x + zone.w);
|
||||
const int Y2 = static_cast<int>(zone.y + zone.h);
|
||||
const int CX = (X1 + X2) / 2;
|
||||
|
||||
constexpr float PHASE_1_END = 0.33F;
|
||||
@@ -78,16 +77,16 @@ void drawBordersAnimated(Rendering::Renderer* renderer, float progress) {
|
||||
}
|
||||
}
|
||||
|
||||
void drawScoreboardAnimated(Graphics::VectorText& text,
|
||||
void drawScoreboardAnimated(const Graphics::VectorText& text,
|
||||
const std::string& scoreboard_text,
|
||||
float progress) {
|
||||
const float EASED = Easing::ease_out_quad(progress);
|
||||
const float EASED = Easing::easeOutQuad(progress);
|
||||
|
||||
constexpr float SCALE = 0.85F;
|
||||
constexpr float SPACING = 0.0F;
|
||||
const SDL_FRect& SCOREBOARD = Defaults::Zones::SCOREBOARD;
|
||||
const float CENTRE_X = SCOREBOARD.w / 2.0F;
|
||||
const float Y_FINAL = SCOREBOARD.y + (SCOREBOARD.h / 2.0F);
|
||||
const SDL_FRect& scoreboard_zone = Defaults::Zones::SCOREBOARD;
|
||||
const float CENTRE_X = scoreboard_zone.w / 2.0F;
|
||||
const float Y_FINAL = scoreboard_zone.y + (scoreboard_zone.h / 2.0F);
|
||||
// Posición inicial: fuera de la pantalla por debajo.
|
||||
const auto Y_INI = static_cast<float>(Defaults::Game::HEIGHT);
|
||||
const float Y_ANIM = Y_INI + ((Y_FINAL - Y_INI) * EASED);
|
||||
|
||||
@@ -42,7 +42,7 @@ void drawBordersAnimated(Rendering::Renderer* renderer, float progress);
|
||||
|
||||
// Dibuja el scoreboard centrado, subiendo desde fuera de la pantalla
|
||||
// hasta su posición final con easing.
|
||||
void drawScoreboardAnimated(Graphics::VectorText& text,
|
||||
void drawScoreboardAnimated(const Graphics::VectorText& text,
|
||||
const std::string& scoreboard_text,
|
||||
float progress);
|
||||
|
||||
|
||||
@@ -25,12 +25,12 @@ void ShipAnimator::init() {
|
||||
// Configurar ship P1
|
||||
ships_[0].player_id = 1;
|
||||
ships_[0].shape = forma_p1;
|
||||
configurar_nau_p1(ships_[0]);
|
||||
configureShipP1(ships_[0]);
|
||||
|
||||
// Configurar ship P2
|
||||
ships_[1].player_id = 2;
|
||||
ships_[1].shape = forma_p2;
|
||||
configurar_nau_p2(ships_[1]);
|
||||
configureShipP2(ships_[1]);
|
||||
}
|
||||
|
||||
void ShipAnimator::update(float delta_time) {
|
||||
@@ -42,13 +42,13 @@ void ShipAnimator::update(float delta_time) {
|
||||
|
||||
switch (ship.state) {
|
||||
case ShipState::ENTERING:
|
||||
actualitzar_entering(ship, delta_time);
|
||||
updateEntering(ship, delta_time);
|
||||
break;
|
||||
case ShipState::FLOATING:
|
||||
actualitzar_floating(ship, delta_time);
|
||||
updateFloating(ship, delta_time);
|
||||
break;
|
||||
case ShipState::EXITING:
|
||||
actualitzar_exiting(ship, delta_time);
|
||||
updateExiting(ship, delta_time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ void ShipAnimator::draw() const {
|
||||
}
|
||||
|
||||
// Renderizar ship (perspectiva ya incorporada a la shape)
|
||||
Rendering::render_shape(
|
||||
Rendering::renderShape(
|
||||
renderer_,
|
||||
ship.shape,
|
||||
ship.current_position,
|
||||
@@ -73,25 +73,25 @@ void ShipAnimator::draw() const {
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::start_entry_animation() {
|
||||
void ShipAnimator::startEntryAnimation() {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Configurar ship P1 para l'animación de entrada
|
||||
ships_[0].state = ShipState::ENTERING;
|
||||
ships_[0].state_time = 0.0F;
|
||||
ships_[0].initial_position = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE);
|
||||
ships_[0].initial_position = computeOffscreenPosition(CLOCK_8_ANGLE);
|
||||
ships_[0].current_position = ships_[0].initial_position;
|
||||
ships_[0].current_scale = ships_[0].initial_scale;
|
||||
|
||||
// Configurar ship P2 para l'animación de entrada
|
||||
ships_[1].state = ShipState::ENTERING;
|
||||
ships_[1].state_time = 0.0F;
|
||||
ships_[1].initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
ships_[1].initial_position = computeOffscreenPosition(CLOCK_4_ANGLE);
|
||||
ships_[1].current_position = ships_[1].initial_position;
|
||||
ships_[1].current_scale = ships_[1].initial_scale;
|
||||
}
|
||||
|
||||
void ShipAnimator::trigger_exit_animation() {
|
||||
void ShipAnimator::triggerExitAnimation() {
|
||||
// Configurar ambdues naves para l'animación de salida
|
||||
for (auto& ship : ships_) {
|
||||
// Canviar state a EXITING
|
||||
@@ -106,7 +106,7 @@ void ShipAnimator::trigger_exit_animation() {
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::skip_to_floating_state() {
|
||||
void ShipAnimator::skipToFloatingState() {
|
||||
// Posar ambdues naves directament en state FLOATING
|
||||
for (auto& ship : ships_) {
|
||||
ship.state = ShipState::FLOATING;
|
||||
@@ -122,17 +122,12 @@ void ShipAnimator::skip_to_floating_state() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ShipAnimator::is_visible() const {
|
||||
auto ShipAnimator::isVisible() const -> bool {
|
||||
// Retorna true si almenys una ship es visible
|
||||
for (const auto& ship : ships_) {
|
||||
if (ship.visible) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return std::ranges::any_of(ships_, [](const TitleShip& ship) { return ship.visible; });
|
||||
}
|
||||
|
||||
void ShipAnimator::trigger_exit_animation_for_player(int player_id) {
|
||||
void ShipAnimator::triggerExitAnimationForPlayer(int player_id) {
|
||||
// Trobar la ship del player especificat
|
||||
for (auto& ship : ships_) {
|
||||
if (ship.player_id == player_id) {
|
||||
@@ -150,24 +145,19 @@ void ShipAnimator::trigger_exit_animation_for_player(int player_id) {
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::set_visible(bool visible) {
|
||||
void ShipAnimator::setVisible(bool visible) {
|
||||
for (auto& ship : ships_) {
|
||||
ship.visible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
bool ShipAnimator::is_animation_complete() const {
|
||||
auto ShipAnimator::isAnimationComplete() const -> bool {
|
||||
// Comprovar si todas las naves són invisibles (han completat l'animación de salida)
|
||||
for (const auto& ship : ships_) {
|
||||
if (ship.visible) {
|
||||
return false; // Aún hay alguna ship visible
|
||||
}
|
||||
}
|
||||
return true; // Todas las naves són invisibles
|
||||
return std::ranges::all_of(ships_, [](const TitleShip& ship) { return !ship.visible; });
|
||||
}
|
||||
|
||||
// Métodos de animación (stubs)
|
||||
void ShipAnimator::actualitzar_entering(TitleShip& ship, float delta_time) {
|
||||
void ShipAnimator::updateEntering(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
ship.state_time += delta_time;
|
||||
@@ -185,7 +175,7 @@ void ShipAnimator::actualitzar_entering(TitleShip& ship, float delta_time) {
|
||||
float progress = std::min(1.0F, elapsed / ENTRY_DURATION);
|
||||
|
||||
// Aplicar easing (ease_out_quad per arribada suau)
|
||||
float eased_progress = Easing::ease_out_quad(progress);
|
||||
float eased_progress = Easing::easeOutQuad(progress);
|
||||
|
||||
// Lerp posición (inicial → objetivo)
|
||||
ship.current_position.x = Easing::lerp(ship.initial_position.x, ship.target_position.x, eased_progress);
|
||||
@@ -202,7 +192,7 @@ void ShipAnimator::actualitzar_entering(TitleShip& ship, float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::actualitzar_floating(TitleShip& ship, float delta_time) {
|
||||
void ShipAnimator::updateFloating(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Actualitzar time i fase de oscil·lació
|
||||
@@ -221,7 +211,7 @@ void ShipAnimator::actualitzar_floating(TitleShip& ship, float delta_time) {
|
||||
ship.current_scale = ship.target_scale;
|
||||
}
|
||||
|
||||
void ShipAnimator::actualitzar_exiting(TitleShip& ship, float delta_time) {
|
||||
void ShipAnimator::updateExiting(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
ship.state_time += delta_time;
|
||||
@@ -230,15 +220,15 @@ void ShipAnimator::actualitzar_exiting(TitleShip& ship, float delta_time) {
|
||||
float progress = std::min(1.0F, ship.state_time / EXIT_DURATION);
|
||||
|
||||
// Aplicar easing (ease_in_quad per aceleración hacia el point de fuga)
|
||||
float eased_progress = Easing::ease_in_quad(progress);
|
||||
float eased_progress = Easing::easeInQuad(progress);
|
||||
|
||||
// Vec2 de fuga (centro del starfield)
|
||||
constexpr Vec2 punt_fuga{.x = VANISHING_POINT_X, .y = VANISHING_POINT_Y};
|
||||
constexpr Vec2 VANISHING_POINT{.x = VANISHING_POINT_X, .y = VANISHING_POINT_Y};
|
||||
|
||||
// Lerp posición hacia el point de fuga (preservar posición inicial actual)
|
||||
// Nota: initial_position conté la posición on estava cuando es va activar EXITING
|
||||
ship.current_position.x = Easing::lerp(ship.initial_position.x, punt_fuga.x, eased_progress);
|
||||
ship.current_position.y = Easing::lerp(ship.initial_position.y, punt_fuga.y, eased_progress);
|
||||
ship.current_position.x = Easing::lerp(ship.initial_position.x, VANISHING_POINT.x, eased_progress);
|
||||
ship.current_position.y = Easing::lerp(ship.initial_position.y, VANISHING_POINT.y, eased_progress);
|
||||
|
||||
// Escala redueix a 0 (simula Z → infinit)
|
||||
ship.current_scale = ship.target_scale * (1.0F - eased_progress);
|
||||
@@ -250,7 +240,7 @@ void ShipAnimator::actualitzar_exiting(TitleShip& ship, float delta_time) {
|
||||
}
|
||||
|
||||
// Configuración
|
||||
void ShipAnimator::configurar_nau_p1(TitleShip& ship) {
|
||||
void ShipAnimator::configureShipP1(TitleShip& ship) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Estat inicial: FLOATING (per test estàtic)
|
||||
@@ -258,10 +248,10 @@ void ShipAnimator::configurar_nau_p1(TitleShip& ship) {
|
||||
ship.state_time = 0.0F;
|
||||
|
||||
// Posicions (clock 8, bottom-left)
|
||||
ship.target_position = {.x = P1_TARGET_X(), .y = P1_TARGET_Y()};
|
||||
ship.target_position = {.x = p1TargetX(), .y = p1TargetY()};
|
||||
|
||||
// Calcular posición inicial (fuera de pantalla)
|
||||
ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE);
|
||||
ship.initial_position = computeOffscreenPosition(CLOCK_8_ANGLE);
|
||||
ship.current_position = ship.initial_position; // Començar fuera de pantalla
|
||||
|
||||
// Escales
|
||||
@@ -285,7 +275,7 @@ void ShipAnimator::configurar_nau_p1(TitleShip& ship) {
|
||||
ship.visible = true;
|
||||
}
|
||||
|
||||
void ShipAnimator::configurar_nau_p2(TitleShip& ship) {
|
||||
void ShipAnimator::configureShipP2(TitleShip& ship) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Estat inicial: FLOATING (per test estàtic)
|
||||
@@ -293,10 +283,10 @@ void ShipAnimator::configurar_nau_p2(TitleShip& ship) {
|
||||
ship.state_time = 0.0F;
|
||||
|
||||
// Posicions (clock 4, bottom-right)
|
||||
ship.target_position = {.x = P2_TARGET_X(), .y = P2_TARGET_Y()};
|
||||
ship.target_position = {.x = p2TargetX(), .y = p2TargetY()};
|
||||
|
||||
// Calcular posición inicial (fuera de pantalla)
|
||||
ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
ship.initial_position = computeOffscreenPosition(CLOCK_4_ANGLE);
|
||||
ship.current_position = ship.initial_position; // Començar fuera de pantalla
|
||||
|
||||
// Escales
|
||||
@@ -320,7 +310,7 @@ void ShipAnimator::configurar_nau_p2(TitleShip& ship) {
|
||||
ship.visible = true;
|
||||
}
|
||||
|
||||
Vec2 ShipAnimator::calcular_posicio_fora_pantalla(float angle_rellotge) const {
|
||||
auto ShipAnimator::computeOffscreenPosition(float angle_rellotge) -> Vec2 {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Convertir angle del rellotge a radians (per exemple: 240° per clock 8)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "core/graphics/shape.hpp"
|
||||
@@ -16,48 +17,51 @@
|
||||
namespace Title {
|
||||
|
||||
// Estats de l'animación de la ship
|
||||
enum class ShipState {
|
||||
enum class ShipState : std::uint8_t {
|
||||
ENTERING, // Entrant desde fuera de pantalla
|
||||
FLOATING, // Flotante en posición estàtica
|
||||
EXITING // Volant hacia el point de fuga
|
||||
};
|
||||
|
||||
// Dades de una ship individual al título
|
||||
// Dades de una ship individual al título.
|
||||
// Todos los miembros tienen inicializador por defecto: ShipAnimator::ships_
|
||||
// es un std::array<TitleShip, 2> y sin estos defaults los campos primitivos
|
||||
// quedarían indeterminados al instanciar el animador.
|
||||
struct TitleShip {
|
||||
// Identificació
|
||||
int player_id; // 1 o 2
|
||||
int player_id{0}; // 1 o 2
|
||||
|
||||
// Estat
|
||||
ShipState state;
|
||||
float state_time; // Temps acumulat en l'state actual
|
||||
ShipState state{ShipState::ENTERING};
|
||||
float state_time{0.0F}; // Temps acumulat en l'state actual
|
||||
|
||||
// Posicions
|
||||
Vec2 initial_position; // Posición de start (fuera de pantalla per ENTERING)
|
||||
Vec2 target_position; // Posición objetivo (rellotge 8 o 4)
|
||||
Vec2 current_position; // Posición interpolada actual
|
||||
Vec2 initial_position{}; // Posición de start (fuera de pantalla per ENTERING)
|
||||
Vec2 target_position{}; // Posición objetivo (rellotge 8 o 4)
|
||||
Vec2 current_position{}; // Posición interpolada actual
|
||||
|
||||
// Escales (simulació eix Z)
|
||||
float initial_scale; // Escala de start (més grande = més a prop)
|
||||
float target_scale; // Escala objetivo (mida flotació)
|
||||
float current_scale; // Escala interpolada actual
|
||||
float initial_scale{1.0F}; // Escala de start (més grande = més a prop)
|
||||
float target_scale{1.0F}; // Escala objetivo (mida flotació)
|
||||
float current_scale{1.0F}; // Escala interpolada actual
|
||||
|
||||
// Flotació
|
||||
float oscillation_phase; // Acumulador de fase per movement sinusoïdal
|
||||
float oscillation_phase{0.0F}; // Acumulador de fase per movement sinusoïdal
|
||||
|
||||
// Parámetros de entrada
|
||||
float entry_delay; // Delay antes de entrar (0.0 per P1, 0.5 per P2)
|
||||
float entry_delay{0.0F}; // Delay antes de entrar (0.0 per P1, 0.5 per P2)
|
||||
|
||||
// Parámetros de oscil·lació per ship
|
||||
float amplitude_x;
|
||||
float amplitude_y;
|
||||
float frequency_x;
|
||||
float frequency_y;
|
||||
float amplitude_x{0.0F};
|
||||
float amplitude_y{0.0F};
|
||||
float frequency_x{0.0F};
|
||||
float frequency_y{0.0F};
|
||||
|
||||
// Forma
|
||||
std::shared_ptr<Graphics::Shape> shape;
|
||||
|
||||
// Visibilitat
|
||||
bool visible;
|
||||
bool visible{false};
|
||||
};
|
||||
|
||||
// Gestor de animación de naves para l'escena de título
|
||||
@@ -71,29 +75,30 @@ class ShipAnimator {
|
||||
void draw() const;
|
||||
|
||||
// Control de state (cridat per TitleScene)
|
||||
void start_entry_animation();
|
||||
void trigger_exit_animation(); // Anima todas las naves
|
||||
void trigger_exit_animation_for_player(int player_id); // Anima solo una ship (P1=1, P2=2)
|
||||
void skip_to_floating_state(); // Salta directament a FLOATING sin animación
|
||||
void startEntryAnimation();
|
||||
void triggerExitAnimation(); // Anima todas las naves
|
||||
void triggerExitAnimationForPlayer(int player_id); // Anima solo una ship (P1=1, P2=2)
|
||||
void skipToFloatingState(); // Salta directament a FLOATING sin animación
|
||||
|
||||
// Control de visibilitat
|
||||
void set_visible(bool visible);
|
||||
[[nodiscard]] bool is_animation_complete() const;
|
||||
[[nodiscard]] bool is_visible() const; // Comprova si alguna ship es visible
|
||||
void setVisible(bool visible);
|
||||
[[nodiscard]] auto isAnimationComplete() const -> bool;
|
||||
[[nodiscard]] auto isVisible() const -> bool; // Comprova si alguna ship es visible
|
||||
|
||||
private:
|
||||
Rendering::Renderer* renderer_;
|
||||
std::array<TitleShip, 2> ships_; // Naves P1 i P2
|
||||
|
||||
// Métodos de animación
|
||||
void actualitzar_entering(TitleShip& ship, float delta_time);
|
||||
void actualitzar_floating(TitleShip& ship, float delta_time);
|
||||
void actualitzar_exiting(TitleShip& ship, float delta_time);
|
||||
// Métodos de animación. Estáticos: solo modifican el TitleShip pasado,
|
||||
// sin tocar otros miembros del ShipAnimator.
|
||||
static void updateEntering(TitleShip& ship, float delta_time);
|
||||
static void updateFloating(TitleShip& ship, float delta_time);
|
||||
static void updateExiting(TitleShip& ship, float delta_time);
|
||||
|
||||
// Configuración
|
||||
void configurar_nau_p1(TitleShip& ship);
|
||||
void configurar_nau_p2(TitleShip& ship);
|
||||
[[nodiscard]] Vec2 calcular_posicio_fora_pantalla(float angle_rellotge) const;
|
||||
// Configuración (también estáticos: trabajan sobre el ship pasado).
|
||||
static void configureShipP1(TitleShip& ship);
|
||||
static void configureShipP2(TitleShip& ship);
|
||||
[[nodiscard]] static auto computeOffscreenPosition(float angle_rellotge) -> Vec2;
|
||||
};
|
||||
|
||||
} // namespace Title
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "core/system/director.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
auto main(int argc, char* argv[]) -> int {
|
||||
// Convertir arguments a std::vector<std::string>
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
|
||||
@@ -14,5 +14,5 @@ int main(int argc, char* argv[]) {
|
||||
Director director(args);
|
||||
|
||||
// Executar bucle principal del juego
|
||||
return director.run();
|
||||
return Director::run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user