refactor(effects): renombra temps_vida/temps_max a elapsed_time/max_lifetime

This commit is contained in:
2026-05-24 07:59:14 +02:00
parent 807f71ffa7
commit 4cfad053f0
6 changed files with 92 additions and 92 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ namespace Effects {
// Política: viu sempre durant min_lifetime, després mor quan
// |velocity| < MIN_SPEED_TO_DIE (definit en Defaults). Així els
// fragments ràpids no "popen" en moviment.
float temps_vida; // Temps transcorregut (segons)
float elapsed_time; // Temps transcorregut (segons)
float min_lifetime; // Temps mínim garantit (segons)
bool active; // Està actiu?
+4 -4
View File
@@ -150,7 +150,7 @@ namespace Effects {
// Vida i shrinking — min_lifetime és el temps mínim garantit; després
// el fragment mor quan |velocity| < MIN_SPEED_TO_DIE.
debris->temps_vida = 0.0F;
debris->elapsed_time = 0.0F;
debris->min_lifetime = lifetime;
debris->factor_shrink = Defaults::Physics::Debris::SHRINK_RATE;
@@ -266,12 +266,12 @@ namespace Effects {
}
// 1. Actualitzar time de vida
debris.temps_vida += delta_time;
debris.elapsed_time += delta_time;
// Política de mort: viu sí o sí durant min_lifetime; després mor
// quan la velocity cau per sota d'un llindar. Així els fragments
// ràpids no desapareixen en moviment.
if (debris.temps_vida >= debris.min_lifetime) {
if (debris.elapsed_time >= debris.min_lifetime) {
const float SPEED_SQ = (debris.velocity.x * debris.velocity.x) +
(debris.velocity.y * debris.velocity.y);
if (SPEED_SQ < Defaults::Physics::Debris::MIN_SPEED_TO_DIE_SQ) {
@@ -344,7 +344,7 @@ namespace Effects {
// 6. Shrink lineal sobre la longitud ORIGINAL (no iteratiu).
// SHRINK_T va de 0 a 1 al llarg de min_lifetime; després queda
// a 1 i el shrink_factor manté el valor mínim (1 - factor_shrink).
const float SHRINK_T = std::min(debris.temps_vida / debris.min_lifetime, 1.0F);
const float SHRINK_T = std::min(debris.elapsed_time / debris.min_lifetime, 1.0F);
const float SHRINK_FACTOR = std::max(0.0F, 1.0F - (debris.factor_shrink * SHRINK_T));
// 7. Reconstruir p1/p2 des de la geometria autoritaritzada:
+2 -2
View File
@@ -16,7 +16,7 @@ namespace Effects {
// tail = head velocity_normalitzada × current_length.
//
// Cicle de vida:
// Fase 1 (temps_vida < grow_duration): current_length creix linealment
// Fase 1 (elapsed_time < grow_duration): current_length creix linealment
// de 0 a max_length. Brillor al màxim.
// Fase 2: current_length = max_length × (speed/initial_speed) i brillor
// amb la mateixa proporció. Mor quan length o brightness cauen sota
@@ -30,7 +30,7 @@ namespace Effects {
float max_length; // Longitud màxima (final de la fase de creixement)
float grow_duration; // Temps de creixement de 0 a max_length (s)
float temps_vida; // Acumulador (s)
float elapsed_time; // Acumulador (s)
float initial_speed; // Speed inicial per a la proporció de fase 2
float brightness; // 0..1
+4 -4
View File
@@ -102,7 +102,7 @@ namespace Effects {
fw->max_length = Defaults::FX::Firework::MAX_LENGTH;
fw->grow_duration = Defaults::FX::Firework::GROW_DURATION;
fw->temps_vida = 0.0F;
fw->elapsed_time = 0.0F;
fw->initial_speed = SPEED;
fw->brightness = initial_brightness;
@@ -119,7 +119,7 @@ namespace Effects {
continue;
}
fw.temps_vida += delta_time;
fw.elapsed_time += delta_time;
// 1. Fricció lineal (aplicar en la direcció del movement).
const float SPEED = std::sqrt(
@@ -144,9 +144,9 @@ namespace Effects {
bounceOffPlayArea(fw.head, fw.velocity);
// 4. Calcular longitud i brillor segons fase.
if (fw.temps_vida < fw.grow_duration) {
if (fw.elapsed_time < fw.grow_duration) {
// Fase 1: creixement lineal de 0 a max_length.
const float T = fw.temps_vida / fw.grow_duration;
const float T = fw.elapsed_time / fw.grow_duration;
fw.current_length = fw.max_length * T;
fw.brightness = Defaults::FX::Firework::INITIAL_BRIGHTNESS;
} else {
+7 -7
View File
@@ -9,9 +9,9 @@
namespace Effects {
// FloatingScore: text animat que muestra points guanyats
// S'activa cuando es destrueix un enemy i s'esvaeix después de un time
struct FloatingScore {
// FloatingScore: text animat que muestra points guanyats
// S'activa cuando es destrueix un enemy i s'esvaeix después de un time
struct FloatingScore {
// Text a mostrar (e.g., "100", "150", "200")
std::string text;
@@ -22,12 +22,12 @@ struct FloatingScore {
Vec2 velocity; // px/s (normalment sin amunt: {0.0f, -30.0f})
// Animación de fade
float temps_vida; // Temps transcorregut (segons)
float temps_max; // Temps de vida màxim (segons)
float brightness; // Brillantor calculada (0.0-1.0)
float elapsed_time; // Temps transcorregut (segons)
float max_lifetime; // Temps de vida màxim (segons)
float brightness; // Brillantor calculada (0.0-1.0)
// Estat
bool active;
};
};
} // namespace Effects
+74 -74
View File
@@ -7,93 +7,93 @@
namespace Effects {
FloatingScoreManager::FloatingScoreManager(Rendering::Renderer* renderer)
: text_(renderer) {
// Inicialitzar todos los slots como inactius
for (auto& pf : pool_) {
pf.active = false;
}
}
void FloatingScoreManager::crear(int points, const Vec2& position) {
// 1. Trobar slot lliure
FloatingScore* pf = findFreeSlot();
if (pf == nullptr) {
return; // Pool ple (improbable)
}
// 2. Inicialitzar puntuación flotante
pf->text = std::to_string(points);
pf->position = position;
pf->velocity = {.x = Defaults::FloatingScore::VELOCITY_X,
.y = Defaults::FloatingScore::VELOCITY_Y};
pf->temps_vida = 0.0F;
pf->temps_max = Defaults::FloatingScore::LIFETIME;
pf->brightness = 1.0F;
pf->active = true;
}
void FloatingScoreManager::update(float delta_time) {
for (auto& pf : pool_) {
if (!pf.active) {
continue;
}
// 1. Actualitzar posición (deriva sin amunt)
pf.position.x += pf.velocity.x * delta_time;
pf.position.y += pf.velocity.y * delta_time;
// 2. Actualitzar time de vida
pf.temps_vida += delta_time;
// 3. Calcular brightness (fade lineal)
float progress = pf.temps_vida / pf.temps_max; // 0.0 → 1.0
pf.brightness = 1.0F - progress; // 1.0 → 0.0
// 4. Desactivar cuando acaba el time
if (pf.temps_vida >= pf.temps_max) {
FloatingScoreManager::FloatingScoreManager(Rendering::Renderer* renderer)
: text_(renderer) {
// Inicialitzar todos los slots como inactius
for (auto& pf : pool_) {
pf.active = false;
}
}
}
void FloatingScoreManager::draw() {
for (const auto& pf : pool_) {
if (!pf.active) {
continue;
void FloatingScoreManager::crear(int points, const Vec2& position) {
// 1. Trobar slot lliure
FloatingScore* pf = findFreeSlot();
if (pf == nullptr) {
return; // Pool ple (improbable)
}
// Renderizar centrat con brightness (fade)
constexpr float SCALE = Defaults::FloatingScore::SCALE;
constexpr float SPACING = Defaults::FloatingScore::SPACING;
text_.renderCentered(pf.text, pf.position, SCALE, SPACING, pf.brightness);
// 2. Inicialitzar puntuación flotante
pf->text = std::to_string(points);
pf->position = position;
pf->velocity = {.x = Defaults::FloatingScore::VELOCITY_X,
.y = Defaults::FloatingScore::VELOCITY_Y};
pf->elapsed_time = 0.0F;
pf->max_lifetime = Defaults::FloatingScore::LIFETIME;
pf->brightness = 1.0F;
pf->active = true;
}
}
void FloatingScoreManager::reset() {
for (auto& pf : pool_) {
pf.active = false;
}
}
void FloatingScoreManager::update(float delta_time) {
for (auto& pf : pool_) {
if (!pf.active) {
continue;
}
auto FloatingScoreManager::getActiveCount() const -> int {
int count = 0;
for (const auto& pf : pool_) {
if (pf.active) {
count++;
// 1. Actualitzar posición (deriva sin amunt)
pf.position.x += pf.velocity.x * delta_time;
pf.position.y += pf.velocity.y * delta_time;
// 2. Actualitzar time de vida
pf.elapsed_time += delta_time;
// 3. Calcular brightness (fade lineal)
float progress = pf.elapsed_time / pf.max_lifetime; // 0.0 → 1.0
pf.brightness = 1.0F - progress; // 1.0 → 0.0
// 4. Desactivar cuando acaba el time
if (pf.elapsed_time >= pf.max_lifetime) {
pf.active = false;
}
}
}
return count;
}
auto FloatingScoreManager::findFreeSlot() -> FloatingScore* {
for (auto& pf : pool_) {
if (!pf.active) {
return &pf;
void FloatingScoreManager::draw() {
for (const auto& pf : pool_) {
if (!pf.active) {
continue;
}
// Renderizar centrat con brightness (fade)
constexpr float SCALE = Defaults::FloatingScore::SCALE;
constexpr float SPACING = Defaults::FloatingScore::SPACING;
text_.renderCentered(pf.text, pf.position, SCALE, SPACING, pf.brightness);
}
}
return nullptr; // Pool ple
}
void FloatingScoreManager::reset() {
for (auto& pf : pool_) {
pf.active = false;
}
}
auto FloatingScoreManager::getActiveCount() const -> int {
int count = 0;
for (const auto& pf : pool_) {
if (pf.active) {
count++;
}
}
return count;
}
auto FloatingScoreManager::findFreeSlot() -> FloatingScore* {
for (auto& pf : pool_) {
if (!pf.active) {
return &pf;
}
}
return nullptr; // Pool ple
}
} // namespace Effects