Skip to content

Commit

Permalink
fix #4388: save windowed size in separate tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jK committed Dec 16, 2014
1 parent d0fd7af commit 71fbd52
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 48 deletions.
17 changes: 10 additions & 7 deletions doc/manpages/spring.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ifdef::DEDICATED[{BINARY} - An open source RTS game engine - Dedicated Server]

Synopsis
--------
ifndef::GUILESS[*{BINARY}* [-f|--fullscreen] [-w|--window] [-x|--xresolution 'SIZE'] [-y|--yresolution 'SIZE'] [-m|--minimise] [--safemode] [-s|--server 'IP_OR_HOSTNAME'] [-p|--projectiledump] [-t|--textureatlas] [--benchmark 'TIME' [--benchmarkstart 'TIME']] [-i|--isolation] [--isolation-dir 'PATH'] [-n|--name 'STRING'] [-C|--config 'FILE'] ['SCRIPT']]
ifndef::GUILESS[*{BINARY}* [-f|--fullscreen] [-w|--window] [-m|--minimise] [--safemode] [-s|--server 'IP_OR_HOSTNAME'] [-p|--projectiledump] [-t|--textureatlas] [--benchmark 'TIME' [--benchmarkstart 'TIME']] [-i|--isolation] [--isolation-dir 'PATH'] [-n|--name 'STRING'] [-C|--config 'FILE'] ['SCRIPT']]
ifdef::HEADLESS[*{BINARY}* [--safemode] [-s|--server 'IP_OR_HOSTNAME'] [-p|--projectiledump] [--benchmark 'TIME' [--benchmarkstart 'TIME']] [-i|--isolation] [--isolation-dir 'PATH'] [-n|--name 'STRING'] [-C|--config 'FILE'] SCRIPT]
ifdef::DEDICATED[*{BINARY}* [-i|--isolation] [--isolation-dir 'PATH'] [-C|--config 'FILE'] SCRIPT]
ifndef::DEDICATED[]
Expand Down Expand Up @@ -90,12 +90,6 @@ ifndef::GUILESS[ ]
ifndef::GUILESS[*-w, --window*::]
ifndef::GUILESS[ Run in windowed mode]
ifndef::GUILESS[ ]
ifndef::GUILESS[*-x, --xresolution*::'SIZE'::]
ifndef::GUILESS[ Set X resolution]
ifndef::GUILESS[ ]
ifndef::GUILESS[*-y, --yresolution*::'SIZE'::]
ifndef::GUILESS[ Set Y resolution]
ifndef::GUILESS[ ]
ifndef::GUILESS[*-b, --minimise*::]
ifndef::GUILESS[ Start in background (minimised)]
ifndef::DEDICATED[ ]
Expand Down Expand Up @@ -187,6 +181,15 @@ Enviroment Variables
*SPRING_NOCOLOR*
Same as `spring --nocolor`.

Script
------
Can either be a:

