1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-10-31 16:29:41 +01:00

Refactor startup to load config before calling Screen::init

This commit is contained in:
Ethan Lee 2020-07-08 14:30:57 -04:00
parent f8bb8cde32
commit d3f9a36941
5 changed files with 83 additions and 71 deletions

View file

@ -4494,7 +4494,7 @@ void Game::unlocknum( int t )
#define LOAD_ARRAY(ARRAY_NAME) LOAD_ARRAY_RENAME(ARRAY_NAME, ARRAY_NAME)
void Game::loadstats()
void Game::loadstats(int *width, int *height, bool *vsync)
{
tinyxml2::XMLDocument doc;
if (!FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc))
@ -4521,10 +4521,6 @@ void Game::loadstats()
hRoot=tinyxml2::XMLHandle(pElem);
}
// WINDOW DIMS, ADDED AT PATCH 22
int width = 320;
int height = 240;
for( pElem = hRoot.FirstChildElement( "Data" ).FirstChild().ToElement(); pElem; pElem=pElem->NextSiblingElement())
{
std::string pKey(pElem->Value());
@ -4575,11 +4571,11 @@ void Game::loadstats()
if (pKey == "window_width")
{
width = atoi(pText);
*width = atoi(pText);
}
if (pKey == "window_height")
{
height = atoi(pText);
*height = atoi(pText);
}
@ -4645,7 +4641,6 @@ void Game::loadstats()
if (pKey == "advanced_smoothing")
{
fullScreenEffect_badSignal = atoi(pText);
graphics.screenbuffer->badSignalEffect = fullScreenEffect_badSignal;
}
if (pKey == "usingmmmmmm")
@ -4684,7 +4679,7 @@ void Game::loadstats()
if (pKey == "vsync")
{
graphics.screenbuffer->vsync = atoi(pText);
*vsync = atoi(pText);
}
if (pKey == "notextoutline")
@ -4736,20 +4731,6 @@ void Game::loadstats()
}
if(fullscreen)
{
graphics.screenbuffer->toggleFullScreen();
}
for (int i = 0; i < stretchMode; i += 1)
{
graphics.screenbuffer->toggleStretchMode();
}
if (useLinearFilter)
{
graphics.screenbuffer->toggleLinearFilter();
}
graphics.screenbuffer->ResizeScreen(width, height);
if (graphics.showmousecursor == true)
{
SDL_ShowCursor(SDL_ENABLE);

View file

@ -125,7 +125,7 @@ public:
void unlocknum(int t);
void loadstats();
void loadstats(int *width, int *height, bool *vsync);
void savestats();

View file

@ -17,21 +17,28 @@ extern "C"
);
}
void Screen::init()
{
void Screen::init(
int windowWidth,
int windowHeight,
bool fullscreen,
bool useVsync,
int stretch,
bool linearFilter,
bool badSignal
) {
m_window = NULL;
m_renderer = NULL;
m_screenTexture = NULL;
m_screen = NULL;
isWindowed = true;
stretchMode = 0;
isFiltered = false;
vsync = false;
isWindowed = !fullscreen;
stretchMode = stretch;
isFiltered = linearFilter;
vsync = useVsync;
filterSubrect.x = 1;
filterSubrect.y = 1;
filterSubrect.w = 318;
filterSubrect.h = 238;
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, isFiltered ? "linear" : "nearest");
// Uncomment this next line when you need to debug -flibit
// SDL_SetHintWithPriority(SDL_HINT_RENDER_DRIVER, "software", SDL_HINT_OVERRIDE);
@ -87,7 +94,9 @@ void Screen::init()
240
);
badSignalEffect = false;
badSignalEffect = badSignal;
ResizeScreen(windowWidth, windowHeight);
}
void Screen::ResizeScreen(int x, int y)

View file

