VOGONS


SDL code refatoring?

Topic actions

First post, by clearer

User metadata
Rank Newbie
Rank
Newbie

(no, this is not done yet, so please go away if you just want the code).

I've had a few minor issues* with DOSBox 0.74 on a dual screen setup on a Linux box with RandR 1.3 (haven't tested this on RandR 1.2) -- I haven't figured out if it's an SDL issue or a DOSBox issue yet, but as far as I can tell it's a DOSBox issue. Anywho -- I looked at the code that uses SDL and it's pretty convoluted IMHO and filled with custom code for Mac OS X, Windows and X11. Are there any good reasons why it's so convoluted and that it has all those extras #ifdef <insert OS macro> ... #endif section? I was thinking about refactoring the code to make it simpler and cleaner, before I look at the my percieved problems.

Oh, and I simplified a function in sdlmain.cpp

static SDL_Surface * GFX_SetupSurfaceScaled(Bit32u flags, Bit32u bpp)
{
// Assume that the mode is not fullscreen (update if required)
Bit16u width = sdl.draw.width * sdl.draw.scalex;
Bit16u height = sdl.draw.height * sdl.draw.scaley;
flags |= SDL_HWSURFACE;

// Update width/height according to fullscreen
if (sdl.desktop.fullscreen)
{
width = sdl.desktop.full.width;
height = sdl.desktop.full.height;
flags |= SDL_FULLSCREEN;
}

sdl.clip.w = width;
sdl.clip.h = height;

// Update clipping according to fixed fullscreen
if (sdl.desktop.fullscreen and sdl.desktop.full.fixed)
{
double ratio_w = double(width) / (sdl.draw.width * sdl.draw.scalex);
double ratio_h = double(height) / (sdl.draw.height * sdl.draw.scaley);
if (ratio_w < ratio_h)
sdl.clip.h = sdl.draw.height * sdl.draw.scaley * ratio_w;
else
sdl.clip.w = sdl.draw.width * sdl.draw.scalex * ratio_h;
}

// Get the surface
sdl.surface = SDL_SetVideoMode(width, height, bpp, flags);

// Update clipping coordinates
if (sdl.surface)
{
sdl.clip.x = (sdl.surface->w - sdl.clip.w) / 2;
sdl.clip.y = (sdl.surface->h - sdl.clip.h) / 2;
}

return sdl.surface;
}

Much easier on the eye and less convoluted than the old one (plus it's commented).

* The issue(s) is that when I make DOSBox leave fullscreen, it turns off one of my monitors, which means I have to manually turn it on again -- notice that DOSBox does not turn it off when entering fullscreen.