2828#include " io-boards/Event.h"
2929#include " libpinmame.h"
3030
31+ #define MAIN_LOOP_SLEEP_US 20 // Main loop sleep time in microseconds
32+
3133SDL_AudioStream* m_pstream = nullptr ;
3234SDL_AudioSpec audioSpec;
3335
@@ -902,44 +904,33 @@ int main(int argc, char** argv)
902904
903905 if (PinmameRun (opt_rom) == PINMAME_STATUS_OK)
904906 {
905- // Pinball machines were slower than modern CPUs. There's no need to
906- // update states too frequently at full speed.
907- int sleep_us = 1000 ;
908- // Poll I/O boards for events (mainly switches) every 50us.
909- int poll_interval_ms = 50 ;
910- int poll_trigger = poll_interval_ms * 1000 / sleep_us;
911907 int index_recv = 0 ;
912908
913909 ppuc->StartUpdates ();
914910
915911 while (running)
916912 {
917- std::this_thread::sleep_for (std::chrono::microseconds (sleep_us ));
913+ std::this_thread::sleep_for (std::chrono::microseconds (MAIN_LOOP_SLEEP_US ));
918914
919915 if (!game_state)
920916 {
921917 continue ;
922918 }
923919
924- if (--poll_trigger <= 0 )
920+ PPUCSwitchState* switchState;
921+ while ((switchState = ppuc->GetNextSwitchState ()) != nullptr )
925922 {
926- poll_trigger = poll_interval_ms * 1000 / sleep_us;
927-
928- PPUCSwitchState* switchState;
929- while ((switchState = ppuc->GetNextSwitchState ()) != nullptr )
923+ if (opt_debug || opt_debug_switches)
930924 {
931- if (opt_debug || opt_debug_switches)
932- {
933- printf (" Switch updated: #%d, %d\n " , switchState->number , switchState->state );
934- }
925+ printf (" Switch updated: #%d, %d\n " , switchState->number , switchState->state );
926+ }
935927
936- // Switches between 200 and 240 are custom switches within the io-boards which should not be sent to
937- // pinmame. Switches above 240 will become negative values, for example 243 => -3.
938- if (switchState->number < 200 || switchState->number > 241 )
939- {
940- int switchNumber = (switchState->number < 241 ) ? switchState->number : 240 - switchState->number ;
941- PinmameSetSwitch (switchNumber, switchState->state );
942- }
928+ // Switches between 200 and 240 are custom switches within the io-boards which should not be sent to
929+ // pinmame. Switches above 240 will become negative values, for example 243 => -3.
930+ if (switchState->number < 200 || switchState->number > 241 )
931+ {
932+ int switchNumber = (switchState->number < 241 ) ? switchState->number : 240 - switchState->number ;
933+ PinmameSetSwitch (switchNumber, switchState->state );
943934 }
944935 }
945936
@@ -957,7 +948,7 @@ int main(int argc, char** argv)
957948 ppuc->SetLampState (lampNo, lampState);
958949 }
959950
960- {
951+ { // Needs to be a separate scope for the lock_guard
961952 // Process any pending render requests
962953 std::lock_guard<std::mutex> lock (renderMutex);
963954 while (!renderQueue.empty ())
0 commit comments