ftp://ftp.linux.ncsu.edu/mirror/ftp.redhat.com/pub/redhat/linux/enterprise/4/en/os...
[xscreensaver] / hacks / glx / pipes.c
index 8ee1538940ea4deabb0ea6117f4de3f044accd41..65e2b579740cb8913a60e4a6f7873de027f8a5e4 100644 (file)
@@ -1,9 +1,8 @@
 /* -*- Mode: C; tab-width: 4 -*- */
 /* pipes --- 3D selfbuiding pipe system */
 
-#if !defined( lint ) && !defined( SABER )
+#if 0
 static const char sccsid[] = "@(#)pipes.c      4.07 97/11/24 xlockmore";
-
 #endif
 
 /*-
@@ -33,10 +32,7 @@ static const char sccsid[] = "@(#)pipes.c    4.07 97/11/24 xlockmore";
  * Since I'm not a native English speaker, my apologies for any grammatical
  * mistake.
  *
- * My e-mail addresses are
- *
- * vianna@cat.cbpf.br 
- *         and
+ * My e-mail address is
  * m-vianna@usa.net
  * Marcelo F. Vianna (Apr-09-1997)
  *
@@ -46,26 +42,22 @@ static const char sccsid[] = "@(#)pipes.c   4.07 97/11/24 xlockmore";
  * 29-Apr-97: Efficiency speed-ups by Marcelo F. Vianna
  */
 
-/*-
- * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock.
- * otherwise caddr_t is not defined correctly
- */
-
-#include <X11/Intrinsic.h>
-
 #ifdef STANDALONE
 # define PROGCLASS                                     "Pipes"
 # define HACK_INIT                                     init_pipes
 # define HACK_DRAW                                     draw_pipes
+# define HACK_RESHAPE                          reshape_pipes
 # define pipes_opts                                    xlockmore_opts
 # define DEFAULTS      "*delay:                100     \n"                     \
                                        "*count:                2       \n"                     \
                                        "*cycles:               5       \n"                     \
                                        "*size:                 500     \n"                     \
+                       "*showFPS:      False   \n"                 \
+                       "*fpsSolid:     True    \n"                 \
                                        "*fisheye:              True    \n"                     \
                                        "*tightturns:   False   \n"                     \
-                                       "*rotatepipes:  True    \n"                     \
-                                       "*noBuffer:             True    \n"
+                                       "*doubleBuffer: True    \n"                     \
+                                       "*rotatepipes:  True    \n"
 # include "xlockmore.h"                                /* from the xscreensaver distribution */
 #else  /* !STANDALONE */
 # include "xlock.h"                                    /* from the xlockmore distribution */
@@ -80,49 +72,51 @@ static const char sccsid[] = "@(#)pipes.c   4.07 97/11/24 xlockmore";
 #define DEF_FISHEYE     "True"
 #define DEF_TIGHTTURNS  "False"
 #define DEF_ROTATEPIPES "True"
+#define DEF_DBUF        "False"
 #define NofSysTypes     3
 
 static int  factory;
 static Bool fisheye, tightturns, rotatepipes;
