@@ -593,17 +593,15 @@ int UmbraEngine::run() {
593
593
}
594
594
595
595
SDL_AppResult UmbraEngine::onFrame () {
596
- static TCOD_key_t key{};
597
- static TCOD_mouse_t mouse{};
598
596
SDL_Event event{};
599
597
600
598
if (paused) {
601
599
if (keyboardMode >= UMBRA_KEYBOARD_SDL) {
602
600
// Flush all SDL events.
603
601
while (SDL_PollEvent (&event)) onEvent (event);
604
602
} else {
605
- TCODSystem::checkForEvent (TCOD_EVENT_KEY_RELEASE | TCOD_EVENT_MOUSE_PRESS, &key , &mouse );
606
- keyboard (key );
603
+ TCODSystem::checkForEvent (TCOD_EVENT_KEY_RELEASE | TCOD_EVENT_MOUSE_PRESS, &key_ , &mouse_ );
604
+ keyboard (key_ );
607
605
}
608
606
TCODConsole::root->flush ();
609
607
return SDL_APP_CONTINUE; // don't update or render anything anew
@@ -633,27 +631,26 @@ SDL_AppResult UmbraEngine::onFrame() {
633
631
// update all active modules
634
632
switch (keyboardMode) {
635
633
case UMBRA_KEYBOARD_WAIT:
636
- TCODSystem::waitForEvent (TCOD_EVENT_KEY_PRESS | TCOD_EVENT_MOUSE, &key , &mouse , true );
634
+ TCODSystem::waitForEvent (TCOD_EVENT_KEY_PRESS | TCOD_EVENT_MOUSE, &key_ , &mouse_ , true );
637
635
break ;
638
636
case UMBRA_KEYBOARD_WAIT_NOFLUSH:
639
- TCODSystem::waitForEvent (TCOD_EVENT_KEY_PRESS | TCOD_EVENT_MOUSE, &key , &mouse , false );
637
+ TCODSystem::waitForEvent (TCOD_EVENT_KEY_PRESS | TCOD_EVENT_MOUSE, &key_ , &mouse_ , false );
640
638
break ;
641
639
case UMBRA_KEYBOARD_PRESSED:
642
- TCODSystem::checkForEvent (TCOD_EVENT_KEY_PRESS | TCOD_EVENT_MOUSE, &key , &mouse );
640
+ TCODSystem::checkForEvent (TCOD_EVENT_KEY_PRESS | TCOD_EVENT_MOUSE, &key_ , &mouse_ );
643
641
break ;
644
642
case UMBRA_KEYBOARD_PRESSED_RELEASED:
645
- TCODSystem::checkForEvent (TCOD_EVENT_KEY | TCOD_EVENT_MOUSE, &key , &mouse );
643
+ TCODSystem::checkForEvent (TCOD_EVENT_KEY | TCOD_EVENT_MOUSE, &key_ , &mouse_ );
646
644
break ;
647
645
case UMBRA_KEYBOARD_RELEASED:
648
646
default :
649
- TCODSystem::checkForEvent (TCOD_EVENT_KEY_RELEASE | TCOD_EVENT_MOUSE, &key , &mouse );
647
+ TCODSystem::checkForEvent (TCOD_EVENT_KEY_RELEASE | TCOD_EVENT_MOUSE, &key_ , &mouse_ );
650
648
break ;
651
649
case UMBRA_KEYBOARD_SDL:
652
- key = {};
653
650
while (SDL_PollEvent (&event)) onEvent (event);
654
651
break ;
655
652
}
656
- keyboard (key );
653
+ keyboard (key_ );
657
654
uint64_t startTime = SDL_GetTicks ();
658
655
// update all active modules by priority order
659
656
activeModules.erase (
@@ -665,8 +662,8 @@ SDL_AppResult UmbraEngine::onFrame() {
665
662
if (!tmpMod->getPause ()) {
666
663
// handle input
667
664
if (keyboardMode < UMBRA_KEYBOARD_SDL) { // Old-style handling.
668
- tmpMod->keyboard (key );
669
- tmpMod->mouse (mouse );
665
+ tmpMod->keyboard (key_ );
666
+ tmpMod->mouse (mouse_ );
670
667
}
671
668
if (tmpMod->isTimedOut (startTime) || !tmpMod->update () || !tmpMod->getActive ()) {
672
669
UmbraModule* module = tmpMod;
@@ -684,6 +681,17 @@ SDL_AppResult UmbraEngine::onFrame() {
684
681
return remove_this;
685
682
}),
686
683
activeModules.end ());
684
+
685
+ // Clear dirty key/mouse states after module update calls
686
+ key_ = {};
687
+ mouse_.lbutton_pressed = false ;
688
+ mouse_.mbutton_pressed = false ;
689
+ mouse_.rbutton_pressed = false ;
690
+ for (auto & module : activeModules) {
691
+ module->keyboard (key_);
692
+ module->mouse (mouse_);
693
+ }
694
+
687
695
uint64_t updateTime = SDL_GetTicks () - startTime;
688
696
TCODConsole::root->setDefaultBackground (TCODColor::black);
689
697
TCODConsole::root->clear ();
@@ -701,21 +709,19 @@ SDL_AppResult UmbraEngine::onFrame() {
701
709
}
702
710
703
711
SDL_AppResult UmbraEngine::onEvent (SDL_Event& event) {
704
- TCOD_key_t key{};
705
- TCOD_mouse_t mouse{};
706
- int is_key_event = tcod::sdl2::process_event (event, key);
707
- int is_mouse_event = tcod::sdl2::process_event (event, key);
712
+ tcod::sdl2::process_event (event, key_);
713
+ tcod::sdl2::process_event (event, mouse_);
708
714
709
715
if (!paused) {
710
716
for (auto & module : activeModules) {
711
717
if (module->getPause ()) continue ;
712
718
module->onEvent (event);
713
719
714
- if (is_key_event) module->keyboard (key );
715
- if (is_mouse_event) module->mouse (mouse );
720
+ module->keyboard (key_ );
721
+ module->mouse (mouse_ );
716
722
}
717
723
}
718
- keyboard (key );
724
+ keyboard (key_ );
719
725
switch (event.type ) {
720
726
case SDL_EVENT_QUIT:
721
727
paused = false ;
0 commit comments