@ -6,7 +6,15 @@
class Screen
{
public:
void init();
void init(
int windowWidth,
int windowHeight,
bool fullscreen,
bool useVsync,
int stretch,
bool linearFilter,
bool badSignal
);
void ResizeScreen(int x, int y);
void ResizeToNearestMultiple();

View file

@ -161,8 +161,6 @@ int main(int argc, char *argv[])
NETWORK_init();
gameScreen.init();
printf("\t\t\n");
printf("\t\t\n");
printf("\t\t VVVVVV\n");
@ -207,36 +205,6 @@ int main(int argc, char *argv[])
// This loads music too...
graphics.reloadresources();
const SDL_PixelFormat* fmt = gameScreen.GetFormat();
graphics.backBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
SDL_SetSurfaceBlendMode(graphics.backBuffer, SDL_BLENDMODE_NONE);
graphics.footerbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 10, fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
SDL_SetSurfaceBlendMode(graphics.footerbuffer, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(graphics.footerbuffer, 127);
FillRect(graphics.footerbuffer, SDL_MapRGB(fmt, 0, 0, 0));
graphics.ghostbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
SDL_SetSurfaceBlendMode(graphics.ghostbuffer, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(graphics.ghostbuffer, 127);
graphics.Makebfont();
graphics.foregroundBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE ,320 ,240 ,fmt->BitsPerPixel,fmt->Rmask,fmt->Gmask,fmt->Bmask,fmt->Amask );
SDL_SetSurfaceBlendMode(graphics.foregroundBuffer, SDL_BLENDMODE_NONE);
graphics.screenbuffer = &gameScreen;
graphics.menubuffer = SDL_CreateRGBSurface(SDL_SWSURFACE ,320 ,240 ,fmt->BitsPerPixel,fmt->Rmask,fmt->Gmask,fmt->Bmask,fmt->Amask );
SDL_SetSurfaceBlendMode(graphics.menubuffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE ,320+16 ,240+16 ,fmt->BitsPerPixel,fmt->Rmask,fmt->Gmask,fmt->Bmask,fmt->Amask );
SDL_SetSurfaceBlendMode(graphics.towerbuffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer_lerp = SDL_CreateRGBSurface(SDL_SWSURFACE, 320+16, 240+16, fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
SDL_SetSurfaceBlendMode(graphics.towerbuffer, SDL_BLENDMODE_NONE);
graphics.tempBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE ,320 ,240 ,fmt->BitsPerPixel,fmt->Rmask,fmt->Gmask,fmt->Bmask,fmt->Amask );
SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE);
game.gamestate = PRELOADER;
game.menustart = false;
@ -246,13 +214,59 @@ int main(int argc, char *argv[])
map.bypos = map.ypos / 2;
//Moved screensetting init here from main menu V2.1
game.loadstats();
int width = 320;
int height = 240;
bool vsync = false;
game.loadstats(&width, &height, &vsync);
gameScreen.init(
width,
height,
game.fullscreen,
vsync,
game.stretchMode,
game.useLinearFilter,
game.fullScreenEffect_badSignal
);
graphics.screenbuffer = &gameScreen;
// FIXME: Thanks to having to work around an SDL2 bug, this destroys the
// renderer created by Screen::init(), which is a bit wasteful!
// This is annoying to fix because we'd have to call gameScreen.init() after
// game.loadstats(), but game.loadstats() assumes gameScreen.init() is already called!
gameScreen.resetRendererWorkaround();
const SDL_PixelFormat* fmt = gameScreen.GetFormat();
#define CREATE_SURFACE(w, h) \
SDL_CreateRGBSurface( \
SDL_SWSURFACE, \
w, h, \
fmt->BitsPerPixel, \
fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask \
)
graphics.backBuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.backBuffer, SDL_BLENDMODE_NONE);
graphics.footerbuffer = CREATE_SURFACE(320, 10);
SDL_SetSurfaceBlendMode(graphics.footerbuffer, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(graphics.footerbuffer, 127);
FillRect(graphics.footerbuffer, SDL_MapRGB(fmt, 0, 0, 0));
graphics.ghostbuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.ghostbuffer, SDL_BLENDMODE_BLEND);
SDL_SetSurfaceAlphaMod(graphics.ghostbuffer, 127);
graphics.Makebfont();
graphics.foregroundBuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.foregroundBuffer, SDL_BLENDMODE_NONE);
graphics.menubuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.menubuffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer = CREATE_SURFACE(320 + 16, 240 + 16);
SDL_SetSurfaceBlendMode(graphics.towerbuffer, SDL_BLENDMODE_NONE);
graphics.towerbuffer_lerp = CREATE_SURFACE(320 + 16, 240 + 16);
SDL_SetSurfaceBlendMode(graphics.towerbuffer, SDL_BLENDMODE_NONE);
graphics.tempBuffer = CREATE_SURFACE(320, 240);
SDL_SetSurfaceBlendMode(graphics.tempBuffer, SDL_BLENDMODE_NONE);
#undef CREATE_SURFACE
if (game.skipfakeload)
game.gamestate = TITLEMODE;