Skip to content

Commit

Permalink
Add --aspect-ratio option to snis_client to allow custom aspect ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
smcameron committed Apr 18, 2015
1 parent f6ebcd3 commit dab38d5
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 21 deletions.
11 changes: 10 additions & 1 deletion quickstart
Expand Up @@ -41,8 +41,17 @@ sleep 0.25

sleep 0.25

# Some common aspect ratios. Note: the game was designed on a machine
# with a 16:9 aspect ratio. Other aspect ratios may have some UI issues.
#
ASPECT_RATIO="" # unspecified, figure it out from window manager
# ASPECT_RATIO="--aspect-ratio 5:4"
# ASPECT_RATIO="--aspect-ratio 4:3"
# ASPECT_RATIO="--aspect-ratio 16:10"
# ASPECT_RATIO="--aspect-ratio 16:9"

# start the game client and server in quickstart mode
./snis_client --fullscreen --quickstart --starship "$shipname" --pw "$password"
./snis_client $ASPECT_RATIO --fullscreen --quickstart --starship "$shipname" --pw "$password"

exit $?

44 changes: 30 additions & 14 deletions snis_client.6
@@ -1,4 +1,4 @@
.TH SPACE-NERDS-IN-SPACE "6" "Nov 2012" "snis_client" "Games"
.TH SPACE-NERDS-IN-SPACE "6" "Apr 2015" "snis_client" "Games"
.SH NAME
snis_client \- Multi player cooperative star ship bridge simulator (client)
.SH SYNOPSIS
Expand All @@ -20,27 +20,43 @@ on a ship establishes a ship name and password, subsequent clients join the ship
created with the wrong name/password.)
.SH Options:
.TP
\fB--aspect-ratio x,y\fR
Specify a requested aspect ratio. By default, the window manager is queried
to determine the display dimensions, and the aspect ratio is made to match.
Other arbitrary aspect ratios may be specified. This may be desirable if
you have a display that is significantly different from the display the game
was designed on (16:9). Common aspect ratios (circa 2015) are 5:4, 4:3, 16:10
and 16:9 (according to wikipedia). The values specified for x and y must be
integers greater than zero and must be separatedy by a comma or a colon. Specifying
and aspect ratio will disable the --fullscreen option. Note: You may experience
some problems with widget and text placement with aspect ratios significantly
different than 16:9.
.TP
\fB\--comms\fR
Request this client process support the COMMS (communication) role.
.TP
\fB\--debug\fR
Request this client process support the DEBUG role.
.TP
\fB\--fullscreen\fR
Use the full display, with no window borders. This option is ignored
if the --aspect-ratio option is also specified.
.TP
\fB\--main\fR
Request this client process support the MAIN SCREEN role.
.PP
.TP
\fB\--navigation\fR
Request this client process support the NAVIGATION role.
.PP
.TP
\fB\--science\fR
Request this client process support the SCIENCE role.
.PP
\fB\--weapons\fR
Request this client process support the WEAPONS role.
.PP
\fB\--debug\fR
Request this client process support the DEBUG role.
.PP
.TP
\fB\--soundserver\fR
Request this client process support the SOUNDSERVER role.
.PP
\fB\--comms\fR
Request this client process support the COMMS (communication) role.
.PP
.TP
\fB\--weapons\fR
Request this client process support the WEAPONS role.
.TP
\fB\--version\fR
Print the program's version number and exit.
.SH ENVIRONMENT VARIABLES
Expand Down
69 changes: 63 additions & 6 deletions snis_client.c
Expand Up @@ -128,6 +128,8 @@
static int SCREEN_WIDTH = 800; // 1366; /* window width, in pixels */
static int SCREEN_HEIGHT = 600; // 768; /* window height, in pixels */
#define ASPECT_RATIO (SCREEN_WIDTH/(float)SCREEN_HEIGHT)
static int requested_aspect_x = -1;
static int requested_aspect_y = -1;

/* helper function to transform from 800x600 original coord system */
static inline int txx(int x) { return x * SCREEN_WIDTH / 800; }
Expand Down Expand Up @@ -190,7 +192,6 @@ GdkGC *gc = NULL; /* our graphics context. */
GtkWidget *main_da; /* main drawing area. */
gint timer_tag;
int fullscreen = 0;
int fixed_aspect_ratio = 0;
int in_the_process_of_quitting = 0;
int current_quit_selection = 0;
int final_quit_selection = 0;
Expand Down Expand Up @@ -12154,7 +12155,8 @@ void really_quit(void)

static void usage(void)
{
fprintf(stderr, "usage: snis_client --lobbyhost lobbyhost --starship starshipname --pw password\n");
fprintf(stderr, "usage: snis_client [--aspect-ratio x,y] --lobbyhost lobbyhost \\\n"
" --starship starshipname --pw password\n");
fprintf(stderr, " Example: ./snis_client --lobbyhost localhost --starship Enterprise --pw tribbles\n");
exit(1);
}
Expand Down Expand Up @@ -12868,6 +12870,47 @@ static void take_your_locale_and_shove_it(void)
setlocale(LC_ALL, "C");
}

static void figure_aspect_ratio(int requested_x, int requested_y,
int *x, int *y)
{
int sw, sh;
GdkScreen *s;

s = gdk_screen_get_default();
if (!s)
return;

sw = gdk_screen_get_width(s);
sh = gdk_screen_get_height(s);

if (requested_x <= 0 || requested_y <= 0) {
*x = sw;
*y = sh;
return;
}

/*
* The requested long axis gets full screen dimension in that axis,
* and the other axis gets adjusted. If that makes the other
* axis exceed screen dimensions, then further adjustments are made.
*/
if (requested_x > requested_y) {
*x = sw;
*y = (int) ((double) sw * (double) requested_y / (double) requested_x);
if (*y > sh) {
*y = sh;
*x = (int) ((double) sh * (double) requested_x / (double) requested_y);
}
} else {
*y = sh;
*x = (int) ((double) sh * (double) requested_x / (double) requested_y);
if (*x > sw) {
*y = (int) ((double) sw * (double) requested_y / (double) requested_x);
*x = sw;
}
}
}

int main(int argc, char *argv[])
{
GtkWidget *vbox;
Expand Down Expand Up @@ -12949,6 +12992,19 @@ int main(int argc, char *argv[])
fullscreen = 1;
continue;
}
if (strcmp(argv[i], "--aspect-ratio") == 0) {
int rc, x, y;
printf("argc = %d, i = %d\n", argc, i);
if (i + 1 >= argc)
usage();
rc = sscanf(argv[i + 1], "%d%*[,:]%d", &x, &y);
if (rc != 2)
usage();
requested_aspect_x = x;
requested_aspect_y = y;
i++;
continue;
}
usage();
}
if (role == 0)
Expand Down Expand Up @@ -12998,10 +13054,11 @@ int main(int argc, char *argv[])
GdkScreen *s;

s = gdk_screen_get_default();
if (s) {
SCREEN_WIDTH = gdk_screen_get_width(s);
SCREEN_HEIGHT = gdk_screen_get_height(s);
}
if (s)
figure_aspect_ratio(requested_aspect_x, requested_aspect_y,
&SCREEN_WIDTH, &SCREEN_HEIGHT);
if (requested_aspect_x >= 0 || requested_aspect_y >= 0)
fullscreen = 0; /* can't request aspect ratio AND fullscreen */
real_screen_width = SCREEN_WIDTH;
real_screen_height = SCREEN_HEIGHT;

Expand Down

0 comments on commit dab38d5

Please sign in to comment.