This commit is contained in:
2026-04-04 23:03:34 +02:00
parent a4ee304a79
commit 63424429ca
10 changed files with 407 additions and 160 deletions

View File

@@ -3,7 +3,7 @@
#include <fstream>
#include "core/jail/jfile.hpp"
#include "core/rendering/screen.hpp"
#include "core/system/director.hpp"
#include "external/gif.h"
JD8_Surface screen = NULL;
@@ -153,7 +153,7 @@ void JD8_Flip() {
pixel_data[x + (y * 320)] = color;
}
}
Screen::get()->present(pixel_data);
Director::get()->publishFrame(pixel_data);
}
void JD8_FreeSurface(JD8_Surface surface) {

View File

@@ -1,99 +1,55 @@
#include "core/jail/jinput.hpp"
#include <string>
#include "core/input/global_inputs.hpp"
#include "core/input/mouse.hpp"
#include "core/jail/jgame.hpp"
#include "core/rendering/overlay.hpp"
#include "game/options.hpp"
const bool* keystates; // = SDL_GetKeyboardState( NULL );
SDL_Event event;
Uint8 cheat[5];
bool key_pressed = false;
int waitTime = 0;
static bool esc_blocked_ = false; // Bloqueja ESC per polling quan l'overlay l'ha consumit
// Comprova si un scancode pertany a les tecles reservades per a la GUI
static bool isGuiKey(SDL_Scancode sc) {
return sc == Options::keys_gui.dec_zoom ||
sc == Options::keys_gui.inc_zoom ||
sc == Options::keys_gui.fullscreen ||
sc == Options::keys_gui.toggle_shader ||
sc == Options::keys_gui.toggle_aspect_ratio ||
sc == Options::keys_gui.toggle_supersampling ||
sc == Options::keys_gui.next_shader ||
sc == Options::keys_gui.next_shader_preset ||
sc == Options::keys_gui.toggle_stretch_filter ||
sc == Options::keys_gui.toggle_render_info;
}
void JI_DisableKeyboard(Uint32 time) {
waitTime = time;
}
void JI_moveCheats(Uint8 new_key) {
cheat[0] = cheat[1];
cheat[1] = cheat[2];
cheat[2] = cheat[3];
cheat[3] = cheat[4];
cheat[4] = new_key;
}
void JI_Update() {
key_pressed = false;
keystates = SDL_GetKeyboardState(NULL);
if (waitTime > 0) waitTime--;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_QUIT) JG_QuitSignal();
if (event.type == SDL_EVENT_KEY_UP) {
// ESC interceptat per l'overlay (doble pulsació per eixir)
if (event.key.scancode == SDL_SCANCODE_ESCAPE) {
if (Overlay::handleEscape()) {
// Consumit: primera pulsació, bloqueja ESC per polling
esc_blocked_ = true;
} else {
// Segona pulsació: desbloqueja i passa al joc
esc_blocked_ = false;
key_pressed = true;
JG_QuitSignal();
}
} else if (!isGuiKey(event.key.scancode)) {
// Tecles normals del joc
key_pressed = true;
JI_moveCheats(event.key.scancode);
}
}
Mouse::handleEvent(event);
}
// Desbloqueja ESC quan la tecla ja no està polsada i l'overlay ha fet timeout
if (esc_blocked_ && !keystates[SDL_SCANCODE_ESCAPE]) {
esc_blocked_ = false;
}
Mouse::updateCursorVisibility();
GlobalInputs::handle();
}
bool JI_KeyPressed(int key) {
if (waitTime > 0) return false;
// Si ESC està bloquejat per l'overlay, no la passem al joc
if (key == SDL_SCANCODE_ESCAPE && esc_blocked_) return false;
return keystates[key] != 0;
}
bool JI_CheatActivated(const char* cheat_code) {
bool found = true;
for (size_t i = 0; i < strlen(cheat_code); i++) {
if (cheat[i] != cheat_code[i]) found = false;
}
return found;
}
bool JI_AnyKey() {
return waitTime > 0 ? false : key_pressed;
}
#include "core/jail/jinput.hpp"
#include <string>
#include "core/system/director.hpp"
// keystates és actualitzat per SDL internament. Des del joc només fem lectures.
const bool* keystates = nullptr;
Uint8 cheat[5];
bool key_pressed = false;
int waitTime = 0;
void JI_DisableKeyboard(Uint32 time) {
waitTime = time;
}
void JI_moveCheats(Uint8 new_key) {
cheat[0] = cheat[1];
cheat[1] = cheat[2];
cheat[2] = cheat[3];
cheat[3] = cheat[4];
cheat[4] = new_key;
}
void JI_Update() {
// El director ha processat tots els events. Ací només refresquem
// el snapshot del teclat i consumim el flag de tecla polsada.
if (keystates == nullptr) {
keystates = SDL_GetKeyboardState(NULL);
}
if (waitTime > 0) waitTime--;
// Consumim el flag de "alguna tecla no-GUI polsada" del director
key_pressed = Director::get()->consumeKeyPressed();
}
bool JI_KeyPressed(int key) {
if (waitTime > 0 || keystates == nullptr) return false;
// ESC bloquejada pel Director (primera pulsació mostra notificació)
if (key == SDL_SCANCODE_ESCAPE && Director::get()->isEscBlocked()) return false;
return keystates[key] != 0;
}
bool JI_CheatActivated(const char* cheat_code) {
bool found = true;
for (size_t i = 0; i < strlen(cheat_code); i++) {
if (cheat[i] != cheat_code[i]) found = false;
}
return found;
}
bool JI_AnyKey() {
return waitTime > 0 ? false : key_pressed;
}