asweigart / asweigart/fpstimer

Enhancement Request: Add FPS Drop Event Callback

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6
Forks
1
PR merge metrics
No merged PRs in 30d

Description

This library is cool. However, I would like to suggest an enhancement that could make the class even more useful in scenarios where frame rate drops are critical.

### Enhancement Proposal:

Add the ability to subscribe to an event (or register a callback function) that is triggered whenever there is an FPS drop. Specifically, this event should be triggered in the sleep() method when sleepTime < 0, indicating that the loop could not maintain the desired frame rate.

```python
def on_fps_drop(*_):
print("Framerate couldn't be maintained")

timer = FPSTimer(framesPerSecond=60)
timer.register_fps_drop_callback(on_fps_drop)
```

It would be really cool if the callback is called with specific argument like:
- Number of frames dropped
- Drop length in seconds (it would be the absolute value of sleepTime)

*PS: The usage of time.perf_counter should be preferred to time.time for better precision.*

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the FPSTimer sleep() method and inspect how sleepTime is calculated, especially the sleepTime < 0 case. Define how the FPS-drop callback is registered and what arguments it receives, then verify that it is invoked on a missed frame without changing normal timer behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.