void SDLSystem::run(RLMachine& machine) { // Give the event handler a chance to run. event_system_->executeEventSystem(machine); text_system_->executeTextSystem(); sound_system_->executeSoundSystem(); graphics_system_->executeGraphicsSystem(machine); if (platform()) platform()->run(machine); boost::shared_ptr<LongOperation> longop = machine.currentLongOperation(); int sleep_time = longop ? longop->sleepTime() : 0; // If forceWait is set, we've detected that the RealLive bytecode is trying // to call refresh() really fast in a loop and that we should inject some // sleep so the CPU doesn't burn. if (forceWait() && sleep_time < 10) sleep_time = 10; // If the longop wants us to sleep for a really long time, we also have a // problem because we cant't handle mouse input smoothly. So we have a // different maximum sleep time depending on whether the mouse is in the // window. int max_time = event_system_->mouseInsideWindow() ? 20 : 50; if (sleep_time > max_time) sleep_time = max_time; if (!forceFastForward() && sleep_time) { event_system_->wait(sleep_time); setForceWait(false); } }
void EventSystem::broadcastEvent(RLMachine& machine, const std::function<void(EventListener&)>& event) { EventListeners::iterator listenerIt = listeners_begin(); for (; listenerIt != listeners_end(); ++listenerIt) { event(**listenerIt); } boost::shared_ptr<LongOperation> current_op = machine.currentLongOperation(); if (current_op) event(*current_op); }
void EventSystem::dispatchEvent(RLMachine& machine, const std::function<bool(EventListener&)>& event) { // In addition to the handled variable, we need to add break statements to // the loops since |event| can be any arbitrary code and may modify listeners // or handlers. (i.e., System::showSyscomMenu) bool handled = false; // Give the mostly passive listeners first shot at handling this event EventListeners::iterator listenerIt = listeners_begin(); for (; !handled && listenerIt != listeners_end(); ++listenerIt) { if (event(**listenerIt)) { handled = true; break; } } // Try to pass the event on to the top of the call stack. boost::shared_ptr<LongOperation> current_op = machine.currentLongOperation(); if (current_op) event(*current_op); }