SDL: Get rid of loop in OSystem_SDL::setGraphicsMode.
This commit is contained in:
parent
e91300f70c
commit
c5e2b5158c
2 changed files with 60 additions and 74 deletions
|
@ -551,16 +551,9 @@ int OSystem_SDL::getDefaultGraphicsMode() const {
|
|||
}
|
||||
|
||||
bool OSystem_SDL::setGraphicsMode(int mode) {
|
||||
const OSystem::GraphicsMode *srcMode;
|
||||
int i;
|
||||
|
||||
// Check if mode is from SDL or OpenGL
|
||||
if (mode < _sdlModesCount) {
|
||||
srcMode = SurfaceSdlGraphicsManager::supportedGraphicsModes();
|
||||
i = 0;
|
||||
} else {
|
||||
srcMode = OpenGLSdlGraphicsManager::supportedGraphicsModes();
|
||||
i = _sdlModesCount;
|
||||
// Check whether a invalid mode is requested.
|
||||
if (mode < 0 || (uint)mode >= _graphicsModeIds.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Very hacky way to set up the old graphics manager state, in case we
|
||||
|
@ -579,74 +572,64 @@ bool OSystem_SDL::setGraphicsMode(int mode) {
|
|||
|
||||
bool switchedManager = false;
|
||||
|
||||
// Loop through modes
|
||||
while (srcMode->name) {
|
||||
if (i == mode) {
|
||||
// If the new mode and the current mode are not from the same graphics
|
||||
// manager, delete and create the new mode graphics manager
|
||||
if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) {
|
||||
debug(1, "switching to plain SDL graphics");
|
||||
_graphicsManager->deactivateManager();
|
||||
delete _graphicsManager;
|
||||
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
|
||||
// If the new mode and the current mode are not from the same graphics
|
||||
// manager, delete and create the new mode graphics manager
|
||||
if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) {
|
||||
debug(1, "switching to plain SDL graphics");
|
||||
_graphicsManager->deactivateManager();
|
||||
delete _graphicsManager;
|
||||
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
|
||||
|
||||
switchedManager = true;
|
||||
} else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) {
|
||||
debug(1, "switching to OpenGL graphics");
|
||||
_graphicsManager->deactivateManager();
|
||||
delete _graphicsManager;
|
||||
_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
|
||||
switchedManager = true;
|
||||
} else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) {
|
||||
debug(1, "switching to OpenGL graphics");
|
||||
_graphicsManager->deactivateManager();
|
||||
delete _graphicsManager;
|
||||
_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
|
||||
|
||||
switchedManager = true;
|
||||
}
|
||||
|
||||
_graphicsMode = mode;
|
||||
|
||||
if (switchedManager) {
|
||||
_graphicsManager->activateManager();
|
||||
|
||||
_graphicsManager->beginGFXTransaction();
|
||||
#ifdef USE_RGB_COLOR
|
||||
_graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat);
|
||||
#else
|
||||
_graphicsManager->initSize(screenWidth, screenHeight, 0);
|
||||
#endif
|
||||
_graphicsManager->setFeatureState(kFeatureAspectRatioCorrection, arState);
|
||||
_graphicsManager->setFeatureState(kFeatureFullscreenMode, fullscreen);
|
||||
_graphicsManager->setFeatureState(kFeatureCursorPalette, cursorPalette);
|
||||
|
||||
// Worst part about this right now, tell the cursor manager to
|
||||
// resetup the cursor + cursor palette if necessarily
|
||||
|
||||
// First we need to try to setup the old state on the new manager...
|
||||
if (_graphicsManager->endGFXTransaction() != kTransactionSuccess) {
|
||||
// Oh my god if this failed the client code might just explode.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Next setup the cursor again
|
||||
CursorMan.pushCursor(0, 0, 0, 0, 0, 0);
|
||||
CursorMan.popCursor();
|
||||
|
||||
// Next setup cursor palette if needed
|
||||
if (cursorPalette) {
|
||||
CursorMan.pushCursorPalette(0, 0, 0);
|
||||
CursorMan.popCursorPalette();
|
||||
}
|
||||
|
||||
_graphicsManager->beginGFXTransaction();
|
||||
// Oh my god if this failed the client code might just explode.
|
||||
return _graphicsManager->setGraphicsMode(srcMode->id);
|
||||
} else {
|
||||
return _graphicsManager->setGraphicsMode(srcMode->id);
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
srcMode++;
|
||||
switchedManager = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
_graphicsMode = mode;
|
||||
|
||||
if (switchedManager) {
|
||||
_graphicsManager->activateManager();
|
||||
|
||||
_graphicsManager->beginGFXTransaction();
|
||||
#ifdef USE_RGB_COLOR
|
||||
_graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat);
|
||||
#else
|
||||
_graphicsManager->initSize(screenWidth, screenHeight, 0);
|
||||
#endif
|
||||
_graphicsManager->setFeatureState(kFeatureAspectRatioCorrection, arState);
|
||||
_graphicsManager->setFeatureState(kFeatureFullscreenMode, fullscreen);
|
||||
_graphicsManager->setFeatureState(kFeatureCursorPalette, cursorPalette);
|
||||
|
||||
// Worst part about this right now, tell the cursor manager to
|
||||
// resetup the cursor + cursor palette if necessarily
|
||||
|
||||
// First we need to try to setup the old state on the new manager...
|
||||
if (_graphicsManager->endGFXTransaction() != kTransactionSuccess) {
|
||||
// Oh my god if this failed the client code might just explode.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Next setup the cursor again
|
||||
CursorMan.pushCursor(0, 0, 0, 0, 0, 0);
|
||||
CursorMan.popCursor();
|
||||
|
||||
// Next setup cursor palette if needed
|
||||
if (cursorPalette) {
|
||||
CursorMan.pushCursorPalette(0, 0, 0);
|
||||
CursorMan.popCursorPalette();
|
||||
}
|
||||
|
||||
_graphicsManager->beginGFXTransaction();
|
||||
// Oh my god if this failed the client code might just explode.
|
||||
return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]);
|
||||
} else {
|
||||
return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]);
|
||||
}
|
||||
}
|
||||
|
||||
int OSystem_SDL::getGraphicsMode() const {
|
||||
|
@ -655,6 +638,7 @@ int OSystem_SDL::getGraphicsMode() const {
|
|||
|
||||
void OSystem_SDL::setupGraphicsModes() {
|
||||
_graphicsModes.clear();
|
||||
_graphicsModeIds.clear();
|
||||
|
||||
const OSystem::GraphicsMode *sdlGraphicsModes = SurfaceSdlGraphicsManager::supportedGraphicsModes();
|
||||
const OSystem::GraphicsMode *openglGraphicsModes = OpenGLSdlGraphicsManager::supportedGraphicsModes();
|
||||
|
@ -684,6 +668,7 @@ void OSystem_SDL::setupGraphicsModes() {
|
|||
int i = 0;
|
||||
OSystem::GraphicsMode *mode = _graphicsModes.begin();
|
||||
while (mode->name) {
|
||||
_graphicsModeIds.push_back(mode->id);
|
||||
mode->id = i++;
|
||||
mode++;
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ protected:
|
|||
|
||||
typedef Common::Array<GraphicsMode> GraphicsModeArray;
|
||||
GraphicsModeArray _graphicsModes;
|
||||
Common::Array<int> _graphicsModeIds;
|
||||
int _graphicsMode;
|
||||
int _sdlModesCount;
|
||||
int _glModesCount;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue