home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-01-12 | 26.1 KB | 996 lines | [TEXT/CWIE] |
- ///--------------------------------------------------------------------------------------
- // SpriteTest.c
- //
- // By: Tony Myles
- //
- // Extensive modifications by Karl Bunker
- //
- ///--------------------------------------------------------------------------------------
-
- #include <Timer.h>
-
- #include <SWIncludes.h> // Automatically include all SpriteWorld.h files
-
- #include <SWGameUtils.h>
- #include <SWDitherDown.h>
- #include <SWDialogUtils.h>
- #include <SWApplication.h>
- #include "SpriteTest.h"
-
- #if __MWERKS__
- #include <profiler.h>
- #endif
-
- #define kBlitterTest false
-
- #define kWorldRectInset 0 // modify to test SpriteWorld rect less than window size
-
- Boolean gGlobesVisible;
- Boolean gTitleVisible;
- Boolean gCollisionDetection;
- ProcType gWhichSpriteProc;
- ProcType gWhichOffscreenProc;
- ProcType gWhichScreenProc;
- short gMoveDelta;
- SpritePtr gMasterGlobeSprite = NULL;
-
-
- /******************** SetupSWStuff ********************/
- OSErr SetupSWStuff(
- SpriteTestPtr* spriteTestP,
- CWindowPtr srcWindowP)
- {
- OSErr err = noErr;
- SpriteTestPtr tempSpriteTestP;
- SpriteWorldPtr spriteWorldP = NULL;
- SpriteLayerPtr globeSpriteLayerP;
- SpritePtr globeSpriteArray[kNumberOfGlobeSprites];
- SpritePtr titleSpriteP;
- SpritePtr twoSpriteP;
- PixPatHandle pixPatH = NULL;
- short spriteNum;
- short oldResRefNum, curResRefNum;
- Rect windowRect, worldRect;
-
-
- *spriteTestP = NULL;
-
- SetPort((GrafPtr)srcWindowP);
-
-
- windowRect = srcWindowP->portRect;
- worldRect = windowRect;
- InsetRect( &worldRect, kWorldRectInset, kWorldRectInset );
-
- ShowWindow( (WindowPtr)srcWindowP );
- TextFont( systemFont );
- TextSize( 12 );
- MoveTo( 40, 80 );
- DrawString( "\pLoading Sprites... please wait" );
-
- tempSpriteTestP = (SpriteTestPtr)NewPtrClear((Size)sizeof(SpriteTestRec));
-
- {
- // create the sprite world
- (void)SWCreateSpriteWorldFromWindow(&spriteWorldP, srcWindowP, &worldRect, NULL, 0);
- }
-
- if (SWStickyError() == noErr)
- {
- tempSpriteTestP->spriteWorldP = spriteWorldP;
-
- // create the sprite layer
- (void)SWCreateSpriteLayer(&globeSpriteLayerP);
- tempSpriteTestP->globeSpriteLayerP = globeSpriteLayerP;
- }
-
- if (SWStickyError() == noErr)
- {
- oldResRefNum = CurResFile();
- curResRefNum = OpenResFile("\pSpriteTest Frames");
- SWSetStickyIfError( ResError() );
- }
-
- if (SWStickyError() == noErr)
- {
- UseResFile(curResRefNum);
-
- (void)SWCreateSpriteFromSinglePict(
- spriteWorldP,
- &gMasterGlobeSprite,
- NULL,
- kBaseResID,
- kBaseResID+1,
- kGlobeHeight,
- kGlobeBorderWidth,
- kFatMask);
-
- (void)SWCreateSpriteFromSinglePict(
- spriteWorldP,
- &twoSpriteP,
- NULL,
- kBaseResID+2,
- kBaseResID+2,
- kTwoHeight,
- kTwoBorderWidth,
- kFatMask);
-
- if (SWStickyError() == noErr)
- {
- if ( spriteWorldP->pixelDepth < 8 )
- {
- DitherDownPict( kBaseResID+2, twoSpriteP->sharedPictGWorld );
- LowerMaskDepth( kBaseResID+2, twoSpriteP->sharedMaskGWorld );
- }
- SWSetSpriteFrameTime( twoSpriteP, kGlobeSpriteFrameTime*4 );
- SWSetSpriteFrameRange( twoSpriteP, 0, kNumberOfTwoFrames - 1 );
- SWSetSpriteFrameAdvanceMode( twoSpriteP, kSWPatrollingMode );
- }
- UseResFile(oldResRefNum);
- CloseResFile(curResRefNum);
- }
-
- if (SWStickyError() == noErr)
- {
- if ( spriteWorldP->pixelDepth == 8 )
- (void)SWCompileSprite( gMasterGlobeSprite );
- // master globe sprite isn't added to any layer, so we have to lock it separately
- SWLockSprite( gMasterGlobeSprite);
- }
-
- if (SWStickyError() == noErr)
- {
-
- for (spriteNum = 0; spriteNum < kNumberOfGlobeSprites; spriteNum++)
- {
- (void)SWCloneSprite(gMasterGlobeSprite, globeSpriteArray + spriteNum, NULL);
- tempSpriteTestP->globeSpriteArray[spriteNum] = globeSpriteArray[spriteNum];
- }
-
- }
-
- if (SWStickyError() == noErr)
- {
- (void)SWCreateSpriteFromPictResource(
- spriteWorldP,
- &titleSpriteP,
- NULL,
- kBaseResID,
- kBaseResID,
- 1,
- kFatMask);
-
- if ( spriteWorldP->pixelDepth < 8 )
- {
- DitherDownPict( kBaseResID, titleSpriteP->frameArray[0]->framePort );
- LowerMaskDepth( kBaseResID, titleSpriteP->frameArray[0]->maskPort );
- }
- tempSpriteTestP->titleSpriteP = titleSpriteP;
- tempSpriteTestP->twoSpriteP = twoSpriteP;
-
- *spriteTestP = tempSpriteTestP;
-
- for (spriteNum = 0; spriteNum < kNumberOfGlobeSprites; spriteNum++)
- {
- if (spriteNum == (kNumberOfGlobeSprites / 2))
- {
- SWAddSprite(globeSpriteLayerP, titleSpriteP);
- SWAddSprite(globeSpriteLayerP, twoSpriteP);
- }
- SWAddSprite(globeSpriteLayerP, globeSpriteArray[spriteNum]);
- }
-
-
- SWAddSpriteLayer(spriteWorldP, globeSpriteLayerP);
-
-
- SWLockSpriteWorld(spriteWorldP);
-
- SWSetPortToBackground(spriteWorldP);
- EraseRect( &spriteWorldP->backRect );
-
- if ( spriteWorldP->pixelDepth >= 8 )
- {
- pixPatH = GetPixPat(kBackDropPixPatID);
- if ( pixPatH != NULL )
- {
- FillCRect(&spriteWorldP->backRect, pixPatH);
- DisposePixPat(pixPatH);
- }
- }
- else
- FillRect(&spriteWorldP->backRect, &qd.ltGray);
-
- SWSetPortToWindow(spriteWorldP);
-
- SetupSpriteWorldElements(tempSpriteTestP);
- }
- if ( SWStickyError() != noErr)
- {
- DisposeSWStuff(tempSpriteTestP);
- }
-
- return SWStickyError();
- }
-
-
- /******************** DisposeSWStuff ********************/
- void DisposeSWStuff(
- SpriteTestPtr spriteTestP)
- {
- if (spriteTestP != NULL)
- {
- if (spriteTestP->spriteWorldP != NULL)
- {
- SWDisposeSpriteWorld(&spriteTestP->spriteWorldP);
- }
- // gMasterGlobeSprite is not added to any layer,
- // so SWDisposeSpriteWorld won't dispose of it
- if ( gMasterGlobeSprite != NULL )
- {
- SWDisposeSprite( &gMasterGlobeSprite );
- }
- DisposePtr((Ptr)spriteTestP);
- }
- }
-
-
- /******************** SetupSpriteWorldElements ********************/
- void SetupSpriteWorldElements(
- SpriteTestPtr spriteTestP)
- {
- register long spriteNum;
- Rect moveBoundsRect;
- Rect titleDestRect;
-
-
- moveBoundsRect = spriteTestP->spriteWorldP->backRect;
-
- // set up the globe sprites
- gMoveDelta = 0;
- for (spriteNum = 0; spriteNum < kNumberOfGlobeSprites; spriteNum++)
- {
- SetupGlobeSprite(spriteTestP->globeSpriteArray[spriteNum], &moveBoundsRect,
- GetRandom(moveBoundsRect.left, moveBoundsRect.right),
- GetRandom(moveBoundsRect.top, moveBoundsRect.bottom));
- }
-
- // set up the title sprites
- titleDestRect = spriteTestP->titleSpriteP->destFrameRect;
-
- CenterRect( &titleDestRect, &moveBoundsRect );
- OffsetRect( &titleDestRect, -(kTwoHeight + 2 ), 0 );
- SWSetSpriteLocation(spriteTestP->titleSpriteP, titleDestRect.left, titleDestRect.top );
-
- SWSetSpriteLocation(spriteTestP->twoSpriteP, titleDestRect.right, titleDestRect.top-7 );
-
- SWSetSpriteWorldMaxFPS( spriteTestP->spriteWorldP, 30 );
- // SWSyncSpriteWorldToVBL( spriteTestP->spriteWorldP, true );
- SWSetCleanUpSpriteWorld(spriteTestP->spriteWorldP);
-
- gGlobesVisible = true;
- gTitleVisible = true;
- gCollisionDetection = false;
- gWhichSpriteProc = kCopyBitsProc;
- gWhichOffscreenProc = kCopyBitsProc;
- gWhichScreenProc = kCopyBitsProc;
- }
-
-
- /******************** SetupGlobeSprite ********************/
-
- void SetupGlobeSprite(
- SpritePtr globeSpriteP,
- Rect *moveBoundsRect,
- short horizLocation,
- short vertLocation)
- {
- Rect tempBoundsRect;
- short horizMoveDelta;
- short vertMoveDelta;
-
- gMoveDelta++;
- if ( gMoveDelta > 17 )
- gMoveDelta = 1;
-
- tempBoundsRect = *moveBoundsRect;
-
- horizMoveDelta = GetRandom(2, 6); // gMoveDelta
- vertMoveDelta = GetRandom(2, 6); // gMoveDelta
-
- if (GetRandom(0, 1) == 0)
- {
- horizMoveDelta = -horizMoveDelta;
- }
-
- if (GetRandom(0, 1) == 0)
- {
- vertMoveDelta = -vertMoveDelta;
- }
-
- // set the sprite’s movement characteristics
- SWSetSpriteMoveBounds(globeSpriteP, &tempBoundsRect);
- SWSetSpriteMoveDelta(globeSpriteP, horizMoveDelta, vertMoveDelta);
- SWSetSpriteMoveProc(globeSpriteP, GlobeSpriteMoveProc);
- SWSetSpriteMoveTime(globeSpriteP, kGlobeSpriteMoveTime);
-
- SWSetSpriteFrameTime(globeSpriteP, kGlobeSpriteFrameTime);
- SWSetSpriteFrameRange(globeSpriteP, 0, kNumberOfGlobeFrames - 1);
- SWSetSpriteFrameAdvance(globeSpriteP, GetRandom(0, 1) ? -1 : 1);
-
- // three to try:
- // PixelBounceCollideProc,
- // RegionBounceCollideProc,
- // RadiusBounceCollideProc
- SWSetSpriteCollideProc(globeSpriteP, RegionBounceCollideProc);
-
- // set the sprite’s initial location
- SWSetSpriteLocation(globeSpriteP, horizLocation, vertLocation);
- }
-
-
- /******************** SpriteTestIdle ********************/
- void SpriteTestIdle(
- SpriteTestPtr spriteTestP )
- {
- if (gCollisionDetection)
- {
- SWCollideSpriteLayer(spriteTestP->spriteWorldP,
- spriteTestP->globeSpriteLayerP, spriteTestP->globeSpriteLayerP);
- }
- SWProcessSpriteWorld( spriteTestP->spriteWorldP );
- SWAnimateSpriteWorld( spriteTestP->spriteWorldP );
- }
-
-
- /******************** UpdateSpriteTest ********************/
- void UpdateSpriteTest(
- SpriteTestPtr spriteTestP,
- WindowPtr updateWindowP)
- {
- SetPort( updateWindowP );
- if ( updateWindowP->portRect.right - updateWindowP->portRect.left >
- spriteTestP->spriteWorldP->backRect.right -
- spriteTestP->spriteWorldP->backRect.left )
- {
- ForeColor( blueColor );
- PaintRect( &updateWindowP->portRect );
- }
- ForeColor( blackColor );
- SWUpdateSpriteWorld(spriteTestP->spriteWorldP, true);
- }
-
-
- /******************** HandleCreateSpriteCommand ********************/
- void HandleCreateSpriteCommand(
- SpriteTestPtr spriteTestP)
- {
- OSErr err;
- SpritePtr globeSpriteP;
- Rect moveBoundsRect;
- Point mouseLocation;
-
-
- err = SWCloneSprite(gMasterGlobeSprite, &globeSpriteP, NULL);
-
- if (err == noErr)
- {
- moveBoundsRect = spriteTestP->spriteWorldP->backRect;
- GetMouse(&mouseLocation);
- mouseLocation.h -= spriteTestP->spriteWorldP->windRect.left;
- mouseLocation.v -= spriteTestP->spriteWorldP->windRect.top;
-
- SetupGlobeSprite(globeSpriteP, &moveBoundsRect, mouseLocation.h, mouseLocation.v);
-
- // Add sprite in front of or behind the title sprite
- if ( GetRandom(0,1) )
- SWAddSprite(spriteTestP->globeSpriteLayerP, globeSpriteP);
- else
- SWInsertSpriteBeforeSprite(globeSpriteP, spriteTestP->titleSpriteP);
- }
- }
-
-
- /******************** HandleSpriteTestTitleCommand ********************/
- void HandleSpriteTestTitleCommand(
- SpriteTestPtr spriteTestP)
- {
- gTitleVisible = !gTitleVisible;
-
- SWSetSpriteVisible(spriteTestP->titleSpriteP, gTitleVisible);
- SWSetSpriteVisible(spriteTestP->twoSpriteP, gTitleVisible);
- }
-
-
- /******************** HandleBouncingBallsCommand ********************/
- void HandleBouncingBallsCommand(
- SpriteTestPtr spriteTestP)
- {
- SpritePtr globeSpriteP;
-
-
- gGlobesVisible = !gGlobesVisible;
-
- globeSpriteP = NULL;
- while ((globeSpriteP = SWGetNextSprite(spriteTestP->globeSpriteLayerP, globeSpriteP)) != NULL)
- {
- if (globeSpriteP != spriteTestP->titleSpriteP && globeSpriteP != spriteTestP->twoSpriteP)
- {
- SWSetSpriteVisible(globeSpriteP, gGlobesVisible);
- }
- }
- }
-
-
- /******************** RemoveClickedSprite ********************/
- void RemoveClickedSprite(
- SpriteTestPtr spriteTestP)
- {
- Point mouseLocation;
- SpritePtr spriteToRemove;
-
-
- if ( spriteTestP != NULL )
- {
- GetMouse(&mouseLocation);
-
- mouseLocation.h -= spriteTestP->spriteWorldP->windRect.left;
- mouseLocation.v -= spriteTestP->spriteWorldP->windRect.top;
- // if a sprite has been clicked on, and it isn't the title sprite,
- // then remove it and dispose of it
- spriteToRemove = SWFindSpriteByPoint(spriteTestP->globeSpriteLayerP, NULL, mouseLocation);
- if ( spriteToRemove != NULL &&
- spriteToRemove != spriteTestP->titleSpriteP &&
- spriteToRemove != spriteTestP->twoSpriteP)
- {
- SWRemoveSpriteFromAnimation( spriteTestP->spriteWorldP, spriteToRemove, true );
- }
- }
- }
-
-
- /******************** SetUpTestDialog ********************/
- void SetUpTestDialog(
- SpriteTestPtr spriteTestP)
- {
- GrafPtr savePort;
- DialogPtr theDialog;
- short itemHit;
- ProcType originalSpriteProc,
- originalOffscreenProc,
- originalScreenProc;
- Boolean runNow;
- Boolean done = false;
- OSErr err = noErr;
-
-
- GetPort( &savePort );
-
- theDialog = GetNewDialog(kSetUpTestResID, nil, (WindowPtr)-1L);
-
- SetDialogDefaultItem( theDialog, ok );
- SetDialogCancelItem( theDialog, cancel );
-
- originalSpriteProc = gWhichSpriteProc;
- originalOffscreenProc = gWhichOffscreenProc;
- originalScreenProc = gWhichScreenProc;
-
- // Check if we can do 8-bit-specific tests
- SetDItemHilite( theDialog, kCompiledSpriteButton,
- (spriteTestP->spriteWorldP->pixelDepth==8) );
- #if SW_PPC
- SetDItemHilite( theDialog, kBlitPixieSpriteButton,
- (spriteTestP->spriteWorldP->pixelDepth >= 8) );
- SetDItemHilite( theDialog, kBlitPixieOffscreenButton,
- (spriteTestP->spriteWorldP->pixelDepth >= 8) );
- SetDItemHilite( theDialog, kBlitPixieScreenButton,
- (spriteTestP->spriteWorldP->pixelDepth >= 8) );
-
- SetDItemHilite( theDialog, kCompiledSpriteButton, false );
- #endif
-
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kRunTestNowCheckBox), true );
-
- SetSetUpTestButtons( theDialog );
-
- ShowWindow( theDialog );
-
- while ( !done )
- {
- ModalDialog( nil, &itemHit );
- switch( itemHit )
- {
- case kCopyBitsSpriteButton:
- gWhichSpriteProc = kCopyBitsProc;
- SetSetUpTestButtons( theDialog );
- break;
- case kBlitPixieSpriteButton:
- gWhichSpriteProc = kBlitPixieProc;
- SetSetUpTestButtons( theDialog );
- break;
- case kCompiledSpriteButton:
- gWhichSpriteProc = kCompiledProc;
- SetSetUpTestButtons( theDialog );
- break;
- case kCopyBitsOffscreenButton:
- gWhichOffscreenProc = kCopyBitsProc;
- SetSetUpTestButtons( theDialog );
- break;
- case kBlitPixieOffscreenButton:
- gWhichOffscreenProc = kBlitPixieProc;
- SetSetUpTestButtons( theDialog );
- break;
- case kCopyBitsScreenButton:
- gWhichScreenProc = kCopyBitsProc;
- SetSetUpTestButtons( theDialog );
- break;
- case kBlitPixieScreenButton:
- gWhichScreenProc = kBlitPixieProc;
- SetSetUpTestButtons( theDialog );
- break;
- case kRunTestNowCheckBox:
- ToggleDItemValue(theDialog, kRunTestNowCheckBox);
- break;
- case ok:
- runNow = GetControlValue( (ControlHandle)GetDItemHandle(theDialog, kRunTestNowCheckBox));
- case cancel:
- done = true;
- break;
- }
- }
- DisposeDialog( theDialog );
- SetPort( savePort );
-
- if ( itemHit == ok )
- {
- if ( runNow )
- RunTheTest( spriteTestP );
- }
- if ( itemHit == cancel )
- {
- gWhichSpriteProc = originalSpriteProc;
- gWhichOffscreenProc = originalOffscreenProc;
- gWhichScreenProc = originalScreenProc;
- }
- }
-
-
-
- /******************** SetSetUpTestButtons ********************/
- void SetSetUpTestButtons(
- DialogPtr theDialog)
- {
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCopyBitsSpriteButton),
- (gWhichSpriteProc == kCopyBitsProc) );
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kBlitPixieSpriteButton),
- (gWhichSpriteProc == kBlitPixieProc) );
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCompiledSpriteButton),
- (gWhichSpriteProc == kCompiledProc) );
-
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCopyBitsOffscreenButton),
- (gWhichOffscreenProc == kCopyBitsProc) );
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kBlitPixieOffscreenButton),
- (gWhichOffscreenProc == kBlitPixieProc) );
-
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCopyBitsScreenButton),
- (gWhichScreenProc == kCopyBitsProc) );
- SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kBlitPixieScreenButton),
- (gWhichScreenProc == kBlitPixieProc) );
- }
-
-
- /******************** RunTheTest ********************/
- void RunTheTest(
- SpriteTestPtr spriteTestP)
- {
- WindowPtr testWindowP = FrontWindow();
- SpritePtr curSpriteP;
- unsigned long frames, seconds;
- long ticks;
- Rect shieldRect;
- Point shieldRectOffset;
- Rect srcRect,
- destRect;
- UnsignedWide startMicroseconds,
- endMicroseconds;
-
-
- // set up for the test
-
- shieldRect = spriteTestP->spriteWorldP->windowFrameP->frameRect;
- LocalToGlobal( &topLeft(shieldRect) );
- LocalToGlobal( &botRight(shieldRect) );
- shieldRectOffset.h = shieldRectOffset.v = 0;
- ShieldCursor( &shieldRect, shieldRectOffset );
-
- SWHideMenuBar(testWindowP);
-
- UpdateSpriteTest( spriteTestP, testWindowP );
-
- curSpriteP = NULL;
- while ((curSpriteP = SWGetNextSprite(spriteTestP->globeSpriteLayerP, curSpriteP)) != NULL)
- {
- if (curSpriteP != spriteTestP->titleSpriteP && curSpriteP != spriteTestP->twoSpriteP)
- {
- SWSetSpriteFrameTime(curSpriteP, 0);
- SWSetSpriteMoveTime(curSpriteP, 0);
- switch ( gWhichSpriteProc )
- {
- case kBlitPixieProc:
- if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
- (void)SWSetSpriteDrawProc(curSpriteP, BlitPixie8BitMaskDrawProc);
- else
- {
- (void)SWSetSpriteDrawProc(curSpriteP, BlitPixieAllBitMaskDrawProc);
- }
- break;
- case kCompiledProc:
- (void)SWSetSpriteDrawProc(curSpriteP, CompiledSprite8BitDrawProc);
- break;
- }
- }
- }
-
- if ( gWhichSpriteProc == kBlitPixieProc || gWhichSpriteProc == kCompiledProc )
- {
- if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
- {
- (void)SWSetSpriteDrawProc(spriteTestP->titleSpriteP, BlitPixie8BitMaskDrawProc);
- (void)SWSetSpriteDrawProc(spriteTestP->twoSpriteP, BlitPixie8BitMaskDrawProc);
- }
- else
- {
- (void)SWSetSpriteDrawProc(spriteTestP->titleSpriteP, BlitPixieAllBitMaskDrawProc);
- (void)SWSetSpriteDrawProc(spriteTestP->twoSpriteP, BlitPixieAllBitMaskDrawProc);
- }
- }
- if ( gWhichOffscreenProc == kBlitPixieProc )
- {
- if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
- {
- (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP,
- BlitPixie8BitRectDrawProc);
- }
- else
- {
- (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP,
- BlitPixieAllBitRectDrawProc);
- }
- }
- if ( gWhichScreenProc == kBlitPixieProc )
- {
- if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
- {
- (void)SWSetSpriteWorldScreenDrawProc(spriteTestP->spriteWorldP,
- BlitPixie8BitRectDrawProc);
- }
- else
- {
- (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP,
- BlitPixieAllBitRectDrawProc);
- }
- }
-
- // Floor it!!!
- SWSetSpriteWorldMaxFPS( spriteTestP->spriteWorldP, 0 );
-
- ticks = TickCount();
-
-
- // the actual tests...
-
- // a straight blitter test -- no animation to screen
-
- if ( kBlitterTest )
- {
- srcRect = gMasterGlobeSprite->frameArray[0]->frameRect;
- destRect = srcRect;
- OffsetRect( &destRect, 3, 0 );
- Microseconds( &startMicroseconds );
-
- if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
- {
- for (frames = 0; frames < 10000; frames++ )
- {
- BlitPixie8BitMaskDrawProc(
- gMasterGlobeSprite->frameArray[0],
- spriteTestP->spriteWorldP->workFrameP,
- &srcRect,
- &destRect);
- }
- }
- else
- {
- for (frames = 0; frames < 10000; frames++ )
- {
- BlitPixieAllBitMaskDrawProc(
- gMasterGlobeSprite->frameArray[0],
- spriteTestP->spriteWorldP->workFrameP,
- &srcRect,
- &destRect);
- }
- }
-
- Microseconds( &endMicroseconds );
- seconds = endMicroseconds.lo - startMicroseconds.lo;
- if ( endMicroseconds.hi != startMicroseconds.hi )
- seconds = 0; // do test over
- }
- else // a test of animation to screen
- {
- /*
- ProfilerSetStatus( true );
- */
- for (frames = 0; ((TickCount() - ticks) < kTestTime) && (!Button()); frames++)
- {
- if (gCollisionDetection)
- {
- SWCollideSpriteLayer(spriteTestP->spriteWorldP,
- spriteTestP->globeSpriteLayerP, spriteTestP->globeSpriteLayerP);
- }
-
- SWProcessSpriteWorld( spriteTestP->spriteWorldP );
- SWAnimateSpriteWorld( spriteTestP->spriteWorldP );
- }
- seconds = ((TickCount() - ticks) / 60);
- }
- /*
- ProfilerSetStatus( false );
- ProfilerDump( "\pSWPPC Profile" );
- ProfilerTerm();
- */
-
- // restore things to default state
- RestoreFromTest( testWindowP, spriteTestP );
-
- DisplayPerformance(frames, seconds);
- }
-
-
-
- /******************** RestoreFromTest ********************/
- void RestoreFromTest(
- WindowPtr testWindowP,
- SpriteTestPtr spriteTestP)
- {
- SpritePtr curSpriteP;
-
-
- // restore things to default state
-
- curSpriteP = NULL;
-
- while ((curSpriteP = SWGetNextSprite(spriteTestP->globeSpriteLayerP, curSpriteP)) != NULL)
- {
- (void)SWSetSpriteDrawProc(curSpriteP, SWStdSpriteDrawProc);
- if (curSpriteP != spriteTestP->titleSpriteP && curSpriteP != spriteTestP->twoSpriteP)
- {
- SWSetSpriteFrameTime(curSpriteP, kGlobeSpriteFrameTime);
- }
- }
-
- (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP, SWStdWorldDrawProc);
- (void)SWSetSpriteWorldScreenDrawProc(spriteTestP->spriteWorldP, SWStdWorldDrawProc);
-
- SWSetSpriteWorldMaxFPS( spriteTestP->spriteWorldP, 30 );
-
- ShowCursor();
- SWShowMenuBar(testWindowP);
- }
-
-
- /******************** DisplayPerformance ********************/
- void DisplayPerformance(
- long frames,
- long seconds)
- {
- Str255 framesString, secondsString, fpsString;
- long fps;
-
- NumToString(frames, framesString);
- NumToString(seconds, secondsString);
-
- fps = (seconds > 0) ? frames / seconds : frames;
-
- NumToString(fps, fpsString);
-
- ParamText(framesString, secondsString, fpsString, "\p");
- NoteAlert(kPerformanceAlertID, NULL);
- }
-
-
- /******************** GlobeSpriteMoveProc ********************/
- SW_FUNC void GlobeSpriteMoveProc(SpritePtr globeSpriteP)
- {
- SWOffsetSprite(globeSpriteP, globeSpriteP->horizMoveDelta, globeSpriteP->vertMoveDelta);
- (void)SWBounceSprite(globeSpriteP);
- }
-
-
- /******************** PixelBounceCollideProc ********************/
- SW_FUNC void PixelBounceCollideProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* sectRect)
- {
-
- // If both sprites use the same collision routine (this one),ignore the second collision.
- if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
- ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
- (srcSpriteP > dstSpriteP)))
- {
- return;
- }
-
- if ( SWPixelCollision(srcSpriteP, dstSpriteP) )
- {
- // if a stationary sprite (the title), just bounce off it
- if ((dstSpriteP->horizMoveDelta == 0) && (dstSpriteP->vertMoveDelta == 0))
- {
- BounceGlobeOffTitle( dstSpriteP, srcSpriteP, sectRect );
- }
- else
- // globe to globe collision; swap movement delta's
- {
- BounceGlobeOffGlobe( srcSpriteP, dstSpriteP );
- }
- }
- }
-
-
- /******************** RegionBounceCollideProc ********************/
- SW_FUNC void RegionBounceCollideProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* sectRect)
- {
-
- // If both sprites use the same collision routine (this one),ignore the second collision.
- if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
- ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
- (srcSpriteP > dstSpriteP)))
- {
- return;
- }
-
-
- if ( SWRegionCollision(srcSpriteP, dstSpriteP) )
- {
- // if a stationary sprite (the title), just bounce off it
- if ((dstSpriteP->horizMoveDelta == 0) && (dstSpriteP->vertMoveDelta == 0))
- {
- BounceGlobeOffTitle( dstSpriteP, srcSpriteP, sectRect );
- }
- else
- // globe to globe collision; swap movement delta's
- {
- BounceGlobeOffGlobe( srcSpriteP, dstSpriteP );
- }
- }
- }
-
-
- /******************** RadiusBounceCollideProc ********************/
- SW_FUNC void RadiusBounceCollideProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* sectRect)
- {
- #pragma unused(sectRect)
-
- // If both sprites use the same collision routine (this one),ignore the second collision.
- if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
- ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
- (srcSpriteP > dstSpriteP)))
- return;
-
- // ignore collision with title sprite
- if ( (srcSpriteP->destFrameRect.right-srcSpriteP->destFrameRect.left !=
- srcSpriteP->destFrameRect.bottom-srcSpriteP->destFrameRect.top) ||
- (dstSpriteP->destFrameRect.right-dstSpriteP->destFrameRect.left !=
- dstSpriteP->destFrameRect.bottom-dstSpriteP->destFrameRect.top))
- return;
-
- if ( SWRadiusCollision( srcSpriteP, dstSpriteP ) )
- {
- BounceGlobeOffGlobe( srcSpriteP, dstSpriteP );
- }
- }
-
-
- /******************** BounceGlobeOffGlobe ********************/
- void BounceGlobeOffGlobe(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP )
- {
- short tempDelta;
- short nextHorizDistA, nextVertDistA,
- nextHorizDistB, nextVertDistB;
-
-
- // reverse spins.
- srcSpriteP->frameAdvance = -srcSpriteP->frameAdvance;
- dstSpriteP->frameAdvance = -dstSpriteP->frameAdvance;
-
- // Calculate what the distance between sprites will be if we don't switch deltas
- nextHorizDistA = srcSpriteP->destFrameRect.left + srcSpriteP->horizMoveDelta -
- (dstSpriteP->destFrameRect.left + dstSpriteP->horizMoveDelta);
- if (nextHorizDistA < 0)
- nextHorizDistA = -nextHorizDistA;
-
- nextVertDistA = srcSpriteP->destFrameRect.top + srcSpriteP->vertMoveDelta -
- (dstSpriteP->destFrameRect.top + dstSpriteP->vertMoveDelta);
- if (nextVertDistA < 0)
- nextVertDistA = -nextVertDistA;
-
- // Calculate what the distance between sprites will be if we do switch deltas
- nextHorizDistB = srcSpriteP->destFrameRect.left + dstSpriteP->horizMoveDelta -
- (dstSpriteP->destFrameRect.left + srcSpriteP->horizMoveDelta);
- if (nextHorizDistB < 0)
- nextHorizDistB = -nextHorizDistB;
-
- nextVertDistB = srcSpriteP->destFrameRect.top + dstSpriteP->vertMoveDelta -
- (dstSpriteP->destFrameRect.top + srcSpriteP->vertMoveDelta);
- if (nextVertDistB < 0)
- nextVertDistB = -nextVertDistB;
-
-
- // Will swapping the horizontal deltas move the sprites farther apart?
- if (nextHorizDistB > nextHorizDistA)
- {
- // swap horizontal deltas
- tempDelta = srcSpriteP->horizMoveDelta;
- srcSpriteP->horizMoveDelta = dstSpriteP->horizMoveDelta;
- dstSpriteP->horizMoveDelta = tempDelta;
- }
-
- // Will swapping the vertical deltas move the sprites farther apart?
- if (nextVertDistB > nextVertDistA)
- {
- // swap vertical deltas
- tempDelta = srcSpriteP->vertMoveDelta;
- srcSpriteP->vertMoveDelta = dstSpriteP->vertMoveDelta;
- dstSpriteP->vertMoveDelta = tempDelta;
- }
- }
-
-
- /******************** BounceGlobeOffTitle ********************/
- void BounceGlobeOffTitle(
- SpritePtr titleSpriteP,
- SpritePtr globeSpriteP,
- Rect* sectRect )
- {
- short absHorizDelta,
- absVertDelta;
-
- absHorizDelta = globeSpriteP->horizMoveDelta;
- if ( absHorizDelta < 0 )
- absHorizDelta = -absHorizDelta;
- absVertDelta = globeSpriteP->vertMoveDelta;
- if ( absVertDelta < 0 )
- absVertDelta = -absVertDelta;
-
- // draw a picture and this test algorithm will become clear
- if ((sectRect->right - sectRect->left) < (sectRect->bottom - sectRect->top) )
- {
- // Hit left or right side
- if ( sectRect->left <= titleSpriteP->destFrameRect.left )
- // hit on left side
- globeSpriteP->horizMoveDelta = -absHorizDelta;
- else
- // hit on right side
- globeSpriteP->horizMoveDelta = absHorizDelta;
- }
- else
- {
- // Hit top or bottom
- if ( sectRect->top <= titleSpriteP->destFrameRect.top )
- // hit on top
- globeSpriteP->vertMoveDelta = -absVertDelta;
- else
- // hit on bottom
- globeSpriteP->vertMoveDelta = absVertDelta;
- }
- }
-