goom_core.c 28.2 KB
Newer Older
1 2
/* Goom Project
 * Copyright (C) <2003> Jean-Christophe Hoelt <jeko@free.fr>
3
 *
4
 * goom_core.c:Contains the core of goom's work.
5
 *
6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
20 21
 */

22 23 24 25
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

26 27
#include <math.h>
#include <stdio.h>
28 29
#include <stdlib.h>
#include <string.h>
30 31

#ifdef HAVE_INTTYPES_H
32
#include <inttypes.h>
33
#endif
34 35

#include "goom.h"
36
#include "goom_tools.h"
37
#include "goom_filters.h"
38
#include "lines.h"
39 40
#include "ifs.h"
#include "tentacle3d.h"
41

42 43 44
#include "sound_tester.h"
#include "goom_plugin_info.h"
#include "goom_fx.h"
45

46
/* #define VERBOSE */
47 48

#define STOP_SPEED 128
49 50
/* TODO: put that as variable in PluginInfo */
#define TIME_BTW_CHG 300
51

52 53 54 55 56
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)
57
{
58
  goomInfo->pixel = (guint32 *) malloc (buffsize * sizeof (guint32) + 128);
59
  memset (goomInfo->pixel, 0, buffsize * sizeof (guint32) + 128);
60
  goomInfo->back = (guint32 *) malloc (buffsize * sizeof (guint32) + 128);
61
  memset (goomInfo->back, 0, buffsize * sizeof (guint32) + 128);
62
  goomInfo->conv = (Pixel *) malloc (buffsize * sizeof (guint32) + 128);
63
  memset (goomInfo->conv, 0, buffsize * sizeof (guint32) + 128);
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

  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));

79
#ifdef VERBOSE
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
80
  printf ("GOOM: init (%d, %d);\n", resx, resy);
81
#endif
82 83 84

  plugin_info_init (goomInfo, 4);

85 86 87 88 89 90 91 92 93
  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;

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
  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;
124 125
}

126 127


Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
128
void
129
goom_set_resolution (PluginInfo * goomInfo, guint32 resx, guint32 resy)
130
{
131 132 133 134 135 136 137 138 139 140 141 142 143
  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);
144

145 146 147
  goom_lines_set_res (goomInfo->gmline1, resx, goomInfo->screen.height);
  goom_lines_set_res (goomInfo->gmline2, resx, goomInfo->screen.height);
}
148

149 150 151 152 153
int
goom_set_screenbuffer (PluginInfo * goomInfo, void *buffer)
{
  goomInfo->outputBuf = (Pixel *) buffer;
  return 1;
154 155
}

156 157 158 159 160 161
/********************************************
*                  UPDATE                  *
********************************************

* WARNING: this is a 600 lines function ! (21-11-2003)
*/
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
162
guint32 *
163 164
goom_update (PluginInfo * goomInfo, gint16 data[2][512], int forceMode,
    float fps)
165
{
166
  Pixel *return_val;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
167 168 169
  guint32 pointWidth;
  guint32 pointHeight;
  int i;
170
  float largfactor;             /* elargissement de l'intervalle d'�volution des points */
171
  Pixel *tmp;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
172

173
  ZoomFilterData *pzfd;
174

175 176 177
  /* 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
178 179

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

182
  /* goom_execute_main_script(goomInfo); */
183 184

  /* ! calcul du deplacement des petits points ... */
185
  largfactor =
186 187
      goomInfo->sound.speedvar / 150.0f + goomInfo->sound.volume / 1.5f;

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
188 189 190
  if (largfactor > 1.5f)
    largfactor = 1.5f;

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 227 228 229 230 231 232 233 234 235
  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);
    }
  }

236
  /* par d�faut pas de changement de zoom */
237 238 239 240 241 242 243 244
  pzfd = NULL;

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

248

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
249 250
  /* diminuer de 1 le temps de lockage */
  /* note pour ceux qui n'ont pas suivis : le lockvar permet d'empecher un */
251 252 253
  /* 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
254 255

  /* on verifie qu'il ne se pas un truc interressant avec le son. */
256 257 258
  if ((goomInfo->sound.timeSinceLastGoom == 0)
      || (forceMode > 0)
      || (goomInfo->update.cyclesSinceLastChange > TIME_BTW_CHG)) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
259 260

    /* changement eventuel de mode */
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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    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
344
  }
345

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
346
  /* tout ceci ne sera fait qu'en cas de non-blocage */
347
  if (goomInfo->update.lockvar == 0) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
348 349
    /* reperage de goom (acceleration forte de l'acceleration du volume) */
    /* -> coup de boost de la vitesse si besoin.. */
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
    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
389
      {
390 391 392
        guint32 vtmp;
        guint32 newvit;

393 394 395 396
        goomInfo->update.lockvar = 50;
        newvit =
            STOP_SPEED + 1 -
            ((float) 3.5f * log10 (goomInfo->sound.speedvar * 60 + 1));
397
        /* retablir le zoom avant.. */
398 399 400 401 402
        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;
403
        }
404 405 406
        if (goom_irand (goomInfo->gRandom, 10) == 0) {
          goomInfo->update.zoomFilterData.reverse = 1;
          goomInfo->update.lockvar = 100;
407 408
        }

