Skip to content

Commit

Permalink
Command line switches
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Feb 2, 2022
1 parent c75e429 commit b44e8ef
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 35 deletions.
3 changes: 0 additions & 3 deletions src/SDLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 0 additions & 2 deletions src/hiscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

using std::min;

extern MBoolean widescreen;

Combo defaultBest =
{
/*bestGrid[kGridAcross][kGridDown] = */
Expand Down
1 change: 0 additions & 1 deletion src/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
43 changes: 21 additions & 22 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
46 changes: 40 additions & 6 deletions src/prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
}
1 change: 1 addition & 0 deletions src/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

void LoadPrefs( void );
void SavePrefs( void );
void ParseCommandLine(int argc, char* argv[]);

0 comments on commit b44e8ef

Please sign in to comment.