goom_core.c 27.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/**
* file: goom_core.c
 * author: Jean-Christophe Hoelt (which is not so proud of it)
 *
 * Contains the core of goom's work.
 *
 * (c)2000-2003, by iOS-software.
 */

#include <math.h>
#include <stdio.h>
12
13
#include <stdlib.h>
#include <string.h>
14
#include <strings.h>
15
16
17
#include <inttypes.h>

#include "goom.h"
18
#include "goom_tools.h"
19
#include "goom_filters.h"
20
#include "lines.h"
21
22
#include "ifs.h"
#include "tentacle3d.h"
23

24
25
26
#include "sound_tester.h"
#include "goom_plugin_info.h"
#include "goom_fx.h"
27

28
/* #define VERBOSE */
29
30

#define STOP_SPEED 128
31
32
/* TODO: put that as variable in PluginInfo */
#define TIME_BTW_CHG 300
33

34
35
36
37
38
static void choose_a_goom_line (PluginInfo * goomInfo, float *param1,
    float *param2, int *couleur, int *mode, float *amplitude, int far);

static void
init_buffers (PluginInfo * goomInfo, int buffsize)
39
{
40
  goomInfo->pixel = (guint32 *) malloc (buffsize * sizeof (guint32) + 128);
41
  memset (goomInfo->pixel, 0, buffsize * sizeof (guint32) + 128);
42
  goomInfo->back = (guint32 *) malloc (buffsize * sizeof (guint32) + 128);
43
  memset (goomInfo->back, 0, buffsize * sizeof (guint32) + 128);
44
  goomInfo->conv = (Pixel *) malloc (buffsize * sizeof (guint32) + 128);
45
  memset (goomInfo->conv, 0, buffsize * sizeof (guint32) + 128);
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

  goomInfo->outputBuf = goomInfo->conv;

  goomInfo->p1 = (Pixel *) ((1 + ((uintptr_t) (goomInfo->pixel)) / 128) * 128);
  goomInfo->p2 = (Pixel *) ((1 + ((uintptr_t) (goomInfo->back)) / 128) * 128);
}

/**************************
*         INIT           *
**************************/
PluginInfo *
goom_init (guint32 resx, guint32 resy)
{
  PluginInfo *goomInfo = (PluginInfo *) malloc (sizeof (PluginInfo));

61
#ifdef VERBOSE
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
62
  printf ("GOOM: init (%d, %d);\n", resx, resy);
63
#endif
64
65
66

  plugin_info_init (goomInfo, 4);

67
68
69
70
71
72
73
74
75
  goomInfo->screen.width = resx;
  goomInfo->screen.height = resy;
  goomInfo->screen.size = resx * resy;

  init_buffers (goomInfo, goomInfo->screen.size);
  goomInfo->gRandom = goom_random_init ((uintptr_t) goomInfo->pixel);

  goomInfo->cycle = 0;

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  goomInfo->star_fx = flying_star_create ();
  goomInfo->star_fx.init (&goomInfo->star_fx, goomInfo);

  goomInfo->zoomFilter_fx = zoomFilterVisualFXWrapper_create ();
  goomInfo->zoomFilter_fx.init (&goomInfo->zoomFilter_fx, goomInfo);

  goomInfo->tentacles_fx = tentacle_fx_create ();
  goomInfo->tentacles_fx.init (&goomInfo->tentacles_fx, goomInfo);

  goomInfo->convolve_fx = convolve_create ();
  goomInfo->convolve_fx.init (&goomInfo->convolve_fx, goomInfo);

  plugin_info_add_visual (goomInfo, 0, &goomInfo->zoomFilter_fx);
  plugin_info_add_visual (goomInfo, 1, &goomInfo->tentacles_fx);
  plugin_info_add_visual (goomInfo, 2, &goomInfo->star_fx);
  plugin_info_add_visual (goomInfo, 3, &goomInfo->convolve_fx);

  goomInfo->ifs_fx = ifs_visualfx_create ();
  goomInfo->ifs_fx.init (&goomInfo->ifs_fx, goomInfo);

  goomInfo->gmline1 = goom_lines_init (goomInfo, resx, goomInfo->screen.height,
      GML_HLINE, goomInfo->screen.height, GML_BLACK,
      GML_CIRCLE, 0.4f * (float) goomInfo->screen.height, GML_VERT);
  goomInfo->gmline2 = goom_lines_init (goomInfo, resx, goomInfo->screen.height,
      GML_HLINE, 0, GML_BLACK,
      GML_CIRCLE, 0.2f * (float) goomInfo->screen.height, GML_RED);

  /* goom_set_main_script(goomInfo, goomInfo->main_script_str); */

  return goomInfo;
106
107
}

