Merge pull request #86 from Eblo/graphics-transition-fps-bugfix

Graphics.transition average FPS bugfix
This commit is contained in:
Splendide Imaginarius 2024-03-17 03:49:10 +00:00 committed by GitHub
commit 4658487bb7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 8 deletions

View file

@ -1085,14 +1085,7 @@ struct GraphicsPrivate {
swapGLBuffer();
SDL_LockMutex(avgFPSLock);
if (avgFPSData.size() > 40)
avgFPSData.erase(avgFPSData.begin());
double time = shState->runTime();
avgFPSData.push_back(time - last_avg_update);
last_avg_update = time;
SDL_UnlockMutex(avgFPSLock);
updateAvgFPS();
}
void checkSyncLock() {
@ -1132,6 +1125,17 @@ struct GraphicsPrivate {
SDL_UnlockMutex(glResourceLock);
}
void updateAvgFPS() {
SDL_LockMutex(avgFPSLock);
if (avgFPSData.size() > 40)
avgFPSData.erase(avgFPSData.begin());
double time = shState->runTime();
avgFPSData.push_back(time - last_avg_update);
last_avg_update = time;
SDL_UnlockMutex(avgFPSLock);
}
};
Graphics::Graphics(RGSSThreadData *data) {
@ -1311,6 +1315,8 @@ void Graphics::transition(int duration, const char *filename, int vague) {
GLMeta::blitEnd();
p->swapGLBuffer();
/* Call this manually, as redrawScreen() is not called during this loop. */
p->updateAvgFPS();
}
glState.blend.pop();

View file

@ -0,0 +1,17 @@
# Test script for mkxp-z Graphics.transition reported FPS bug fix.
# Run via the "customScript" field in mkxp.json.
puts 'No transition. Counter should be normal'
normal_duration = 2
Graphics.wait(normal_duration * Graphics.frame_rate)
transition_duration = 10 # Default value used in RGSS
num_transitions = 20
puts 'Performing transitions. If the FPS counter notably dips, the bug is not fixed.'
num_transitions.times do
Graphics.freeze
Graphics.transition(transition_duration)
Graphics.wait(transition_duration)
end
exit