MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / handleInput

Method handleInput

source/game/StarInput.cpp:431–523  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431bool Input::handleInput(InputEvent const& input, bool gameProcessed) {
432 m_inputEvents.emplace_back(input, gameProcessed);
433 if (auto keyDown = input.ptr<KeyDownEvent>()) {
434 auto keyToMod = KeysToMods.rightPtr(keyDown->key);
435 if (keyToMod)
436 m_pressedMods |= *keyToMod;
437
438 if (!gameProcessed && !m_textInputActive) {
439 auto& state = m_keyStates[keyDown->key];
440 if (keyToMod)
441 state.mods |= *keyToMod;
442 state.press();
443
444 if (auto binds = m_bindMappings.ptr(keyDown->key)) {
445 for (auto bind : filterBindEntries(*binds, keyDown->mods))
446 addBindState(bind).press();
447 }
448 }
449 }
450 else if (auto keyUp = input.ptr<KeyUpEvent>()) {
451 auto keyToMod = KeysToMods.rightPtr(keyUp->key);
452 if (keyToMod)
453 m_pressedMods &= ~*keyToMod;
454
455 // We need to be able to release input even when gameProcessed is true, but only if it's already down.
456 if (auto state = m_keyStates.ptr(keyUp->key)) {
457 if (keyToMod)
458 state->mods &= ~*keyToMod;
459 state->release();
460 }
461
462 if (auto binds = m_bindMappings.ptr(keyUp->key)) {
463 for (auto& bind : *binds) {
464 if (auto state = m_bindStates.ptr(bind.entry))
465 state->release();
466 }
467 }
468 }
469 else if (auto mouseDown = input.ptr<MouseButtonDownEvent>()) {
470 m_mousePosition = mouseDown->mousePosition;
471 if (!gameProcessed) {
472 auto& state = m_mouseStates[mouseDown->mouseButton];
473 state.pressPositions.append(mouseDown->mousePosition);
474 state.press();
475
476 if (auto binds = m_bindMappings.ptr(mouseDown->mouseButton)) {
477 for (auto bind : filterBindEntries(*binds, m_pressedMods))
478 addBindState(bind).press();
479 }
480 }
481 }
482 else if (auto mouseUp = input.ptr<MouseButtonUpEvent>()) {
483 m_mousePosition = mouseUp->mousePosition;
484 if (auto state = m_mouseStates.ptr(mouseUp->mouseButton)) {
485 state->releasePositions.append(mouseUp->mousePosition);
486 state->release();
487 }
488

Callers 1

processInputMethod · 0.80

Calls 6

pressMethod · 0.80
releaseMethod · 0.80
emplace_backMethod · 0.45
rightPtrMethod · 0.45
ptrMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected