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
|
||||
.claude
|
||||
.vscode/
|
||||
.claude/
|
||||
.cache/
|
||||
build/
|
||||
data/config/config.txt
|
||||
*.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() {
|
||||
// Resetear todos los KeyBindings.active a false
|
||||
for (auto& key : keyboard_.bindings) {
|
||||
@@ -349,7 +360,7 @@ void Input::update() {
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -367,6 +378,16 @@ void Input::update() {
|
||||
|
||||
auto Input::handleEvent(const SDL_Event& event) -> std::string {
|
||||
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:
|
||||
return addGamepad(event.gdevice.which);
|
||||
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||
|
||||
@@ -175,6 +175,7 @@ class Input {
|
||||
|
||||
// --- Métodos de reseteo de estado de entrada ---
|
||||
void resetInputStates();
|
||||
void resetJustPressed();
|
||||
|
||||
// --- Eventos ---
|
||||
auto handleEvent(const SDL_Event& event) -> std::string;
|
||||
|
||||
@@ -984,9 +984,9 @@ void Game::run() {
|
||||
|
||||
while (Section::name == Section::Name::GAME) {
|
||||
const float DELTA_TIME = calculateDeltaTime();
|
||||
handleEvents();
|
||||
checkInput();
|
||||
update(DELTA_TIME);
|
||||
handleEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
@@ -1128,6 +1128,7 @@ auto Game::allPlayersAreNotPlaying() -> bool {
|
||||
|
||||
// Comprueba los eventos que hay en cola
|
||||
void Game::handleEvents() {
|
||||
input_->resetJustPressed();
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
|
||||
Reference in New Issue
Block a user