feat(camera): implement async base64 screenshot capture #70
Open
IlyaChichkov wants to merge 3 commits intodevelopfrom
Open
feat(camera): implement async base64 screenshot capture #70IlyaChichkov wants to merge 3 commits intodevelopfrom
IlyaChichkov wants to merge 3 commits intodevelopfrom
Conversation
- Created `GameThreadDispatcher.cs` as a persistent Unity `MonoBehaviour`. - Implemented a thread-safe `ConcurrentQueue<Action>` to bridge background HTTP threads and the synchronous Unity Main Thread. - Added `InvokeAsync` wrappers utilizing `TaskCompletionSource` so controllers can seamlessly `await` Main Thread operations (like capturing textures or interacting with UI components). - Updated `RIMAPI_Mod` constructor to generate an invisible GameObject (`DontDestroyOnLoad`) and attach the dispatcher component during mod initialization.
…resizing - Introduced `MakeScreenshotAsync` to capture the live game view and return it directly to the API client as a Base64 Data URI. - Added support for cleanly hiding the RimWorld UI (`HideUI`) by yielding to `WaitForEndOfFrame` before reading the screen buffer. - Built dynamic image resizing via temporary `RenderTexture` and `Graphics.Blit` to support custom width/height requests. - Implemented strict GPU memory cleanup (`Object.Destroy`, `RenderTexture.ReleaseTemporary`) inside try/finally blocks to prevent texture memory leaks. - Reorganized camera models (renamed `CameraStreamDto` and created `CameraDto`) for better domain isolation.
- Added 3 distinct Bruno (.yml) test configurations for the /api/v1/game/start endpoint: 1. Standard Auto 2. Hardcore Randy 3. Exact Seed & Tile - Converted all JSON request payload keys from PascalCase to standard REST snake_case.
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.
Closes #69
Description
This PR implements the requested feature to capture the live in-game screen and return it directly as a Base64 image payload, without requiring saving to disk.
The implementation required a careful architectural upgrade to bridge the asynchronous HTTP background threads with RimWorld's synchronous Unity Main Thread.
Key Changes:
MakeScreenshotAsyncEndpoint: Captures the live game view and returns aCameraScreenshotResponseDtocontaining the Base64 Data URI.GameThreadDispatcher: Implemented a new core persistent UnityMonoBehaviourwith a thread-safeConcurrentQueue. This allows background HTTP threads to safelyawaitoperations that must run on the main thread.HideUI) before capturing the screen buffer.RenderTextureandGraphics.Blitto support custom width/height API requests.Object.Destroy,RenderTexture.ReleaseTemporary) inside try/finally blocks to prevent texture memory leaks.CameraStreamDtoand createdCameraDtofor better domain isolation..ymltest configurations for both native file and base64 screenshot endpoints.