Implementar sistema de auto-reinicio con temporizador de inactividad
- Añadir getter isStopped() en Ball para detectar pelotas quietas - Sistema de temporizador de 5 segundos que detecta cuando todas las pelotas están paradas - Auto-reinicio aleatorio cuando se cumple el tiempo de inactividad: * Escenario aleatorio usando test_.size() (1 a 100,000 pelotas) * Tema aleatorio usando sizeof(themes_) (5 temas disponibles) * Reset inteligente del temporizador si alguna pelota se mueve - Integración no intrusiva en update() del bucle principal - Usa infraestructura existente (SDL_GetTicks, initBalls, rand) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -55,6 +55,7 @@ class Ball {
|
|||||||
float getLossCoefficient() const { return loss_; }
|
float getLossCoefficient() const { return loss_; }
|
||||||
GravityDirection getGravityDirection() const { return gravity_direction_; }
|
GravityDirection getGravityDirection() const { return gravity_direction_; }
|
||||||
bool isOnSurface() const { return on_surface_; }
|
bool isOnSurface() const { return on_surface_; }
|
||||||
|
bool isStopped() const { return stopped_; }
|
||||||
|
|
||||||
// Getters para batch rendering
|
// Getters para batch rendering
|
||||||
SDL_FRect getPosition() const { return pos_; }
|
SDL_FRect getPosition() const { return pos_; }
|
||||||
|
|||||||
@@ -147,6 +147,9 @@ void Engine::update() {
|
|||||||
if (show_text_) {
|
if (show_text_) {
|
||||||
show_text_ = !(SDL_GetTicks() - text_init_time_ > TEXT_DURATION);
|
show_text_ = !(SDL_GetTicks() - text_init_time_ > TEXT_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verificar auto-reinicio cuando todas las pelotas están quietas
|
||||||
|
checkAutoRestart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::handleEvents() {
|
void Engine::handleEvents() {
|
||||||
@@ -769,4 +772,48 @@ void Engine::initializeThemes() {
|
|||||||
{255, 0, 64} // 345° - Magenta claro-Rojo
|
{255, 0, 64} // 345° - Magenta claro-Rojo
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::checkAutoRestart() {
|
||||||
|
// Verificar si TODAS las pelotas están paradas
|
||||||
|
bool all_stopped = true;
|
||||||
|
for (const auto &ball : balls_) {
|
||||||
|
if (!ball->isStopped()) {
|
||||||
|
all_stopped = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (all_stopped) {
|
||||||
|
if (!all_balls_were_stopped_) {
|
||||||
|
// Primera vez que se detecta que todas están paradas
|
||||||
|
all_balls_stopped_start_time_ = SDL_GetTicks();
|
||||||
|
all_balls_were_stopped_ = true;
|
||||||
|
} else {
|
||||||
|
// Ya estaban paradas, verificar tiempo transcurrido
|
||||||
|
Uint64 current_time = SDL_GetTicks();
|
||||||
|
if (current_time - all_balls_stopped_start_time_ >= AUTO_RESTART_DELAY) {
|
||||||
|
performRandomRestart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Al menos una pelota se está moviendo - resetear temporizador
|
||||||
|
all_balls_were_stopped_ = false;
|
||||||
|
all_balls_stopped_start_time_ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::performRandomRestart() {
|
||||||
|
// Escenario aleatorio usando tamaño del array
|
||||||
|
scenario_ = rand() % test_.size();
|
||||||
|
|
||||||
|
// Tema aleatorio usando tamaño del array de temas
|
||||||
|
current_theme_ = static_cast<ColorTheme>(rand() % (sizeof(themes_) / sizeof(themes_[0])));
|
||||||
|
|
||||||
|
// Reinicializar pelotas con nuevo escenario y tema
|
||||||
|
initBalls(scenario_);
|
||||||
|
|
||||||
|
// Resetear temporizador
|
||||||
|
all_balls_were_stopped_ = false;
|
||||||
|
all_balls_stopped_start_time_ = 0;
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,11 @@ private:
|
|||||||
bool fullscreen_enabled_ = false;
|
bool fullscreen_enabled_ = false;
|
||||||
bool real_fullscreen_enabled_ = false;
|
bool real_fullscreen_enabled_ = false;
|
||||||
|
|
||||||
|
// Auto-restart system
|
||||||
|
Uint64 all_balls_stopped_start_time_ = 0; // Momento cuando todas se pararon
|
||||||
|
bool all_balls_were_stopped_ = false; // Flag de estado anterior
|
||||||
|
static constexpr Uint64 AUTO_RESTART_DELAY = 5000; // 5 segundos en ms
|
||||||
|
|
||||||
// Resolución dinámica para modo real fullscreen
|
// Resolución dinámica para modo real fullscreen
|
||||||
int current_screen_width_ = SCREEN_WIDTH;
|
int current_screen_width_ = SCREEN_WIDTH;
|
||||||
int current_screen_height_ = SCREEN_HEIGHT;
|
int current_screen_height_ = SCREEN_HEIGHT;
|
||||||
@@ -96,6 +101,8 @@ private:
|
|||||||
void toggleRealFullscreen();
|
void toggleRealFullscreen();
|
||||||
std::string gravityDirectionToString(GravityDirection direction) const;
|
std::string gravityDirectionToString(GravityDirection direction) const;
|
||||||
void initializeThemes();
|
void initializeThemes();
|
||||||
|
void checkAutoRestart();
|
||||||
|
void performRandomRestart();
|
||||||
|
|
||||||
// Sistema de zoom dinámico
|
// Sistema de zoom dinámico
|
||||||
int calculateMaxWindowZoom() const;
|
int calculateMaxWindowZoom() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user