Allow for -size to specify custom resolution.

This commit is contained in:
Steve 2018-12-10 13:44:33 +00:00
parent 2a71a88371
commit 984a551c80
10 changed files with 97 additions and 19 deletions

View File

@ -1,5 +1,12 @@
Changelog
1.5
* Added command line switch -size to allow for custom window sizes.
- For example: -size 900x600 for a width and height of 900 x 600.
* Graphics and fonts now use texture atlases to help with performance.
* Misc. bug fixes.
1.4
* Add Mac make file

View File

@ -1,5 +1,5 @@
VERSION = 1.4
REVISION = 3
VERSION = 1.5
REVISION = 0
LOCALE_MO = $(patsubst %.po,%.mo,$(wildcard locale/*.po))
OUT = bin

View File

@ -4,7 +4,7 @@
"group" : "options",
"type" : "WT_SELECT",
"text" : "Window Size",
"options" : "640 x 360;1280 x 720;1600 x 900;1920 x 1080;2560 x 1440;3840 x 2160",
"options" : "640 x 360;1280 x 720;1600 x 900;1920 x 1080;2560 x 1440;3840 x 2160;",
"x" : -1,
"y" : 175,
"w" : 400,

View File

@ -42,7 +42,7 @@ int main(int argc, char *argv[])
initLookups();
initSDL();
initSDL(argc, argv);
initGameSystem();

View File

@ -39,7 +39,7 @@ extern void init18N(int argc, char *argv[]);
extern void initCredits(void);
extern void initGameSystem(void);
extern void initLookups(void);
extern void initSDL(void);
extern void initSDL(int argc, char *argv[]);
extern void initTitle(void);
extern int isControl(int type);
extern void loadGame(void);

View File

@ -456,7 +456,6 @@ struct Widget {
char text[MAX_NAME_LENGTH];
char **options;
int numOptions;
int currentOption;
int visible;
int enabled;
int isModal;

View File

@ -20,10 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "init.h"
static void loadConfig(void);
static void loadConfig(int argc, char *argv[]);
static void loadConfigFile(char *filename);
void saveConfig(void);
static void showLoadingStep(float step, float maxSteps);
static void handleCommandLineConfig(int argc, char *argv[]);
void init18N(int argc, char *argv[])
{
@ -51,7 +52,7 @@ void init18N(int argc, char *argv[])
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "atof(2.75) is %f", atof("2.75"));
}
void initSDL(void)
void initSDL(int argc, char *argv[])
{
int rendererFlags, windowFlags;
@ -61,9 +62,10 @@ void initSDL(void)
/* done in src/plat/ */
createSaveFolder();
loadConfig();
loadConfig(argc, argv);
rendererFlags = SDL_RENDERER_ACCELERATED;
if (app.vSync)
{
rendererFlags |= SDL_RENDERER_PRESENTVSYNC;
@ -140,7 +142,8 @@ void initGameSystem(void)
initStars,
initControls,
initTrophies,
initFighterDatabase
initFighterDatabase,
updateCustomResolutionOption
};
initAtlas();
@ -188,7 +191,7 @@ static void showLoadingStep(float step, float maxSteps)
SDL_Delay(1);
}
static void loadConfig(void)
static void loadConfig(int argc, char *argv[])
{
char *configFilename;
@ -203,6 +206,12 @@ static void loadConfig(void)
loadConfigFile(configFilename);
}
handleCommandLineConfig(argc, argv);
/* don't go higher than 8K or lower than 320 x 240 */
app.winWidth = MIN(MAX(app.winWidth, 320), 7680);
app.winHeight = MIN(MAX(app.winHeight, 240), 4320);
/* so that the player doesn't get confused if this is a new game */
saveConfig();
}
@ -223,7 +232,7 @@ static void loadConfigFile(char *filename)
app.musicVolume = cJSON_GetObjectItem(root, "musicVolume")->valueint;
app.soundVolume = cJSON_GetObjectItem(root, "soundVolume")->valueint;
app.vSync = getJSONValue(root, "vSync", 1);
controlsJSON = cJSON_GetObjectItem(root, "controls");
if (controlsJSON)
{
@ -314,6 +323,19 @@ void saveConfig(void)
free(out);
}
static void handleCommandLineConfig(int argc, char *argv[])
{
int i;
for (i = 1 ; i < argc ; i++)
{
if (strcmp(argv[i], "-size") == 0)
{
sscanf(argv[i + 1], "%dx%d", &app.winWidth, &app.winHeight);
}
}
}
void cleanup(void)
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Cleaning up ...");

