Improve gif player performance with vsync support and frame rate control#42
Improve gif player performance with vsync support and frame rate control#42
Conversation
…for gif player Co-authored-by: Voidless7125 <167136334+Voidless7125@users.noreply.github.com>
…f player Co-authored-by: Voidless7125 <167136334+Voidless7125@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the GIF player by integrating VEX vsync support, adding configurable frame‐rate control, and optimizing rendering performance.
- Introduces
enable_vsyncandmax_fpsparameters with defaults fromConfigManager - Replaces
memcpyin hot paths with direct color assignment and adds buffer/dimension checks - Adds frame‐rate limiting logic and proper use of
Brain.Screen.render()for smoother playback
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/functions.cpp | Integrate vsync/config and apply a 30 FPS default cap |
| src/display/gifplayer/gifplayer.cpp | Add emu_read checks, dimension validation, optimized rendering and frame timing logic |
| include/display/gifdec.h | Expose new constructors and setters with Doxygen stubs |
Comments suppressed due to low confidence (2)
include/display/gifdec.h:112
- The
setVsyncandsetMaxFpsmethods should have Doxygen comments explaining their parameters and behavior to match the style of the constructors.
void setVsync(bool enable) { _enable_vsync = enable; }
src/functions.cpp:206
- The standalone
ifbreaks the originalelse ifchain, causing later branches to always be evaluated after the autonomous loop. Change it back toelse ifto preserve mutual exclusivity.
if (Competition.isAutonomous())
| if (!emu_memory || !buffer || len == 0) | ||
| { | ||
| return -1; | ||
| } |
There was a problem hiding this comment.
[nitpick] Returning -1 for len == 0 may be misleading since reading zero bytes usually returns 0. Consider returning 0 to represent EOF or no bytes read.
| if (!emu_memory || !buffer || len == 0) | |
| { | |
| return -1; | |
| } | |
| if (!emu_memory || !buffer) | |
| { | |
| return -1; | |
| } | |
| if (len == 0) | |
| { | |
| return 0; | |
| } |
| height = read_num(fd); | ||
|
|
||
| // Validate dimensions to prevent excessive memory allocation | ||
| if (width == 0 || height == 0 || width > 4096 || height > 4096) |
There was a problem hiding this comment.
[nitpick] The literal 4096 is a magic number for max dimensions. Extract it into a named constant (e.g., kMaxGifDimension) to improve readability and ease future maintenance.
| if (width == 0 || height == 0 || width > 4096 || height > 4096) | |
| if (width == 0 || height == 0 || width > kMaxGifDimension || height > kMaxGifDimension) |
| gif->width, gif->height); | ||
|
|
||
| // Use VEX render API with vsync support | ||
| if (instance->_enable_vsync) |
There was a problem hiding this comment.
Accessing _enable_vsync and _max_fps from both the main thread and the render thread can cause data races. Use std::atomic or a mutex to synchronize these shared fields.
This PR significantly improves the gif player implementation by adding VEX render pipeline integration, configurable frame rate control, and performance optimizations.
Key Improvements
🔄 VEX Render Pipeline Integration
Brain.Screen.render(bSyncWait, true)calls with configurable vsyncConfigManager.getVsyncGif()setting by default with runtime override support⚡ Performance Optimizations
🎛️ Enhanced Configuration
🛡️ Better Error Handling
API Changes
New Constructor:
New Methods:
setVsync(bool enable)- Toggle vsync at runtimesetMaxFps(int fps)- Adjust frame rate limit (0 = no limit)Performance Impact
The improvements deliver:
Before:
After:
Fixes #36.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
http://168.63.129.16:80/machine//usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.