108
109


Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
110
void
111
goom_set_resolution (PluginInfo * goomInfo, guint32 resx, guint32 resy)
112
{
113
114
115
116
117
118
119
120
121
122
123
124
125
  free (goomInfo->pixel);
  free (goomInfo->back);
  free (goomInfo->conv);

  goomInfo->screen.width = resx;
  goomInfo->screen.height = resy;
  goomInfo->screen.size = resx * resy;

  init_buffers (goomInfo, goomInfo->screen.size);

  /* init_ifs (goomInfo, resx, goomInfo->screen.height); */
  goomInfo->ifs_fx.free (&goomInfo->ifs_fx);
  goomInfo->ifs_fx.init (&goomInfo->ifs_fx, goomInfo);
126

127
128
129
  goom_lines_set_res (goomInfo->gmline1, resx, goomInfo->screen.height);
  goom_lines_set_res (goomInfo->gmline2, resx, goomInfo->screen.height);
}
130

131
132
133
134
135
int
goom_set_screenbuffer (PluginInfo * goomInfo, void *buffer)
{
  goomInfo->outputBuf = (Pixel *) buffer;
  return 1;
136
137
}

138
139
140
141
142
143
/********************************************
*                  UPDATE                  *
********************************************

* WARNING: this is a 600 lines function ! (21-11-2003)
*/
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
144
guint32 *
145
146
goom_update (PluginInfo * goomInfo, gint16 data[2][512], int forceMode,
    float fps)
147
{
148
  Pixel *return_val;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
149
150
151
  guint32 pointWidth;
  guint32 pointHeight;
  int i;
152
  float largfactor;             /* elargissement de l'intervalle d'volution des points */
153
  Pixel *tmp;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
154

155
  ZoomFilterData *pzfd;
156

157
158
159
  /* test if the config has changed, update it if so */
  pointWidth = (goomInfo->screen.width * 2) / 5;
  pointHeight = ((goomInfo->screen.height) * 2) / 5;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
160
161

  /* ! etude du signal ... */
162
  evaluate_sound (data, &(goomInfo->sound));
163

164
  /* goom_execute_main_script(goomInfo); */
165
166

  /* ! calcul du deplacement des petits points ... */
167
  largfactor =
168
169
      goomInfo->sound.speedvar / 150.0f + goomInfo->sound.volume / 1.5f;

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
170
171
172
  if (largfactor > 1.5f)
    largfactor = 1.5f;

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  goomInfo->update.decay_ifs--;
  if (goomInfo->update.decay_ifs > 0)
    goomInfo->update.ifs_incr += 2;
  if (goomInfo->update.decay_ifs == 0)
    goomInfo->update.ifs_incr = 0;

  if (goomInfo->update.recay_ifs) {
    goomInfo->update.ifs_incr -= 2;
    goomInfo->update.recay_ifs--;
    if ((goomInfo->update.recay_ifs == 0) && (goomInfo->update.ifs_incr <= 0))
      goomInfo->update.ifs_incr = 1;
  }

  if (goomInfo->update.ifs_incr > 0)
    goomInfo->ifs_fx.apply (&goomInfo->ifs_fx, goomInfo->p2, goomInfo->p1,
        goomInfo);

  if (goomInfo->curGState->drawPoints) {
    for (i = 1; i * 15 <= goomInfo->sound.speedvar * 80.0f + 15; i++) {
      goomInfo->update.loopvar += goomInfo->sound.speedvar * 50 + 1;

      pointFilter (goomInfo, goomInfo->p1,
          YELLOW,
          ((pointWidth - 6.0f) * largfactor + 5.0f),
          ((pointHeight - 6.0f) * largfactor + 5.0f),
          i * 152.0f, 128.0f, goomInfo->update.loopvar + i * 2032);
      pointFilter (goomInfo, goomInfo->p1, ORANGE,
          ((pointWidth / 2) * largfactor) / i + 10.0f * i,
          ((pointHeight / 2) * largfactor) / i + 10.0f * i,
          96.0f, i * 80.0f, goomInfo->update.loopvar / i);
      pointFilter (goomInfo, goomInfo->p1, VIOLET,
          ((pointHeight / 3 + 5.0f) * largfactor) / i + 10.0f * i,
          ((pointHeight / 3 + 5.0f) * largfactor) / i + 10.0f * i,
          i + 122.0f, 134.0f, goomInfo->update.loopvar / i);
      pointFilter (goomInfo, goomInfo->p1, BLACK,
          ((pointHeight / 3) * largfactor + 20.0f),
          ((pointHeight / 3) * largfactor + 20.0f),
          58.0f, i * 66.0f, goomInfo->update.loopvar / i);
      pointFilter (goomInfo, goomInfo->p1, WHITE,
          (pointHeight * largfactor + 10.0f * i) / i,
          (pointHeight * largfactor + 10.0f * i) / i,
          66.0f, 74.0f, goomInfo->update.loopvar + i * 500);
    }
  }

  /* par dfaut pas de changement de zoom */
  pzfd = NULL;

  /* 
   * Test forceMode
   */
#ifdef VERBOSE
  if (forceMode != 0) {
    printf ("forcemode = %d\n", forceMode);
227
  }
228
229
#endif

230

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
231
232
  /* diminuer de 1 le temps de lockage */
  /* note pour ceux qui n'ont pas suivis : le lockvar permet d'empecher un */
233
234
235
  /* changement d'etat du plugin juste apres un autre changement d'etat. oki */
  if (--goomInfo->update.lockvar < 0)
    goomInfo->update.lockvar = 0;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
236
237

  /* on verifie qu'il ne se pas un truc interressant avec le son. */
238
239
240
  if ((goomInfo->sound.timeSinceLastGoom == 0)
      || (forceMode > 0)
      || (goomInfo->update.cyclesSinceLastChange > TIME_BTW_CHG)) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
241
242

    /* changement eventuel de mode */
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
    if (goom_irand (goomInfo->gRandom, 16) == 0)
      switch (goom_irand (goomInfo->gRandom, 34)) {
        case 0:
        case 10:
          goomInfo->update.zoomFilterData.hypercosEffect =
              goom_irand (goomInfo->gRandom, 2);
        case 13:
        case 20:
        case 21:
          goomInfo->update.zoomFilterData.mode = WAVE_MODE;
          goomInfo->update.zoomFilterData.reverse = 0;
          goomInfo->update.zoomFilterData.waveEffect =
              (goom_irand (goomInfo->gRandom, 3) == 0);
          if (goom_irand (goomInfo->gRandom, 2))
            goomInfo->update.zoomFilterData.vitesse =
                (goomInfo->update.zoomFilterData.vitesse + 127) >> 1;
          break;
        case 1:
        case 11:
          goomInfo->update.zoomFilterData.mode = CRYSTAL_BALL_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 0;
          goomInfo->update.zoomFilterData.hypercosEffect = 0;
          break;
        case 2:
        case 12:
          goomInfo->update.zoomFilterData.mode = AMULETTE_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 0;
          goomInfo->update.zoomFilterData.hypercosEffect = 0;
          break;
        case 3:
          goomInfo->update.zoomFilterData.mode = WATER_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 0;
          goomInfo->update.zoomFilterData.hypercosEffect = 0;
          break;
        case 4:
        case 14:
          goomInfo->update.zoomFilterData.mode = SCRUNCH_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 0;
          goomInfo->update.zoomFilterData.hypercosEffect = 0;
          break;
        case 5:
        case 15:
        case 22:
          goomInfo->update.zoomFilterData.mode = HYPERCOS1_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 0;
          goomInfo->update.zoomFilterData.hypercosEffect =
              (goom_irand (goomInfo->gRandom, 3) == 0);
          break;
        case 6:
        case 16:
          goomInfo->update.zoomFilterData.mode = HYPERCOS2_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 0;
          goomInfo->update.zoomFilterData.hypercosEffect = 0;
          break;
        case 7:
        case 17:
          goomInfo->update.zoomFilterData.mode = CRYSTAL_BALL_MODE;
          goomInfo->update.zoomFilterData.waveEffect =
              (goom_irand (goomInfo->gRandom, 4) == 0);
          goomInfo->update.zoomFilterData.hypercosEffect =
              goom_irand (goomInfo->gRandom, 2);
          break;
        case 8:
        case 18:
        case 19:
          goomInfo->update.zoomFilterData.mode = SCRUNCH_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 1;
          goomInfo->update.zoomFilterData.hypercosEffect = 1;
          break;
        case 29:
        case 30:
          goomInfo->update.zoomFilterData.mode = YONLY_MODE;
          break;
        case 31:
        case 32:
        case 33:
          goomInfo->update.zoomFilterData.mode = SPEEDWAY_MODE;
          break;
        default:
          goomInfo->update.zoomFilterData.mode = NORMAL_MODE;
          goomInfo->update.zoomFilterData.waveEffect = 0;
          goomInfo->update.zoomFilterData.hypercosEffect = 0;
      }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
326
  }
