home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / MandelVroom / src / tasks.c < prev   
C/C++ Source or Header  |  1989-05-30  |  4KB  |  226 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file contains functions used to manage tasks used by
  25.  * MandelVroom for picture generation and picture recoloring.
  26.  */
  27.  
  28. #include "mandp.h"
  29.  
  30. LONG MainPri =  0;
  31. LONG TaskPri = -1;
  32.  
  33. LONG pSigMask, pSigBit;
  34.  
  35. PauseChild( Pict )
  36.   register struct Picture *Pict;
  37. {
  38.   if (Pict->gTask) {
  39.  
  40.     if (Pict->GenState == GENERATESTATE) {
  41.  
  42.       SetTaskPri( Pict->gTask, MainPri );
  43.  
  44.       Pict->GenState = PAUSESTATE;
  45.  
  46.       Wait( pSigMask );
  47.  
  48.       SetTaskPri( Pict->gTask, TaskPri );
  49.     }
  50.   }
  51. }
  52.  
  53. ChildSignal( Pict )
  54.   register struct Picture *Pict;
  55. {
  56. #ifdef MULTI
  57.   if ( Pict->GenState == PAUSESTATE ) {
  58.     Signal( mTask, pSigMask );
  59.     Wait( Pict->gSigMask );
  60.   }
  61. #endif
  62. }
  63.  
  64. AwakenChild( Pict )
  65.   register struct Picture *Pict;
  66. {
  67.   if (Pict->gTask) {
  68.     if (Pict->GenState == PAUSESTATE) {
  69.  
  70.       Pict->GenState = GENERATESTATE;
  71.  
  72.       Signal( Pict->gTask, Pict->gSigMask );
  73.  
  74.       if (Pict->gTask->tc_State == TS_WAIT) {
  75.         printf("Child still waiting\n");
  76.       }
  77.     }
  78.   }
  79. }
  80.  
  81. CheckEOL( Pict )
  82.   register struct Picture *Pict;
  83. {
  84.   ChildPause( Pict );
  85.  
  86.   ReColorLine( Pict );
  87.  
  88.   Pict->CurLine++;
  89. }
  90.  
  91. KillDoneChild( Pict )
  92.   register struct Picture *Pict;
  93. {
  94.   if (Pict->gTask) {
  95.  
  96.     SetTaskPri( Pict->gTask, MainPri );
  97.  
  98.     Pict->GenState = KILLSTATE;   /* Child is spinning waiting for this */
  99.     Wait( pSigMask );      /* wait till child says it notices this */
  100.  
  101.     DeleteTask(Pict->gTask);
  102.     Pict->gTask = NULL;
  103.   }
  104. }
  105.  
  106. GetTaskSig( Pict )
  107.   register struct Picture *Pict;
  108. {
  109.   register LONG bit;
  110.  
  111.   Pict->gSigBit = bit = AllocSignal( (long) -1 );
  112.  
  113.   if ( bit == -1 )
  114.     return( UNSUCCESSFUL );
  115.  
  116.   Pict->gSigMask = 1 << bit;
  117.  
  118.   return( SUCCESSFUL );
  119. }
  120.  
  121. int
  122. OpenTasks()
  123. {
  124.   mTask = FindTask( NULL );
  125.  
  126.   mSigBit = AllocSignal( (long) -1 );
  127.  
  128.   if ( mSigBit == -1 ) {
  129.     return (-1);
  130.   }
  131.  
  132.   mSigMask = 1 << mSigBit;
  133.  
  134.   pSigBit = AllocSignal( (long) -1 );
  135.  
  136.   if ( pSigBit == -1 ) {
  137.  
  138.     FreeSignal( mSigBit );
  139.     return (-1);
  140.   }
  141.  
  142.   pSigMask = 1 << pSigBit;
  143.  
  144.   return( 0 );
  145. }
  146.  
  147. CloseTasks()
  148. {
  149.   FreeSignal( mSigBit );
  150.   FreeSignal( pSigBit );
  151. }
  152.  
  153. /* This is called by main task */
  154.  
  155. ThrowTask( Pict )
  156.   register struct Picture *Pict;
  157. {
  158.   register struct Task *gTask = Pict->gTask;
  159.  
  160.   if (gTask) {
  161.  
  162.     PauseChild( Pict );
  163.     DeleteTask( gTask );
  164.     Pict->gTask = NULL;
  165.  
  166.     SetGenGad( Pict );
  167.   }
  168. }
  169.  
  170. CloseZoomedPicts( Pict )
  171.   register struct Picture *Pict;
  172. {
  173.   register struct Node    *zNode;
  174.   register struct Picture *ZoomPict;
  175.  
  176.   struct Picture *PictAddr();
  177.  
  178.   zNode = Pict->zList.lh_Head;
  179.  
  180.   while ( zNode = RemHead( &Pict->zList ) ) {
  181.  
  182.     ZoomPict = PictAddr( zNode );
  183.  
  184.     CloseZoomBox(ZoomPict);
  185.   }
  186. }
  187.  
  188. /* Calculate pointer to the beginning of Picture struct */
  189.  
  190. struct Picture *
  191. PictAddr( zNodeAddr )
  192.   register struct Node *zNodeAddr;
  193. {
  194.   register char *ZoomPict;
  195.  
  196.   ZoomPict = (char *) zNodeAddr;
  197.  
  198.   ZoomPict -= ((char *) &CurPict->zNode - (char *) &CurPict->pNode);
  199.  
  200.   return( (struct Picture *) ZoomPict );
  201. }
  202.  
  203. PauseReColor( Pict )
  204.   register struct Picture *Pict;
  205. {
  206.   if (Pict->gTask) {
  207.  
  208.     if (Pict->ColorState == GENERATESTATE) {
  209.  
  210.       Pict->ColorState = PAUSESTATE;
  211.  
  212.       (void) Wait( pSigMask );
  213.     }
  214.   }
  215. }
  216.  
  217. ReColorPause( Pict )
  218.   register struct Picture *Pict;
  219. {
  220.   if ( Pict->ColorState == PAUSESTATE ) {
  221.  
  222.     Signal( mTask, pSigMask );
  223.     (void) Wait( 0L );
  224.   }
  225. }
  226.