home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / SpriteWorld 2.2 / SpriteWorld files / Utils / SWApplication.c < prev    next >
Encoding:
Text File  |  1998-12-14  |  3.3 KB  |  136 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    SWApplication.c
  3. //
  4. //    Portions are Copyright: © 1993 Tony Myles, All rights reserved worldwide.
  5. ///--------------------------------------------------------------------------------------
  6.  
  7. #ifndef __SPRITEWORLD__
  8. #include "SpriteWorld.h"
  9. #endif
  10.  
  11. #include <Gestalt.h>
  12. #include "SWApplication.h"
  13.  
  14.     // The user can put a pointer to their SpriteWorld here, allowing FatalError()
  15.     // to remove the VBL task, if any, before quitting.
  16. extern SpriteWorldPtr    gCleanUpSpriteWorldP;
  17.  
  18.  
  19. ///--------------------------------------------------------------------------------------
  20. //    Initialize
  21. ///--------------------------------------------------------------------------------------
  22.  
  23. void Initialize(short numberOfMasters)
  24. {
  25.     EventRecord tempEvent;
  26.  
  27.     MaxApplZone();
  28.  
  29.     while (numberOfMasters--)
  30.     {
  31.         MoreMasters();
  32.     }
  33.  
  34.     InitGraf(&qd.thePort);
  35.     InitFonts();
  36.     InitWindows();
  37.     InitMenus();
  38.     TEInit();
  39.     InitDialogs(NULL);
  40.     InitCursor();
  41.     FlushEvents(everyEvent, 0);
  42.  
  43.     (void)EventAvail(everyEvent, &tempEvent);
  44.     (void)EventAvail(everyEvent, &tempEvent);
  45.     (void)EventAvail(everyEvent, &tempEvent);
  46. }
  47.  
  48.  
  49. ///--------------------------------------------------------------------------------------
  50. //    ReportError
  51. ///--------------------------------------------------------------------------------------
  52.  
  53. void    ReportError(OSErr err, char* filename, int lineNumber)
  54. {
  55.     SetCursor(&qd.arrow);
  56.     ShowCursor();
  57.     
  58.     if (err == memFullErr)
  59.     {
  60.         ErrorAlert(err, filename, lineNumber, kOutOfMemoryStringIndex);
  61.     }
  62.     else if (err == resNotFound)
  63.     {
  64.         ErrorAlert(err, filename, lineNumber, kCantFindResourceStringIndex);
  65.     }
  66.     else
  67.     {
  68.         ErrorAlert(err, filename, lineNumber, kFatalErrorStringIndex);
  69.     }
  70. }
  71.  
  72.  
  73. ///--------------------------------------------------------------------------------------
  74. //    DoCantFindResource
  75. ///--------------------------------------------------------------------------------------
  76.  
  77. void    DoCantFindResource( char* filename, int lineNumber )
  78. {
  79.     OSErr err;
  80.  
  81.     err = ResError();
  82.  
  83.     if (err == noErr)
  84.     {
  85.         err = resNotFound;
  86.     }
  87.  
  88.     ErrorAlert(err, filename, lineNumber, kCantFindResourceStringIndex);
  89. }
  90.  
  91.  
  92. ///--------------------------------------------------------------------------------------
  93. //    ErrorAlert
  94. ///--------------------------------------------------------------------------------------
  95.  
  96. void    ErrorAlert(OSErr err, char* filename, int lineNumber, short errorStringIndex)
  97. {
  98.     Str255        messageString, errorString, fileString = "\p", lineString;
  99.     short        n;
  100.  
  101.     GetIndString(messageString, kErrorStringListResID, errorStringIndex);
  102.  
  103.     if (messageString[0] == 0)
  104.     {
  105.         BlockMove(kSeriousDamageString, messageString, sizeof(kSeriousDamageString));
  106.     }
  107.     
  108.     for (n = 0; filename[n] != 0; n++)
  109.     {
  110.         fileString[n+1] = filename[n];
  111.     }
  112.     fileString[0] += n;
  113.  
  114.     NumToString(err, errorString);
  115.     NumToString(lineNumber, lineString);
  116.     ParamText(messageString, fileString, lineString, errorString);
  117.     
  118.     (void)StopAlert(kErrorAlertResID, NULL);
  119.     
  120.     if (gCleanUpSpriteWorldP != NULL)
  121.         SWSyncSpriteWorldToVBL(gCleanUpSpriteWorldP, false);
  122.     
  123.     ExitToShell();
  124. }
  125.  
  126.  
  127. ///--------------------------------------------------------------------------------------
  128. //    CantRunOnThisMachine
  129. ///--------------------------------------------------------------------------------------
  130.  
  131. void    CantRunOnThisMachine( void )
  132. {
  133.     (void)StopAlert(kCantRunAlertResID, NULL);
  134. }
  135.  
  136.