327

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
328
  /* tout ceci ne sera fait qu'en cas de non-blocage */
329
  if (goomInfo->update.lockvar == 0) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
330
331
    /* reperage de goom (acceleration forte de l'acceleration du volume) */
    /* -> coup de boost de la vitesse si besoin.. */
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
    if (goomInfo->sound.timeSinceLastGoom == 0) {

      int i;

      goomInfo->update.goomvar++;

      /* SELECTION OF THE GOOM STATE */
      if ((!goomInfo->update.stateSelectionBlocker)
          && (goom_irand (goomInfo->gRandom, 3))) {
        goomInfo->update.stateSelectionRnd =
            goom_irand (goomInfo->gRandom, goomInfo->statesRangeMax);
        goomInfo->update.stateSelectionBlocker = 3;
      } else if (goomInfo->update.stateSelectionBlocker)
        goomInfo->update.stateSelectionBlocker--;

      for (i = 0; i < goomInfo->statesNumber; i++)
        if ((goomInfo->update.stateSelectionRnd >= goomInfo->states[i].rangemin)
            && (goomInfo->update.stateSelectionRnd <=
                goomInfo->states[i].rangemax))
          goomInfo->curGState = &(goomInfo->states[i]);

      if ((goomInfo->curGState->drawIFS) && (goomInfo->update.ifs_incr <= 0)) {
        goomInfo->update.recay_ifs = 5;
        goomInfo->update.ifs_incr = 11;
      }

      if ((!goomInfo->curGState->drawIFS) && (goomInfo->update.ifs_incr > 0)
          && (goomInfo->update.decay_ifs <= 0))
        goomInfo->update.decay_ifs = 100;

      if (!goomInfo->curGState->drawScope)
        goomInfo->update.stop_lines = 0xf000 & 5;

      if (!goomInfo->curGState->drawScope) {
        goomInfo->update.stop_lines = 0;
        goomInfo->update.lineMode = goomInfo->update.drawLinesDuration;
      }

      /* if (goomInfo->update.goomvar % 1 == 0) */
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
371
      {
372
373
374
        guint32 vtmp;
        guint32 newvit;

375
376
377
378
        goomInfo->update.lockvar = 50;
        newvit =
            STOP_SPEED + 1 -
            ((float) 3.5f * log10 (goomInfo->sound.speedvar * 60 + 1));
379
        /* retablir le zoom avant.. */
380
381
382
383
384
        if ((goomInfo->update.zoomFilterData.reverse)
            && (!(goomInfo->cycle % 13)) && (rand () % 5 == 0)) {
          goomInfo->update.zoomFilterData.reverse = 0;
          goomInfo->update.zoomFilterData.vitesse = STOP_SPEED - 2;
          goomInfo->update.lockvar = 75;
385
        }
386
387
388
        if (goom_irand (goomInfo->gRandom, 10) == 0) {
          goomInfo->update.zoomFilterData.reverse = 1;
          goomInfo->update.lockvar = 100;
389
390
        }

391
392
393
394
395
        if (goom_irand (goomInfo->gRandom, 10) == 0)
          goomInfo->update.zoomFilterData.vitesse = STOP_SPEED - 1;
        if (goom_irand (goomInfo->gRandom, 12) == 0)
          goomInfo->update.zoomFilterData.vitesse = STOP_SPEED + 1;

396
        /* changement de milieu.. */
397
        switch (goom_irand (goomInfo->gRandom, 25)) {
398
          case 0:
399
400
401
402
403
404
          case 3:
          case 6:
            goomInfo->update.zoomFilterData.middleY =
                goomInfo->screen.height - 1;
            goomInfo->update.zoomFilterData.middleX =
                goomInfo->screen.width / 2;
405
406
            break;
          case 1:
407
408
409
          case 4:
            goomInfo->update.zoomFilterData.middleX =
                goomInfo->screen.width - 1;
410
411
            break;
          case 2:
412
413
          case 5:
            goomInfo->update.zoomFilterData.middleX = 1;
414
415
            break;
          default:
416
417
418
419
            goomInfo->update.zoomFilterData.middleY =
                goomInfo->screen.height / 2;
            goomInfo->update.zoomFilterData.middleX =
                goomInfo->screen.width / 2;
420
421
        }

422
423
424
425
426
        if ((goomInfo->update.zoomFilterData.mode == WATER_MODE)
            || (goomInfo->update.zoomFilterData.mode == YONLY_MODE)
            || (goomInfo->update.zoomFilterData.mode == AMULETTE_MODE)) {
          goomInfo->update.zoomFilterData.middleX = goomInfo->screen.width / 2;
          goomInfo->update.zoomFilterData.middleY = goomInfo->screen.height / 2;
427
428
        }

429
        switch (vtmp = (goom_irand (goomInfo->gRandom, 15))) {
430
          case 0:
431
432
433
434
435
436
            goomInfo->update.zoomFilterData.vPlaneEffect =
                goom_irand (goomInfo->gRandom, 3)
                - goom_irand (goomInfo->gRandom, 3);
            goomInfo->update.zoomFilterData.hPlaneEffect =
                goom_irand (goomInfo->gRandom, 3)
                - goom_irand (goomInfo->gRandom, 3);
437
438
            break;
          case 3:
439
440
441
442
            goomInfo->update.zoomFilterData.vPlaneEffect = 0;
            goomInfo->update.zoomFilterData.hPlaneEffect =
                goom_irand (goomInfo->gRandom, 8)
                - goom_irand (goomInfo->gRandom, 8);
443
444
445
446
447
            break;
          case 4:
          case 5:
          case 6:
          case 7:
448
449
450
451
452
            goomInfo->update.zoomFilterData.vPlaneEffect =
                goom_irand (goomInfo->gRandom, 5)
                - goom_irand (goomInfo->gRandom, 5);
            goomInfo->update.zoomFilterData.hPlaneEffect =
                -goomInfo->update.zoomFilterData.vPlaneEffect;
453
454
            break;
          case 8:
455
456
457
458
            goomInfo->update.zoomFilterData.hPlaneEffect =
                5 + goom_irand (goomInfo->gRandom, 8);
            goomInfo->update.zoomFilterData.vPlaneEffect =
                -goomInfo->update.zoomFilterData.hPlaneEffect;
459
460
            break;
          case 9:
461
462
463
464
            goomInfo->update.zoomFilterData.vPlaneEffect =
                5 + goom_irand (goomInfo->gRandom, 8);
            goomInfo->update.zoomFilterData.hPlaneEffect =
                -goomInfo->update.zoomFilterData.hPlaneEffect;
465
466
            break;
          case 13:
467
468
469
470
471
472
473
474
475
476
477
478
            goomInfo->update.zoomFilterData.hPlaneEffect = 0;
            goomInfo->update.zoomFilterData.vPlaneEffect =
                goom_irand (goomInfo->gRandom, 10)
                - goom_irand (goomInfo->gRandom, 10);
            break;
          case 14:
            goomInfo->update.zoomFilterData.hPlaneEffect =
                goom_irand (goomInfo->gRandom, 10)
                - goom_irand (goomInfo->gRandom, 10);
            goomInfo->update.zoomFilterData.vPlaneEffect =
                goom_irand (goomInfo->gRandom, 10)
                - goom_irand (goomInfo->gRandom, 10);
479
480
481
            break;
          default:
            if (vtmp < 10) {
482
483
              goomInfo->update.zoomFilterData.vPlaneEffect = 0;
              goomInfo->update.zoomFilterData.hPlaneEffect = 0;
484
485
486
            }
        }

487
488
        if (goom_irand (goomInfo->gRandom, 5) != 0)
          goomInfo->update.zoomFilterData.noisify = 0;
489
        else {
490
491
492
          goomInfo->update.zoomFilterData.noisify =
              goom_irand (goomInfo->gRandom, 2) + 1;
          goomInfo->update.lockvar *= 2;
493
494
        }

495
496
497
498
        if (goomInfo->update.zoomFilterData.mode == AMULETTE_MODE) {
          goomInfo->update.zoomFilterData.vPlaneEffect = 0;
          goomInfo->update.zoomFilterData.hPlaneEffect = 0;
          goomInfo->update.zoomFilterData.noisify = 0;
499
500
        }

501
502
503
504
505
506
        if ((goomInfo->update.zoomFilterData.middleX == 1)
            || (goomInfo->update.zoomFilterData.middleX ==
                (signed int) goomInfo->screen.width - 1)) {
          goomInfo->update.zoomFilterData.vPlaneEffect = 0;
          if (goom_irand (goomInfo->gRandom, 2))
            goomInfo->update.zoomFilterData.hPlaneEffect = 0;
507
508
        }

509
510
        if ((signed int) newvit < goomInfo->update.zoomFilterData.vitesse) {    /* on accelere */
          pzfd = &goomInfo->update.zoomFilterData;
511
          if (((newvit < STOP_SPEED - 7) &&
512
513
514
515
516
517
518
519
                  (goomInfo->update.zoomFilterData.vitesse < STOP_SPEED - 6) &&
                  (goomInfo->cycle % 3 == 0))
              || (goom_irand (goomInfo->gRandom, 40) == 0)) {
            goomInfo->update.zoomFilterData.vitesse =
                STOP_SPEED - goom_irand (goomInfo->gRandom, 2)
                + goom_irand (goomInfo->gRandom, 2);
            goomInfo->update.zoomFilterData.reverse =
                !goomInfo->update.zoomFilterData.reverse;
520
          } else {
521
522
            goomInfo->update.zoomFilterData.vitesse =
                (newvit + goomInfo->update.zoomFilterData.vitesse * 7) / 8;
523
          }
524
          goomInfo->update.lockvar += 50;
525
        }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
526
      }
527
528
529
530
531

      if (goomInfo->update.lockvar > 150) {
        goomInfo->update.switchIncr = goomInfo->update.switchIncrAmount;
        goomInfo->update.switchMult = 1.0f;
      }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
532
533
    }
    /* mode mega-lent */