409 410 411 412 413
        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;

414
        /* changement de milieu.. */
415
        switch (goom_irand (goomInfo->gRandom, 25)) {
416
          case 0:
417 418 419 420 421 422
          case 3:
          case 6:
            goomInfo->update.zoomFilterData.middleY =
                goomInfo->screen.height - 1;
            goomInfo->update.zoomFilterData.middleX =
                goomInfo->screen.width / 2;
423 424
            break;
          case 1:
425 426 427
          case 4:
            goomInfo->update.zoomFilterData.middleX =
                goomInfo->screen.width - 1;
428 429
            break;
          case 2:
430 431
          case 5:
            goomInfo->update.zoomFilterData.middleX = 1;
432 433
            break;
          default:
434 435 436 437
            goomInfo->update.zoomFilterData.middleY =
                goomInfo->screen.height / 2;
            goomInfo->update.zoomFilterData.middleX =
                goomInfo->screen.width / 2;
438 439
        }

440 441 442 443 444
        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;
445 446
        }

447
        switch (vtmp = (goom_irand (goomInfo->gRandom, 15))) {
448
          case 0:
449 450 451 452 453 454
            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);
455 456
            break;
          case 3:
457 458 459 460
            goomInfo->update.zoomFilterData.vPlaneEffect = 0;
            goomInfo->update.zoomFilterData.hPlaneEffect =
                goom_irand (goomInfo->gRandom, 8)
                - goom_irand (goomInfo->gRandom, 8);
461 462 463 464 465
            break;
          case 4:
          case 5:
          case 6:
          case 7:
466 467 468 469 470
            goomInfo->update.zoomFilterData.vPlaneEffect =
                goom_irand (goomInfo->gRandom, 5)
                - goom_irand (goomInfo->gRandom, 5);
            goomInfo->update.zoomFilterData.hPlaneEffect =
                -goomInfo->update.zoomFilterData.vPlaneEffect;
471 472
            break;
          case 8:
473 474 475 476
            goomInfo->update.zoomFilterData.hPlaneEffect =
                5 + goom_irand (goomInfo->gRandom, 8);
            goomInfo->update.zoomFilterData.vPlaneEffect =
                -goomInfo->update.zoomFilterData.hPlaneEffect;
477 478
            break;
          case 9:
479 480 481 482
            goomInfo->update.zoomFilterData.vPlaneEffect =
                5 + goom_irand (goomInfo->gRandom, 8);
            goomInfo->update.zoomFilterData.hPlaneEffect =
                -goomInfo->update.zoomFilterData.hPlaneEffect;
483 484
            break;
          case 13:
485 486 487 488 489 490 491 492 493 494 495 496
            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);
497 498 499
            break;
          default:
            if (vtmp < 10) {
500 501
              goomInfo->update.zoomFilterData.vPlaneEffect = 0;
              goomInfo->update.zoomFilterData.hPlaneEffect = 0;
502 503 504
            }
        }

505 506
        if (goom_irand (goomInfo->gRandom, 5) != 0)
          goomInfo->update.zoomFilterData.noisify = 0;
507
        else {
508 509 510
          goomInfo->update.zoomFilterData.noisify =
              goom_irand (goomInfo->gRandom, 2) + 1;
          goomInfo->update.lockvar *= 2;
511 512
        }

513 514 515 516
        if (goomInfo->update.zoomFilterData.mode == AMULETTE_MODE) {
          goomInfo->update.zoomFilterData.vPlaneEffect = 0;
          goomInfo->update.zoomFilterData.hPlaneEffect = 0;
          goomInfo->update.zoomFilterData.noisify = 0;
517 518
        }

519 520 521 522 523 524
        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;
525 526
        }

527 528
        if ((signed int) newvit < goomInfo->update.zoomFilterData.vitesse) {    /* on accelere */
          pzfd = &goomInfo->update.zoomFilterData;
529
          if (((newvit < STOP_SPEED - 7) &&
530 531 532 533 534 535 536 537
                  (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;
538
          } else {
539 540
            goomInfo->update.zoomFilterData.vitesse =
                (newvit + goomInfo->update.zoomFilterData.vitesse * 7) / 8;
541
          }
542
          goomInfo->update.lockvar += 50;
543
        }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
544
      }
545 546 547 548 549

      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
550 551
    }
    /* mode mega-lent */
552
    if (goom_irand (goomInfo->gRandom, 700) == 0) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
553
      /* 
554
       * printf ("coup du sort...\n") ;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
555
       */
556 557 558 559 560 561 562 563
      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
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
  /*
   * 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++;
  }

  /*
590
   * arreter de decr�menter au bout d'un certain temps
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 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
   */
  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
687
  }
688

689 690 691 692 693 694 695
  /*
   * 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;
696
  } else if ((goomInfo->cycle % 80 == 0)
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
      && (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
720

721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
      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
762

763 764 765 766
  return_val = goomInfo->p1;
  tmp = goomInfo->p1;
  goomInfo->p1 = goomInfo->p2;
  goomInfo->p2 = tmp;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
767 768

  /* affichage et swappage des buffers.. */
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
  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);

803
  plugin_info_free (goomInfo);
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 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
  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
850
  }
851 852

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