Repository navigation
Conversation
|
Hi, @coolzi and thanks for PR! While it looks cool as proof of concept; in order to progress with new feature, you need to create issue first with basic explanation of native api available on various OS. Note: you don't have to fill out every os yourself - I might be able to fill some gaps. What is needed is general overview of what api engine has to abstract. Then we can consider, what api representation will fit best. |
| void disconnect(); | ||
| void setActive(bool active); | ||
| // Button callbacks also carry the analog value for trigger buttons. | ||
| void button(Button button, bool pressed, float value); |
There was a problem hiding this comment.
is those functions meant to be private?
There was a problem hiding this comment.
These are now protected in GameController::Impl (77803a5). They are needed by the derived Detail::MacosController to feed native button/axis updates and connection/focus changes into the shared state and queue. The public GameController handle exposes only device(), state(), axis() and pull(); applications cannot inject native events. The queue helper push() and the stored state remain private.
| @@ -0,0 +1,43 @@ | |||
| cmake_minimum_required(VERSION 3.16) | |||
There was a problem hiding this comment.
I really see no value in such test-cases - there is very little they can do on test-machine with no devices
| State state() const; | ||
| Vec2 axis(Stick stick) const; | ||
|
|
||
| // Synchronous callbacks on the caller's thread, with no internal lock held. |
There was a problem hiding this comment.
In Tempest I prefer to keep code easy to use, with no need of long comments. What you have in doc is enough.
|
|
||
| #include "../gamecontroller.h" | ||
|
|
||
| namespace Tempest::Detail { |
There was a problem hiding this comment.
no need to put it into ::Detail - basically same as SystemApi;
also let put into a dedicated directory: system/controller/controllerapi.h
| class ControllerApi final { | ||
| public: | ||
| static std::vector<GameController> controllers(); | ||
| static GameController controller(std::shared_ptr<ControllerState> state); |
There was a problem hiding this comment.
why this function is public?
given, that we ended up with a single usable public function - maybe transfer it to Tempest::Application::controllers ?
| std::vector<std::shared_ptr<ControllerState>> MacOSControllerApi::controllers() const { | ||
| requireMainThread(); | ||
| std::vector<std::shared_ptr<ControllerState>> result; | ||
| result.reserve(impl->devices.size()); |
There was a problem hiding this comment.
It would make sense here, to have separation:
GameController - user-land one, only rerouted api calls into ::Impl.
Detail::MacosController - implements event pull and tracks mac-os specific state
|
|
||
| // UI-thread boundary between native event-processing steps. May re-enter | ||
| // through a modal loop; subscribers must unbind before being destroyed. | ||
| static Signal<void()>& onEventLoop(); |
There was a problem hiding this comment.
This is used by the OpenGothic consumer to deliver deferred menu commands that may enter Dialog::exec(). Input is drained first; the UI command runs after that drain returns, so a nested dialog does not recursively enter the same controller's pull().
Dialog::exec() repeatedly calls Application::processEvents(). On macOS this processes native events but does not run Tempest's Timer dispatcher, which is called by the outer implExec() loop. The hook provides a delivery point both in that outer loop and inside nested dialogs, allowing input and cancellation to reach the active modal level. The controller backend itself does not subscribe to it.
I tried replacing the hook with a Timer in the local native regression fixture. With a Timer, the local native regression entered the parent dialog but never dispatched the queued command to open its child; the watchdog fired and seven assertions failed. The retained hook passes the nested-modal regression. Fixing Timer dispatch would be a separate event-loop change.
There was a problem hiding this comment.
On macOS this processes native events but does not run Tempest's Timer dispatcher, which is called by the outer implExec() loop.
Thats a bug. implProcessEvents meant to run timers
| if(id == 0) | ||
| throw std::overflow_error("GameController connection ID exhausted"); | ||
| } while(!next.compare_exchange_weak(id, id + 1)); | ||
| return id; |
There was a problem hiding this comment.
is it just overcomplicated and slow way to do atomic_add ?!
|
|
||
| GameController::Impl::Impl(std::string name, uint32_t buttons, uint32_t axes, | ||
| const State& initial, bool active) | ||
| : info{connectionId(), std::move(name), buttons & buttonMask, axes & axisMask}, active(active) { |
There was a problem hiding this comment.
what is a reason to have connectionId, provided that it's not part of native api?
| size_t count; | ||
| { | ||
| std::lock_guard<std::mutex> guard(sync); | ||
| count = events.size(); |
There was a problem hiding this comment.
this is wrong - you poking size of data is one critical section and iterating in another.
overall not even needed, provided that intent is to drain all events and loop body already stops, of array of events is empty
| } | ||
|
|
||
| namespace { | ||
| uint32_t supportedButtons(GCController* controller) { |
There was a problem hiding this comment.
need to have it static; dummy namespace is not needed
| using DeviceId = uint64_t; | ||
|
|
||
| enum class Button : uint8_t { | ||
| South, East, West, North, |
There was a problem hiding this comment.
need to add None = 0, for events that are not related to buttons
| enum class ResetReason : uint8_t { None, FocusLost, Disconnected, Overflow, FocusGained }; | ||
|
|
||
| Type type = Type::Reset; | ||
| DeviceId device = 0; |
There was a problem hiding this comment.
why do you need deviceId here?
shouldn't be needed, since pull to tied to on specific device
|
|
||
| // UI-thread boundary between native event-processing steps. May re-enter | ||
| // through a modal loop; subscribers must unbind before being destroyed. | ||
| static Signal<void()>& onEventLoop(); |
There was a problem hiding this comment.
On macOS this processes native events but does not run Tempest's Timer dispatcher, which is called by the outer implExec() loop.
Thats a bug. implProcessEvents meant to run timers
|
Hi @Try, could you approve the CI run for this PR and review the latest commit, |
Construct controller fixtures through a shared friend helper so the tests and the library use the same private constructor symbol.
|
Thanks for rerunning CI, @Try! The MSVC linking issue is fixed in |
|
@coolzi if you still working on PR, why don't you run CI on your local fork? |
Add per-connection controller input following the API discussion in #138.
API
Application::controllers()enumerates copyableGameControllerhandles. Copies and repeated enumeration share one native connection, current state and event queue. Handles compare by their shared implementation; reconnecting creates a different identity. There is no synthetic numeric device ID or redundant device field in per-controller events.GameControllerdelegates to its sharedImpl.Detail::MacosControllerimplements the native connection, reusing the portable queue/state.ControllerApilives insystem/controller, separately fromSystemApi; no public handle-construction helper is exposed.pull(callback)removes one event under a short queue lock, then invokes application code on the caller's thread outside that lock. It drains until the live queue is empty, including events added during a callback. An indefinitely active producer can keep the call running. The application serializes pulls across copies and must not reenter the same connection's pull. Cancellation replaces pending input immediately; a throwing callback leaves untouched events queued.axis(Stick)andstate()read synchronized current values without consuming events;device()exposes metadata and supported controls.Button::None = 0identifies non-button events and is excluded from capability/state masks. Empty/moved-from handles safely return empty values. Disconnected handles retain their identity and terminal event.Focus loss/recovery, overflow and disconnect produce per-connection cancellation events. Focus recovery refreshes the native sample before publishing its reset. Gameplay bindings, dead zones and neutral rearming remain application policy.
macOS integration
Enumeration runs on the main thread after AppKit launch, without requiring a Tempest window. The registry removes observers/handlers and releases native resources on the main thread; stale handles and final handle release on a worker remain safe. GameController.framework is weak-linked, with native availability checked before discovery. Other platforms currently return no controllers; this adds no Windows runtime dependency.
The macOS
implProcessEventspath now dispatches ordinary Tempest timers, including inside nestedDialog::exec()loops. Timer iteration handles reentry, callback-time registry mutation and exceptions, and stops after application exit. The duplicate outer timer dispatch andApplication::onEventLoop()workaround are removed. The local OpenGothic consumer uses a Timer for deferred menu delivery. The guardedfinishLaunchingcompletes AppKit startup when Tempest creates NSApplication and drives its own event loop.Validation
TempestTestsproject builds and passes 210/210 tests on macOS arm64, including 20 controller regressions. Its complete CTest run passes 8/8: the normal suite plus seven native Timer scenarios registered in the same test project.processEvents; relocating dispatch alone reproduces the shared timer-cursor defect. The corresponding fixed checks pass.LC_LOAD_WEAK_DYLIBfor GameController in the built library and companion executable.No new physical-controller session, older-macOS run, real non-macOS build or full-engine sanitizer result is claimed. USB and sustained physical 60/120 FPS remain outside the companion acceptance scope. See
docs/game-controller.mdfor the contract and test commands.