home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20251 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  2.7 KB

  1. Path: sparky!uunet!think.com!hsdndev!news.cs.umb.edu!casim.bio.umb.edu!etter
  2. From: etter@casim.bio.umb.edu (Ron J. Etter)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Foreground-background-foreground switch doubles speed?
  5. Message-ID: <1992Dec23.162004.9820@cs.umb.edu>
  6. Date: 23 Dec 92 16:20:04 GMT
  7. Sender: news@cs.umb.edu (USENET News System)
  8. Organization: UMass/Boston
  9. Lines: 71
  10. X-Xxmessage-Id: <A75DFD0715011AC9@casim.bio.umb.edu>
  11. X-Xxdate: Wed, 23 Dec 92 11: 24:55 GMT
  12. Nntp-Posting-Host: casim.bio.umb.edu
  13. X-Useragent: Nuntius v1.1.1d16
  14.  
  15. I am writing a simulation program in Think Pascal and have encountered 
  16. some strange (I think) behavior in my code (most likely) or possibly 
  17. WaitNextEvent.  In short, the problem is that the speed of the program 
  18. while in the foreground (with no other applications running) is almost 
  19. twice as fast if it has been sent to the background and then brought 
  20. back to the foreground compared to just leaving it in the foreground.  I 
  21. don`t understand why simply switching the program in and out of the 
  22. background should influence the foreground speed.  I`d appreciate it if 
  23. someone could tell me what I am doing wrong or if they have experienced 
  24. a similar problem.  Below is the source and a description of how the 
  25. code works.  
  26.  
  27. During each loop of the simulation, a function is called to determine if 
  28. the user has pressed a stop button on the screen.  The stop function 
  29. contains a call to WaitNextEvent so the program can be switched between 
  30. foreground and background.  It is background enabled.   Below is the
  31. code.  SleepTicks is set to 1 at startup. Thanks in advance for any 
  32. help you might provide. 
  33.  
  34.  
  35. {-------------------------------------------------------------------}
  36.     function StopRun: boolean;
  37.         const
  38.             mousemovedmessage = $FA;
  39.             SuspendResumeMessage = 1;
  40.             ResumeMask = 1;
  41.         var
  42.             Event: EventRecord;
  43.             wh: point;
  44.             stop: boolean;
  45. begin
  46.     stop := false;
  47.     if WaitNextEvent(EveryEvent, Event, SleepTicks, nil) then
  48.         begin
  49.             case Event.what of
  50.                 KeyDown: 
  51.                     Stop := true;
  52.                 MouseDown: 
  53.                     begin
  54.                         wh := Event.Where;
  55.                         GlobalToLocal(wh);
  56.                     stop := PtInRgn(wh, StopRgn[modeltype]);
  57.                         end;
  58.                 app4Evt: 
  59.                     case BSR(event.message, 24) of
  60.                         MouseMovedMessage: 
  61.                             ;
  62.                         SuspendResumeMessage: 
  63.                 if BAND(event.message, ResumeMask) <> 0 then
  64.                             begin{Resume event}
  65.                                 SleepTicks := 1;
  66.                                 DrawWindow;
  67.                                 end
  68.                             else
  69.                             begin {Suspend event}
  70.                                 SleepTicks := 2;
  71.                                 end;
  72.                     end; {case BSR}
  73.                 otherwise {Do nothing}
  74.             end; {case}
  75.         end; {waitNextEvent}
  76.  
  77.         if stop then
  78.             begin
  79.                 InvertRgn(StopRgn[modeltype]);
  80.                 Delay(5, ticks);
  81.                 InvertRgn(StopRgn[modeltype]);
  82.             end;
  83.         StopRun := stop;
  84.     end;
  85. {--------------------------------------------------------------------}
  86.