home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Think Class Libraries / SAT-TCL 1.0b2 / CGameClasses ƒ / GameIntf.p < prev   
Encoding:
Text File  |  1996-06-03  |  5.7 KB  |  165 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {    GameIntf.p                                                                                                    }
  4. {}
  5. {    Interface file for the classes which optimize event processing for games.         }
  6. {    These classes are based on the concept of a "Game Director", which when        }
  7. {    playing the game, becomes the gopher and handles all user control events.        }
  8. {    In the Dawdle method of this director, animation calls are made etc.                }
  9. {}
  10. {    For a real game, you may want to override the Game Switchboard further,    }
  11. {    so that mouse clicks, instead of being dispatched to pull down menus etc.,        }
  12. {    are sent to the gopher as triggers for the ships laser guns (say).                    }
  13. {}
  14. {    Game Classes                                                                                                }
  15. {    Copyright © 1996 by Patrick C Hew. All rights reserved.                                }
  16. {}
  17. {    THINK Class Library                                                                                                                                                                                }
  18. {    Copyright © 1989 by Symantec Corporation.  All rights reserved.                    }
  19. {}
  20. {    Revision History:                                                                                            }
  21. {}
  22. {    Version:    1.00 for TCL 1.1.2                                                                        }
  23. {    Date:         02 June 1996                                                                                }
  24. {    Author:        Patrick C Hew     <phew@ucc.gu.uwa.edu.au>                                    }
  25. {    Notes:        Initial release - CFastApp and CFastSwitchboard .                            }
  26. {}
  27. {****************************************************}
  28.  
  29.  
  30. unit GameIntf;
  31.  
  32. interface
  33.  
  34.     uses
  35.         TCL;
  36.  
  37. {****************************************************}
  38. {}
  39. {    CGameApp                                                                                                        }
  40. {}
  41. {    Application class, optimized to the needs of gameplay.                                    }
  42. {}
  43. {****************************************************}
  44.  
  45.     type
  46.         CGameApp = object(CApplication)
  47.  
  48.                 { Flag for whether we are in game mode or not. }
  49.                 isInGameMode: Boolean;
  50.  
  51.                 { Flag for whether to give time to background events during game mode. }
  52.                 isBkgdFriendlyInGameMode: Boolean;
  53.  
  54.                 { Private pointer to the switchboard. }
  55.                 itsGameSwitchboard: CGameSwitchboard;
  56.  
  57.                 { Initializes a Game Application object. }
  58.                 procedure IGameApp (extraMasters: Integer;
  59.                                             aRainyDayFund: Longint;
  60.                                             aCriticalBalance: Longint;
  61.                                             aToolboxBalance: Longint);
  62.  
  63.                 { Creates the single Game Switchboard object used by the application. }
  64.                 { We store a pointer for our own use. }
  65.                 procedure MakeSwitchboard;
  66.                 override;
  67.  
  68.                 { It is expected that there is a Game Director, handling game animation etc. }
  69.                 { in its Dawdle method. This method streamlines the call during gameplay. }
  70.                 { It is assumed that during gameplay, the following hold :-    }
  71.                 { 1    There are no memory emergencies to correct, so the Rainy Day memory }
  72.                 {        fund does not need to be reset. It will, in any case, be reset when we }
  73.                 {        leave game mode. }
  74.                 { 2    The Game Director is the gopher. }
  75.                 { 3    Only the Game Director needs to receive a Dawdle method. Reasonable, }
  76.                 {        unless you have a special director reporting to the Game Director; for }
  77.                 {        instance, a window set up for controls. In such a case, you may want }
  78.                 {        to make the gopher send a Dawdle message to its supervisor. }
  79.                 { 4    There are no other Dawdle chores to perform. }
  80.                 procedure Idle (macEvent: EventRecord);
  81.                 override;
  82.  
  83.                 { Streamlined processing of events during gameplay. }
  84.                 { It is assumed that during gameplay, the following hold :-                                }
  85.                 { 1    The desktop does not need to be cleaned up. This holds if there are no            }
  86.                 {        floating windows.                                                                                        }
  87.                 { 2    There are no urgent chores to be performed.                                                }
  88.                 { 3    There is no switching to or from desk accessories.                                    }
  89.                 procedure Process1Event;
  90.                 override;
  91.  
  92.                 { Turn off game mode before quitting. }
  93.                 procedure DoCommand (theCommand: LongInt);
  94.                 override;
  95.  
  96.                 { Return whether or not we are in game mode. }
  97.                 function GetInGameMode: Boolean;
  98.  
  99.                 { Configure for fast event processing. }
  100.                 procedure BeginGameMode;
  101.  
  102.                 { Return to normal event processing. }
  103.                 procedure EndGameMode;
  104.  
  105.                 { Get the state of background friendliness in game mode. }
  106.                 function GetBkgdFriendlyInGameMode: Boolean;
  107.  
  108.                 { Set the background friendliness in game mode. }
  109.                 procedure SetBkgdFriendlyInGameMode (aBkgdFriendlyInGameMode: Boolean);
  110.  
  111.             end; { CGameApp }
  112.  
  113.  
  114. {****************************************************}
  115. {}
  116. {    CGameSwitchboard                                                                                        }
  117. {}
  118. {    Switchboard class, optimized to the needs of gameplay.                                    }
  119. {}
  120. {    For a real game, you may want to override the Game Switchboard further,    }
  121. {    so that mouse clicks, instead of being dispatched to pull down menus etc.,        }
  122. {    are sent to the gopher as triggers for the ships laser guns (say).                    }
  123. {}
  124. {****************************************************}
  125.  
  126.     type
  127.         CGameSwitchboard = object(CSwitchboard)
  128.  
  129.                 { Flag for whether we are in game mode or not. }
  130.                 { This flag should always synchronize with that in the CGameApp. }
  131.                 { It is stored locally for speed. }
  132.                 isInGameMode: Boolean;
  133.  
  134.                 { Flag for whether to give time to background events. }
  135.                 isBackgroundFriendly: Boolean;
  136.  
  137.                 { Initialize a Game Switchboard object. }
  138.                 procedure IGameSwitchboard;
  139.  
  140.                 { Set the game mode. }
  141.                 procedure SetInGameMode (aInGameMode: Boolean);
  142.  
  143.                 { Get the current background friendliness. }
  144.                 function GetBackgroundFriendly: Boolean;
  145.  
  146.                 { Set the background friendliness. }
  147.                 procedure SetBackgroundFriendly (aBackgroundFriendly: Boolean);
  148.  
  149.                 { Gets an event, subject to background friendliness. }
  150.                 function GetAnEvent (var macEvent: EventRecord): Boolean;
  151.                 override;
  152.  
  153.                 { Process event, subject to the requirement that a Dawdle message be }
  154.                 { sent to the Game Director on each iteration of the event loop. }
  155.                 { It is assumed that during game play, the Game Director has sole }
  156.                 { control the appearance of the mouse; that is, the automatic configuring }
  157.                 { of the mouse by TCL can be omitted. }
  158.                 procedure ProcessEvent;
  159.                 override;
  160.  
  161.             end; { CGameSwitchboard }
  162.  
  163. implementation
  164.  
  165. end. { GameIntf }