RW2026 - Abans d'anar li vaig dir a Claude que arreglara coses de input i game pq pareixia que al disparar es perdien inputs
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
.vscode
|
.vscode/
|
||||||
.claude
|
.claude/
|
||||||
|
.cache/
|
||||||
build/
|
build/
|
||||||
data/config/config.txt
|
data/config/config.txt
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
|||||||
@@ -325,6 +325,17 @@ void Input::initSDLGamePad() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Input::resetJustPressed() {
|
||||||
|
for (auto& key : keyboard_.bindings) {
|
||||||
|
key.second.just_pressed = false;
|
||||||
|
}
|
||||||
|
for (auto& gamepad : gamepads_) {
|
||||||
|
for (auto& binding : gamepad->bindings) {
|
||||||
|
binding.second.just_pressed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Input::resetInputStates() {
|
void Input::resetInputStates() {
|
||||||
// Resetear todos los KeyBindings.active a false
|
// Resetear todos los KeyBindings.active a false
|
||||||
for (auto& key : keyboard_.bindings) {
|
for (auto& key : keyboard_.bindings) {
|
||||||
@@ -349,7 +360,7 @@ void Input::update() {
|
|||||||
bool key_is_down_now = key_states[binding.second.scancode];
|
bool key_is_down_now = key_states[binding.second.scancode];
|
||||||
|
|
||||||
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo
|
// El estado .is_held del fotograma anterior nos sirve para saber si es un pulso nuevo
|
||||||
binding.second.just_pressed = key_is_down_now && !binding.second.is_held;
|
binding.second.just_pressed = binding.second.just_pressed || (key_is_down_now && !binding.second.is_held);
|
||||||
binding.second.is_held = key_is_down_now;
|
binding.second.is_held = key_is_down_now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,6 +378,16 @@ void Input::update() {
|
|||||||
|
|
||||||
auto Input::handleEvent(const SDL_Event& event) -> std::string {
|
auto Input::handleEvent(const SDL_Event& event) -> std::string {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
if (!event.key.repeat) {
|
||||||
|
for (auto& [action, binding] : keyboard_.bindings) {
|
||||||
|
if (binding.scancode == event.key.scancode) {
|
||||||
|
binding.just_pressed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SDL_EVENT_GAMEPAD_ADDED:
|
case SDL_EVENT_GAMEPAD_ADDED:
|
||||||
return addGamepad(event.gdevice.which);
|
return addGamepad(event.gdevice.which);
|
||||||
case SDL_EVENT_GAMEPAD_REMOVED:
|
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ class Input {
|
|||||||
|
|
||||||
// --- Métodos de reseteo de estado de entrada ---
|
// --- Métodos de reseteo de estado de entrada ---
|
||||||
void resetInputStates();
|
void resetInputStates();
|
||||||
|
void resetJustPressed();
|
||||||
|
|
||||||
// --- Eventos ---
|
// --- Eventos ---
|
||||||
auto handleEvent(const SDL_Event& event) -> std::string;
|
auto handleEvent(const SDL_Event& event) -> std::string;
|
||||||
|
|||||||
@@ -984,9 +984,9 @@ void Game::run() {
|
|||||||
|
|
||||||
while (Section::name == Section::Name::GAME) {
|
while (Section::name == Section::Name::GAME) {
|
||||||
const float DELTA_TIME = calculateDeltaTime();
|
const float DELTA_TIME = calculateDeltaTime();
|
||||||
|
handleEvents();
|
||||||
checkInput();
|
checkInput();
|
||||||
update(DELTA_TIME);
|
update(DELTA_TIME);
|
||||||
handleEvents(); // Tiene que ir antes del render
|
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1128,6 +1128,7 @@ auto Game::allPlayersAreNotPlaying() -> bool {
|
|||||||
|
|
||||||
// Comprueba los eventos que hay en cola
|
// Comprueba los eventos que hay en cola
|
||||||
void Game::handleEvents() {
|
void Game::handleEvents() {
|
||||||
|
input_->resetJustPressed();
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user