Fase 0: eliminar tot el codi llegacy (polars + primitives + bool dibuixar)
Aplicada la directiva "res llegacy" abans d'arrencar la migracio a fisica vectorial + SDL3 GPU. Cada bossa de cruft que arrossegava el port de Pascal queda eliminada. Borrats (huerfanos): - source/core/rendering/primitives.hpp/.cpp (modul/diferencia/angle_punt/ crear_poligon_regular) - source/core/rendering/polygon_renderer.hpp/.cpp (rota_tri/rota_pol) - core::types::Triangle, Poligon, IPunt - Defaults::Entities::MAX_IPUNTS i alias a constants.hpp - EscenaJoc::chatarra_cosmica_ (mai usat) - Bresenham comentat dins de Rendering::linea() Simplificat (parametre 'dibuixar' llegacy que sempre era true): - Rendering::linea(...): treta la signatura bool dibuixar, retorn void - Rendering::render_shape(...): treta la signatura bool dibuixar - 11 callsites de linea() actualitzats (escena_joc, debris_manager) - 12 callsites de render_shape() actualitzats Modernitzats: - 5 fitxers .shp netejats de comentaris polar->cartesia historics - types.hpp queda nomes amb Punt (l'unica coordenada del joc) - debris_manager.hpp afegit include explicit de defaults.hpp Net: 452 linies eliminades, 56 afegides. Compila i enllaca correctament. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -101,7 +101,6 @@ constexpr float SCOREBOARD_PADDING_H = 0.0F; // Game::WIDTH * 0.015f;
|
||||
namespace Entities {
|
||||
constexpr int MAX_ORNIS = 15;
|
||||
constexpr int MAX_BALES = 3;
|
||||
constexpr int MAX_IPUNTS = 30;
|
||||
|
||||
constexpr float SHIP_RADIUS = 12.0F;
|
||||
constexpr float ENEMY_RADIUS = 20.0F;
|
||||
|
||||
@@ -162,7 +162,6 @@ void Starfield::dibuixar() {
|
||||
estrella.posicio,
|
||||
0.0F, // angle (les estrelles no giren)
|
||||
escala, // escala dinàmica
|
||||
true, // dibuixar
|
||||
1.0F, // progress (sempre visible)
|
||||
brightness // brightness dinàmica
|
||||
);
|
||||
|
||||
@@ -224,7 +224,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
// Ajustar X e Y para que posicio represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Punt char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, true, 1.0F, brightness);
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, 1.0F, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
|
||||
@@ -4,99 +4,35 @@
|
||||
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "core/rendering/coordinate_transform.hpp"
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// [NUEVO] Color global compartit (actualitzat per ColorOscillator via
|
||||
// SDLManager)
|
||||
SDL_Color g_current_line_color = {255, 255, 255, 255}; // Blanc inicial
|
||||
// Color global compartit (actualitzat per ColorOscillator via SDLManager)
|
||||
SDL_Color g_current_line_color = {255, 255, 255, 255};
|
||||
|
||||
bool linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, bool dibuixar, float brightness) {
|
||||
// Algorisme de Bresenham per dibuixar línies
|
||||
// Basat en el codi Pascal original
|
||||
|
||||
// Helper function: retorna el signe d'un nombre
|
||||
auto sign = [](int x) -> int {
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (x > 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
// Variables per a l'algorisme (no utilitzades fins Fase 10 - detecció de
|
||||
// col·lisions) int x = x1, y = y1; int xs = x2 - x1; int ys = y2 - y1; int
|
||||
// xm = sign(xs); int ym = sign(ys); xs = std::abs(xs); ys = std::abs(ys);
|
||||
|
||||
// Suprimir warning de variable no usada
|
||||
(void)sign;
|
||||
|
||||
// Detecció de col·lisió (TODO per Fase 10)
|
||||
// El codi Pascal original llegia pixels del framebuffer bit-packed
|
||||
// i comptava col·lisions. Per ara, usem SDL_RenderDrawLine i retornem false.
|
||||
bool colisio = false;
|
||||
|
||||
// Dibuixar amb SDL3 (més eficient que Bresenham píxel a píxel)
|
||||
if (dibuixar && (renderer != nullptr)) {
|
||||
// Transformar coordenades lògiques (640x480) a físiques (resolució real)
|
||||
float scale = g_current_scale_factor;
|
||||
int px1 = transform_x(x1, scale);
|
||||
int py1 = transform_y(y1, scale);
|
||||
int px2 = transform_x(x2, scale);
|
||||
int py2 = transform_y(y2, scale);
|
||||
|
||||
// Aplicar brightness al color oscil·lat global
|
||||
SDL_Color color_final;
|
||||
color_final.r = static_cast<uint8_t>(g_current_line_color.r * brightness);
|
||||
color_final.g = static_cast<uint8_t>(g_current_line_color.g * brightness);
|
||||
color_final.b = static_cast<uint8_t>(g_current_line_color.b * brightness);
|
||||
color_final.a = 255;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, color_final.r, color_final.g, color_final.b, 255);
|
||||
|
||||
// Renderitzar amb coordenades físiques
|
||||
SDL_RenderLine(renderer, static_cast<float>(px1), static_cast<float>(py1), static_cast<float>(px2), static_cast<float>(py2));
|
||||
void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness) {
|
||||
if (renderer == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Algorisme de Bresenham original (conservat per a futura detecció de
|
||||
// col·lisió)
|
||||
/*
|
||||
if (xs > ys) {
|
||||
// Línia plana (<45 graus)
|
||||
int count = -(xs / 2);
|
||||
while (x != x2) {
|
||||
count = count + ys;
|
||||
x = x + xm;
|
||||
if (count > 0) {
|
||||
y = y + ym;
|
||||
count = count - xs;
|
||||
}
|
||||
// Aquí aniria la detecció de col·lisió píxel a píxel
|
||||
}
|
||||
} else {
|
||||
// Línia pronunciada (>=45 graus)
|
||||
int count = -(ys / 2);
|
||||
while (y != y2) {
|
||||
count = count + xs;
|
||||
y = y + ym;
|
||||
if (count > 0) {
|
||||
x = x + xm;
|
||||
count = count - ys;
|
||||
}
|
||||
// Aquí aniria la detecció de col·lisió píxel a píxel
|
||||
}
|
||||
}
|
||||
*/
|
||||
// Transformar coordenades lògiques (640x480) a físiques (resolució real)
|
||||
const float SCALE = g_current_scale_factor;
|
||||
const int PX1 = transform_x(x1, SCALE);
|
||||
const int PY1 = transform_y(y1, SCALE);
|
||||
const int PX2 = transform_x(x2, SCALE);
|
||||
const int PY2 = transform_y(y2, SCALE);
|
||||
|
||||
return colisio;
|
||||
// Aplicar brightness al color oscil·lat global
|
||||
const auto R = static_cast<uint8_t>(g_current_line_color.r * brightness);
|
||||
const auto G = static_cast<uint8_t>(g_current_line_color.g * brightness);
|
||||
const auto B = static_cast<uint8_t>(g_current_line_color.b * brightness);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, R, G, B, 255);
|
||||
SDL_RenderLine(renderer, static_cast<float>(PX1), static_cast<float>(PY1),
|
||||
static_cast<float>(PX2), static_cast<float>(PY2));
|
||||
}
|
||||
|
||||
// [NUEVO] Establir el color global de les línies
|
||||
void setLineColor(SDL_Color color) { g_current_line_color = color; }
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
namespace Rendering {
|
||||
// Algorisme de Bresenham per dibuixar línies
|
||||
// Retorna true si hi ha col·lisió (per Fase 10)
|
||||
// brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
bool linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, bool dibuixar, float brightness = 1.0F);
|
||||
|
||||
// [NUEVO] Establir el color global de les línies (oscil·lació)
|
||||
// Dibuixa una línia entre dos punts en coordenades lògiques (640x480).
|
||||
// brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor).
|
||||
void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness = 1.0F);
|
||||
|
||||
// Estableix el color global de les línies (utilitzat per ColorOscillator).
|
||||
void setLineColor(SDL_Color color);
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
// polygon_renderer.cpp - Implementació de renderitzat de polígons
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
//
|
||||
// ==============================================================================
|
||||
// DEPRECATED: Use core/rendering/shape_renderer.cpp instead
|
||||
// ==============================================================================
|
||||
|
||||
#include "core/rendering/polygon_renderer.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
void rota_tri(SDL_Renderer* renderer, const Triangle& tri, float angul, float velocitat, bool dibuixar) {
|
||||
// Rotar i dibuixar triangle (nau)
|
||||
// Conversió de coordenades polars a cartesianes amb rotació
|
||||
// Basat en el codi Pascal original: lines 271-284
|
||||
|
||||
// Convertir cada punt polar a cartesià
|
||||
// x = (r + velocitat) * cos(angle_punt + angle_nau) + centre.x
|
||||
// y = (r + velocitat) * sin(angle_punt + angle_nau) + centre.y
|
||||
|
||||
int x1 = static_cast<int>(std::round((tri.p1.r + velocitat) *
|
||||
std::cos(tri.p1.angle + angul))) +
|
||||
tri.centre.x;
|
||||
|
||||
int y1 = static_cast<int>(std::round((tri.p1.r + velocitat) *
|
||||
std::sin(tri.p1.angle + angul))) +
|
||||
tri.centre.y;
|
||||
|
||||
int x2 = static_cast<int>(std::round((tri.p2.r + velocitat) *
|
||||
std::cos(tri.p2.angle + angul))) +
|
||||
tri.centre.x;
|
||||
|
||||
int y2 = static_cast<int>(std::round((tri.p2.r + velocitat) *
|
||||
std::sin(tri.p2.angle + angul))) +
|
||||
tri.centre.y;
|
||||
|
||||
int x3 = static_cast<int>(std::round((tri.p3.r + velocitat) *
|
||||
std::cos(tri.p3.angle + angul))) +
|
||||
tri.centre.x;
|
||||
|
||||
int y3 = static_cast<int>(std::round((tri.p3.r + velocitat) *
|
||||
std::sin(tri.p3.angle + angul))) +
|
||||
tri.centre.y;
|
||||
|
||||
// Dibuixar les 3 línies que formen el triangle
|
||||
linea(renderer, x1, y1, x2, y2, dibuixar);
|
||||
linea(renderer, x1, y1, x3, y3, dibuixar);
|
||||
linea(renderer, x3, y3, x2, y2, dibuixar);
|
||||
}
|
||||
|
||||
void rota_pol(SDL_Renderer* renderer, const Poligon& pol, float angul, bool dibuixar) {
|
||||
// Rotar i dibuixar polígon (enemics i bales)
|
||||
// Conversió de coordenades polars a cartesianes amb rotació
|
||||
// Basat en el codi Pascal original: lines 286-296
|
||||
|
||||
// Array temporal per emmagatzemar punts convertits a cartesianes
|
||||
std::array<Punt, Defaults::Entities::MAX_IPUNTS> xy;
|
||||
|
||||
// Convertir cada punt polar a cartesià
|
||||
for (uint8_t i = 0; i < pol.n; i++) {
|
||||
xy[i].x = static_cast<int>(std::round(
|
||||
pol.ipuntx[i].r * std::cos(pol.ipuntx[i].angle + angul))) +
|
||||
pol.centre.x;
|
||||
|
||||
xy[i].y = static_cast<int>(std::round(
|
||||
pol.ipuntx[i].r * std::sin(pol.ipuntx[i].angle + angul))) +
|
||||
pol.centre.y;
|
||||
}
|
||||
|
||||
// Dibuixar línies entre punts consecutius
|
||||
for (uint8_t i = 0; i < pol.n - 1; i++) {
|
||||
linea(renderer, xy[i].x, xy[i].y, xy[i + 1].x, xy[i + 1].y, dibuixar);
|
||||
}
|
||||
|
||||
// Tancar el polígon (últim punt → primer punt)
|
||||
linea(renderer, xy[pol.n - 1].x, xy[pol.n - 1].y, xy[0].x, xy[0].y, dibuixar);
|
||||
}
|
||||
|
||||
} // namespace Rendering
|
||||
@@ -1,22 +0,0 @@
|
||||
// polygon_renderer.hpp - Renderitzat de polígons polars
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
//
|
||||
// ==============================================================================
|
||||
// DEPRECATED: Use core/rendering/shape_renderer.hpp instead
|
||||
// ==============================================================================
|
||||
// This file is kept temporarily for chatarra_cosmica_ (Phase 10: explosions)
|
||||
// TODO Phase 10: Replace with particle system or remove completely
|
||||
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Rendering {
|
||||
// Rotar i dibuixar triangle (nau)
|
||||
void rota_tri(SDL_Renderer* renderer, const Triangle& tri, float angul, float velocitat, bool dibuixar);
|
||||
|
||||
// Rotar i dibuixar polígon (enemics i bales)
|
||||
void rota_pol(SDL_Renderer* renderer, const Poligon& pol, float angul, bool dibuixar);
|
||||
} // namespace Rendering
|
||||
@@ -1,66 +0,0 @@
|
||||
// primitives.cpp - Implementació de funcions geomètriques
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
//
|
||||
// ==============================================================================
|
||||
// DEPRECATED: Use Shape system instead (.shp files + ShapeLoader)
|
||||
// ==============================================================================
|
||||
|
||||
#include "primitives.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
|
||||
float modul(const Punt& p) {
|
||||
// Càlcul de la magnitud d'un vector: sqrt(x² + y²)
|
||||
return std::sqrt((p.x * p.x) + (p.y * p.y));
|
||||
}
|
||||
|
||||
void diferencia(const Punt& o, const Punt& d, Punt& p) {
|
||||
// Resta de vectors (origen - destí)
|
||||
p.x = o.x - d.x;
|
||||
p.y = o.y - d.y;
|
||||
}
|
||||
|
||||
int distancia(const Punt& o, const Punt& d) {
|
||||
// Distància entre dos punts
|
||||
Punt p;
|
||||
diferencia(o, d, p);
|
||||
return static_cast<int>(std::round(modul(p)));
|
||||
}
|
||||
|
||||
float angle_punt(const Punt& p) {
|
||||
// Càlcul de l'angle d'un punt (arctan)
|
||||
if (p.y != 0) {
|
||||
return std::atan(p.x / p.y);
|
||||
}
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
void crear_poligon_regular(Poligon& pol, uint8_t n, float r) {
|
||||
// Crear un polígon regular amb n costats i radi r
|
||||
// Distribueix els punts uniformement al voltant d'un cercle
|
||||
|
||||
float interval = 2.0F * Defaults::Math::PI / n;
|
||||
float act = 0.0F;
|
||||
|
||||
for (uint8_t i = 0; i < n; i++) {
|
||||
pol.ipuntx[i].r = r;
|
||||
pol.ipuntx[i].angle = act;
|
||||
act += interval;
|
||||
}
|
||||
|
||||
// Inicialitzar propietats del polígon
|
||||
pol.centre.x = 320.0F;
|
||||
pol.centre.y = 200.0F;
|
||||
pol.angle = 0.0F;
|
||||
// Convertir velocitat de px/frame a px/s: 2 px/frame × 20 FPS = 40 px/s
|
||||
pol.velocitat = Defaults::Physics::ENEMY_SPEED * 20.0F;
|
||||
pol.n = n;
|
||||
// Convertir rotació de rad/frame a rad/s: 0.0785 rad/frame × 20 FPS = 1.57
|
||||
// rad/s (~90°/s)
|
||||
pol.drotacio = 0.078539816F * 20.0F;
|
||||
pol.rotacio = 0.0F;
|
||||
pol.esta = true;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// primitives.hpp - Funcions geomètriques bàsiques
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
//
|
||||
// ==============================================================================
|
||||
// DEPRECATED: Use Shape system instead (.shp files + ShapeLoader)
|
||||
// ==============================================================================
|
||||
// This file is kept temporarily for chatarra_cosmica_ (Phase 10: explosions)
|
||||
// TODO Phase 10: Replace with particle system or remove completely
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "core/types.hpp"
|
||||
|
||||
// Funcions matemàtiques geomètriques pures (sense dependències d'estat)
|
||||
|
||||
// Càlcul de la magnitud d'un vector
|
||||
float modul(const Punt& p);
|
||||
|
||||
// Diferència entre dos punts (vector origen - destí)
|
||||
void diferencia(const Punt& o, const Punt& d, Punt& p);
|
||||
|
||||
// Distància entre dos punts
|
||||
int distancia(const Punt& o, const Punt& d);
|
||||
|
||||
// Càlcul de l'angle d'un punt
|
||||
float angle_punt(const Punt& p);
|
||||
|
||||
// Creació de polígons regulars
|
||||
void crear_poligon_regular(Poligon& pol, uint8_t n, float r);
|
||||
@@ -77,7 +77,6 @@ void render_shape(SDL_Renderer* renderer,
|
||||
const Punt& posicio,
|
||||
float angle,
|
||||
float escala,
|
||||
bool dibuixar,
|
||||
float progress,
|
||||
float brightness,
|
||||
const Rotation3D* rotation_3d) {
|
||||
@@ -102,7 +101,8 @@ void render_shape(SDL_Renderer* renderer,
|
||||
Punt p1 = transform_point(primitive.points[i], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Punt p2 = transform_point(primitive.points[i + 1], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y), static_cast<int>(p2.x), static_cast<int>(p2.y), dibuixar, brightness);
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
|
||||
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
|
||||
}
|
||||
} else { // PrimitiveType::LINE
|
||||
// LINE: exactament 2 punts
|
||||
@@ -110,7 +110,8 @@ void render_shape(SDL_Renderer* renderer,
|
||||
Punt p1 = transform_point(primitive.points[0], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Punt p2 = transform_point(primitive.points[1], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y), static_cast<int>(p2.x), static_cast<int>(p2.y), dibuixar, brightness);
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
|
||||
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ struct Rotation3D {
|
||||
// - posicio: posició del centre en coordenades mundials
|
||||
// - angle: rotació en radians (0 = amunt, sentit horari)
|
||||
// - escala: factor d'escala (1.0 = mida original)
|
||||
// - dibuixar: flag per dibuixar (false per col·lisions futures)
|
||||
// - progress: progrés de l'animació (0.0-1.0, default 1.0 = tot visible)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render_shape(SDL_Renderer* renderer,
|
||||
@@ -46,7 +45,6 @@ void render_shape(SDL_Renderer* renderer,
|
||||
const Punt& posicio,
|
||||
float angle,
|
||||
float escala = 1.0F,
|
||||
bool dibuixar = true,
|
||||
float progress = 1.0F,
|
||||
float brightness = 1.0F,
|
||||
const Rotation3D* rotation_3d = nullptr);
|
||||
|
||||
+1
-38
@@ -1,43 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
|
||||
// Punt polar (coordenades polars)
|
||||
struct IPunt {
|
||||
float r; // Radi
|
||||
float angle; // Angle en radians
|
||||
};
|
||||
|
||||
// Punt cartesià
|
||||
// Punt cartesià - ÚNICA estructura de coordenades del joc
|
||||
struct Punt {
|
||||
float x, y;
|
||||
};
|
||||
|
||||
// ==============================================================================
|
||||
// DEPRECATED: Legacy types (replaced by Shape system)
|
||||
// ==============================================================================
|
||||
// These types are kept temporarily for chatarra_cosmica_ (Phase 10: explosions)
|
||||
// TODO Phase 10: Replace with particle system or remove completely
|
||||
|
||||
// Nau (triangle) - DEPRECATED: Now using Shape system (ship.shp)
|
||||
struct Triangle {
|
||||
IPunt p1, p2, p3;
|
||||
Punt centre;
|
||||
float angle;
|
||||
float velocitat;
|
||||
};
|
||||
|
||||
// Polígon (enemics i bales) - DEPRECATED: Now using Shape system (.shp files)
|
||||
struct Poligon {
|
||||
std::array<IPunt, Defaults::Entities::MAX_IPUNTS> ipuntx;
|
||||
Punt centre;
|
||||
float angle;
|
||||
float velocitat;
|
||||
uint8_t n;
|
||||
float drotacio;
|
||||
float rotacio;
|
||||
bool esta;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user