534
    if (goom_irand (goomInfo->gRandom, 700) == 0) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
535
      /* 
536
       * printf ("coup du sort...\n") ;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
537
       */
538
539
540
541
542
543
544
545
      pzfd = &goomInfo->update.zoomFilterData;
      goomInfo->update.zoomFilterData.vitesse = STOP_SPEED - 1;
      goomInfo->update.zoomFilterData.pertedec = 8;
      goomInfo->update.zoomFilterData.sqrtperte = 16;
      goomInfo->update.goomvar = 1;
      goomInfo->update.lockvar += 50;
      goomInfo->update.switchIncr = goomInfo->update.switchIncrAmount;
      goomInfo->update.switchMult = 1.0f;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
546
547
548
    }
  }

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
  /*
   * gros frein si la musique est calme
   */
  if ((goomInfo->sound.speedvar < 0.01f)
      && (goomInfo->update.zoomFilterData.vitesse < STOP_SPEED - 4)
      && (goomInfo->cycle % 16 == 0)) {
    pzfd = &goomInfo->update.zoomFilterData;
    goomInfo->update.zoomFilterData.vitesse += 3;
    goomInfo->update.zoomFilterData.pertedec = 8;
    goomInfo->update.zoomFilterData.sqrtperte = 16;
    goomInfo->update.goomvar = 0;
  }

  /*
   * baisser regulierement la vitesse...
   */
  if ((goomInfo->cycle % 73 == 0)
      && (goomInfo->update.zoomFilterData.vitesse < STOP_SPEED - 5)) {
    pzfd = &goomInfo->update.zoomFilterData;
    goomInfo->update.zoomFilterData.vitesse++;
  }

  /*
   * arreter de decrmenter au bout d'un certain temps
   */
  if ((goomInfo->cycle % 101 == 0)
      && (goomInfo->update.zoomFilterData.pertedec == 7)) {
    pzfd = &goomInfo->update.zoomFilterData;
    goomInfo->update.zoomFilterData.pertedec = 8;
    goomInfo->update.zoomFilterData.sqrtperte = 16;
  }

  /*
   * Permet de forcer un effet.
   */
  if ((forceMode > 0) && (forceMode <= NB_FX)) {
    pzfd = &goomInfo->update.zoomFilterData;
    pzfd->mode = forceMode - 1;
  }

  if (forceMode == -1) {
    pzfd = NULL;
  }

  /*
   * Changement d'effet de zoom !
   */
  if (pzfd != NULL) {
    int dif;

    goomInfo->update.cyclesSinceLastChange = 0;

    goomInfo->update.switchIncr = goomInfo->update.switchIncrAmount;

    dif =
        goomInfo->update.zoomFilterData.vitesse -
        goomInfo->update.previousZoomSpeed;
    if (dif < 0)
      dif = -dif;

    if (dif > 2) {
      goomInfo->update.switchIncr *= (dif + 2) / 2;
    }
    goomInfo->update.previousZoomSpeed =
        goomInfo->update.zoomFilterData.vitesse;
    goomInfo->update.switchMult = 1.0f;

    if (((goomInfo->sound.timeSinceLastGoom == 0)
            && (goomInfo->sound.totalgoom < 2)) || (forceMode > 0)) {
      goomInfo->update.switchIncr = 0;
      goomInfo->update.switchMult = goomInfo->update.switchMultAmount;
    }
  } else {
    if (goomInfo->update.cyclesSinceLastChange > TIME_BTW_CHG) {
      pzfd = &goomInfo->update.zoomFilterData;
      goomInfo->update.cyclesSinceLastChange = 0;
    } else
      goomInfo->update.cyclesSinceLastChange++;
  }