- Spring URL (spring://[username[:password]@]host[:port])
- start script (often named script.txt)
- replay file (*.sdf)
- save game (*.ssf)

Portable Mode
-------------
An all-in-one-folder setup, which allows to run Spring without installation.
Expand Down
6 changes: 6 additions & 0 deletions rts/Game/UnsyncedGameCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "System/EventHandler.h"

#include <SDL_events.h>
#include <SDL_video.h>


static std::vector<std::string> _local_strSpaceTokenize(const std::string& text) {
Expand Down Expand Up @@ -1584,8 +1585,11 @@ class FullscreenActionExecutor : public IUnsyncedActionExecutor {
globalRendering->fullScreen = !globalRendering->fullScreen;
}

const int2 res = globalRendering->GetWantedViewSize(globalRendering->fullScreen);
const bool borderless = configHandler->GetBool("WindowBorderless");
if (globalRendering->fullScreen) {
SDL_SetWindowSize(globalRendering->window, res.x, res.y);

if (borderless) {
SDL_SetWindowFullscreen(globalRendering->window, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else {
Expand All @@ -1594,6 +1598,8 @@ class FullscreenActionExecutor : public IUnsyncedActionExecutor {
} else {
SDL_SetWindowFullscreen(globalRendering->window, 0);
SDL_SetWindowBordered(globalRendering->window, borderless ? SDL_FALSE : SDL_TRUE);
SDL_SetWindowSize(globalRendering->window, res.x, res.y);
SDL_SetWindowPosition(globalRendering->window, configHandler->GetInt("WindowPosX"), configHandler->GetInt("WindowPosY"));
}
return true;
}
Expand Down
33 changes: 30 additions & 3 deletions rts/Rendering/GlobalRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "System/creg/creg_cond.h"

#include <string>
#include <SDL_video.h>

CONFIG(bool, CompressTextures).defaultValue(false).safemodeValue(true).description("Runtime compress most textures to save VideoRAM."); // in safemode enabled, cause it ways more likely the gpu runs out of memory than this extension cause crashes!
CONFIG(int, ForceShaders).defaultValue(-1).minimumValue(-1).maximumValue(1);
Expand All @@ -31,6 +32,8 @@ CGlobalRendering* globalRendering;
const float CGlobalRendering::MAX_VIEW_RANGE = 8000.0f;
const float CGlobalRendering::NEAR_PLANE = 2.8f;
const float CGlobalRendering::SMF_INTENSITY_MULT = 210.0f / 255.0f;
const int CGlobalRendering::minWinSizeX = 400;
const int CGlobalRendering::minWinSizeY = 300;

CR_BIND(CGlobalRendering, )

Expand Down Expand Up @@ -309,12 +312,36 @@ void CGlobalRendering::SetFullScreen(bool configFullScreen, bool cmdLineWindowed
}
}

void CGlobalRendering::SetViewSize(int vsx, int vsy)

int2 CGlobalRendering::GetWantedViewSize(const bool fullscreen)
{
viewSizeX = vsx;
viewSizeY = vsy;
int2 res = int2(configHandler->GetInt("XResolution"), configHandler->GetInt("YResolution"));

if (!fullscreen) {
res = int2(configHandler->GetInt("XResolutionWindowed"), configHandler->GetInt("YResolutionWindowed"));
}

// Use Native Desktop Resolution
// and yes SDL2 can do this itself when sizeX & sizeY are set to zero, but
// oh wonder SDL2 fails then when you use Display Cloneing and similar
// -> i.e. DVI monitor runs then at 640x400 and HDMI at full-HD (yes with display _cloning_!)
{
SDL_DisplayMode dmode;
SDL_GetDesktopDisplayMode(0, &dmode); //TODO make screen configurable?
if (res.x<=0) res.x = dmode.w;
if (res.y<=0) res.y = dmode.h;
}

// In Windowed Mode Limit Minimum Window Size
if (!fullscreen) {
res.x = std::max(res.x, minWinSizeX);
res.y = std::max(res.y, minWinSizeY);
}

return res;
}


void CGlobalRendering::SetDualScreenParams() {
dualScreenMode = configHandler->GetBool("DualScreenMode");

Expand Down
8 changes: 6 additions & 2 deletions rts/Rendering/GlobalRendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "System/creg/creg_cond.h"
#include "System/Misc/SpringTime.h"
#include "System/type2.h"

struct SDL_Window;

Expand All @@ -22,11 +23,10 @@ class CGlobalRendering {
public:
void PostInit();
void SetFullScreen(bool configFullScreen, bool cmdLineWindowed, bool cmdLineFullScreen);
void SetViewSize(int vsx, int vsy);
void SetDualScreenParams();
void UpdateViewPortGeometry();
void UpdatePixelGeometry();

int2 GetWantedViewSize(const bool fullscreen);

/**
* @brief time offset
Expand Down Expand Up @@ -257,6 +257,10 @@ class CGlobalRendering {
/// magic constant to reduce overblending on SMF maps
/// (scales the MapInfo::light_t::ground*Color values)
static const float SMF_INTENSITY_MULT;


static const int minWinSizeX;
static const int minWinSizeY;
};

extern CGlobalRendering* globalRendering;
Expand Down
69 changes: 33 additions & 36 deletions rts/System/SpringApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@

CONFIG(unsigned, SetCoreAffinity).defaultValue(0).safemodeValue(1).description("Defines a bitmask indicating which CPU cores the main-thread should use.");
CONFIG(unsigned, SetCoreAffinitySim).defaultValue(0).safemodeValue(1).description("Defines a bitmask indicating which CPU cores the sim-thread should use.");
CONFIG(bool, UseHighResTimer).defaultValue(false).description("On Windows, sets whether Spring will use low- or high-resolution timer functions for tasks like graphical interpolation between game frames.");
CONFIG(int, PathingThreadCount).defaultValue(0).safemodeValue(1).minimumValue(0);

CONFIG(int, FSAALevel).defaultValue(0).minimumValue(0).maximumValue(8).description("If >0 enables FullScreen AntiAliasing.");
CONFIG(int, SmoothLines).defaultValue(2).headlessValue(0).safemodeValue(0).minimumValue(0).maximumValue(3).description("Smooth lines.\n 0 := off\n 1 := fastest\n 2 := don't care\n 3 := nicest");
CONFIG(int, SmoothPoints).defaultValue(2).headlessValue(0).safemodeValue(0).minimumValue(0).maximumValue(3).description("Smooth points.\n 0 := off\n 1 := fastest\n 2 := don't care\n 3 := nicest");
CONFIG(float, TextureLODBias).defaultValue(0.0f).minimumValue(-4.0f).maximumValue(4.0f);
CONFIG(bool, FixAltTab).defaultValue(false);

CONFIG(std::string, FontFile).defaultValue("fonts/FreeSansBold.otf").description("Sets the font of Spring engine text.");
CONFIG(std::string, SmallFontFile).defaultValue("fonts/FreeSansBold.otf").description("Sets the font of Spring engine small text.");
CONFIG(int, FontSize).defaultValue(23).description("Sets the font size (in pixels) of the MainMenu and more.");
Expand All @@ -97,18 +101,19 @@ CONFIG(int, FontOutlineWidth).defaultValue(3).description("Sets the width of the
CONFIG(float, FontOutlineWeight).defaultValue(25.0f).description("Sets the opacity of Spring engine text, such as the title screen version number, clock, and basic UI. Does not affect LuaUI elements.");
CONFIG(int, SmallFontOutlineWidth).defaultValue(2).description("see FontOutlineWidth");
CONFIG(float, SmallFontOutlineWeight).defaultValue(10.0f).description("see FontOutlineWeight");

CONFIG(bool, Fullscreen).defaultValue(true).headlessValue(false).description("Sets whether the game will run in fullscreen, as opposed to a window. For Windowed Fullscreen of Borderless Window, set this to 0, WindowBorderless to 1, and WindowPosX and WindowPosY to 0.");
CONFIG(bool, UseHighResTimer).defaultValue(false).description("On Windows, sets whether Spring will use low- or high-resolution timer functions for tasks like graphical interpolation between game frames.");
CONFIG(int, XResolution).defaultValue(0).headlessValue(8).minimumValue(0).description("Sets the width of the game screen. If set to 0 Spring will autodetect the current resolution of your desktop.");
CONFIG(int, YResolution).defaultValue(0).headlessValue(8).minimumValue(0).description("Sets the height of the game screen. If set to 0 Spring will autodetect the current resolution of your desktop.");
CONFIG(int, XResolutionWindowed).defaultValue(0).headlessValue(8).minimumValue(0).description("See XResolution, just for windowed.");
CONFIG(int, YResolutionWindowed).defaultValue(0).headlessValue(8).minimumValue(0).description("See YResolution, just for windowed.");
CONFIG(int, WindowPosX).defaultValue(32).description("Sets the horizontal position of the game window, if Fullscreen is 0. When WindowBorderless is set, this should usually be 0.");
CONFIG(int, WindowPosY).defaultValue(32).description("Sets the vertical position of the game window, if Fullscreen is 0. When WindowBorderless is set, this should usually be 0.");
CONFIG(int, WindowState).defaultValue(CGlobalRendering::WINSTATE_MAXIMIZED);
CONFIG(bool, WindowBorderless).defaultValue(false).description("When set and Fullscreen is 0, will put the game in Borderless Window mode, also known as Windowed Fullscreen. When using this, it is generally best to also set WindowPosX and WindowPosY to 0");
CONFIG(int, PathingThreadCount).defaultValue(0).safemodeValue(1).minimumValue(0);
CONFIG(std::string, name).defaultValue(UnnamedPlayerName).description("Sets your name in the game. Since this is overridden by lobbies with your lobby username when playing, it usually only comes up when viewing replays or starting the engine directly for testing purposes.");
CONFIG(bool, BlockCompositing).defaultValue(false).safemodeValue(true).description("Disables kwin compositing to fix tearing, possible fixes low FPS in windowed mode, too.");

CONFIG(std::string, name).defaultValue(UnnamedPlayerName).description("Sets your name in the game. Since this is overridden by lobbies with your lobby username when playing, it usually only comes up when viewing replays or starting the engine directly for testing purposes.");

static SDL_GLContext sdlGlCtx;
static SDL_Window* window;
Expand Down Expand Up @@ -197,7 +202,6 @@ bool SpringApp::Initialize()

globalRendering = new CGlobalRendering();
globalRendering->SetFullScreen(configHandler->GetBool("Fullscreen"), cmdline->IsSet("window"), cmdline->IsSet("fullscreen"));
globalRendering->SetViewSize(configHandler->GetInt("XResolution"), configHandler->GetInt("YResolution"));

#if !(defined(WIN32) || defined(__APPLE__) || defined(HEADLESS))
// this MUST run before any other X11 call (esp. those by SDL!)
Expand Down Expand Up @@ -341,22 +345,8 @@ bool SpringApp::CreateSDLWindow(const char* title)
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, globalRendering->FSAA);
}

// Use Native Desktop Resolution
// and yes SDL2 can do this itself when sizeX & sizeY are set to zero, but
// oh wonder SDL2 failes then when you use Display Cloneing and similar
// -> i.e. DVI monitor runs then at 640x400 and HDMI at full-HD (yes with display _cloning_!)
SDL_DisplayMode dmode;
SDL_GetDesktopDisplayMode(0, &dmode);
if (globalRendering->viewSizeX<=0) globalRendering->viewSizeX = dmode.w;
if (globalRendering->viewSizeY<=0) globalRendering->viewSizeY = dmode.h;

// In Windowed Mode Limit Minimum Window Size
static const int minViewSizeX = 400;
static const int minViewSizeY = 300;
if (!globalRendering->fullScreen) {
globalRendering->viewSizeX = std::max(globalRendering->viewSizeX, minViewSizeX);
globalRendering->viewSizeY = std::max(globalRendering->viewSizeY, minViewSizeY);
}
// Get wanted resolution
int2 res = globalRendering->GetWantedViewSize(globalRendering->fullScreen);

// Borderless
const bool borderless = configHandler->GetBool("WindowBorderless");
Expand All @@ -383,7 +373,7 @@ bool SpringApp::CreateSDLWindow(const char* title)
// Create Window
window = SDL_CreateWindow(title,
globalRendering->winPosX, globalRendering->winPosY,
globalRendering->viewSizeX, globalRendering->viewSizeY,
res.x, res.y,
sdlflags);
if (!window) {
char buf[1024];
Expand All @@ -393,7 +383,7 @@ bool SpringApp::CreateSDLWindow(const char* title)
}

// Create GL Context
SDL_SetWindowMinimumSize(window, minViewSizeX, minViewSizeY);
SDL_SetWindowMinimumSize(window, globalRendering->minWinSizeX, globalRendering->minWinSizeY);
sdlGlCtx = SDL_GL_CreateContext(window);
globalRendering->window = window;

Expand Down Expand Up @@ -465,18 +455,22 @@ void SpringApp::SaveWindowPosition()
{
#ifndef HEADLESS
configHandler->Set("Fullscreen", globalRendering->fullScreen);
if (!globalRendering->fullScreen) {
GetDisplayGeometry();
if (globalRendering->winState == CGlobalRendering::WINSTATE_DEFAULT) {
configHandler->Set("WindowPosX", globalRendering->winPosX);
configHandler->Set("WindowPosY", globalRendering->winPosY);
configHandler->Set("WindowState", globalRendering->winState);
} else
if (globalRendering->winState == CGlobalRendering::WINSTATE_MINIMIZED) {
// don't automatically save minimized states
} else {
configHandler->Set("WindowState", globalRendering->winState);
}
if (globalRendering->fullScreen) {
return;
}

GetDisplayGeometry();
if (globalRendering->winState == CGlobalRendering::WINSTATE_DEFAULT) {
configHandler->Set("WindowPosX", globalRendering->winPosX);
configHandler->Set("WindowPosY", globalRendering->winPosY);
configHandler->Set("WindowState", globalRendering->winState);
configHandler->Set("XResolutionWindowed", globalRendering->winSizeX);
configHandler->Set("YResolutionWindowed", globalRendering->winSizeY);
} else
if (globalRendering->winState == CGlobalRendering::WINSTATE_MINIMIZED) {
// don't automatically save minimized states
} else {
configHandler->Set("WindowState", globalRendering->winState);
}
#endif
}
Expand Down Expand Up @@ -620,8 +614,6 @@ void SpringApp::ParseCmdLine(const std::string& binaryName)
cmdline->AddSwitch(0, "sync-version", "Display program sync version (for online gaming)");
cmdline->AddSwitch('f', "fullscreen", "Run in fullscreen mode");
cmdline->AddSwitch('w', "window", "Run in windowed mode");
cmdline->AddInt( 'x', "xresolution", "Set X resolution");
cmdline->AddInt( 'y', "yresolution", "Set Y resolution");
cmdline->AddSwitch('b', "minimise", "Start in background (minimised)");
cmdline->AddSwitch(0, "nocolor", "Disables colorized stdout");
cmdline->AddSwitch('q', "quiet", "Ignore unrecognized arguments");
Expand Down Expand Up @@ -964,8 +956,13 @@ bool SpringApp::MainEventHandler(const SDL_Event& event)
switch (event.type) {
case SDL_WINDOWEVENT: {
switch (event.window.event) {
case SDL_WINDOWEVENT_MOVED: {
SaveWindowPosition();
} break;
//case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED: {
Watchdog::ClearTimer(WDT_MAIN, true);
SaveWindowPosition();
InitOpenGL();
activeController->ResizeEvent();
mouseInput->InstallWndCallback();
Expand Down

0 comments on commit 71fbd52

Please sign in to comment.