Fix Graphics.fadeout/.fadein causing screen flashing in libretro builds

This commit is contained in:
刘皓 2025-04-18 11:54:23 -04:00
parent 996e47ed81
commit ced3e697bd
No known key found for this signature in database
GPG key ID: 7901753DB465B711
3 changed files with 14 additions and 10 deletions

View file

@ -127,13 +127,15 @@ namespace mkxp_sandbox {
SANDBOX_COROUTINE(coro,
int32_t duration;
int32_t i;
int32_t brightness;
VALUE operator()(VALUE self, VALUE value) {
BOOST_ASIO_CORO_REENTER (this) {
SANDBOX_AWAIT_AND_SET(duration, rb_num2int, value);
brightness = shState->graphics().getBrightness();
for (i = 0; i < duration; ++i) {
shState->graphics().fadeout(duration, i, i);
shState->graphics().fadeout(duration, i, i, brightness);
SANDBOX_YIELD;
}
}
@ -149,13 +151,15 @@ namespace mkxp_sandbox {
SANDBOX_COROUTINE(coro,
int32_t duration;
int32_t i;
int32_t brightness;
VALUE operator()(VALUE self, VALUE value) {
BOOST_ASIO_CORO_REENTER (this) {
SANDBOX_AWAIT_AND_SET(duration, rb_num2int, value);
brightness = shState->graphics().getBrightness();
for (i = 0; i < duration; ++i) {
shState->graphics().fadein(duration, i, i);
shState->graphics().fadein(duration, i, i, brightness);
SANDBOX_YIELD;
}
}

View file

@ -1458,14 +1458,14 @@ void Graphics::wait(int duration, int start, int stop) {
}
}
void Graphics::fadeout(int duration, int start, int stop) {
void Graphics::fadeout(int duration, int start, int stop, int brightness) {
FBO::unbind();
float curr = p->brightness;
float curr = brightness >= 0 && brightness <= 255 ? brightness : p->brightness;
float diff = 255.0f - curr;
for (int i = std::min(stop, duration - 1); i >= start; --i) {
setBrightness(diff + (curr / duration) * i);
for (int i = start; i <= stop && i < duration;) {
setBrightness(diff + (curr / duration) * (duration - ++i));
if (p->frozen) {
int scaleIsSpecial = GLMeta::blitScaleIsSpecial(p->integerScaleBuffer, false, IntRect(0, 0, p->scSize.x, p->scSize.y), p->frozenScene, IntRect(0, 0, p->scRes.x, p->scRes.y));
@ -1485,10 +1485,10 @@ void Graphics::fadeout(int duration, int start, int stop) {
}
}
void Graphics::fadein(int duration, int start, int stop) {
void Graphics::fadein(int duration, int start, int stop, int brightness) {
FBO::unbind();
float curr = p->brightness;
float curr = brightness >= 0 && brightness <= 255 ? brightness : p->brightness;
float diff = 255.0f - curr;
for (int i = start; i <= stop && i < duration;) {

View file

@ -55,8 +55,8 @@ public:
DECL_ATTR( Brightness, int )
void wait(int duration, int start = 0, int stop = INT_MAX);
void fadeout(int duration, int start = 0, int stop = INT_MAX);
void fadein(int duration, int start = 0, int stop = INT_MAX);
void fadeout(int duration, int start = 0, int stop = INT_MAX, int brightness = -1);
void fadein(int duration, int start = 0, int stop = INT_MAX, int brightness = -1);
Bitmap *snapToBitmap();