View File

@ -66,6 +66,7 @@ extern void initStars(void);
extern void initStats(void);
extern void initTrophies(void);
extern void initWidgets(void);
extern void updateCustomResolutionOption(void);
extern void loadCapitalShipDefs(void);
extern void loadFighterDefs(void);
extern void loadItemDefs(void);

View File

@ -120,6 +120,29 @@ static void drawMain(void)
app.textWidth = 0;
}
void updateCustomResolutionOption(void)
{
Widget *w;
char value[MAX_NAME_LENGTH];
int i;
sprintf(value, "%d x %d", app.winWidth, app.winHeight);
w = getWidget("windowSize", "options");
for (i = 0 ; i < w->numOptions - 1 ; i++)
{
if (strcmp(w->options[i], value) == 0)
{
w->numOptions--;
return;
}
}
w->options[w->numOptions - 1] = malloc(strlen(value) + 1);
strcpy(w->options[w->numOptions - 1], value);
}
static void controls(void)
{
initControlsDisplay();

View File

@ -28,6 +28,7 @@ static void createOptions(Widget *w, char *options);
static void changeSelectedValue(Widget *w, int dir);
static void createSelectButtons(Widget *w);
static void handleControlWidgets(void);
static void updateSelectWidgets(void);
static Widget head;
static Widget *tail;
@ -56,6 +57,8 @@ void doWidgets(void)
{
if (drawingWidgets)
{
updateSelectWidgets();
handleMouse();
handleKeyboard();
@ -69,6 +72,29 @@ void doWidgets(void)
drawingWidgets = 0;
}
static void updateSelectWidgets(void)
{
Widget *w;
for (w = head.next; w != NULL ; w = w->next)
{
if (w->type == WT_SELECT_BUTTON && w->parent)
{
w->visible = 1;
if (w->value == -1 && w->parent->value == 0)
{
w->visible = 0;
}
if (w->value == 1 && w->parent->value == w->parent->numOptions - 1)
{
w->visible = 0;
}
}
}
}
Widget *getWidget(const char *name, const char *group)
{
Widget *w;
@ -150,7 +176,7 @@ void drawWidgets(const char *group)
case WT_SELECT:
drawText(w->rect.x + 10, w->rect.y + 2, 20, TA_LEFT, colors.white, w->text);
drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->currentOption]);
drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->value]);
break;
case WT_CONTROL_CONFIG:
@ -195,15 +221,15 @@ void drawWidgets(const char *group)
static void changeSelectedValue(Widget *w, int dir)
{
int oldOption = w->currentOption;
int oldOption = w->value;
w->currentOption += dir;
w->value += dir;
w->currentOption = MIN(MAX(0, w->currentOption), w->numOptions - 1);
w->value = MIN(MAX(0, w->value), w->numOptions - 1);
w->onChange(w->options[w->currentOption]);
w->onChange(w->options[w->value]);
if (oldOption != w->currentOption)
if (oldOption != w->value)
{
playSound(SND_GUI_CLICK);
}
@ -220,7 +246,7 @@ void setWidgetOption(const char *name, const char *group, const char *value)
{
if (strcmp(w->options[i], value) == 0)
{
w->currentOption = i;
w->value = i;
return;
}
}