home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-11 | 3.3 KB | 200 lines | [TEXT/MPCC] |
- // Control.c
- // Control the progress of Mike's Life
- // Copyright ©1995 Michael D. Crawford. All Rights Reserved.
- // 11 Jun 95 Mike Crawford crawford@scruznet.com
- //
- // Revision History:
- // 11 Jun 95 MDC New today
-
- #include <QDOffscreen.h>
- #include "Control.h"
- #include "LifeModules.h"
-
- void ZeroBytes( char *p, unsigned long theSize );
-
- static Boolean gLifeMarchesOn;
-
- short gNumWindows;
-
- tLifeWorldRecord gLifeWorlds[ kMaxWindows ];
- Boolean gLifeSlots[ kMaxWindows ];
-
- void DoLifeNull( void )
- {
- tLifeWorldPtr worldPtr;
- WindowPtr winPtr;
-
- if ( !gLifeMarchesOn )
- return;
-
- winPtr = FrontWindow();
-
- if (!winPtr )
- return;
-
- worldPtr = WinToLifeWorld( winPtr );
- if ( !worldPtr )
- return;
-
- LifeStep( worldPtr );
-
- DrawLifeWorld( worldPtr );
-
- return;
- }
-
- void InitControl( void )
- {
- short i;
-
- gLifeMarchesOn = false;
-
- gNumWindows = 0;
-
- for ( i = 0; i < kMaxWindows; i++ ){
- ZeroBytes( (char*)&gLifeWorlds[ i ], sizeof( tLifeWorldRecord ) );
- gLifeSlots[ i ] = false;
- }
-
- return;
- }
-
- tLifeWorldPtr NewLifeWorld( void )
- {
- tLifeWorldPtr worldPtr;
- short i;
-
- if ( gNumWindows >= kMaxWindows )
- return (tLifeWorldPtr)NULL;
-
- gNumWindows++;
-
- // Search for a free slot
- // This is hokey... should have an array of pointers rather than a static array of elements
-
- for ( i = 0; i < kMaxWindows; i++ ){
- if ( !gLifeSlots[ i ] ){
- worldPtr = &(gLifeWorlds[ i ] );
- ZeroBytes( (char*)worldPtr, sizeof( tLifeWorldRecord ) );
- gLifeSlots[ i ] = true;
- return worldPtr;
- }
- }
-
- DebugStr( "\pOut of slots... should never get here" );
-
- return (tLifeWorldPtr)NULL;
- }
-
- void FreeLifeWorld( tLifeWorldPtr worldPtr )
- {
- short i;
-
- for ( i = 0; i < kMaxWindows; i++ ){
- if ( &(gLifeWorlds[ i ] ) == worldPtr ){
- gLifeSlots[ i ] = false;
- return;
- }
- }
-
- DebugStr( "\pFreeLifeWorld got bogus worldPtr" );
-
- return;
- }
-
- tLifeWorldPtr WinToLifeWorld( WindowPtr win )
- {
- tLifeWorldPtr worldPtr;
- short i;
-
- for ( i = 0; i < kMaxWindows; i++ ){
- if ( gLifeSlots[ i ] ){
- if ( gLifeWorlds[ i ].win == win ){
- worldPtr = &( gLifeWorlds[ i ] );
- return worldPtr;
- }
- }
- }
-
- return (tLifeWorldPtr)NULL;
- }
-
- void ToggleCell( tLifeWorldPtr worldPtr, long h, long v )
- {
- #ifdef NEVER
- GWorldPtr gPtr;
- short rowBytes;
- PixMapHandle pHdl;
- unsigned char *pixPtr;
-
- if ( worldPtr->isHip )
- gPtr = worldPtr->hip;
- else
- gPtr = worldPtr->hop;
-
- pHdl = GetGWorldPixMap( gPtr );
- rowBytes = (*pHdl)->rowBytes & 0x3ff;
-
- pixPtr = ( (unsigned char*)(*pHdl)->baseAddr ) + h + rowBytes * v;
-
- if ( *pixPtr )
- *pixPtr = (unsigned char)0;
- else
- *pixPtr = (unsigned char)0xff;
- #endif
-
- return;
- }
-
- void DrawCell( WindowPtr winPtr, tLifeWorldPtr worldPtr, long h, long v )
- {
- #ifdef NEVER
- GWorldPtr gPtr;
- short rowBytes;
- PixMapHandle pHdl;
- unsigned char *pixPtr;
- Rect cellRect;
-
- if ( worldPtr->isHip )
- gPtr = worldPtr->hip;
- else
- gPtr = worldPtr->hop;
-
- SetRect( &cellRect, (short)h, (short)v, (short)(h + 1), (short)(v + 1) );
-
- SetGWorld( (GWorldPtr)winPtr, (GDHandle)NULL );
-
- pHdl = GetGWorldPixMap( gPtr );
-
- CopyBits( &( (GrafPtr)gPtr )->portBits,
- &winPtr->portBits,
- &cellRect,
- &cellRect,
- srcCopy,
- (RgnHandle)NULL );
-
- #endif
- return;
- }
-
- void ZeroBytes( char *p, unsigned long theSize )
- {
- while( theSize-- )
- *p++ = 0;
-
- return;
- }
-
- void StartRunning( void )
- {
- gLifeMarchesOn = true;
- return;
- }
-
- void StopRunning( void )
- {
- gLifeMarchesOn = false;
- return;
- }
-
-