#ifdef VERBOSE
  if (pzfd) {
    printf ("GOOM: pzfd->mode = %d\n", pzfd->mode);
  }
#endif

  /* Zoom here ! */
  zoomFilterFastRGB (goomInfo, goomInfo->p1, goomInfo->p2, pzfd,
      goomInfo->screen.width, goomInfo->screen.height,
      goomInfo->update.switchIncr, goomInfo->update.switchMult);

  /*
   * Affichage tentacule
   */

  goomInfo->tentacles_fx.apply (&goomInfo->tentacles_fx, goomInfo->p1,
      goomInfo->p2, goomInfo);
  goomInfo->star_fx.apply (&goomInfo->star_fx, goomInfo->p2, goomInfo->p1,
      goomInfo);

  /*
   * Gestion du Scope
   */

  /*
   * arret demande
   */
  if ((goomInfo->update.stop_lines & 0xf000)
      || (!goomInfo->curGState->drawScope)) {
    float param1, param2, amplitude;
    int couleur;
    int mode;

    choose_a_goom_line (goomInfo, &param1, &param2, &couleur, &mode, &amplitude,
        1);
    couleur = GML_BLACK;

    goom_lines_switch_to (goomInfo->gmline1, mode, param1, amplitude, couleur);
    goom_lines_switch_to (goomInfo->gmline2, mode, param2, amplitude, couleur);
    goomInfo->update.stop_lines &= 0x0fff;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
669
  }
