1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00

Implement "Desktop" resolution (0x0, default). Also fix music slider update in options menu

This makes the window resizable in desktop mode, and fixed size otherwise.
Fullscreen desktop has always the dame resolution as the desktop.
Add config setting to specify initial display.
Add config setting for the refresh rate (not yet properly integrated)

Closes #17
This commit is contained in:
fgenesis 2017-01-13 13:06:31 +01:00
parent 40e5385636
commit b781b45789
8 changed files with 280 additions and 145 deletions

View file

@ -775,13 +775,13 @@ void DSQ::setVersionLabelText()
versionLabel->setText(os.str());
}
static bool sdlVideoModeOK(const int w, const int h, const int bpp)
static bool sdlVideoModeOK(int disp, const int w, const int h, const int bpp)
{
#ifdef BBGE_BUILD_SDL2
SDL_DisplayMode mode;
const int modecount = SDL_GetNumDisplayModes(0);
const int modecount = SDL_GetNumDisplayModes(disp);
for (int i = 0; i < modecount; i++) {
SDL_GetDisplayMode(0, i, &mode);
SDL_GetDisplayMode(disp, i, &mode);
if (!mode.w || !mode.h || (w >= mode.w && h >= mode.h)) {
return true;
}
@ -897,17 +897,19 @@ This build is not yet final, and as such there are a couple things lacking. They
debugLog("VoiceOvers Disabled");
SDL_Init(SDL_INIT_VIDEO);
if (fullscreen && !sdlVideoModeOK(user.video.resx, user.video.resy, user.video.bits))
if (fullscreen && !sdlVideoModeOK(user.video.displayindex, user.video.resx, user.video.resy, user.video.bits))
{
// maybe we can force a sane resolution if SetVideoMode is going to fail...
user.video.resx = 800;
user.video.resy = 600;
if (!sdlVideoModeOK(user.video.resx, user.video.resy, user.video.bits))
user.video.hz = 60;
user.video.displayindex = 0;
if (!sdlVideoModeOK(0, user.video.resx, user.video.resy, user.video.bits))
fullscreen = false; // last chance.
}
debugLog("Init Graphics Library...");
initGraphicsLibrary(user.video.resx, user.video.resy, fullscreen, user.video.vsync, user.video.bits);
initGraphicsLibrary(user.video.resx, user.video.resy, fullscreen, user.video.vsync, user.video.bits, user.video.displayindex);
debugLog("OK");
debugLog("Init Sound Library...");
@ -1704,8 +1706,6 @@ void DSQ::unloadDevice()
void DSQ::reloadDevice()
{
loadFonts();
Core::reloadDevice();
darkLayer.reloadDevice();

View file

@ -1693,6 +1693,31 @@ RenderObject *InGameMenu::createBasicKeyConfig()
return keyConfig;
}
static std::string screenModeStr(const ScreenMode& m)
{
std::ostringstream os;
if(!m.x && !m.y)
{
os << dsq->continuity.stringBank.get(2142);
}
else
{
os << m.x << "x" << m.y;
if(m.hz)
os << " (" << m.hz << "hz)";
}
return os.str();
}
static bool isCurrentScreenMode(const ScreenMode& m)
{
if(!m.x && !m.y && core->isDesktopResolution())
return true;
return m.x == dsq->user.video.resx && m.y == dsq->user.video.resy && (!m.hz || dsq->user.video.hz == m.hz);
}
void InGameMenu::create()
{
float menuz = 4;
@ -1795,12 +1820,9 @@ void InGameMenu::create()
resBox->position = Vector(196, 285);
for (i = 0; i < core->screenModes.size(); i++)
{
std::ostringstream os;
os << core->screenModes[i].x << "x" << core->screenModes[i].y;
if(core->screenModes[i].hz)
os << " (" << core->screenModes[i].hz << "hz)";
resBox->addItem(os.str());
if (core->screenModes[i].x == dsq->user.video.resx && core->screenModes[i].y == dsq->user.video.resy)
const ScreenMode& m = core->screenModes[i];
resBox->addItem(screenModeStr(m));
if (isCurrentScreenMode(m))
{
resBox->enqueueSelectItem(i);
}
@ -3256,6 +3278,18 @@ void InGameMenu::onOptionsMenu()
void InGameMenu::onOptionsSave()
{
if (resBox)
{
int itm = resBox->getSelectedItem();
if(itm < core->screenModes.size()) // Required because the menu appends another element if it can't select one in the list
{
const ScreenMode& m = core->screenModes[itm];
dsq->user.video.resx = m.x;
dsq->user.video.resy = m.y;
dsq->user.video.hz = m.hz;
}
}
dsq->user.apply();
if (dsq->user.video.resx != dsq->user_backup.video.resx
@ -3872,19 +3906,20 @@ void InGameMenu::toggleOptionsMenu(bool f, bool skipBackup, bool isKeyConfig)
if (ripplesCheck)
ripplesCheck->setValue(core->afterEffectManager!=0);
switchToActionSet(selectedActionSetIdx);
if (resBox)
{
std::ostringstream os;
os << core->width << "x" << core->height;
if (!resBox->setSelectedItem(os.str()))
// Note: This adds one past the original list (core->screenModes)
ScreenMode m = core->isDesktopResolution() ? ScreenMode(0,0,0) : ScreenMode(core->width, core->height, 0);
std::string mstr = screenModeStr(m);
if (!resBox->setSelectedItem(mstr))
{
resBox->addItem(os.str());
resBox->setSelectedItem(os.str());
resBox->addItem(mstr);
resBox->setSelectedItem(mstr);
}
}
switchToActionSet(selectedActionSetIdx);
opt_cancel->setDirMove(DIR_UP, targetingCheck);
targetingCheck->setDirMove(DIR_DOWN, opt_cancel);
@ -4025,19 +4060,6 @@ void InGameMenu::updateOptionsMenu(float dt)
if (blurEffectsCheck)
dsq->user.video.blur = blurEffectsCheck->getValue();
if (resBox)
{
std::string s = resBox->getSelectedItemString();
if (!s.empty())
{
int pos = s.find('x');
std::istringstream is1(s.substr(0, pos));
is1 >> dsq->user.video.resx;
std::istringstream is2(s.substr(pos+1, s.size()-(pos+1)));
is2 >> dsq->user.video.resy;
}
}
bool apply = false;
optsfxdly += dt;
if (sfxslider->hadInput())
@ -4051,6 +4073,10 @@ void InGameMenu::updateOptionsMenu(float dt)
dsq->voice("naija_somethingfamiliar");
apply = true;
}
else if(musslider->hadInput() || musslider->isGrabbed())
{
apply = true;
}
else if (optsfxdly > 0.6f)
{
optsfxdly = 0;

View file

@ -131,6 +131,7 @@ void UserSettings::save()
{
xml_screenMode->SetAttribute("resx", video.resx);
xml_screenMode->SetAttribute("resy", video.resy);
xml_screenMode->SetAttribute("hz", video.hz);
xml_screenMode->SetAttribute("bits", video.bits);
xml_screenMode->SetAttribute("fbuffer", video.fbuffer);
xml_screenMode->SetAttribute("full", video.full);
@ -138,6 +139,7 @@ void UserSettings::save()
xml_screenMode->SetAttribute("darkfbuffer", video.darkfbuffer);
xml_screenMode->SetAttribute("darkbuffersize", video.darkbuffersize);
xml_screenMode->SetAttribute("displaylists", video.displaylists);
xml_screenMode->SetAttribute("displayindex", video.displayindex);
}
xml_video->InsertEndChild(xml_screenMode);
@ -452,6 +454,7 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
{
xml_screenMode->QueryIntAttribute("resx", &video.resx);
xml_screenMode->QueryIntAttribute("resy", &video.resy);
xml_screenMode->QueryIntAttribute("hz", &video.hz);
xml_screenMode->QueryIntAttribute("bits", &video.bits);
xml_screenMode->QueryIntAttribute("fbuffer", &video.fbuffer);
xml_screenMode->QueryIntAttribute("full", &video.full);
@ -459,6 +462,7 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
xml_screenMode->QueryIntAttribute("darkfbuffer", &video.darkfbuffer);
xml_screenMode->QueryIntAttribute("darkbuffersize", &video.darkbuffersize);
xml_screenMode->QueryIntAttribute("displaylists", &video.displaylists);
xml_screenMode->QueryIntAttribute("displayindex", &video.displayindex);
}
readInt(xml_video, "SaveSlotScreens", "on", &video.saveSlotScreens);

View file

@ -65,6 +65,8 @@ public:
fpsSmoothing = 30;
resx = 800;
resy = 600;
hz = 60;
displayindex = 0;
full = 1;
fbuffer = 1;
darkfbuffer = 1;
@ -77,7 +79,7 @@ public:
int blur;
int noteEffects;
int fpsSmoothing;
int resx, resy, full, fbuffer, bits, vsync, darkfbuffer, darkbuffersize;
int resx, resy, full, fbuffer, bits, vsync, darkfbuffer, darkbuffersize, hz, displayindex;
int saveSlotScreens;
int parallaxOn0, parallaxOn1, parallaxOn2;
int numParticles;

View file

@ -69,6 +69,7 @@ static std::ofstream _logOut;
#define KMOD_GUI KMOD_META
#endif
void Core::resetCamera()
{
cameraPos = Vector(0,0);
@ -145,11 +146,45 @@ void Core::setup_opengl()
}
void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp, int display)
{
assert(lib_graphics);
bool wasFullscreen = _fullscreen;
const int oldDisplay = getDisplayIndex();
if(display == -1)
display = oldDisplay;
int screenw = 0, screenh = 0;
if(display >= 0)
{
SDL_DisplayMode desktop;
if(SDL_GetDesktopDisplayMode(display, &desktop) == 0)
{
screenw = desktop.w;
screenh = desktop.h;
}
else // fail-safe
{
screenw = 800;
screenh = 600;
display = oldDisplay;
}
// Move window to specified display if necessary
if(display != oldDisplay)
{
SDL_Rect bounds;
SDL_GetDisplayBounds(display,&bounds);
SDL_SetWindowPosition(gScreen, bounds.x, bounds.y);
}
}
const int oldw = width;
const int oldh = height;
const bool useDesktop = w == 0 || h == 0 || (oldw && w == -1 && oldh && h == -1 && _useDesktopResolution);
const bool wasFullscreen = _fullscreen;
if (fullscreen == -1)
fullscreen = _fullscreen;
@ -157,6 +192,12 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
if (vsync == -1)
vsync = _vsync;
if(useDesktop)
{
w = screenw;
h = screenh;
}
if (w == -1)
w = width;
@ -166,10 +207,6 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
if (bpp == -1)
bpp = _bpp;
int oldw = width;
int oldh = height;
width = w;
height = h;
_vsync = vsync;
_fullscreen = fullscreen;
_bpp = bpp;
@ -183,52 +220,58 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
else
SDL_GL_SetSwapInterval(0);
if(w != oldw|| h != oldh)
SDL_SetWindowSize(gScreen, w, h);
// Record window position so we can properly restore it when leaving fullscreen
if(fullscreen && !wasFullscreen)
SDL_GetWindowPosition(gScreen, &winPosX, &winPosY);
if(!!fullscreen != wasFullscreen)
{
int screenflags = 0;
if(fullscreen)
{
// Record window position so we can properly restore it when leaving fullscreen
if(!wasFullscreen)
SDL_GetWindowPosition(gScreen, &winPosX, &winPosY);
// Use desktop fullscreen if possible, but only if the resolution
// matches the actual desktop resolution.
// Else we'll get unused areas on the screen.
int disp = SDL_GetWindowDisplayIndex(gScreen);
if(disp >= 0)
{
SDL_DisplayMode desktop;
if(SDL_GetDesktopDisplayMode(disp, &desktop) == 0)
{
if(w == desktop.w && h == desktop.h)
{
screenflags = SDL_WINDOW_FULLSCREEN_DESKTOP;
debugLog("Switching to desktop fullscreen");
}
}
}
if(!screenflags)
{
screenflags = SDL_WINDOW_FULLSCREEN;
debugLog("Switching to fullscreen");
}
screenflags |= useDesktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
}
SDL_SetWindowFullscreen(gScreen, screenflags);
if(!fullscreen)
{
SDL_SetWindowSize(gScreen, w, h);
if(wasFullscreen)
if(!fullscreen && wasFullscreen)
{
// Need to do this; else the window ends up at (0, 0) with the title bar outside the screen area
SDL_SetWindowPosition(gScreen, winPosX, winPosY);
}
}
bool resize = true;
bool reloadRes = false;
if(useDesktop != _useDesktopResolution)
{
if(useDesktop)
createWindow(oldw, oldh, true, fullscreen);
else
createWindow(w, h, false, fullscreen);
reloadRes = true;
if(useDesktop)
{
SDL_MaximizeWindow(gScreen);
resize = false;
}
}
// First time called + windowed mode --> maximize window
else if(!oldw && !oldh && useDesktop && !fullscreen)
{
SDL_MaximizeWindow(gScreen);
resize = false;
}
if(resize && !fullscreen && !useDesktop)
{
if(w != oldw|| h != oldh)
{
SDL_SetWindowSize(gScreen, w, h);
int c = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
SDL_SetWindowPosition(gScreen, c, c);
}
}
#else
@ -237,16 +280,33 @@ void Core::initGraphics(int w, int h, int fullscreen, int vsync, int bpp)
#endif
_useDesktopResolution = useDesktop;
SDL_GetWindowSize(gScreen, &w, &h);
updateWindowDrawSize(w, h);
if(reloadRes)
{
unloadResources();
reloadResources();
resetTimer();
}
}
void Core::updateWindowDrawSize(int w, int h)
{
width = w;
height = h;
setup_opengl();
enable2DWide(w, h);
reloadDevice();
resetTimer();
}
void Core::onWindowResize(int w, int h)
{
initGraphics(w, h);
updateWindowDrawSize(w, h);
}
void Core::setFullscreen(bool full)
@ -440,6 +500,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
doScreenshot = false;
baseCullRadius = 1;
width = height = 0;
_fullscreen = false;
afterEffectManagerLayer = 0;
renderObjectLayers.resize(1);
invGlobalScale = 1.0;
@ -586,6 +647,20 @@ bool Core::isFullscreen()
return _fullscreen;
}
bool Core::isDesktopResolution()
{
return _useDesktopResolution;
}
int Core::getDisplayIndex()
{
#ifdef BBGE_BUILD_SDL2
return SDL_GetWindowDisplayIndex(gScreen);
#else
return 0;
#endif
}
bool Core::isShuttingDown()
{
return shuttingDown;
@ -752,7 +827,7 @@ void Core::setClearColor(const Vector &c)
}
bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsync, int bpp)
bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsync, int bpp, int display)
{
assert(!gScreen);
@ -783,62 +858,7 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
#endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
{
#ifdef BBGE_BUILD_SDL2
Uint32 flags = 0;
flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE;
if (fullscreen)
flags |= SDL_WINDOW_FULLSCREEN;
gScreen = SDL_CreateWindow(appName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
if (gScreen == NULL)
{
std::ostringstream os;
os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError();
errorLog(os.str());
SDL_Quit();
exit(0);
}
gGLctx = SDL_GL_CreateContext(gScreen);
if (gGLctx == NULL)
{
std::ostringstream os;
os << "Couldn't create OpenGL context!\n" << SDL_GetError();
errorLog(os.str());
SDL_Quit();
exit(0);
}
{
const char *name = SDL_GetCurrentVideoDriver();
std::ostringstream os2;
os2 << "Video Driver Name [" << name << "]";
debugLog(os2.str());
}
#else
Uint32 flags = 0;
flags = SDL_OPENGL;
if (fullscreen)
flags |= SDL_FULLSCREEN;
gScreen = SDL_SetVideoMode(width, height, bpp, flags);
if (gScreen == NULL)
{
std::ostringstream os;
os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError();
SDL_Quit();
exit_error(os.str());
}
{
char name[256];
SDL_VideoDriverName((char*)name, 256);
std::ostringstream os2;
os2 << "Video Driver Name [" << name << "]";
debugLog(os2.str());
}
#endif
}
createWindow(width, height, !width && !height, fullscreen);
#if BBGE_BUILD_OPENGL_DYNAMIC
if (SDL_GL_LoadLibrary(NULL) == -1)
@ -866,7 +886,7 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
enumerateScreenModes();
initGraphics(width, height, fullscreen, vsync, bpp);
initGraphics(width, height, fullscreen, vsync, bpp, display);
_hasFocus = true;
@ -874,11 +894,90 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn
return true;
}
void Core::createWindow(int w, int h, bool resizable, bool fullscreen)
{
if(w <= 0)
w = 640;
if(h <= 0)
h = 480;
#ifdef BBGE_BUILD_SDL2
if(gScreen)
{
SDL_DestroyWindow(gScreen);
gScreen = NULL;
}
if(gGLctx)
{
SDL_GL_MakeCurrent(gScreen, NULL);
SDL_GL_DeleteContext(gGLctx);
gGLctx = NULL;
}
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
if(resizable)
flags |= SDL_WINDOW_RESIZABLE;
//if(fullscreen) // Ignore fullscreen setting here, it's applied later
// flags |= SDL_WINDOW_FULLSCREEN;
gScreen = SDL_CreateWindow(appName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
if (gScreen == NULL)
{
std::ostringstream os;
os << "Couldn't set resolution [" << w << "x" << h << "]\n" << SDL_GetError();
errorLog(os.str());
SDL_Quit();
exit(0);
}
gGLctx = SDL_GL_CreateContext(gScreen);
if (gGLctx == NULL)
{
std::ostringstream os;
os << "Couldn't create OpenGL context!\n" << SDL_GetError();
errorLog(os.str());
SDL_Quit();
exit(0);
}
{
const char *name = SDL_GetCurrentVideoDriver();
std::ostringstream os2;
os2 << "Video Driver Name [" << name << "]";
debugLog(os2.str());
}
#else
Uint32 flags = 0;
flags = SDL_OPENGL;
if(fullscreen)
flags |= SDL_FULLSCREEN;
if (resizable)
flags |= SDL_RESIZABLE;
gScreen = SDL_SetVideoMode(width, height, bpp, flags);
if (gScreen == NULL)
{
std::ostringstream os;
os << "Couldn't set resolution [" << width << "x" << height << "]\n" << SDL_GetError();
SDL_Quit();
exit_error(os.str());
}
{
char name[256];
SDL_VideoDriverName((char*)name, 256);
std::ostringstream os2;
os2 << "Video Driver Name [" << name << "]";
debugLog(os2.str());
}
#endif
}
void Core::enumerateScreenModes()
{
screenModes.clear();
#ifdef BBGE_BUILD_SDL2
screenModes.push_back(ScreenMode(0, 0, 0)); // "Desktop" screen mode
SDL_DisplayMode mode;
const int modecount = SDL_GetNumDisplayModes(0);
if(modecount == 0){
@ -890,7 +989,7 @@ void Core::enumerateScreenModes()
SDL_GetDisplayMode(0, i, &mode);
if (mode.w && mode.h && (mode.w > mode.h))
{
screenModes.push_back(ScreenMode(i, mode.w, mode.h, mode.refresh_rate));
screenModes.push_back(ScreenMode(mode.w, mode.h, mode.refresh_rate));
}
}

View file

@ -41,10 +41,10 @@ class ParticleManager;
struct ScreenMode
{
ScreenMode() { idx = x = y = hz = 0; }
ScreenMode(int i, int x, int y, int hz) : idx(i), x(x), y(y), hz(hz) {}
ScreenMode() { x = y = hz = 0; }
ScreenMode(int x, int y, int hz) : x(x), y(y), hz(hz) {}
int idx, x, y, hz;
int x, y, hz;
};
struct CoreSettings
@ -278,7 +278,8 @@ public:
unsigned getTicks();
void initGraphics(int w, int h, int fullscreen=-1, int vsync=-1, int bpp=-1);
void initGraphics(int w, int h, int fullscreen=-1, int vsync=-1, int bpp=-1, int display=-1); // pass 0x0 for desktop resolution
void updateWindowDrawSize(int w, int h);
Vector getGameCursorPosition();
Vector getGamePosition(const Vector &v);
@ -413,6 +414,8 @@ public:
void updateInputGrab();
bool isFullscreen();
bool isDesktopResolution();
int getDisplayIndex();
int getVirtualOffX();
int getVirtualOffY();
@ -480,7 +483,8 @@ protected:
bool initSoundLibrary(const std::string &defaultDevice);
bool initInputLibrary();
void initJoystickLibrary();
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp);
bool initGraphicsLibrary(int w, int h, bool fullscreen, bool vsync, int bpp, int display);
void createWindow(int w, int h, bool resizable, bool fullscreen);
void shutdownInputLibrary();
void shutdownJoystickLibrary();
void shutdownGraphicsLibrary();
@ -510,7 +514,7 @@ protected:
int nowTicks, thenTicks;
int _vsync, _bpp;
bool _fullscreen;
bool _fullscreen, _useDesktopResolution;
int winPosX, winPosY; // pre-fullscreen
CountedPtr<Texture> texError;

View file

@ -97,6 +97,8 @@ bool FrameBuffer::init(int width, int height, bool fitToScreen)
return false;
}
unloadDevice();
//
// Create a frame-buffer object and a render-buffer object...
//
@ -177,7 +179,6 @@ void FrameBuffer::unloadDevice()
if (g_frameBuffer)
{
debugLog("bind 0");
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 );
debugLog("frameBuffer handle present, deleting");
@ -187,7 +188,6 @@ void FrameBuffer::unloadDevice()
if (g_dynamicTextureID)
{
debugLog("bind 0");
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 );
debugLog("dynamic texture ID handle present, deleting");
@ -197,7 +197,6 @@ void FrameBuffer::unloadDevice()
if (g_depthRenderBuffer)
{
debugLog("bind 0");
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 );
debugLog("depth render buffer handle present, deleting");

View file

@ -251,6 +251,7 @@
2139 No Joystick
2140 Joystick:
2141 Not available:
2142 Desktop
2150 Movement
2151 Menu
2152 Quick Keys