refactor: eliminar Rotation3D i el seu camí de codi (codi mort)
L'struct Rotation3D, la funció apply3dRotation i el paràmetre opcional rotation_3d de renderShape mai s'activaven en cap caller: - Ship, Enemy i Bullet passaven explícitament nullptr. - Title scene, logo scene, starfield, vector_text i ship_animator usaven el default nullptr (set els 7 callers). CLAUDE.md descriu un sistema 3D del title screen que ja no està viu — el comentari en ship_animator.cpp aclareix que la perspectiva s'ha bakeat dins de la shape, així que la rotació dinàmica era residu històric. Esborrats: struct Rotation3D + ctors + hasRotation(), apply3dRotation(), la branca rotation_3d a transformPoint() i el seu paràmetre, el paràmetre rotation_3d de renderShape, i els arguments nullptr als 3 callers d'entitats. Hallazgo #16 de CODE_REVIEW.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,41 +17,40 @@
|
||||
|
||||
namespace {
|
||||
|
||||
// Velocidad inicial vectorial a partir de un ángulo (rad).
|
||||
// angle=0 apunta hacia arriba (eje Y negativo SDL), como el resto del juego.
|
||||
auto angleToDirection(float angle) -> Vec2 {
|
||||
return Vec2{
|
||||
.x = std::cos(angle - (Constants::PI / 2.0F)),
|
||||
.y = std::sin(angle - (Constants::PI / 2.0F)),
|
||||
};
|
||||
}
|
||||
|
||||
// Recupera el "ángulo equivalente" de un body en movimiento (para zigzag).
|
||||
// Si está parado, devuelve 0.
|
||||
auto velocityToAngle(const Vec2& velocity) -> float {
|
||||
if (velocity.lengthSquared() < 0.0001F) {
|
||||
return 0.0F;
|
||||
// Velocidad inicial vectorial a partir de un ángulo (rad).
|
||||
// angle=0 apunta hacia arriba (eje Y negativo SDL), como el resto del juego.
|
||||
auto angleToDirection(float angle) -> Vec2 {
|
||||
return Vec2{
|
||||
.x = std::cos(angle - (Constants::PI / 2.0F)),
|
||||
.y = std::sin(angle - (Constants::PI / 2.0F)),
|
||||
};
|
||||
}
|
||||
|
||||
// Recupera el "ángulo equivalente" de un body en movimiento (para zigzag).
|
||||
// Si está parado, devuelve 0.
|
||||
auto velocityToAngle(const Vec2& velocity) -> float {
|
||||
if (velocity.lengthSquared() < 0.0001F) {
|
||||
return 0.0F;
|
||||
}
|
||||
// El movimiento (vx, vy) corresponde a angle - PI/2; invertimos.
|
||||
return std::atan2(velocity.y, velocity.x) + (Constants::PI / 2.0F);
|
||||
}
|
||||
// El movimiento (vx, vy) corresponde a angle - PI/2; invertimos.
|
||||
return std::atan2(velocity.y, velocity.x) + (Constants::PI / 2.0F);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Enemy::Enemy(Rendering::Renderer* renderer)
|
||||
: Entity(renderer),
|
||||
|
||||
tracking_strength_(0.5F)
|
||||
{
|
||||
|
||||
tracking_strength_(0.5F) {
|
||||
brightness_ = Defaults::Brightness::ENEMIC;
|
||||
|
||||
// Configuración del cuerpo físico — defaults para enemy genérico.
|
||||
// init() ajusta velocidad y masa según el tipo (Pentagon/Quadrat/Molinillo).
|
||||
body_.setMass(5.0F); // Más liviano que la nave (10.0)
|
||||
body_.radius = 0.0F; // 0 hasta spawn (no colisiona inactivo)
|
||||
body_.restitution = 1.0F; // Rebote elástico perfecto contra paredes
|
||||
body_.linear_damping = 0.0F; // Sin fricción: mantienen velocidad
|
||||
body_.angular_damping = 0.0F; // Idem
|
||||
body_.setMass(5.0F); // Más liviano que la nave (10.0)
|
||||
body_.radius = 0.0F; // 0 hasta spawn (no colisiona inactivo)
|
||||
body_.restitution = 1.0F; // Rebote elástico perfecto contra paredes
|
||||
body_.linear_damping = 0.0F; // Sin fricción: mantienen velocidad
|
||||
body_.angular_damping = 0.0F; // Idem
|
||||
}
|
||||
|
||||
void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
@@ -225,12 +224,17 @@ void Enemy::draw() const {
|
||||
const float SCALE = computeCurrentScale();
|
||||
SDL_Color color{};
|
||||
switch (type_) {
|
||||
case EnemyType::PENTAGON: color = Defaults::Palette::PENTAGON; break;
|
||||
case EnemyType::QUADRAT: color = Defaults::Palette::QUADRAT; break;
|
||||
case EnemyType::MOLINILLO: color = Defaults::Palette::MOLINILLO; break;
|
||||
case EnemyType::PENTAGON:
|
||||
color = Defaults::Palette::PENTAGON;
|
||||
break;
|
||||
case EnemyType::QUADRAT:
|
||||
color = Defaults::Palette::QUADRAT;
|
||||
break;
|
||||
case EnemyType::MOLINILLO:
|
||||
color = Defaults::Palette::MOLINILLO;
|
||||
break;
|
||||
}
|
||||
Rendering::renderShape(renderer_, shape_, center_, rotacio_, SCALE, 1.0F, brightness_,
|
||||
/*rotation_3d=*/nullptr, color);
|
||||
Rendering::renderShape(renderer_, shape_, center_, rotacio_, SCALE, 1.0F, brightness_, color);
|
||||
}
|
||||
|
||||
void Enemy::destruir() {
|
||||
@@ -269,7 +273,7 @@ void Enemy::behaviorPentagon(float delta_time) {
|
||||
if (RAND_VAL < ZIGZAG_PROB_PER_SECOND * delta_time) {
|
||||
const float CURRENT_ANGLE = velocityToAngle(body_.velocity);
|
||||
const float DELTA = (static_cast<float>(std::rand()) / RAND_MAX) *
|
||||
Defaults::Enemies::Pentagon::CANVI_ANGLE_MAX;
|
||||
Defaults::Enemies::Pentagon::CANVI_ANGLE_MAX;
|
||||
const float NEW_ANGLE = CURRENT_ANGLE + ((std::rand() % 2 == 0) ? DELTA : -DELTA);
|
||||
const float SPEED = body_.velocity.length();
|
||||
setVelocityFromAngle(NEW_ANGLE, SPEED);
|
||||
@@ -294,7 +298,7 @@ void Enemy::behaviorQuadrat(float delta_time) {
|
||||
|
||||
// Mezcla LERP: velocidad actual con la deseada según tracking_strength_.
|
||||
body_.velocity = (body_.velocity * (1.0F - tracking_strength_)) +
|
||||
(DESIRED_VEL * tracking_strength_);
|
||||
(DESIRED_VEL * tracking_strength_);
|
||||
|
||||
// Renormalizar a la velocidad escalar original
|
||||
const float NEW_SPEED = body_.velocity.length();
|
||||
@@ -342,19 +346,19 @@ void Enemy::updatePalpitation(float delta_time) {
|
||||
animacio_.palpitacio_fase = 0.0F;
|
||||
|
||||
const float FREQ_RANGE = Defaults::Enemies::Animation::PALPITACIO_FREQ_MAX -
|
||||
Defaults::Enemies::Animation::PALPITACIO_FREQ_MIN;
|
||||
Defaults::Enemies::Animation::PALPITACIO_FREQ_MIN;
|
||||
animacio_.palpitacio_frequencia = Defaults::Enemies::Animation::PALPITACIO_FREQ_MIN +
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * FREQ_RANGE);
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * FREQ_RANGE);
|
||||
|
||||
const float AMP_RANGE = Defaults::Enemies::Animation::PALPITACIO_AMPLITUD_MAX -
|
||||
Defaults::Enemies::Animation::PALPITACIO_AMPLITUD_MIN;
|
||||
Defaults::Enemies::Animation::PALPITACIO_AMPLITUD_MIN;
|
||||
animacio_.palpitacio_amplitud = Defaults::Enemies::Animation::PALPITACIO_AMPLITUD_MIN +
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * AMP_RANGE);
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * AMP_RANGE);
|
||||
|
||||
const float DUR_RANGE = Defaults::Enemies::Animation::PALPITACIO_DURACIO_MAX -
|
||||
Defaults::Enemies::Animation::PALPITACIO_DURACIO_MIN;
|
||||
Defaults::Enemies::Animation::PALPITACIO_DURACIO_MIN;
|
||||
animacio_.palpitacio_temps_restant = Defaults::Enemies::Animation::PALPITACIO_DURACIO_MIN +
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * DUR_RANGE);
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * DUR_RANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,15 +384,15 @@ void Enemy::updateRotationAcceleration(float delta_time) {
|
||||
animacio_.drotacio_t = 0.0F;
|
||||
|
||||
const float MULT_RANGE = Defaults::Enemies::Animation::ROTACIO_ACCEL_MULTIPLIER_MAX -
|
||||
Defaults::Enemies::Animation::ROTACIO_ACCEL_MULTIPLIER_MIN;
|
||||
Defaults::Enemies::Animation::ROTACIO_ACCEL_MULTIPLIER_MIN;
|
||||
const float MULTIPLIER = Defaults::Enemies::Animation::ROTACIO_ACCEL_MULTIPLIER_MIN +
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * MULT_RANGE);
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * MULT_RANGE);
|
||||
animacio_.drotacio_objetivo = animacio_.drotacio_base * MULTIPLIER;
|
||||
|
||||
const float DUR_RANGE = Defaults::Enemies::Animation::ROTACIO_ACCEL_DURACIO_MAX -
|
||||
Defaults::Enemies::Animation::ROTACIO_ACCEL_DURACIO_MIN;
|
||||
Defaults::Enemies::Animation::ROTACIO_ACCEL_DURACIO_MIN;
|
||||
animacio_.drotacio_duracio = Defaults::Enemies::Animation::ROTACIO_ACCEL_DURACIO_MIN +
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * DUR_RANGE);
|
||||
((static_cast<float>(std::rand()) / RAND_MAX) * DUR_RANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user