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 / lists.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  7KB  |  379 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 that create, delete, and performs
  25.  * operations on lists of projects.
  26.  */
  27.  
  28. #include "mandp.h"
  29.  
  30. extern LONG MainPri, TaskPri;
  31.  
  32. #define LT_PICTLIST 0xff
  33. #define LT_ZOOMLIST 0xfe
  34.  
  35. struct List pList = {
  36.   (struct Node *) &pList.lh_Tail,
  37.   (struct Node *) NULL,
  38.   (struct Node *) &pList.lh_Head,
  39.   LT_PICTLIST
  40. };
  41.  
  42. union PictNode {
  43.   struct Node    *Node;
  44.   struct Picture *Pict;
  45. };
  46.  
  47. struct Picture *
  48. NewPict( Type )
  49.   UBYTE Type;
  50. {
  51.   register union PictNode ln;
  52.   register struct List *Head;
  53.  
  54.   extern struct NewWindow NewMand;
  55.  
  56.   ln.Pict = (struct Picture *)
  57.             safeAllocMem( (long) sizeof(struct Picture), (long) MEMF_CLEAR);
  58.  
  59.   if (ln.Pict == NULL)
  60.     return( ln.Pict );
  61.  
  62.   ln.Node->ln_Type = Type;
  63.   ln.Node->ln_Name = ln.Pict->Title;
  64.  
  65. #if 0
  66.   strcpy( ln.Pict->Title, "* ");
  67. #endif
  68.  
  69.   if ( Type == MANDPICT ) {
  70.  
  71.     InitMand( ln.Pict );
  72.   }
  73.  
  74.   ln.Pict->NewWind = &NewMand;
  75.  
  76.   ln.Pict->TopEdge = 12;
  77.  
  78.   if ( pList.lh_Head->ln_Succ == NULL ) {
  79.  
  80.     ToggleEnableds();
  81.   }
  82.  
  83.   AddHead( &pList, ln.Node );
  84.  
  85.   ln.Pict->gSigBit = -1;
  86.  
  87.   Head = &ln.Pict->zList;
  88.  
  89.   Head->lh_Head     = (struct Node *) &Head->lh_Tail;
  90.   Head->lh_TailPred = (struct Node *) &Head->lh_Head;
  91.   Head->lh_Type     = LT_ZOOMLIST;
  92.  
  93.   ln.Pict->WindowSemi.ss_Link.ln_Name = NULL;
  94.   ln.Pict->WindowSemi.ss_Link.ln_Pri  = 0;
  95.  
  96.   AddSemaphore( &ln.Pict->WindowSemi );
  97.  
  98.   return( ln.Pict );
  99. }
  100.  
  101. /* Dale Luck's Add Semaphore code */
  102.  
  103. myAddSemaphore( ss )
  104.   struct SignalSempahore *ss;
  105. {
  106.   extern struct ExecBase *SysBase;
  107.  
  108.   InitSemaphore(ss);
  109.   Forbid();
  110.   Enqueue(&SysBase->SemaphoreList, ss);
  111.   Permit();
  112. }
  113.  
  114.  
  115. DisposePict( NPict )
  116.   register struct Picture *NPict;
  117. {
  118.   Remove( &NPict->pNode );
  119.  
  120.   RemSemaphore( &NPict->WindowSemi );
  121.  
  122.   if (NPict == CurPict)
  123.     CurPict = NULL;
  124.  
  125.   FreeMem( (char *) NPict, (long) sizeof( struct Picture ) );
  126.  
  127.   if ( pList.lh_Head->ln_Succ == NULL ) {
  128.  
  129.     ToggleEnableds();
  130.   }
  131. }
  132.  
  133. GetCurPict( )
  134. {
  135.   register struct Picture *NewPict;
  136.  
  137.   if ( pList.lh_Head->ln_Succ ) {
  138.  
  139.     NewPict = (struct Picture *) pList.lh_Head;
  140.  
  141.     MakeCurProj( NewPict );
  142.  
  143.   } else {
  144.  
  145.     CurPict = NULL;
  146.   }
  147. }
  148.  
  149. ThrowPicts()
  150. {
  151.   register union PictNode ln;
  152.   register union PictNode lnt;
  153.  
  154.   ln.Node = pList.lh_Head;
  155.  
  156.   while ( ln.Node->ln_Succ ) {
  157.  
  158.     lnt.Node = ln.Node;
  159.     ln.Node = ln.Node->ln_Succ;
  160.     ThrowPict( lnt.Pict );
  161.   }
  162. }
  163.  
  164. ThrowPict( Pict )
  165.   register struct Picture *Pict;
  166. {
  167.   ThrowTask( Pict );
  168.  
  169.   KillReColor( Pict );
  170.  
  171.   FreeCounts( Pict );
  172.  
  173.   FreeHist( Pict->Hist );
  174.   Pict->Hist = NULL;
  175.  
  176.   ClosePicture( Pict );
  177.   DisposePict( Pict );
  178. }
  179.  
  180. ReColorPicts()
  181. {
  182.   register union PictNode ln;
  183.  
  184.   ln.Node = pList.lh_Head;
  185.  
  186.   while ( ln.Node->ln_Succ ) {
  187.  
  188.     ReColor( ln.Pict );
  189.     ln.Node = ln.Node->ln_Succ;
  190.   }
  191. }
  192.  
  193. CheckNewScreen( ViewModes )
  194.   USHORT ViewModes;
  195. {
  196.   register union PictNode ln;
  197.  
  198.   struct NewScreen MaybeScreen;
  199.   register struct NewScreen *ns;
  200.  
  201.   ns = &MaybeScreen;
  202.  
  203.   ns->ViewModes = ViewModes;
  204.  
  205.   NewScreenSize( ns );
  206.  
  207.   ln.Node = pList.lh_Head;
  208.  
  209.   while ( ln.Node->ln_Succ ) {
  210.  
  211.     if (ln.Pict->Window && ( ln.Pict->Window->Width  > ns->Width  ||
  212.                              ln.Pict->Window->Height > ns->Height))
  213.       return( UNSUCCESSFUL );
  214.  
  215.     ln.Node = ln.Node->ln_Succ;
  216.   }
  217.   return( SUCCESSFUL );
  218. }
  219.  
  220. ReOpenPicts()
  221. {
  222.   register union PictNode ln;
  223.   register union PictNode temp_ln;
  224.  
  225.   extern struct NewWindow NewMand;
  226.  
  227.   ln.Node = pList.lh_Head;
  228.  
  229.   while ( ln.Node->ln_Succ ) {
  230.  
  231.     ReleaseSemaphore( &ln.Pict->WindowSemi );
  232.  
  233.     if ( OpenPicture( ln.Pict ) != 0 ) {
  234.  
  235.       temp_ln.Node = ln.Node;
  236.  
  237.       ln.Node = ln.Node->ln_Succ;
  238.  
  239.       ThrowPict( temp_ln.Pict );
  240.  
  241.     } else {
  242.       if ( ln.Pict->Counts && ! (ln.Pict->Flags & NO_RAM_GENERATE) ) {
  243.         ReColor( ln.Pict );
  244.       }
  245.  
  246.       AwakenChild( ln.Pict );
  247.  
  248.       if ( ln.Pict->GenState == GENPENDSTATE ) {
  249.         Generate( ln.Pict );
  250.       }
  251.  
  252.       ln.Node = ln.Node->ln_Succ;
  253.     }
  254.   }
  255.   ServiceTasks();
  256. }
  257.  
  258. ClosePicts()
  259. {
  260.   register union PictNode ln;
  261.  
  262.   ln.Node = pList.lh_Head;
  263.  
  264.   while ( ln.Node->ln_Succ ) {
  265.  
  266.     if ( ln.Pict->cTask ) {
  267.  
  268.       KillReColor( ln.Pict );
  269.     }
  270.  
  271.  
  272.  
  273.     ObtainSemaphore( &ln.Pict->WindowSemi );
  274.  
  275.     ClosePicture( ln.Pict );
  276.  
  277.     ln.Node = ln.Node->ln_Succ;
  278.   }
  279. }
  280.  
  281. ServiceTasks()
  282. {
  283.   register union PictNode ln;
  284.  
  285.   ln.Node = pList.lh_Head;
  286.  
  287.   while ( ln.Node->ln_Succ ) {
  288.  
  289.     switch( ln.Pict->GenChildState ) {
  290.  
  291.       case NOSIGSTATE:
  292.       case GENCOMPLETE:
  293.  
  294.            KillDoneChild( ln.Pict );
  295.            SetGenGad( ln.Pict );
  296.            ln.Pict->gTask = NULL;
  297.            PrintTime( ln.Pict );
  298.            break;
  299.     }
  300.  
  301.     if ( ln.Pict->ColorChildState == RECOLORCOMPLETE ) {
  302.       KillReColor( ln.Pict );
  303.       AwakenChild( ln.Pict );
  304.     }
  305.  
  306.     ln.Node = ln.Node->ln_Succ;
  307.   }
  308. }
  309.  
  310. PrintTime( Pict )
  311.  register struct Picture *Pict;
  312. {
  313.  LONG t2[3];
  314.  LONG *t1,t;
  315.  
  316.  if (FromWB)
  317.    return;
  318.  
  319.  return;
  320.  
  321.  DateStamp(t2);
  322.  
  323.  t1 = Pict->TimeStamp;
  324.  
  325.  t = ((t2[0]-t1[0]) * 1440 + t2[1] - t1[1]) * 3000 + t2[2] - t1[2] ;
  326.  
  327.  printf("time is %ld.%ld seconds\n",t/50,2*(t%50));
  328. }
  329.  
  330. ReColorLine( Pict )
  331.   register struct Picture *Pict;
  332. {
  333.   register struct RastPort *Rp;
  334.   register UBYTE *ColorXLate;
  335.   register SHORT *LinePtr;
  336.   register LONG   Top;
  337.   register LONG   Width;
  338.   register struct Window   *Window;
  339.  
  340.   LONG i;
  341.  
  342.   (void) SetTaskPri( Pict->gTask, MainPri );
  343.  
  344.   ObtainSemaphore( &Pict->WindowSemi );
  345.  
  346.   Top     = Pict->CurLine;
  347.   Width   = Pict->CountX;
  348.   Window  = Pict->Window;
  349.  
  350.   if ( Window ) {
  351.  
  352.     ColorXLate = Pict->ClrXlate;
  353.  
  354.     if ( Pict->Flags & NO_RAM_GENERATE ) {
  355.  
  356.       LinePtr = Pict->Counts;
  357.     } else {
  358.       LinePtr = Pict->Counts + Top * Width;
  359.     }
  360.  
  361.     Top   += Pict->TopMarg;
  362.     Width += Pict->LeftMarg;
  363.  
  364.     Rp = Window->RPort;
  365.  
  366.     for (i = Pict->LeftMarg; i < Width; i++) {
  367.  
  368.       SetAPen( Rp, (long) *(ColorXLate + *LinePtr++) );
  369.  
  370.       if ( i < Window->Width - Pict->RightMarg )
  371.         WritePixel( Rp, i, Top );
  372.     }
  373.   }
  374.  
  375.   ReleaseSemaphore( &Pict->WindowSemi );
  376.  
  377.   (void) SetTaskPri( Pict->gTask, TaskPri );
  378. }
  379.