~ubuntu-branches/ubuntu/lucid/xscreensaver/lucid

« back to all changes in this revision

Viewing changes to hacks/glx/sproingies.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2007-12-06 09:53:12 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206095312-fkzcwe4vqm50z208
Tags: 5.04-1ubuntu1
* Merge from debian unstable, remaining changes:
  - split xscreensaver into xscreensaver, xscreensaver-data (hacks we ship),
    xscreensaver-data-extra (hacks in universe). split out gl hacks for
    universe to xscreensaver-gl-extra
  - use fridge for rss screensavers
  - create and install .desktop files for gnome-screensaver

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * See sproingiewrap.c
25
25
 */
26
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
# include "config.h"
 
29
#endif /* HAVE_CONFIG_H */
 
30
 
27
31
#ifdef STANDALONE
28
32
# include "xlockmoreI.h"                /* from the xscreensaver distribution */
29
33
#else /* !STANDALONE */
32
36
 
33
37
#ifdef USE_GL
34
38
 
35
 
#include <GL/gl.h>
36
 
#include <GL/glu.h>
 
39
#ifdef HAVE_COCOA
 
40
# include <OpenGL/glu.h>
 
41
#else
 
42
# include <GL/glu.h>
 
43
#endif
 
44
 
37
45
#include "gllist.h"
38
 
 
39
 
#define MAXSPROING 100
40
 
#define T_COUNT 40
41
 
#define BOOM_FRAME 50
42
 
 
43
 
struct sPosColor {
44
 
        int         x, y, z, frame, life;
45
 
        GLfloat     r, g, b;
 
46
#include "sproingies.h"
 
47
 
 
48
#define MAXSPROING           100
 
49
#define TARGET_COUNT         40
 
50
#define BOOM_FRAME           50
 
51
#define NO_FRAME             (-10)
 
52
#define RESET_SPROINGIE_LIFE (-30 + myrand(28))
 
53
#define NEW_SPROINGIE_LIFE   (40 + myrand(200))
 
54
#define JUMP_LEFT            0
 
55
#define JUMP_RIGHT           1
 
56
 
 
57
#define FIRST_FRAME          0
 
58
#define LAST_FRAME           5 
 
59
/*-
 
60
 * The sproingies have six "real" frames, (s1_1 to s1_6) that show a
 
61
 * sproingie jumping off a block, headed down and to the right. 
 
62
 * The frames are numbered from 0 (FIRST_FRAME) to 5 (LAST_FRAME). 
 
63
 * 
 
64
 * There are other frame numbers for special cases (e.g. BOOM_FRAME).
 
65
 */
 
66
struct sPosColor {   /* Position and color of the sproingie     */
 
67
        int x, y, z;     /*   Position                              */
 
68
        int frame;       /*   Current frame (0-5)                   */
 
69
        int life;        /*   Life points                           */
 
70
        GLfloat r, g, b; /*   Color RGB                             */
 
71
        int direction;   /*   Direction of next hop (left or right) */
46
72
};
47
73
 
48
74
typedef struct {
49
75
        int         rotx, roty, dist, wireframe, flatshade, groundlevel,
50
76
                    maxsproingies, mono;
51
77
        int         sframe, target_rx, target_ry, target_dist, target_count;
52
 
        struct gllist *sproingies[6];
53
 
        struct gllist *SproingieBoom;
 
78
        const struct gllist *sproingies[6];
 
79
        const struct gllist *SproingieBoom;
54
80
        GLuint TopsSides;
55
81
        struct sPosColor *positions;
56
82
} sp_instance;
58
84
static sp_instance *si_list = NULL;
59
85
static int  active_screens = 0;
60
86
 
61
 
void        SproingieSwap(void);
62
 
 
63
 
extern struct gllist *s1_1;
64
 
extern struct gllist *s1_2;
65
 
extern struct gllist *s1_3;
66
 
extern struct gllist *s1_4;
67
 
extern struct gllist *s1_5;
68
 
extern struct gllist *s1_6;
69
 
extern struct gllist *s1_b;
 
87
extern const struct gllist *s1_1;
 
88
extern const struct gllist *s1_2;
 
89
extern const struct gllist *s1_3;
 
90
extern const struct gllist *s1_4;
 
91
extern const struct gllist *s1_5;
 
92
extern const struct gllist *s1_6;
 
93
extern const struct gllist *s1_b;
70
94
 
71
95
static int
72
96
myrand(int range)
74
98
        return ((int) (((float) range) * LRAND() / (MAXRAND)));
75
99
}
76
100
 
 
101
static int smart_sproingies = 0;
 
102
 
77
103
static      GLuint
78
104
build_TopsSides(int wireframe)
79
105
{
234
260
        }
235
261
}
236
262
 
237
 
