Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/sail Rework the game startup so it uses curses nicely....
details: https://anonhg.NetBSD.org/src/rev/afb73b6a9bda
branches: trunk
changeset: 756859:afb73b6a9bda
user: dholland <dholland%NetBSD.org@localhost>
date: Fri Aug 06 09:14:40 2010 +0000
description:
Rework the game startup so it uses curses nicely. There are now menus
and stuff for picking scenarios and ships and all that.
diffstat:
games/sail/dr_main.c | 58 +++-
games/sail/extern.h | 29 +-
games/sail/globals.c | 22 +-
games/sail/lo_main.c | 65 +++-
games/sail/main.c | 63 +++-
games/sail/pl_7.c | 888 ++++++++++++++++++++++++++++++++++++++++++++++++++-
games/sail/pl_main.c | 202 ++---------
7 files changed, 1126 insertions(+), 201 deletions(-)
diffs (truncated from 1694 to 300 lines):
diff -r 04ecdaac0550 -r afb73b6a9bda games/sail/dr_main.c
--- a/games/sail/dr_main.c Fri Aug 06 06:58:53 2010 +0000
+++ b/games/sail/dr_main.c Fri Aug 06 09:14:40 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dr_main.c,v 1.14 2009/03/14 19:36:42 dholland Exp $ */
+/* $NetBSD: dr_main.c,v 1.15 2010/08/06 09:14:40 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,17 +34,22 @@
#if 0
static char sccsid[] = "@(#)dr_main.c 8.2 (Berkeley) 4/16/94";
#else
-__RCSID("$NetBSD: dr_main.c,v 1.14 2009/03/14 19:36:42 dholland Exp $");
+__RCSID("$NetBSD: dr_main.c,v 1.15 2010/08/06 09:14:40 dholland Exp $");
#endif
#endif /* not lint */
#include <err.h>
+#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "extern.h"
#include "driver.h"
+#include "player.h" /* XXX for LEAVE_FORK */
+#include "restart.h"
+
+static int driver_wait_fd = -1;
int
dr_main(void)
@@ -54,23 +59,28 @@
int nat[NNATION];
int value = 0;
+ /*
+ * XXX need a way to print diagnostics back to the player
+ * process instead of stomping on the curses screen.
+ */
+
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
if (game < 0 || game >= NSCENE) {
- errx(1, "driver: Bad game number %d", game);
+ errx(1, "\ndriver: Bad game number %d", game);
}
cc = &scene[game];
ls = SHIP(cc->vessels);
if (sync_open() < 0) {
- err(1, "driver: syncfile");
+ err(1, "\ndriver: syncfile");
}
for (n = 0; n < NNATION; n++)
nat[n] = 0;
foreachship(sp) {
if (sp->file == NULL &&
(sp->file = calloc(1, sizeof (struct File))) == NULL) {
- fprintf(stderr, "DRIVER: Out of memory.\n");
+ fprintf(stderr, "\nDRIVER: Out of memory.\n");
exit(1);
}
sp->file->index = sp - SHIP(0);
@@ -86,6 +96,12 @@
windspeed = cc->windspeed;
winddir = cc->winddir;
people = 0;
+
+ /* report back to the player process that we've started */
+ if (driver_wait_fd >= 0) {
+ close(driver_wait_fd);
+ }
+
for (;;) {
sleep(7);
if (Sync() < 0) {
@@ -112,3 +128,35 @@
sync_close(1);
return value;
}
+
+void
+startdriver(void)
+{
+ int fds[2];
+ char c;
+
+ if (pipe(fds)) {
+ warn("pipe");
+ leave(LEAVE_FORK);
+ return;
+ }
+
+ switch (fork()) {
+ case 0:
+ close(fds[0]);
+ driver_wait_fd = fds[1];
+ longjmp(restart, MODE_DRIVER);
+ /*NOTREACHED*/
+ case -1:
+ warn("fork");
+ close(fds[0]);
+ close(fds[1]);
+ leave(LEAVE_FORK);
+ break;
+ default:
+ hasdriver++;
+ close(fds[1]);
+ read(fds[0], &c, 1);
+ close(fds[0]);
+ }
+}
diff -r 04ecdaac0550 -r afb73b6a9bda games/sail/extern.h
--- a/games/sail/extern.h Fri Aug 06 06:58:53 2010 +0000
+++ b/games/sail/extern.h Fri Aug 06 09:14:40 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.35 2009/08/12 09:05:08 dholland Exp $ */
+/* $NetBSD: extern.h,v 1.36 2010/08/06 09:14:40 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -43,13 +43,15 @@
#define MODE_LOGGER 3
/* command line flags */
-extern int randomize; /* -x, give first available ship */
-extern int longfmt; /* -l, print score in long format */
-extern int nobells; /* -b, don't ring bell before Signal */
+extern bool randomize; /* -x, give first available ship */
+extern bool longfmt; /* -l, print score in long format */
+extern bool nobells; /* -b, don't ring bell before Signal */
- /* other initial modes */
+ /* other initial data */
extern gid_t gid;
extern gid_t egid;
+#define MAXNAMESIZE 20
+extern char myname[MAXNAMESIZE];
#define dieroll() ((random()) % 6 + 1)
#define sqr(a) ((a) * (a))
@@ -103,7 +105,7 @@
#define NLOG 10
struct logs {
- char l_name[20];
+ char l_name[MAXNAMESIZE];
int l_uid;
int l_shipnum;
int l_gamenum;
@@ -121,7 +123,7 @@
short sn_turn;
};
-#define NSCENE nscene
+#define NSCENE /*nscene*/ 32
#define NSHIP 10
#define NBP 3
@@ -137,7 +139,7 @@
struct File {
int index;
- char captain[20]; /* 0 */
+ char captain[MAXNAMESIZE]; /* 0 */
short points; /* 20 */
unsigned char loadL; /* 22 */
unsigned char loadR; /* 24 */
@@ -185,7 +187,7 @@
const char *name; /* 14 */
struct ship ship[NSHIP]; /* 16 */
};
-extern struct scenario scene[];
+extern struct scenario scene[NSCENE];
extern int nscene;
struct shipspecs {
@@ -234,6 +236,7 @@
extern const char MT[9][3];
extern const char *const countryname[];
+extern const char *const shortclassname[];
extern const char *const classname[];
extern const char *const directionname[];
extern const char *const qualname[];
@@ -251,6 +254,7 @@
extern int people;
extern int hasdriver;
+
/* assorted.c */
void table(struct ship *, struct ship *, int, int, int, int);
void Cleansnag(struct ship *, struct ship *, int, int);
@@ -285,12 +289,14 @@
/* dr_main.c */
int dr_main(void);
+void startdriver(void);
/* game.c */
int maxturns(struct ship *, bool *);
int maxmove(struct ship *, int, int);
/* lo_main.c */
+void lo_curses(void);
int lo_main(void);
/* misc.c */
@@ -349,9 +355,12 @@
void downview(void);
void leftview(void);
void rightview(void);
+void startup(void);
/* pl_main.c */
-int pl_main(void);
+void pl_main_init(void);
+void pl_main_uninit(void);
+void pl_main(void);
/* sync.c */
void fmtship(char *, size_t, const char *, struct ship *);
diff -r 04ecdaac0550 -r afb73b6a9bda games/sail/globals.c
--- a/games/sail/globals.c Fri Aug 06 06:58:53 2010 +0000
+++ b/games/sail/globals.c Fri Aug 06 09:14:40 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: globals.c,v 1.15 2009/08/12 09:05:08 dholland Exp $ */
+/* $NetBSD: globals.c,v 1.16 2010/08/06 09:14:40 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)globals.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: globals.c,v 1.15 2009/08/12 09:05:08 dholland Exp $");
+__RCSID("$NetBSD: globals.c,v 1.16 2010/08/06 09:14:40 dholland Exp $");
#endif
#endif /* not lint */
@@ -44,7 +44,7 @@
static struct shipspecs specs[];
-struct scenario scene[] = {
+struct scenario scene[NSCENE] = {
/*
* int winddir;
* int windspeed;
@@ -526,6 +526,16 @@
"Brig"
};
+const char *const shortclassname[] = {
+ "Rowboat",
+ "Ship",
+ "Ship",
+ "Frigate",
+ "Corvette",
+ "Sloop",
+ "Brig"
+};
+
const char *const directionname[] = {
"dead ahead",
"off the starboard bow",
@@ -555,9 +565,9 @@
int mode;
jmp_buf restart;
-int randomize; /* -x, give first available ship */
-int longfmt; /* -l, print score in long format */
-int nobells; /* -b, don't ring bell before Signal */
+bool randomize; /* -x, give first available ship */
+bool longfmt; /* -l, print score in long format */
+bool nobells; /* -b, don't ring bell before Signal */
gid_t gid;
gid_t egid;
diff -r 04ecdaac0550 -r afb73b6a9bda games/sail/lo_main.c
--- a/games/sail/lo_main.c Fri Aug 06 06:58:53 2010 +0000
+++ b/games/sail/lo_main.c Fri Aug 06 09:14:40 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lo_main.c,v 1.18 2010/01/17 22:56:32 wiz Exp $ */
+/* $NetBSD: lo_main.c,v 1.19 2010/08/06 09:14:40 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)lo_main.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: lo_main.c,v 1.18 2010/01/17 22:56:32 wiz Exp $");
+__RCSID("$NetBSD: lo_main.c,v 1.19 2010/08/06 09:14:40 dholland Exp $");
#endif
#endif /* not lint */
@@ -45,18 +45,79 @@
Home |
Main Index |
Thread Index |
Old Index