diff options
Diffstat (limited to 'runtime/shims/gameinput.cpp')
| -rw-r--r-- | runtime/shims/gameinput.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/runtime/shims/gameinput.cpp b/runtime/shims/gameinput.cpp index 402179cde..8b428d689 100644 --- a/runtime/shims/gameinput.cpp +++ b/runtime/shims/gameinput.cpp | |||
| @@ -865,7 +865,19 @@ bool matches(const Callback& c, const Event& e) { | |||
| 865 | } | 865 | } |
| 866 | } | 866 | } |
| 867 | 867 | ||
| 868 | // The token of the callback running on this thread, for kCurrentCallbackToken; 0 outside a callback. | ||
| 869 | thread_local GameInputCallbackToken t_running_token = kInvalidCallbackToken; | ||
| 870 | |||
| 871 | GameInputCallbackToken resolve_token(GameInputCallbackToken token) { | ||
| 872 | return token == kCurrentCallbackToken ? t_running_token : token; | ||
| 873 | } | ||
| 874 | |||
| 868 | void call(const Callback& c, const Event& e) { | 875 | void call(const Callback& c, const Event& e) { |
| 876 | struct Running { // restored on return, so a callback that drives another delivery keeps its own token | ||
| 877 | GameInputCallbackToken saved = t_running_token; | ||
| 878 | explicit Running(GameInputCallbackToken t) { t_running_token = t; } | ||
| 879 | ~Running() { t_running_token = saved; } | ||
| 880 | } running(c.token); | ||
| 869 | switch (c.type) { | 881 | switch (c.type) { |
| 870 | case CbType::Device: | 882 | case CbType::Device: |
| 871 | reinterpret_cast<GameInputDeviceCallback>(c.fn)(c.token, c.context, e.device, e.timestamp, e.current, e.previous); | 883 | reinterpret_cast<GameInputDeviceCallback>(c.fn)(c.token, c.context, e.device, e.timestamp, e.current, e.previous); |
| @@ -2486,6 +2498,8 @@ public: | |||
| 2486 | } | 2498 | } |
| 2487 | 2499 | ||
| 2488 | void STDMETHODCALLTYPE StopCallback(GameInputCallbackToken token) override { | 2500 | void STDMETHODCALLTYPE StopCallback(GameInputCallbackToken token) override { |
| 2501 | token = resolve_token(token); | ||
| 2502 | if (token == kInvalidCallbackToken) return; | ||
| 2489 | std::lock_guard lock(g().mu); | 2503 | std::lock_guard lock(g().mu); |
| 2490 | for (Callback& c : g().callbacks) | 2504 | for (Callback& c : g().callbacks) |
| 2491 | if (c.token == token) c.active = false; | 2505 | if (c.token == token) c.active = false; |
| @@ -2494,6 +2508,8 @@ public: | |||
| 2494 | // Removes the callback and, unless called from inside a callback, waits for one that is running to return. | 2508 | // Removes the callback and, unless called from inside a callback, waits for one that is running to return. |
| 2495 | // VERIFY: the timeout is not honoured; the wait is for at most one callback. | 2509 | // VERIFY: the timeout is not honoured; the wait is for at most one callback. |
| 2496 | bool STDMETHODCALLTYPE UnregisterCallback(GameInputCallbackToken token, uint64_t) override { | 2510 | bool STDMETHODCALLTYPE UnregisterCallback(GameInputCallbackToken token, uint64_t) override { |
| 2511 | token = resolve_token(token); | ||
| 2512 | if (token == kInvalidCallbackToken) return false; | ||
| 2497 | State& s = g(); | 2513 | State& s = g(); |
| 2498 | bool found = false; | 2514 | bool found = false; |
| 2499 | { | 2515 | { |