This commit is contained in:
2026-04-05 00:49:29 +02:00
parent f8b60cb641
commit 91f88ded09
6 changed files with 43 additions and 2 deletions

View File

@@ -7,6 +7,7 @@
#include "core/rendering/menu.hpp"
#include "core/rendering/text.hpp"
#include "core/system/director.hpp"
#include "game/options.hpp"
namespace Overlay {
@@ -151,6 +152,18 @@ namespace Overlay {
esc_waiting_ = false;
}
// Indicador de pausa persistent (cantó superior dret)
if (Director::get() && Director::get()->isPaused()) {
const char* pause_text = "PAUSA";
int w = font_->width(pause_text);
int x = SCREEN_W - w - 4;
int y = 4;
// Ombra
font_->draw(pixel_data, x + 1, y + 1, pause_text, 0xFF000000);
// Text en roig
font_->draw(pixel_data, x, y, pause_text, 0xFF0000FF);
}
// Menú flotant per damunt de tot
if (Menu::isOpen()) {
Menu::render(pixel_data);

View File

@@ -7,6 +7,7 @@
#include "core/input/global_inputs.hpp"
#include "core/input/key_remap.hpp"
#include "core/input/mouse.hpp"
#include "core/jail/jail_audio.hpp"
#include "core/jail/jgame.hpp"
#include "core/jail/jinput.hpp"
#include "core/rendering/menu.hpp"
@@ -37,6 +38,15 @@ auto Director::get() -> Director* {
return instance_;
}
void Director::togglePause() {
paused_ = !paused_;
if (paused_) {
JA_PauseMusic();
} else {
JA_ResumeMusic();
}
}
void Director::run() {
// Llança el game thread
game_thread_ = std::thread(&Director::gameThreadFunc, this);
@@ -64,9 +74,10 @@ void Director::run() {
esc_blocked_ = false;
}
// Consumeix un frame nou si n'hi ha un disponible (no bloqueja)
// Consumeix un frame nou si n'hi ha un disponible (no bloqueja).
// Si estem en pausa, no consumim: el game thread es queda bloquejat a publishFrame.
bool new_frame = false;
{
if (!paused_) {
std::lock_guard lock(mutex_);
if (frame_ready_ && latest_frame_ != nullptr) {
memcpy(game_frame, latest_frame_, sizeof(game_frame));
@@ -131,6 +142,14 @@ void Director::handleEvents() {
menu_keys_held_[event.key.scancode] = true;
continue;
}
// Pausa: F11 (o tecla configurada) pausa/reprén la simulació
if (event.type == SDL_EVENT_KEY_DOWN && !event.key.repeat &&
event.key.scancode == Options::keys_gui.pause_toggle) {
togglePause();
Overlay::showNotification(paused_ ? "PAUSA" : "REPRES");
menu_keys_held_[event.key.scancode] = true;
continue;
}
// Menú: F12 (o tecla configurada) obre/tanca el menú flotant
if (event.type == SDL_EVENT_KEY_DOWN && !event.key.repeat &&
event.key.scancode == Options::keys_gui.menu_toggle) {

View File

@@ -34,6 +34,10 @@ class Director {
// Indica si ESC està bloquejada (el joc no l'ha de veure)
auto isEscBlocked() const -> bool { return esc_blocked_ || esc_swallow_until_release_; }
// Pausa: bloqueja el consum de frames del game thread + pausa la música
void togglePause();
auto isPaused() const -> bool { return paused_; }
private:
Director() = default;
~Director() = default;
@@ -56,6 +60,7 @@ class Director {
std::atomic<bool> game_thread_done_{false};
std::atomic<bool> key_pressed_{false};
std::atomic<bool> esc_blocked_{false};
std::atomic<bool> paused_{false};
// Quan el menú tanca amb ESC, empassem-nos l'ESC fins que l'usuari la deixe anar,
// per no fer eixir el joc al proper poll de JI_KeyPressed.
std::atomic<bool> esc_swallow_until_release_{false};