670

671
672
673
674
675
676
677
  /*
   * arret aleatore.. changement de mode de ligne..
   */
  if (goomInfo->update.lineMode != goomInfo->update.drawLinesDuration) {
    goomInfo->update.lineMode--;
    if (goomInfo->update.lineMode == -1)
      goomInfo->update.lineMode = 0;
678
  } else if ((goomInfo->cycle % 80 == 0)
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
      && (goom_irand (goomInfo->gRandom, 5) == 0) && goomInfo->update.lineMode)
    goomInfo->update.lineMode--;

  if ((goomInfo->cycle % 120 == 0)
      && (goom_irand (goomInfo->gRandom, 4) == 0)
      && (goomInfo->curGState->drawScope)) {
    if (goomInfo->update.lineMode == 0)
      goomInfo->update.lineMode = goomInfo->update.drawLinesDuration;
    else if (goomInfo->update.lineMode == goomInfo->update.drawLinesDuration) {
      float param1, param2, amplitude;
      int couleur1, couleur2;
      int mode;

      goomInfo->update.lineMode--;
      choose_a_goom_line (goomInfo, &param1, &param2, &couleur1,
          &mode, &amplitude, goomInfo->update.stop_lines);

      couleur2 = 5 - couleur1;
      if (goomInfo->update.stop_lines) {
        goomInfo->update.stop_lines--;
        if (goom_irand (goomInfo->gRandom, 2))
          couleur2 = couleur1 = GML_BLACK;
      }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
702

703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
      goom_lines_switch_to (goomInfo->gmline1, mode, param1, amplitude,
          couleur1);
      goom_lines_switch_to (goomInfo->gmline2, mode, param2, amplitude,
          couleur2);
    }
  }

  /*
   * si on est dans un goom : afficher les lignes...
   */
  if ((goomInfo->update.lineMode != 0)
      || (goomInfo->sound.timeSinceLastGoom < 5)) {
    goomInfo->gmline2->power = goomInfo->gmline1->power;

    goom_lines_draw (goomInfo, goomInfo->gmline1, data[0], goomInfo->p2);
    goom_lines_draw (goomInfo, goomInfo->gmline2, data[1], goomInfo->p2);

    if (((goomInfo->cycle % 121) == 9)
        && (goom_irand (goomInfo->gRandom, 3) == 1)
        && ((goomInfo->update.lineMode == 0)
            || (goomInfo->update.lineMode ==
                goomInfo->update.drawLinesDuration))) {
      float param1, param2, amplitude;
      int couleur1, couleur2;
      int mode;

      choose_a_goom_line (goomInfo, &param1, &param2, &couleur1,
          &mode, &amplitude, goomInfo->update.stop_lines);
      couleur2 = 5 - couleur1;

      if (goomInfo->update.stop_lines) {
        goomInfo->update.stop_lines--;
        if (goom_irand (goomInfo->gRandom, 2))
          couleur2 = couleur1 = GML_BLACK;
      }
      goom_lines_switch_to (goomInfo->gmline1, mode, param1, amplitude,
          couleur1);
      goom_lines_switch_to (goomInfo->gmline2, mode, param2, amplitude,
          couleur2);
    }
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
744

745
746
747
748
  return_val = goomInfo->p1;
  tmp = goomInfo->p1;
  goomInfo->p1 = goomInfo->p2;
  goomInfo->p2 = tmp;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
749
750

  /* affichage et swappage des buffers.. */
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
  goomInfo->cycle++;

  goomInfo->convolve_fx.apply (&goomInfo->convolve_fx, return_val,
      goomInfo->outputBuf, goomInfo);

  return (guint32 *) goomInfo->outputBuf;
}

