home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!hsdndev!news.cs.umb.edu!casim.bio.umb.edu!etter
- From: etter@casim.bio.umb.edu (Ron J. Etter)
- Newsgroups: comp.sys.mac.programmer
- Subject: Foreground-background-foreground switch doubles speed?
- Message-ID: <1992Dec23.162004.9820@cs.umb.edu>
- Date: 23 Dec 92 16:20:04 GMT
- Sender: news@cs.umb.edu (USENET News System)
- Organization: UMass/Boston
- Lines: 71
- X-Xxmessage-Id: <A75DFD0715011AC9@casim.bio.umb.edu>
- X-Xxdate: Wed, 23 Dec 92 11: 24:55 GMT
- Nntp-Posting-Host: casim.bio.umb.edu
- X-Useragent: Nuntius v1.1.1d16
-
- I am writing a simulation program in Think Pascal and have encountered
- some strange (I think) behavior in my code (most likely) or possibly
- WaitNextEvent. In short, the problem is that the speed of the program
- while in the foreground (with no other applications running) is almost
- twice as fast if it has been sent to the background and then brought
- back to the foreground compared to just leaving it in the foreground. I
- don`t understand why simply switching the program in and out of the
- background should influence the foreground speed. I`d appreciate it if
- someone could tell me what I am doing wrong or if they have experienced
- a similar problem. Below is the source and a description of how the
- code works.
-
- During each loop of the simulation, a function is called to determine if
- the user has pressed a stop button on the screen. The stop function
- contains a call to WaitNextEvent so the program can be switched between
- foreground and background. It is background enabled. Below is the
- code. SleepTicks is set to 1 at startup. Thanks in advance for any
- help you might provide.
-
-
- {-------------------------------------------------------------------}
- function StopRun: boolean;
- const
- mousemovedmessage = $FA;
- SuspendResumeMessage = 1;
- ResumeMask = 1;
- var
- Event: EventRecord;
- wh: point;
- stop: boolean;
- begin
- stop := false;
- if WaitNextEvent(EveryEvent, Event, SleepTicks, nil) then
- begin
- case Event.what of
- KeyDown:
- Stop := true;
- MouseDown:
- begin
- wh := Event.Where;
- GlobalToLocal(wh);
- stop := PtInRgn(wh, StopRgn[modeltype]);
- end;
- app4Evt:
- case BSR(event.message, 24) of
- MouseMovedMessage:
- ;
- SuspendResumeMessage:
- if BAND(event.message, ResumeMask) <> 0 then
- begin{Resume event}
- SleepTicks := 1;
- DrawWindow;
- end
- else
- begin {Suspend event}
- SleepTicks := 2;
- end;
- end; {case BSR}
- otherwise {Do nothing}
- end; {case}
- end; {waitNextEvent}
-
- if stop then
- begin
- InvertRgn(StopRgn[modeltype]);
- Delay(5, ticks);
- InvertRgn(StopRgn[modeltype]);
- end;
- StopRun := stop;
- end;
- {--------------------------------------------------------------------}
-