#define RESET_SPROINGIE (-30 + myrand(28))
238
 
 
239
263
static void
240
264
AdvanceSproingie(int t, sp_instance * si)
241
265
{
244
268
        struct sPosColor *S2 = &(si->positions[0]);
245
269
 
246
270
        if (thisSproingie->life > 0) {
247
 
                if ((++(thisSproingie->frame)) > 11) {
 
271
                if ((++(thisSproingie->frame)) > LAST_FRAME) {
248
272
                        if (thisSproingie->frame >= BOOM_FRAME) {
249
273
                                if ((thisSproingie->r -= 0.08) < 0.0)
250
274
                                        thisSproingie->r = 0.0;
253
277
                                if ((thisSproingie->b -= 0.08) < 0.0)
254
278
                                        thisSproingie->b = 0.0;
255
279
                                if ((--(thisSproingie->life)) < 1) {
256
 
                                        thisSproingie->life = RESET_SPROINGIE;
 
280
                                        thisSproingie->life = RESET_SPROINGIE_LIFE;
257
281
                                }
258
282
                                return;
259
283
                        }
260
 
                        thisSproingie->x += 1;
261
 
                        thisSproingie->y -= 2;
262
 
                        thisSproingie->z += 1;
263
 
                        thisSproingie->frame = 0;
 
284
                        thisSproingie->frame = FIRST_FRAME;
264
285
 
 
286
                        /* Check for collisions */
265
287
                        for (t2 = 0; t2 < si->maxsproingies; ++t2) {
266
288
                                if ((t2 != t) && (thisSproingie->x == S2->x) &&
267
289
                                    (thisSproingie->y == S2->y) && (thisSproingie->z == S2->z) &&
268
 
                                    (S2->life > 10) && (S2->frame < 6)) {
 
290
                                    (S2->life > 10) && (S2->frame < LAST_FRAME + 1)) {
269
291
#if 0
270
292
                                        if (thisSproingie->life > S2->life) {
271
293
                                                S2->life = 10;
288
310
                                ++S2;
289
311
                        }
290
312
                }
 
313
                /* Time to disappear... */
291
314
                if (!((thisSproingie->life == 10) &&
292
 
                      (thisSproingie->frame > 0) &&
 
315
                      (thisSproingie->frame > FIRST_FRAME) &&
293
316
                      (thisSproingie->frame < BOOM_FRAME))) {
294
317
                        if ((--(thisSproingie->life)) < 1) {
295
 
                                thisSproingie->life = RESET_SPROINGIE;
 
318
                                thisSproingie->life = RESET_SPROINGIE_LIFE;
296
319
                        } else if (thisSproingie->life < 9) {
297
320
                                thisSproingie->frame -= 2;
298
 
                        }
299
 
                }               /* else wait here for frame 0 to come about. */
 
321
                        } 
 
322
                }               /* ... else wait here for frame FIRST_FRAME to come about. */
300
323
        } else if (++(thisSproingie->life) >= 0) {
301
 
                if (t > 1) {
 
324
                if (1 || t > 1) {
302
325
                        g_higher = -3 + myrand(5);
303
326
                        g_back = -2 + myrand(5);
304
327
                } else if (t == 1) {
309
332
                        g_back = 0;
310
333
                }
311
334
 
312
 
                thisSproingie->x = (-g_higher - g_back);
313
 
                thisSproingie->y = (g_higher << 1);
314
 
                thisSproingie->z = (g_back - g_higher);
315
 
                thisSproingie->life = 40 + myrand(200);
316
 
                thisSproingie->frame = -10;
317
 
                thisSproingie->r = (GLfloat) (40 + myrand(200)) / 255.0;
318
 
                thisSproingie->g = (GLfloat) (40 + myrand(200)) / 255.0;
319
 
                thisSproingie->b = (GLfloat) (40 + myrand(200)) / 255.0;
 
335
                thisSproingie->x     = (-g_higher - g_back);
 
336
                thisSproingie->y     = (g_higher << 1);
 
337
                thisSproingie->z     = (g_back - g_higher);
 
338
                thisSproingie->life  = NEW_SPROINGIE_LIFE;
 
339
                thisSproingie->frame = NO_FRAME;
 
340
                thisSproingie->r     = (GLfloat) (40 + myrand(200)) / 255.0;
 
341
                thisSproingie->g     = (GLfloat) (40 + myrand(200)) / 255.0;
 
342
                thisSproingie->b     = (GLfloat) (40 + myrand(200)) / 255.0;
320
343
 
321
344
                for (t2 = 0; t2 < si->maxsproingies; ++t2) {
322
345
                        if ((t2 != t) && (thisSproingie->x == S2->x) &&
323
346
                            (thisSproingie->y == S2->y) && (thisSproingie->z == S2->z) &&
324
 
                            (S2->life > 10) && (S2->frame < 0)) {
325
 
                                /* If one is already being born, just wait. */
 
347
                            (S2->life > 10) && (S2->frame < FIRST_FRAME)) {
 
348
                                /* If another is already on this place, wait. */
326
349
                                thisSproingie->life = -1;
327
350
                        }
328
351
                        ++S2;
337
360
        int         ddx, t;
338
361
        struct sPosColor *thisSproingie = &(si->positions[0]);
339
362
 
 
363
        /* Although the sproingies cycle has six frames, the blocks cycle  */
 
364
        /* has twelve. After a full cycle (12 frames), re-center positions */
 
365
        /* of sproingies                                                   */
340
366
        if (++si->sframe > 11) {
341
 
                si->sframe = 0;
 
367
                si->sframe = FIRST_FRAME;
342
368
                for (t = 0; t < si->maxsproingies; ++t) {
343
369
                        thisSproingie->x -= 1;
344
370
                        thisSproingie->y += 2;
346
372
                        ++thisSproingie;
347
373
                }
348
374
        }
 
375
 
349
376
        for (t = 0; t < si->maxsproingies; ++t) {
350
377
                AdvanceSproingie(t, si);
351
378
        }
371
398
 
372
399
                if ((si->target_rx == si->rotx) && (si->target_ry == si->roty) &&
373
400
                    (si->target_dist == si->dist)) {
374
 
                        si->target_count = T_COUNT;
 
401
                        si->target_count = TARGET_COUNT;
375
402
                        if (si->target_dist <= 32)
376
403
                                si->target_count >>= 2;
377
404
                }
410
437
                positions[t].y = 0;
411
438
                positions[t].z = 0;
412
439
                positions[t].life = -2;
413
 
                positions[t].frame = 0;
 
440
                positions[t].frame = FIRST_FRAME;
414
441
        }
415
442
}
416
443
 
476
503
        roty = (roty - 45) % 360;
477
504
}
478
505
 
479
 
#endif
 
506
#endif /* __AUXFUNCS__ */
480
507
 
481
508
static void
482
509
RenderSproingie(int t, sp_instance * si)
502
529
                        glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_color);
503
530
                }
