From http://www.jwz.org/xscreensaver/xscreensaver-5.16.tar.gz
[xscreensaver] / hacks / glx / glschool.c
index ecaa6aadbdac9ffe42f8b688ee063c2efd325818..1ef4c130db171c0969c93526a194406e376de92f 100644 (file)
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
+#define DEF_NFISH      "100"
+#define DEF_FOG                "False"
+#define DEF_DRAWBBOX   "True"
+#define DEF_DRAWGOAL   "False"
+#define DEF_GOALCHGF   "50"
+#define DEF_MAXVEL     "7.0"
+#define DEF_MINVEL     "1.0"
+#define DEF_ACCLIMIT   "8.0"
+#define DEF_DISTEXP    "2.2"
+#define DEF_AVOIDFACT  "1.5"
+#define DEF_MATCHFACT  "0.15"
+#define DEF_CENTERFACT "0.1"
+#define DEF_TARGETFACT "80"
+#define DEF_MINRADIUS  "30.0"
+#define DEF_MOMENTUM   "0.9"
+#define DEF_DISTCOMP   "10.0"
+
 static int                     NFish;
 static Bool                    DoFog;
 static Bool                    DoDrawBBox;
@@ -63,22 +80,22 @@ static XrmOptionDescRec opts[] = {
 };
 
 static argtype vars[] = {
-       {&NFish,                "nfish",                "NFish",                "100", t_Int},
-       {&DoFog,                "fog",                  "DoFog",                "False", t_Bool},
-       {&DoDrawBBox,   "drawbbox",             "DoDrawBBox",   "True", t_Bool},
-       {&DoDrawGoal,   "drawgoal",             "DoDrawGoal",   "False", t_Bool},
-       {&GoalChgFreq,  "goalchgf",             "GoalChgFreq",  "50",  t_Int},
-       {&MaxVel,               "maxvel",               "MaxVel",               "7.0",  t_Float},
-       {&MinVel,               "minvel",               "MinVel",               "1.0",  t_Float},
-       {&AccLimit,             "acclimit",             "AccLimit",             "8.0",  t_Float},
-       {&DistExp,              "distexp",              "DistExp",              "2.2",  t_Float},
-       {&AvoidFact,    "avoidfact",    "AvoidFact",    "1.5",  t_Float},
-       {&MatchFact,    "matchfact",    "MatchFact",    "0.15",  t_Float},
-       {&CenterFact,   "centerfact",   "CenterFact",   "0.1",  t_Float},
-       {&TargetFact,   "targetfact",   "TargetFact",   "80",  t_Float},
-       {&MinRadius,    "minradius",    "MinRadius",    "30.0",  t_Float},
-       {&Momentum,             "momentum",             "Momentum",             "0.9",  t_Float},
-       {&DistComp,             "distcomp",             "DistComp",             "10.0",  t_Float},
+       {&NFish,                "nfish",                "NFish",                DEF_NFISH, t_Int},
+       {&DoFog,                "fog",                  "DoFog",                DEF_FOG, t_Bool},
+       {&DoDrawBBox,   "drawbbox",             "DoDrawBBox",   DEF_DRAWBBOX, t_Bool},
+       {&DoDrawGoal,   "drawgoal",             "DoDrawGoal",   DEF_DRAWGOAL, t_Bool},
+       {&GoalChgFreq,  "goalchgf",             "GoalChgFreq",  DEF_GOALCHGF,  t_Int},
+       {&MaxVel,               "maxvel",               "MaxVel",               DEF_MAXVEL,  t_Float},
+       {&MinVel,               "minvel",               "MinVel",               DEF_MINVEL,     t_Float},
+       {&AccLimit,             "acclimit",             "AccLimit",             DEF_ACCLIMIT,  t_Float},
+       {&DistExp,              "distexp",              "DistExp",              DEF_DISTEXP,  t_Float},
+       {&AvoidFact,    "avoidfact",    "AvoidFact",    DEF_AVOIDFACT,  t_Float},
+       {&MatchFact,    "matchfact",    "MatchFact",    DEF_MATCHFACT,  t_Float},
+       {&CenterFact,   "centerfact",   "CenterFact",   DEF_CENTERFACT,  t_Float},
+       {&TargetFact,   "targetfact",   "TargetFact",   DEF_TARGETFACT,  t_Float},
+       {&MinRadius,    "minradius",    "MinRadius",    DEF_MINRADIUS,  t_Float},
+       {&Momentum,             "momentum",             "Momentum",             DEF_MOMENTUM,  t_Float},
+       {&DistComp,             "distcomp",             "DistComp",             DEF_DISTCOMP,  t_Float},
 };
 
 ENTRYPOINT ModeSpecOpt glschool_opts = {countof(opts), opts, countof(vars), vars, NULL};
@@ -92,6 +109,7 @@ typedef struct {
        GLuint          bboxList;
        GLuint          goalList;
        GLuint          fishList;
+        int            fish_polys, box_polys;
        XColor          *colors;
        School          *school;
        GLXContext      *context;
@@ -110,7 +128,7 @@ reshape_glschool(ModeInfo *mi, int width, int height)
        if (sc->school != (School *)0) {
                setBBox(sc->school, -aspect*160, aspect*160, -130, 130, -450, -50.0);
                glDeleteLists(sc->bboxList, 1);
-               createBBoxList(&SCHOOL_BBOX(sc->school), &sc->bboxList, wire);
+                createBBoxList(&SCHOOL_BBOX(sc->school), &sc->bboxList, wire);
        }
        reshape(width, height);
 }
@@ -156,7 +174,8 @@ init_glschool(ModeInfo *mi)
 
        initGLEnv(DoFog);
        initFishes(sc->school);
-       createDrawLists(&SCHOOL_BBOX(sc->school), &sc->bboxList, &sc->goalList, &sc->fishList, wire);
+       createDrawLists(&SCHOOL_BBOX(sc->school), &sc->bboxList, &sc->goalList, &sc->fishList,
+                        &sc->fish_polys, &sc->box_polys, wire);
        computeAccelerations(sc->school);
 }
 
@@ -174,6 +193,8 @@ draw_glschool(ModeInfo *mi)
 
        glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(sc->context));
 
+        mi->polygon_count = 0;
+
        if ((sc->goalCounter % GoalChgFreq) == 0)
                newGoal(sc->school);
        sc->goalCounter++;
@@ -182,7 +203,9 @@ draw_glschool(ModeInfo *mi)
        sc->rotCounter = (sc->rotCounter%360);
 
        applyMovements(sc->school);
-       drawSchool(sc->colors, sc->school, sc->bboxList, sc->goalList, sc->fishList, sc->rotCounter, sc->drawGoal, sc->drawBBox);
+       drawSchool(sc->colors, sc->school, sc->bboxList, sc->goalList, sc->fishList, sc->rotCounter, sc->drawGoal, sc->drawBBox, 
+                   sc->fish_polys, sc->box_polys,
+                   &mi->polygon_count);
        computeAccelerations(sc->school);
 
        if (mi->fps_p)