+static Bool dbuf_p;
 
 static XrmOptionDescRec opts[] =
 {
-       {"-factory", ".pipes.factory", XrmoptionSepArg, (caddr_t) NULL},
-       {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "on"},
-       {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "off"},
-       {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "on"},
-       {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "off"},
-      {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "on"},
-      {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "off"}
+       {"-factory", ".pipes.factory", XrmoptionSepArg, 0},
+       {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, "on"},
+       {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, "off"},
+       {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, "on"},
+       {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, "off"},
+      {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "on"},
+      {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "off"},
+      {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, "on"},
+      {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, "off"},
 };
 static argtype vars[] =
 {
-       {(caddr_t *) & factory, "factory", "Factory", DEF_FACTORY, t_Int},
-       {(caddr_t *) & fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
-       {(caddr_t *) & tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
-       {(caddr_t *) & rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool}
+       {&factory, "factory", "Factory", DEF_FACTORY, t_Int},
+       {&fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
+       {&tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
+       {&rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool},
+       {&dbuf_p, "doubleBuffer", "DoubleBuffer", DEF_DBUF, t_Bool}
 };
 static OptionStruct desc[] =
 {
        {"-factory num", "how much extra equipment in pipes (0 for none)"},
        {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
        {"-/+tightturns", "turn on/off tight turns"},
-       {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"}
+       {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"},
+       {"-/+db", "turn on/off double buffering"}
 };
 
 ModeSpecOpt pipes_opts =
-{7, opts, 4, vars, desc};
+{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
 
 #ifdef USE_MODULES
 ModStruct   pipes_description =
 {"pipes", "init_pipes", "draw_pipes", "release_pipes",
-#if defined( MESA ) && defined( SLOW )
  "draw_pipes",
-#else
- "change_pipes",
-#endif
  "change_pipes", NULL, &pipes_opts,
- 1000, 2, 5, 500, 1.0, "",
+ 1000, 2, 5, 500, 4, 1.0, "",
  "Shows a selfbuilding pipe system", 0, NULL};
 
 #endif
@@ -148,9 +142,8 @@ ModStruct   pipes_description =
 /*************************************************************************/
 
 typedef struct {
-#if defined( MESA ) && defined( SLOW )
        int         flip;
-#endif
+
        GLint       WindH, WindW;
        int         Cells[HCELLS][VCELLS][HCELLS];
        int         usedcolors[DEFINEDCOLORS];
@@ -406,7 +399,7 @@ MakeValve(ModeInfo * mi, int newdir)
        glCallList(pp->betweenbolts);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
        glCallList(pp->bolts);
-       if (!MI_WIN_IS_MONO(mi)) {
+       if (!MI_IS_MONO(mi)) {
                if (pp->system_color == MaterialRed) {
                        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
                } else if (pp->system_color == MaterialBlue) {
@@ -494,8 +487,8 @@ MakeShape(ModeInfo * mi, int newdir)
        }
 }
 
-static void
-reshape(ModeInfo * mi, int width, int height)
+void
+reshape_pipes(ModeInfo * mi, int width, int height)
 {
        pipesstruct *pp = &pipes[MI_SCREEN(mi)];
 
@@ -505,6 +498,8 @@ reshape(ModeInfo * mi, int width, int height)
        /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
        gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
        glMatrixMode(GL_MODELVIEW);
+
+  glClear(GL_COLOR_BUFFER_BIT);
 }
 
 static void
@@ -538,7 +533,7 @@ pinit(ModeInfo * mi, int zera)
 
        if (zera) {
                pp->system_number = 1;
-               glDrawBuffer(GL_FRONT_AND_BACK);
+               glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                (void) memset(pp->Cells, 0, sizeof (pp->Cells));
                for (X = 0; X < HCELLS; X++) {
@@ -563,7 +558,7 @@ pinit(ModeInfo * mi, int zera)
        pp->counter = 0;
        pp->turncounter = 0;
 
-       if (!MI_WIN_IS_MONO(mi)) {
+       if (!MI_IS_MONO(mi)) {
                int         collist[DEFINEDCOLORS];
                int         i, j, lower = 1000;
 
@@ -639,29 +634,32 @@ init_pipes(ModeInfo * mi)
        pp->window = MI_WINDOW(mi);
        if ((pp->glx_context = init_GL(mi)) != NULL) {
 
-               reshape(mi, MI_WIN_WIDTH(mi), MI_WIN_HEIGHT(mi));
-               pp->initial_rotation = -10.0;
+               reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
+               if (rotatepipes)
+                 pp->initial_rotation = NRAND(180); /* jwz */
+               else
+                 pp->initial_rotation = -10.0;
                pinit(mi, 1);
 
                if (factory > 0) {
-                       pp->valve = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_BigValve);
-                       pp->bolts = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_Bolts3D);
-                       pp->betweenbolts = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
+                       pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
+                       pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
+                       pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
 
-                       pp->elbowbolts = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_ElbowBolts);
-                       pp->elbowcoins = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_ElbowCoins);
+                       pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
+                       pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
 
-                       pp->guagehead = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageHead);
-                       pp->guageface = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageFace);
-                       pp->guagedial = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageDial);
-                       pp->guageconnector = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageConnector);
+                       pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
+                       pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
+                       pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
+                       pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
                }
                /* else they are all 0, thanks to calloc(). */
 
-               if (MI_BATCHCOUNT(mi) < 1 || MI_BATCHCOUNT(mi) > NofSysTypes + 1) {
+               if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
                        pp->system_type = NRAND(NofSysTypes) + 1;
                } else {
-                       pp->system_type = MI_BATCHCOUNT(mi);
+                       pp->system_type = MI_COUNT(mi);
                }
 
                if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
@@ -696,20 +694,13 @@ draw_pipes(ModeInfo * mi)
        if (!pp->glx_context)
                return;
 
-       glXMakeCurrent(display, window, *(pp->glx_context));
-
-#if defined( MESA ) && defined( SLOW )
-       glDrawBuffer(GL_BACK);
-#else
-       glDrawBuffer(GL_FRONT);
-#endif
        glPushMatrix();
 
        glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
        if (rotatepipes)
                glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
 
-       if (!MI_WIN_IS_ICONIC(mi)) {
+       if (!MI_IS_ICONIC(mi)) {
                /* Width/height ratio handled by gluPerspective() now. */
                glScalef(Scale4Window, Scale4Window, Scale4Window);
        } else {
@@ -733,15 +724,14 @@ draw_pipes(ModeInfo * mi)
                glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
                /* Finish the system with another sphere */
                mySphere(0.6);
-#if defined( MESA ) && defined( SLOW )
-               glXSwapBuffers(display, window);
-#endif
+
                glPopMatrix();
 
                /* If the maximum number of system was drawn, restart (clearing the screen), */
                /* else start a new system. */
                if (++pp->system_number > pp->number_of_systems) {
-                       (void) sleep(1);
+          if (!mi->fps_p)
+            sleep(1);
                        pinit(mi, 1);
                } else {
                        pinit(mi, 0);
@@ -971,11 +961,10 @@ draw_pipes(ModeInfo * mi)
 
        glFlush();
 
-#if defined( MESA ) && defined( SLOW )
-       pp->flip = !pp->flip;
-       if (pp->flip)
-               glXSwapBuffers(display, window);
-#endif
+    if (dbuf_p)
+      glXSwapBuffers(display, window);
+
+    if (mi->fps_p) do_fps (mi);
 }
 
 void