/****************************************
*                CLOSE                 *
****************************************/
void
goom_close (PluginInfo * goomInfo)
{
  if (goomInfo->pixel != NULL)
    free (goomInfo->pixel);
  if (goomInfo->back != NULL)
    free (goomInfo->back);
  if (goomInfo->conv != NULL)
    free (goomInfo->conv);

  goomInfo->pixel = goomInfo->back = NULL;
  goomInfo->conv = NULL;
  goom_random_free (goomInfo->gRandom);
  goom_lines_free (&goomInfo->gmline1);
  goom_lines_free (&goomInfo->gmline2);

  /* release_ifs (); */
  goomInfo->ifs_fx.free (&goomInfo->ifs_fx);
  goomInfo->convolve_fx.free (&goomInfo->convolve_fx);
  goomInfo->star_fx.free (&goomInfo->star_fx);
  goomInfo->tentacles_fx.free (&goomInfo->tentacles_fx);
  goomInfo->zoomFilter_fx.free (&goomInfo->zoomFilter_fx);

785
  plugin_info_free (goomInfo);
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
  free (goomInfo);
}


/* *** */
void
choose_a_goom_line (PluginInfo * goomInfo, float *param1, float *param2,
    int *couleur, int *mode, float *amplitude, int far)
{
  *mode = goom_irand (goomInfo->gRandom, 3);
  *amplitude = 1.0f;
  switch (*mode) {
    case GML_CIRCLE:
      if (far) {
        *param1 = *param2 = 0.47f;
        *amplitude = 0.8f;
        break;
      }
      if (goom_irand (goomInfo->gRandom, 3) == 0) {
        *param1 = *param2 = 0;
        *amplitude = 3.0f;
      } else if (goom_irand (goomInfo->gRandom, 2)) {
        *param1 = 0.40f * goomInfo->screen.height;
        *param2 = 0.22f * goomInfo->screen.height;
      } else {
        *param1 = *param2 = goomInfo->screen.height * 0.35;
      }
      break;
    case GML_HLINE:
      if (goom_irand (goomInfo->gRandom, 4) || far) {
        *param1 = goomInfo->screen.height / 7;
        *param2 = 6.0f * goomInfo->screen.height / 7.0f;
      } else {
        *param1 = *param2 = goomInfo->screen.height / 2.0f;
        *amplitude = 2.0f;
      }
      break;
    case GML_VLINE:
      if (goom_irand (goomInfo->gRandom, 3) || far) {
        *param1 = goomInfo->screen.width / 7.0f;
        *param2 = 6.0f * goomInfo->screen.width / 7.0f;
      } else {
        *param1 = *param2 = goomInfo->screen.width / 2.0f;
        *amplitude = 1.5f;
      }
      break;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
832
  }
833
834

  *couleur = goom_irand (goomInfo->gRandom, 6);
835
}