diff --git a/src/SDLU.cpp b/src/SDLU.cpp index a83b99b..77cfe61 100644 --- a/src/SDLU.cpp +++ b/src/SDLU.cpp @@ -31,9 +31,6 @@ static MPoint s_mousePosition; // for event loop static MBoolean s_isForeground = true; -extern MBoolean widescreen; -extern MBoolean fullscreen; - // for checktyping struct BufferedKey { diff --git a/src/hiscore.cpp b/src/hiscore.cpp index 8d78491..db22b6b 100644 --- a/src/hiscore.cpp +++ b/src/hiscore.cpp @@ -28,8 +28,6 @@ using std::min; -extern MBoolean widescreen; - Combo defaultBest = { /*bestGrid[kGridAcross][kGridDown] = */ diff --git a/src/level.cpp b/src/level.cpp index ef01fce..6edd9df 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -85,7 +85,6 @@ const int kCursorWidth = 32; const int kCursorHeight = 32; extern MBoolean useNewTitle; -extern MBoolean widescreen; static void InsertCursor( MPoint mouseHere, SDL_Surface* scratch, SDL_Surface* surface ) { diff --git a/src/main.cpp b/src/main.cpp index c8aa078..c0b20bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -313,25 +313,21 @@ static char candyCrisisResources[512]; MBoolean fullscreen = false; MBoolean widescreen = false; -MBoolean useNewTitle = true; -MBoolean bilinearFiltering = false; +MBoolean useNewTitle = widescreen; +MBoolean crispUpscaling = false; int windowedScale = 2; -#if _WIN32 -int WinMain( - _In_ HINSTANCE, - _In_opt_ HINSTANCE, - _In_ LPSTR, - _In_ int) -#else -int main(int, char *[]) -#endif +int main(int argc, char *argv[]) { - Initialize( ); + Initialize( ); LoadPrefs( ); - - ReserveMonitor( ); + ParseCommandLine( argc, argv ); + + if ( widescreen ) + useNewTitle = true; + + ReserveMonitor( ); ShowTitle( ); ChooseMusic( 13 ); @@ -571,18 +567,14 @@ void ReserveMonitor( void ) SDL_ShowCursor( SDL_DISABLE ); SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, bilinearFiltering? "best": "0"); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, crispUpscaling? "0": "best"); int resW = 640; int resH = widescreen? 360: 480; - - if (fullscreen) { - SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP, &g_window, &g_renderer); - } else { - SDL_CreateWindowAndRenderer(resW*windowedScale, resH*windowedScale, SDL_WINDOW_RESIZABLE, &g_window, &g_renderer); - } - SDL_RenderSetIntegerScale(g_renderer, bilinearFiltering ? SDL_FALSE : SDL_TRUE); + SDL_CreateWindowAndRenderer(resW*windowedScale, resH*windowedScale, SDL_WINDOW_RESIZABLE, &g_window, &g_renderer); + + SDL_RenderSetIntegerScale(g_renderer, crispUpscaling ? SDL_TRUE : SDL_FALSE); SDL_RenderSetLogicalSize(g_renderer, resW, resH); SDL_SetWindowTitle(g_window, "Candy Crisis"); @@ -598,12 +590,19 @@ void ReserveMonitor( void ) SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, 640, 480); + + SetFullscreen(fullscreen); } void ReleaseMonitor( void ) { } +void SetFullscreen( MBoolean fullscreenMode ) +{ + SDL_SetWindowFullscreen(g_window, fullscreenMode? SDL_WINDOW_FULLSCREEN_DESKTOP: 0); +} + int Warp( void ) { return 8; diff --git a/src/main.h b/src/main.h index b5f2dc9..839c53b 100644 --- a/src/main.h +++ b/src/main.h @@ -253,7 +253,7 @@ extern signed char nextA[2], nextB[2], nextM[2], nextG[2], colorA[2], colorB[2], extern int chain[2]; extern int blobTime[2], startTime, endTime; extern MBoolean finished, pauseKey, showStartMenu; -extern MBoolean fullscreen; +extern MBoolean fullscreen, widescreen, crispUpscaling; extern signed char grid[2][kGridAcross][kGridDown], suction[2][kGridAcross][kGridDown], charred[2][kGridAcross][kGridDown], glow[2][kGridAcross][kGridDown]; extern MRect playerWindowZRect, playerWindowRect[2]; diff --git a/src/prefs.cpp b/src/prefs.cpp index f2c4dbc..1fe40b8 100644 --- a/src/prefs.cpp +++ b/src/prefs.cpp @@ -22,12 +22,14 @@ struct Preference Preference prefList[] = { - { "MusicOn", &musicOn, sizeof(MBoolean ) }, - { "SoundOn", &soundOn, sizeof(MBoolean ) }, - { "KeyBindings", playerKeys, sizeof(playerKeys) }, - { "HighScores", scores, sizeof(scores ) }, - { "BestCombo", &best, sizeof(best ) }, - { "Fullscreen", &fullscreen, sizeof(fullscreen) }, + { "MusicOn", &musicOn, sizeof(MBoolean ) }, + { "SoundOn", &soundOn, sizeof(MBoolean ) }, + { "KeyBindings", playerKeys, sizeof(playerKeys ) }, + { "HighScores", scores, sizeof(scores ) }, + { "BestCombo", &best, sizeof(best ) }, + { "Fullscreen", &fullscreen, sizeof(fullscreen ) }, + { "Widescreen", &widescreen, sizeof(widescreen ) }, + { "CrispUpscaling", &crispUpscaling, sizeof(crispUpscaling ) }, }; static std::fstream GetPrefsStream(std::ios::openmode openmode) @@ -111,3 +113,35 @@ void SavePrefs() stream.write((const char*)pref.valuePtr, pref.valueLength); } } + +void ParseCommandLine(int argc, char* argv[]) +{ + for (int i = 1; i < argc; i++) + { + const char* arg = argv[i]; + + if (!strcmp(arg, "--crisp")) crispUpscaling = true; + if (!strcmp(arg, "--fullscreen")) fullscreen = true; + if (!strcmp(arg, "--widescreen")) widescreen = true; + + if (!strcmp(arg, "--no-crisp")) crispUpscaling = false; + if (!strcmp(arg, "--no-fullscreen")) fullscreen = false; + if (!strcmp(arg, "--no-widescreen")) widescreen = false; + + if (!strcmp(arg, "--help") || !strcmp(arg, "-h")) + { + printf( + "Candy Crisis source port - https://github.com/jorio/candycrisis\n" + "\n" + " --crisp pixel-perfect upscaling\n" + " --no-crisp upscale with bilinear filtering\n" + " --fullscreen run the game fullscreen\n" + " --no-fullscreen run the game in a window\n" + " --widescreen crop viewport to 16:9 aspect ratio\n" + " --no-widescreen use original 4:3 aspect ratio\n" + "\n" + ); + exit(0); + } + } +} diff --git a/src/prefs.h b/src/prefs.h index 1453f40..173d732 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -2,3 +2,4 @@ void LoadPrefs( void ); void SavePrefs( void ); +void ParseCommandLine(int argc, char* argv[]);