home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Life 1.0d2 / LifeModules.c < prev    next >
Encoding:
Text File  |  1995-07-11  |  4.0 KB  |  193 lines  |  [TEXT/MMCC]

  1. // LifeModules.c
  2. // Handle the Life Implementation Modules for Mike's Life.
  3. // Copyright ©1995 Michael D. Crawford.  All Rights Reserved.
  4. // 23 Jun 95 Mike Crawford crawford@scruznet.com
  5. //
  6. // Revision History:
  7. // 23 Jun 95    MDC    New today
  8. //
  9. // The Atrium in Southfield, Michigan is a pretty good place to eat at
  10. // four in the morning.  It has those little jukeboxes at each table
  11. // so you can play bad music to annoy the other diners.
  12. //
  13. // Don't get the Greek Salad.  It sucks.
  14. //
  15. // Get the CD of the band "Yellow".  It is very good.
  16.  
  17. #include <QDOffscreen.h>
  18. #include "Control.h"
  19. #include "LifeModules.h"
  20. #include "StupidWay.h"
  21.  
  22. #define kProcMenuID    200
  23.  
  24. OSErr CountPlugIns( short *numPtr );
  25. void MyAppendMenu( MenuHandle mHdl, StringPtr item );
  26.  
  27. short gNumModules;
  28. tLifeProcsPtr    gLifeProcs;
  29.  
  30. OSErr InitModules( void )
  31. {
  32.     short        numPlugIns;
  33.     short        numBuiltIns;
  34.     MenuHandle    procMenu;
  35.     OSErr        err;
  36.     
  37.     procMenu = GetMenu( kProcMenuID );            // This allocates an empty module menu
  38.     if ( !procMenu )
  39.         return resNotFound;
  40.  
  41.     err = CountPlugIns( &numPlugIns );
  42.     if ( err )
  43.         return err;
  44.  
  45. #define kNumBuiltIns    1
  46.     numBuiltIns = kNumBuiltIns;
  47.     
  48.     gNumModules = numBuiltIns + numPlugIns;
  49.  
  50.     // We don't want to use handles on PowerPC, because it
  51.     // blows a cache line to dereference a handle.  :’-<
  52.  
  53.     gLifeProcs = (tLifeProcsPtr)NewPtr( sizeof(tLifeProcRecord) * gNumModules );
  54.     if ( !gLifeProcs )
  55.         return memFullErr;
  56.     
  57.     // Add in the built-ins first
  58.     
  59.     err = AddStupidWay( &gLifeProcs[ 0 ] );
  60.     
  61.     return noErr;
  62. }
  63.  
  64. OSErr AddLifeProcs( tLifeProcsPtr lifeProcPtr,
  65.                         short procType,
  66.                         StringPtr menuStr,
  67.                         tStepProc stepProc,
  68.                         tLifeAllocProc allocProc,
  69.                         tClearRectProc clearPixProc,
  70.                         tFreeProc freeProc,
  71.                         tToggleCellProc toggleProc,
  72.                         tDrawCellProc drawCellProc,
  73.                         tDrawWinProc drawProc,
  74.                         FSSpecPtr specPtr )
  75. {
  76.     MenuHandle    procMenu;
  77.  
  78.     // Fill in a life proc record
  79.     
  80.     lifeProcPtr->procType = procType;
  81.  
  82.     lifeProcPtr->stepProc = stepProc;
  83.     lifeProcPtr->allocProc = allocProc;
  84.     lifeProcPtr->clearPixProc = clearPixProc;
  85.     lifeProcPtr->freeProc = freeProc;
  86.     lifeProcPtr->toggleProc = toggleProc;
  87.     lifeProcPtr->drawCellProc = drawCellProc;
  88.     lifeProcPtr->drawProc = drawProc;
  89.     lifeProcPtr->fileSpec.vRefNum = specPtr->vRefNum;
  90.     lifeProcPtr->fileSpec.parID = specPtr->parID;
  91.     
  92.     BlockMove( &( specPtr->name[ 0 ] ),
  93.                 &( lifeProcPtr->fileSpec.name[ 0 ] ),
  94.                 specPtr->name[ 0 ] + 1 );
  95.  
  96. #ifdef MAYBE_SOMEDAY
  97.     switch( procType ){            // Do type-specific initialization
  98.         case kBuiltIn:
  99.             break;
  100.         case k68kCodeResource:
  101.             break;
  102.         case kPPCCodeFrag:
  103.             break;
  104.     }
  105. #endif
  106.  
  107.     procMenu = GetMHandle( kProcMenuID );
  108.     if ( !procMenu )
  109.         return resNotFound;
  110.  
  111.     MyAppendMenu( procMenu, menuStr );
  112.     
  113.     return noErr;
  114. }
  115.  
  116. void MyAppendMenu( MenuHandle mHdl, StringPtr itemStr )
  117. {
  118.     // STUB Fix this so special chars aren't interpreted
  119.     
  120.     AppendMenu( mHdl, itemStr );
  121.     
  122.     return;
  123. }
  124.  
  125. OSErr CountPlugIns( short *numPtr )
  126. {
  127.     *numPtr = 0;
  128.     
  129.     return noErr;
  130. }
  131.  
  132. OSErr AllocLifeWorld( tLifeWorldPtr worldPtr, long height, long width )
  133. {
  134.     tLifeProcsPtr    lifeProcPtr;
  135.     OSErr            err;
  136.  
  137.  
  138.     lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
  139.  
  140.     err = (*(lifeProcPtr->allocProc))( worldPtr, height, width );
  141.  
  142.     return err;
  143. }
  144.  
  145. OSErr LifeStep( tLifeWorldPtr worldPtr )
  146. {
  147.     tLifeProcsPtr    lifeProcPtr;
  148.     OSErr            err;
  149.  
  150.     lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
  151.  
  152.     err = (*(lifeProcPtr->stepProc))( worldPtr );
  153.  
  154.     return err;
  155. }
  156.  
  157. OSErr ClearCells( tLifeWorldPtr worldPtr, tLongRect *rPtr )
  158. {
  159.     tLifeProcsPtr    lifeProcPtr;
  160.     OSErr            err;
  161.  
  162.     lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
  163.  
  164.     err = (*(lifeProcPtr->clearPixProc))( worldPtr, rPtr );
  165.  
  166.     return err;
  167. }
  168.  
  169. OSErr DrawLifeWorld( tLifeWorldPtr worldPtr )
  170. {
  171.     tLifeProcsPtr    lifeProcPtr;
  172.     OSErr            err;
  173.  
  174.     lifeProcPtr = (tLifeProcsPtr)( worldPtr->lifeModuleProcs );
  175.  
  176.     err = (*(lifeProcPtr->drawProc))( worldPtr );
  177.  
  178.     return err;
  179. }
  180.  
  181.  
  182. void *GetModuleProcs( short moduleNumber )
  183. {
  184.     tLifeProcsPtr lifeProcPtr;
  185.     
  186. //    assert( ( moduleNumber >= 0 && moduleNumber < gNumModules ) );
  187.     
  188.     lifeProcPtr = &( gLifeProcs[ moduleNumber ] );
  189.  
  190.     return lifeProcPtr;
  191. }
  192.  
  193.