504
531
        }
505
 
        if (thisSproingie->frame < 0) {
 
532
 
 
533
        if (thisSproingie->frame < FIRST_FRAME) {
506
534
                glEnable(GL_CLIP_PLANE0);
507
535
                glTranslatef((GLfloat) (thisSproingie->x),
508
536
                             (GLfloat) (thisSproingie->y) +
512
540
                        (si->wireframe ? 0.0 : 0.1);
513
541
                glClipPlane(GL_CLIP_PLANE0, clipplane);
514
542
/**             glCallList(si->sproingies[0]);*/
515
 
/**/    renderList(si->sproingies[0]);
 
543
/**/    renderList(si->sproingies[0], si->wireframe);
516
544
                glDisable(GL_CLIP_PLANE0);
517
545
        } else if (thisSproingie->frame >= BOOM_FRAME) {
518
546
                glTranslatef((GLfloat) (thisSproingie->x) + 0.5,
532
560
 * PURIFY 4.0.1 reports an unitialized memory read on the next line when using
533
561
 * MesaGL 2.2.  This has been tracked to MesaGL 2.2 src/points.c line 313. */
534
562
/**             glCallList(si->SproingieBoom);*/
535
 
/**/    renderList(si->SproingieBoom);
 
563
/**/    renderList(si->SproingieBoom, si->wireframe);
536
564
                glPointSize(1.0);
537
565
                if (!si->wireframe) {
538
566
                        glEnable(GL_LIGHTING);
539
567
                }
540
 
        } else if (thisSproingie->frame > 5) {
541
 
                glTranslatef((GLfloat) (thisSproingie->x + 1),
542
 
                             (GLfloat) (thisSproingie->y - 1), (GLfloat) (thisSproingie->z - 1));
543
 
                glRotatef((GLfloat) - 90.0, 0.0, 1.0, 0.0);
544
 
/**             glCallList(si->sproingies[thisSproingie->frame - 6]);*/
545
 
/**/    renderList(si->sproingies[thisSproingie->frame - 6]);
546
568
        } else {
547
 
                glTranslatef((GLfloat) (thisSproingie->x), (GLfloat) (thisSproingie->y),
548
 
                             (GLfloat) (thisSproingie->z));
 
569
                if (thisSproingie->direction == JUMP_LEFT) {
 
570
                        /* When the sproingie jumps to the left, the frames must be */
 
571
                        /* rotated and translated */
 
572
                        glTranslatef((GLfloat) (thisSproingie->x    ),
 
573
                                                 (GLfloat) (thisSproingie->y    ), 
 
574
                                                 (GLfloat) (thisSproingie->z - 1));
 
575
                        glRotatef((GLfloat) - 90.0, 0.0, 1.0, 0.0);
 
576
                        if (thisSproingie->frame == LAST_FRAME) {
 
577
                                thisSproingie->x -= 0;
 
578
                                thisSproingie->y -= 1;
 
579
                                thisSproingie->z += 1;
 
580
                        } 
 
581
                } else {
 
582
                        glTranslatef((GLfloat) (thisSproingie->x),
 
583
                                                 (GLfloat) (thisSproingie->y), 
 
584
                                                 (GLfloat) (thisSproingie->z));
 
585
                        glRotatef((GLfloat) - 0.0, 0.0, 1.0, 0.0);
 
586
                        if (thisSproingie->frame == LAST_FRAME) {
 
587
                                thisSproingie->x += 1;
 
588
                                thisSproingie->y -= 1;
 
589
                                thisSproingie->z -= 0;
 
590
                        }
 
591
                }
 
592
/*      } */
549
593
/**             glCallList(si->sproingies[thisSproingie->frame]);*/
550
 
/**/    renderList(si->sproingies[thisSproingie->frame]);
 
594
/**/    renderList(si->sproingies[thisSproingie->frame], si->wireframe);
 
595
 
 
596
                /* Every 6 frame cycle... */
 
597
                if (thisSproingie->frame == LAST_FRAME) {
 
598
                        /* ...check if the sproingies have gone out of the bricks */
 
599
                        if (((thisSproingie->x - thisSproingie->z == 6) &&
 
600
                                 (2*thisSproingie->x + thisSproingie->y == 6)) ||
 
601
                                ((thisSproingie->z - thisSproingie->x == 5) &&
 
602
                                 (2*thisSproingie->x + thisSproingie->y == -5))) {
 
603
                                /* If they have, then they die */
 
604
                                if (thisSproingie->life > 0 && thisSproingie->frame < BOOM_FRAME && thisSproingie->frame > FIRST_FRAME) {
 
605
                                        thisSproingie->frame = BOOM_FRAME;
 
606
                                }
 
607
                        } else {
 
608
                                /* If not, they choose a direction for the next hop */
 
609
                                if (smart_sproingies) {
 
610
                                        if ((thisSproingie->x - thisSproingie->z == 5) &&   
 
611
                                                (2*thisSproingie->x + thisSproingie->y == 5)) {
 
612
                                                thisSproingie->direction = JUMP_LEFT;
 
613
                                        } else if ((thisSproingie->z - thisSproingie->x == 4) &&   
 
614
                                                 (2*thisSproingie->x + thisSproingie->y == -4)) {
 
615
                                                thisSproingie->direction = JUMP_RIGHT;
 
616
                                        } else {
 
617
                                                thisSproingie->direction = myrand(2);
 
618
                                        }
 
619
                                } else {
 
620
                                        thisSproingie->direction = myrand(2);
 
621
                                }
 
622
                        }
 
623
                }
551
624
        }
552
625
 
553
626
        glPopMatrix();
657
730
 
658
731
        glPopMatrix();
659
732
        glFlush();
660
 
 
661
 
        SproingieSwap();
662
733
}
663
734
 
664
735
void
665
736
NextSproingieDisplay(int screen,int pause)
666
737
{
667
738
        NextSproingie(screen);
668
 
        if (pause) usleep(pause);
 
739
/*        if (pause) usleep(pause);  don't do this! -jwz */
669
740
        DisplaySproingies(screen,pause);
670
741
}
671
742
 
711
782
}
712
783
 
713
784
void
714
 
InitSproingies(int wfmode, int grnd, int mspr, int screen, int numscreens,
715
 
               int mono)
 
785
InitSproingies(int wfmode, int grnd, int mspr, int smrtspr, 
 
786
                           int screen, int numscreens, int mono)
716
787
{
717
788
        GLfloat     ambient[] =
718
789
        {0.2, 0.2, 0.2, 1.0};
743
814
        if (mspr >= MAXSPROING)
744
815
                mspr = MAXSPROING - 1;
745
816
 
 
817
        smart_sproingies = smrtspr; 
 
818
 
746
819
        si->rotx = 0;
747
820
        si->roty = -45;
748
821
        si->dist = (16 << 2);
772
845
                si->positions[t].y = 0;
773
846
                si->positions[t].z = 0;
774
847
                si->positions[t].life = (-t * ((si->maxsproingies > 19) ? 1 : 4)) - 2;
775
 
                si->positions[t].frame = 0;
 
848
                si->positions[t].frame = FIRST_FRAME;
 
849
                si->positions[t].direction = myrand(2);
776
850
        }
777
851
 
778
852
#if 0                           /* Test boom */
843
917
        }
844
918
}
845
919
 
846
 
#endif
 
920
#endif /* USE_GL */
847
921
 
848
922
/* End of sproingies.c */
 
923