3DS: Defer texture updates when the palette changes

Fixes a performance issue with the Gob engine where the palette is
updated a large number of times during a single frame.
This commit is contained in:
Bastien Bouclet 2020-02-14 06:21:46 +01:00
parent ac87c01895
commit e1358b966a
3 changed files with 10 additions and 6 deletions

View File

@ -329,12 +329,9 @@ float OSystem_3DS::getScaleRatio() const {
void OSystem_3DS::setPalette(const byte *colors, uint start, uint num) { void OSystem_3DS::setPalette(const byte *colors, uint start, uint num) {
assert(start + num <= 256); assert(start + num <= 256);
memcpy(_palette + 3 * start, colors, 3 * num); memcpy(_palette + 3 * start, colors, 3 * num);
_gameTextureDirty = true;
// Manually update all color that were changed
if (_gameScreen.format.bytesPerPixel == 1) {
flushGameScreen();
}
} }
void OSystem_3DS::grabPalette(byte *colors, uint start, uint num) const { void OSystem_3DS::grabPalette(byte *colors, uint start, uint num) const {
assert(start + num <= 256); assert(start + num <= 256);
memcpy(colors, _palette + 3 * start, 3 * num); memcpy(colors, _palette + 3 * start, 3 * num);
@ -391,7 +388,7 @@ Graphics::Surface *OSystem_3DS::lockScreen() {
return &_gameScreen; return &_gameScreen;
} }
void OSystem_3DS::unlockScreen() { void OSystem_3DS::unlockScreen() {
flushGameScreen(); _gameTextureDirty = true;
} }
void OSystem_3DS::updateScreen() { void OSystem_3DS::updateScreen() {
@ -399,6 +396,11 @@ void OSystem_3DS::updateScreen() {
return; return;
} }
if (_gameTextureDirty) {
flushGameScreen();
_gameTextureDirty = false;
}
// updateFocus(); // updateFocus();
updateMagnify(); updateMagnify();

View File

@ -78,6 +78,7 @@ OSystem_3DS::OSystem_3DS():
_magY(0), _magY(0),
_magWidth(400), _magWidth(400),
_magHeight(240), _magHeight(240),
_gameTextureDirty(false),
_overlayVisible(false), _overlayVisible(false),
_screenChangeId(0), _screenChangeId(0),
_magnifyMode(MODE_MAGOFF), _magnifyMode(MODE_MAGOFF),

View File

@ -222,6 +222,7 @@ private:
byte _cursorPalette[3 * 256]; byte _cursorPalette[3 * 256];
Graphics::Surface _gameScreen; Graphics::Surface _gameScreen;
bool _gameTextureDirty;
Sprite _gameTopTexture; Sprite _gameTopTexture;
Sprite _gameBottomTexture; Sprite _gameBottomTexture;
Sprite _overlay; Sprite _overlay;