Fase 1a: Punt -> Vec2 amb operadors moderns
Primera sub-fase del naming sweep. Punt era un struct sense
operacions, conservat per compatibilitat amb el Pascal original.
Substituit per Vec2, un aggregate amb operadors aritmetics, dot,
length, normalized i length_squared (camelBack: lengthSquared)
seguint les regles del .clang-tidy del projecte.
Canvis:
- core/types.hpp reescrit: nou struct Vec2 amb +=,-=,*=,/=,
unary -, ==, dot, length, lengthSquared, normalized
- Operadors fora de la classe: +, -, *, / (amb float per ambdues
bandes), - unari, ==
- Vec2 segueix sent aggregate (sense constructors definits):
els 'designated initializers' del codi existent funcionen igual:
Vec2{.x = ..., .y = ...}
- Sed global sobre 35 fitxers: tots els 'Punt' -> 'Vec2'
Net: 35 fitxers tocats, +180 / -114. Compila i enllaça.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Effects {
|
||||
|
||||
// Helper: transformar punt amb rotació, escala i trasllació
|
||||
// (Copiat de shape_renderer.cpp:12-34)
|
||||
static Punt transform_point(const Punt& point, const Punt& shape_centre, const Punt& posicio, float angle, float escala) {
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& posicio, float angle, float escala) {
|
||||
// 1. Centrar el punt respecte al centre de la forma
|
||||
float centered_x = point.x - shape_centre.x;
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
@@ -45,12 +45,12 @@ DebrisManager::DebrisManager(SDL_Renderer* renderer)
|
||||
}
|
||||
|
||||
void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Punt& centre,
|
||||
const Vec2& centre,
|
||||
float angle,
|
||||
float escala,
|
||||
float velocitat_base,
|
||||
float brightness,
|
||||
const Punt& velocitat_objecte,
|
||||
const Vec2& velocitat_objecte,
|
||||
float velocitat_angular,
|
||||
float factor_herencia_visual,
|
||||
const std::string& sound) {
|
||||
@@ -62,12 +62,12 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
Audio::get()->playSound(sound, Audio::Group::GAME);
|
||||
|
||||
// Obtenir centre de la forma per a transformacions
|
||||
const Punt& shape_centre = shape->get_centre();
|
||||
const Vec2& shape_centre = shape->get_centre();
|
||||
|
||||
// Iterar sobre totes les primitives de la forma
|
||||
for (const auto& primitive : shape->get_primitives()) {
|
||||
// Processar cada segment de línia
|
||||
std::vector<std::pair<Punt, Punt>> segments;
|
||||
std::vector<std::pair<Vec2, Vec2>> segments;
|
||||
|
||||
if (primitive.type == Graphics::PrimitiveType::POLYLINE) {
|
||||
// Polyline: extreure segments consecutius
|
||||
@@ -84,9 +84,9 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
// Crear debris per a cada segment
|
||||
for (const auto& [local_p1, local_p2] : segments) {
|
||||
// 1. Transformar punts locals → coordenades mundials
|
||||
Punt world_p1 =
|
||||
Vec2 world_p1 =
|
||||
transform_point(local_p1, shape_centre, centre, angle, escala);
|
||||
Punt world_p2 =
|
||||
Vec2 world_p2 =
|
||||
transform_point(local_p2, shape_centre, centre, angle, escala);
|
||||
|
||||
// 2. Trobar slot lliure
|
||||
@@ -101,7 +101,7 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
debris->p2 = world_p2;
|
||||
|
||||
// 4. Calcular direcció d'explosió (radial, des del centre cap a fora)
|
||||
Punt direccio = calcular_direccio_explosio(world_p1, world_p2, centre);
|
||||
Vec2 direccio = calcular_direccio_explosio(world_p1, world_p2, centre);
|
||||
|
||||
// 5. Velocitat inicial (base ± variació aleatòria + velocitat heretada)
|
||||
float speed =
|
||||
@@ -271,7 +271,7 @@ void DebrisManager::actualitzar(float delta_time) {
|
||||
}
|
||||
|
||||
// 3. Calcular centre del segment
|
||||
Punt centre = {.x = (debris.p1.x + debris.p2.x) / 2.0F,
|
||||
Vec2 centre = {.x = (debris.p1.x + debris.p2.x) / 2.0F,
|
||||
.y = (debris.p1.y + debris.p2.y) / 2.0F};
|
||||
|
||||
// 4. Actualitzar posició del centre
|
||||
@@ -327,9 +327,9 @@ Debris* DebrisManager::trobar_slot_lliure() {
|
||||
return nullptr; // Pool ple
|
||||
}
|
||||
|
||||
Punt DebrisManager::calcular_direccio_explosio(const Punt& p1,
|
||||
const Punt& p2,
|
||||
const Punt& centre_objecte) const {
|
||||
Vec2 DebrisManager::calcular_direccio_explosio(const Vec2& p1,
|
||||
const Vec2& p2,
|
||||
const Vec2& centre_objecte) const {
|
||||
// 1. Calcular centre del segment
|
||||
float centro_seg_x = (p1.x + p2.x) / 2.0F;
|
||||
float centro_seg_y = (p1.y + p2.y) / 2.0F;
|
||||
|
||||
Reference in New Issue
Block a user