| 631 | } |
| 632 | |
| 633 | void GodotModule::runOnGodotThread(std::function<void()> f, bool wait) { |
| 634 | if (wait) { |
| 635 | std::mutex waitMutex; |
| 636 | std::condition_variable waitVar; |
| 637 | bool ready = false; |
| 638 | std::function<void()> runFunc = [&f, &waitMutex, &waitVar, &ready]() { |
| 639 | f(); |
| 640 | std::unique_lock<std::mutex> lock(waitMutex); |
| 641 | ready = true; |
| 642 | lock.unlock(); |
| 643 | waitVar.notify_one(); |
| 644 | }; |
| 645 | std::unique_lock<std::mutex> lock(waitMutex); |
| 646 | AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data); |
| 647 | data->thread.enqueue(runFunc); |
| 648 | waitVar.wait(lock, [&ready] { return ready; }); |
| 649 | } else { |
| 650 | AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data); |
| 651 | data->thread.enqueue(f); |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | void GodotModule::iterate() { |
| 656 | godot::GodotInstance *instance = nullptr; |