home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / SprocketExamples / SprocketInvaders / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-14  |  3.7 KB  |  158 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        main.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (sjb)    Steve Bollinger
  21.         (BWS)    Brent Schorsch
  22.  
  23.     Change History (most recent first):
  24.  
  25.         <14>     6/18/98    sjb        InputSprocket.h comes from <> place
  26.         <13>     6/12/98    BWS        Now uses InputSprocket 68k
  27. */
  28.  
  29. //•    ------------------------------------------------------------------------------------------    •
  30. //•
  31. //•    Copyright © 1996 Apple Computer, Inc., All Rights Reserved
  32. //•
  33. //•
  34. //•        You may incorporate this sample code into your applications without
  35. //•        restriction, though the sample code has been provided "AS IS" and the
  36. //•        responsibility for its operation is 100% yours.  However, what you are
  37. //•        not permitted to do is to redistribute the source as "DSC Sample Code"
  38. //•        after having made changes. If you're going to re-distribute the source,
  39. //•        we require that you make it clear in the source that the code was
  40. //•        descended from Apple Sample Code, but that you've made changes.
  41. //•
  42. //•        Authors:
  43. //•            Chris De Salvo
  44. //•            Jamie Osborne
  45. //•
  46. //•    ------------------------------------------------------------------------------------------    •
  47.  
  48. //•    ------------------------------    Includes
  49.  
  50. #include <Fonts.h>
  51. #include <Movies.h>
  52. #include <StandardFile.h>
  53.  
  54. #include <DrawSprocket.h>
  55. #include <InputSprocket.h>
  56.  
  57. #include "ErrorHandler.h"
  58. #include "EventHandler.h"
  59. #include "Graphics.h"
  60. #include "MenuHandler.h"
  61. #include "MoviePlayback.h"
  62. #include "RedbookHandler.h"
  63. #include "SoundHandler.h"
  64. #include "NetSprocketSupport.h"
  65.  
  66. //•    ------------------------------    Private Definitions
  67. //•    ------------------------------    Private Types
  68. //•    ------------------------------    Private Variables
  69.  
  70. static StandardFileReply    gTheReply;
  71.  
  72. //•    ------------------------------    Private Functions
  73.  
  74. void main(void);
  75. static void ToolboxInit(void);
  76.  
  77. //•    ------------------------------    Public Variables
  78. //•    --------------------    main
  79.  
  80. void
  81. main(void)
  82. {
  83. //•    When we start up we record the state of the modifier keys on the keyboard
  84. //•    and then pass those values to the various initialization routines in the game.
  85. SInt16    startupModifiers;
  86. #if !GENERATINGPOWERPC
  87. UInt32 inputSprocketVersion;
  88. #endif
  89.  
  90.     ToolboxInit();
  91.  
  92.     //•    Make sure that the DrawSprocket and InputSprocket libraries are present
  93.     if (DSpStartup == nil)
  94.         FatalError("This game requires DrawSprocket.");
  95.  
  96.     if (ISpInit == nil)
  97.         FatalError("This game requires InputSprocket.");
  98.  
  99. #if !GENERATINGPOWERPC
  100.     // require InputSprocket 1.3.0 for 68k
  101.     inputSprocketVersion = * (UInt32 *) &(ISpGetVersion());
  102.     if (inputSprocketVersion < 0x01300000)
  103.         FatalError("This game requires InputSprocket 1.3");
  104. #endif
  105.     
  106.     //•    Reseed the random number generator
  107.     qd.randSeed =  TickCount();
  108.  
  109.     startupModifiers = EventInit();
  110.     gNetSprocketPresent = InitNetworking();
  111.  
  112.     MenuInit();
  113.  
  114.     GraphicsInit(startupModifiers);
  115.     SoundHandlerInit();
  116.     RedbookHandlerInit();
  117.     
  118.     //•    Run the game
  119.     EventLoop();
  120.  
  121.     ShutdownMoviePlayback();
  122.  
  123.     //•    Shut down the handlers and quit
  124.     SoundHandlerReset();
  125.     GraphicsReset();
  126.  
  127.     if (gNetSprocketPresent)
  128.         ShutdownNetworking();
  129.     
  130.     ISpStop();
  131.  
  132.     FlushEvents(everyEvent, 0);
  133.     ExitToShell();
  134. }
  135.  
  136. //•    --------------------    main
  137.  
  138. static void
  139. ToolboxInit(void)
  140. {
  141.     MaxApplZone();
  142.  
  143.     InitGraf(&qd.thePort);
  144.     InitFonts();
  145.     InitWindows();
  146.     InitMenus();
  147.     TEInit();
  148.     InitDialogs(nil);
  149.     InitCursor();
  150.  
  151.     //•    Initialize the Quicktime Movie Toolbox
  152.     EnterMovies();
  153.  
  154.     //•    Flush out mouse and keyboard events.  This prevents some things like clicking through
  155.     //•    to the Finder while the app is launching, etc.
  156.     FlushEvents(mDownMask | keyDownMask | autoKeyMask, 0);
  157. }
  158.