home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * Newton -- Yossi Friedman, July 1988
- *
- * Command line options:
- * -f file specifies an alternate model catalog file (the default appears in
- * config.h)
- * -D run in demo mode. This means that all the windows are opened in
- * pre-specified locations.
- *
- * if compiled with the -DCONFIG_FILE flag, then
- *
- * -c file specifies an alternate configuration file (the default appears in
- * config.h)
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <gl.h>
- #include <device.h>
-
- #define MAIN
-
- #include "config.h"
- #include "newton.h"
- #include "windows.h"
- #include "slider.h"
-
- #ifdef MP
- #include <sys/types.h>
- #include <sys/prctl.h>
- #endif /* MP */
-
-
- int auto_mode;
-
- char *usage
- #ifdef CONFIG_FILE
- = "Usage: newton [-f model_catalog] [-c newton_config] [-D]";
- #else /* CONFIG_FILE */
- = "Usage: newton [-f model_catalog] [-D]";
- #endif /* CONFIG_FILE */
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- char *p, *progname;
- int demo_mode;
- int i, j;
- long x0, y0, x1, size_x, size_y;
-
- demo_mode = 0;
- auto_mode = 0;
-
- progname = strrchr(argv[0], '/') ;
- if (progname == NULL) progname = argv[0];
- else progname++;
-
- while (--argc) {
- if (**++argv != '-')
- break;
-
- switch ((*argv)[1]) {
- case 'a':
- auto_mode = 1;
- break;
-
- case 'f':
- if (--argc == 0) {
- fprintf(stderr, "newton: %s\n", usage);
- exit(1);
- }
- model_catalog = *++argv;
- break;
-
- #ifdef CONFIG_FILE
-
- case 'c':
- if (--argc == 0) {
- fprintf(stderr, "newton: %s\n", usage);
- exit(1);
- }
- model_config = *++argv;
- break;
-
- #endif /* CONFIG_FILE */
-
- case 'D':
- demo_mode = 1;
- break;
-
- default:
- fprintf(stderr, "newton: %s\n", usage);
- exit(1);
- }
- }
-
- if (argc) {
- fprintf(stderr, "newton: %s\n", usage);
- exit(1);
- }
-
- /*
- * set the model directory
- */
- if ((p = strrchr(model_catalog, '/')) != NULL) {
- *p++ = '\0';
- if (chdir(model_catalog) != 0) {
- fprintf(stderr, "newton: Could not chdir to ");
- if (model_catalog[0] == '/')
- fprintf(stderr, "%s\n", model_catalog);
- else
- fprintf(stderr, "%s/%s\n", cwd(), model_catalog);
- exit(1);
- }
- model_catalog = p;
- }
-
- #ifdef MP
-
- /*
- * figure out the number of processors
- */
- nproc = prctl(PR_MAXPPROCS);
- if (nproc > MAX_NPROC) {
- fprintf(stderr, "newton: nproc (%d) > MAX_NPROC(%d)\n", nproc, MAX_NPROC);
- nproc = MAX_NPROC;
- }
-
- /*
- * start up the slave(s)
- */
-
- for (i = 1; i < nproc; i++)
- slave_pid[i] = sproc(slave, PR_SALL, i);
-
- #endif /* MP */
-
- /*
- * execute the part of the initialization vital for the demo mode, this
- * is kind of a kludge...
- */
- initialize_physics();
- initialize_sliders();
- initialize_draw();
-
- #ifdef CONFIG_FILE
- initialize_config();
- #endif /* CONFIG_FILE */
-
-
- if (demo_mode) {
- /*
- * This is pretty disgusting. It kills the generality of the
- * rest of the program, but such is life.
- * it is based on the knowledge that:
- * - the size of the screen is 1280x1024;
- * - the window manager fattens windows by 23 pixels at the top, and
- * and 5 pixels on all other sides;
- * - there are exactly 6 sliders;
- * - each slider is of size 520x40 pixels;
- * - the aspect ratio of the main window is 5/4.
- */
-
- #define SLIDER_WIDTH 520
- #define SLIDER_HEIGHT 50
-
- size_x = SLIDER_WIDTH;
- size_y = SLIDER_HEIGHT;
- x0 = 200 + 5;
- y0 = 10 + 5;
- for (i = 0, j = 4; i < 3; i++, j -= 2) {
- prefposition(x0, x0 + size_x, y0, y0 + size_y);
- new_window(open_slider(sliders[j].sid), sliders[j].sid);
-
- x1 = x0 + size_x + 5 + 10 + 5;
-
- prefposition(x1, x1 + size_x, y0, y0 + size_y);
- new_window(open_slider(sliders[j+1].sid), sliders[j+1].sid);
-
- y0 += size_y + 23 + 10 + 5;
- }
-
- size_y = (YMAXSCREEN + 1) - y0 - (23 + 10);
- size_x = size_y * 5 / 4;
- x0 = 200 + ((XMAXSCREEN + 1 - 200) - (5 + size_x + 5)) / 2 + 5;
-
- prefposition(x0, x0 + size_x, y0, y0 + size_y);
- new_window(open_model_window(progname), -1);
- }
- else
- new_window(open_model_window(progname), -1);
-
- find_current_window();
-
- play();
-
- my_exit(0);
- }
-
-
-
- new_window(wid, sid)
- long wid;
- int sid;
- {
- long old_wid;
- struct window *wp;
- long bot_left[2], size[2];
-
- old_wid = winget();
- winset(wid);
-
- getorigin(&bot_left[X], &bot_left[Y]);
- getsize(&size[X], &size[Y]);
-
- wp = (struct window *) malloc(sizeof(struct window));
- if (wp == NULL) {
- fprintf(stderr, "newton: Could not malloc\n");
- my_exit(1);
- }
-
- wp->wid = wid;
- wp->bot_left[X] = bot_left[X];
- wp->bot_left[Y] = bot_left[Y];
- wp->top_right[X] = bot_left[X] + size[X];
- wp->top_right[Y] = bot_left[Y] + size[Y];
- wp->sid = sid;
-
- wp->next = windows;
- windows = wp;
-
- if (old_wid != -1)
- winset(old_wid);
- }
-
-
- close_current_window()
- {
- struct window *wc, *wp;
-
- for (wp = NULL, wc = windows; wc != NULL; wp = wc, wc = wc->next)
- if (wc == current_window)
- break;
- if (wc == NULL) {
- fprintf(stderr, "newton: No current window\n");
- goto finale;
- }
-
- if (wp == NULL)
- windows = wc->next;
- else
- wp->next = wc->next;
-
- free(wc);
-
- finale:
- find_current_window();
- }
-
-
- find_current_window()
- {
- short mx, my;
-
- mx = getvaluator(MOUSEX);
- my = getvaluator(MOUSEY);
-
- for (
- current_window = windows;
- current_window != NULL;
- current_window = current_window->next
- )
- if (
- (current_window->bot_left[X] < mx) &&
- (mx < current_window->top_right[X])
- &&
- (current_window->bot_left[Y] < my) &&
- (my < current_window->top_right[Y])
- )
- break;
-
- /*
- * technically, current_window can end up as NULL. This can occur if
- * the user closes a slider. I assume that whenever the above code
- * determines that current_window is NULL, I would get an INPUTCHANGE
- * from the window manager before anything else happens.
- */
- }
-
-
- my_exit(code)
- int code;
- {
- SLAVE_FUNC(SLAVE_DIE);
- exit(code);
- }
-