Use async HTTP requests for UI and stats (#835)#845
Open
Eclipse1982 wants to merge 1 commit into
Open
Conversation
Replace blocking HTTP calls in menu code paths with asynchronous requests so the client no longer freezes (or shows a black screen at launch) while waiting on the stats API: - Add Net_HttpGetInstanceAsync and Net_HttpGetInstancesAsync, async counterparts to the JSON instance helpers, and expose them through the cgame import. - Fetch the GUID hash asynchronously at startup; the result is applied on the main thread via a NOTIFICATION_GUID_HASHED MVC event. - Fetch the leaderboard asynchronously; completed results are staged and applied in respondToEvent on NOTIFICATION_LEADERBOARD_FETCHED. - Fetch player stats asynchronously; completed responses are staged and applied in respondToEvent on NOTIFICATION_STATS_FETCHED. Stats also refresh when the GUID hash arrives. - Generation counters discard stale responses when a newer fetch has been issued; completion callbacks never touch UI state directly. - Add check_http unit tests covering both new async JSON helpers.
c84a48e to
ef9d838
Compare
Owner
|
Fantastic! Thank you. I'm working on some improvements to the JSON deserialization code here first. I'll commit that and up-merge into your branch and get this over the finish line. This is a big win for user experience. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the blocking HTTP requests in the UI / stats code paths with asynchronous requests, so the client no longer shows a black screen at launch (GUID hash fetch) or freezes when opening the Leaderboard and Stats menus while waiting on the stats API.
Completion callbacks run on the HTTP session thread; results are staged and marshaled to the main thread via
MVC_NOTIFICATION_EVENT, and view controllers refresh inrespondToEvent— following the pattern suggested in the issue and already used byNOTIFICATION_SERVER_PARSED.Fixes #835
Changes
Net_HttpGetInstanceAsync/Net_HttpGetInstancesAsync— async counterparts to the JSON instance helpers — and exposed them through the cgame import (cgi.HttpGetInstanceAsync,cgi.HttpGetInstancesAsync).Cl_InitGuidHashnow fires an async request at startup; the hash is applied toguid_hashedon the main thread via a newNOTIFICATION_GUID_HASHEDevent, so startup never blocks on the network. The call was moved afterUi_Init, becauseMVC_NOTIFICATION_EVENTis only registered with SDL once ObjectivelyMVC initializes — a completion firing earlier would push event type0and the hash would be silently dropped.LeaderboardViewControllerfetches asynchronously (initial load and sort-column clicks); rows are staged under a mutex and applied inrespondToEventonNOTIFICATION_LEADERBOARD_FETCHED. It also reloads when the GUID hash arrives so the local player's row highlights.StatsViewControllerfetches asynchronously, showing placeholders untilNOTIFICATION_STATS_FETCHEDdelivers the response; it refreshes whenNOTIFICATION_GUID_HASHEDarrives (previously a cold start could show "Sign in" until the next visit).check_httpunit tests covering both new async helpers against the local test HTTP server.Testing
make -j$(nproc))make check)Notes
linux/docker/Dockerfile.build. The changed files compile without warnings (pre-existing warnings elsewhere in the tree are untouched).make check: 18/19 suites pass, includingcheck_httpwith the two new async tests. The one failure ischeck_filesystem("Failed to load quetoo.cfg") — an environment issue in the build container (no game data installed), unrelated to this change.giblets.quetoo.org), headless under Xvfb/llvmpipe: client reaches the main menu with stats placeholders immediately, the GUID hash arrives asynchronously and the Stats tab populates, the Leaderboard tab loads live rows, sort-column clicks refetch and reorder without any UI stall, andselectOwnRowhighlights the local player after the async reload. No warnings or errors in the console log.