From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / sproingiewrap.c
index 402b910370c014699e61a472b3fb0a720756861c..722b725b90995232ad3b5aeb26ec37cf90a6f016 100644 (file)
@@ -54,6 +54,7 @@ static const char sccsid[] = "@(#)sproingiewrap.c     4.07 97/11/24 xlockmore";
                                        "*wireframe:    False   \n"
 
 # define refresh_sproingies 0
+# define release_sproingies 0
 # define sproingies_handle_event 0
 # include "xlockmore.h"                                /* from the xscreensaver distribution */
 #else  /* !STANDALONE */
@@ -85,7 +86,7 @@ ENTRYPOINT ModeSpecOpt sproingies_opts =
 
 #ifdef USE_MODULES
 ModStruct   sproingies_description =
-{"sproingies", "init_sproingies", "draw_sproingies", "release_sproingies",
+{"sproingies", "init_sproingies", "draw_sproingies", NULL,
  "refresh_sproingies", "init_sproingies", NULL, &sproingies_opts,
  1000, 5, 0, 400, 4, 1.0, "",
  "Shows Sproingies!  Nontoxic.  Safe for pets and small children", 0, NULL};
@@ -96,14 +97,6 @@ ModStruct   sproingies_description =
 
 #include <time.h>
 
-void        NextSproingie(int screen);
-void        NextSproingieDisplay(int screen,int pause);
-void        DisplaySproingies(int screen,int pause);
-void        ReshapeSproingies(int w, int h);
-void        CleanupSproingies(int screen);
-void        InitSproingies(int wfmode, int grnd, int mspr, int smrtspr,
-                                                  int screen, int numscreens, int mono);
-
 typedef struct {
        GLfloat     view_rotx, view_roty, view_rotz;
        GLint       gear1, gear2, gear3;
@@ -113,11 +106,15 @@ typedef struct {
        GLXContext *glx_context;
        int         mono;
        Window      window;
+       sp_instance si;
 } sproingiesstruct;
 
 static sproingiesstruct *sproingies = NULL;
 
 
+static void free_sproingies (ModeInfo * mi);
+
+
 ENTRYPOINT void
 init_sproingies (ModeInfo * mi)
 {
@@ -130,11 +127,7 @@ init_sproingies (ModeInfo * mi)
        sproingiesstruct *sp;
        int         wfmode = 0, grnd = 0, mspr, w, h;
 
-       if (sproingies == NULL) {
-               if ((sproingies = (sproingiesstruct *) calloc(MI_NUM_SCREENS(mi),
-                                        sizeof (sproingiesstruct))) == NULL)
-                       return;
-       }
+       MI_INIT (mi, sproingies, free_sproingies);
        sp = &sproingies[screen];
 
        sp->mono = (MI_IS_MONO(mi) ? 1 : 0);
@@ -152,7 +145,7 @@ init_sproingies (ModeInfo * mi)
                        mspr = 100;
 
                /* wireframe, ground, maxsproingies */
-               InitSproingies(wfmode, grnd, mspr, smrt_spr, MI_SCREEN(mi), MI_NUM_SCREENS(mi), sp->mono);
+               InitSproingies(&sp->si, wfmode, grnd, mspr, smrt_spr, sp->mono);
 
                /* Viewport is specified size if size >= MINSIZE && size < screensize */
                if (size == 0) {
@@ -173,7 +166,7 @@ init_sproingies (ModeInfo * mi)
                glMatrixMode(GL_MODELVIEW);
                glLoadIdentity();
 
-               DisplaySproingies(MI_SCREEN(mi),mi->pause);
+               DisplaySproingies(&sp->si);
 
        } else {
                MI_CLEARWINDOW(mi);
@@ -196,7 +189,7 @@ draw_sproingies (ModeInfo * mi)
 
     glPushMatrix();
     glRotatef(current_device_rotation(), 0, 0, 1);
-       NextSproingieDisplay(MI_SCREEN(mi),mi->pause);  /* It will swap. */
+       NextSproingieDisplay(&sp->si);  /* It will swap. */
     glPopMatrix();
 
     if (mi->fps_p) do_fps (mi);
@@ -223,26 +216,16 @@ reshape_sproingies (ModeInfo *mi, int w, int h)
 }
 
 
-ENTRYPOINT void
-release_sproingies (ModeInfo * mi)
+static void
+free_sproingies (ModeInfo * mi)
 {
-       if (sproingies != NULL) {
-               int         screen;
-
-               for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-                       sproingiesstruct *sp = &sproingies[screen];
-
-                       if (sp->glx_context) {
+       sproingiesstruct *sp = &sproingies[MI_SCREEN(mi)];
 
-                               glXMakeCurrent(MI_DISPLAY(mi), sp->window, *(sp->glx_context));
-                               CleanupSproingies(MI_SCREEN(mi));
-                       }
-               }
+       if (sp->glx_context) {
 
-               (void) free((void *) sproingies);
-               sproingies = NULL;
+               glXMakeCurrent(MI_DISPLAY(mi), sp->window, *(sp->glx_context));
+               CleanupSproingies(&sp->si);
        }
-       FreeAllGL(mi);
 }
 
 XSCREENSAVER_MODULE ("Sproingies", sproingies)