[Glxtreem-commits] GLXtreem/Source GLXTimer.pas,1.1,1.2
Brought to you by:
andreaz
|
From: <dan...@us...> - 2004-03-11 01:34:22
|
Update of /cvsroot/glxtreem/GLXtreem/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18104/Source Modified Files: GLXTimer.pas Log Message: Changed Timer so that multiple GLXDraws can subscribe to the same Timer Index: GLXTimer.pas =================================================================== RCS file: /cvsroot/glxtreem/GLXtreem/Source/GLXTimer.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GLXTimer.pas 10 Mar 2004 16:55:30 -0000 1.1 --- GLXTimer.pas 11 Mar 2004 01:16:00 -0000 1.2 *************** *** 32,36 **** { The type of event that is called by the timer. } ! Type TGLXTimerEvent = procedure(Sender: TObject; FrameTime: Single) of object; --- 32,38 ---- { The type of event that is called by the timer. } ! Type ! TGLXTimerEvent = procedure(Sender: TObject; FrameTime: Single) of object; ! PGLXTimerEvent = ^TGLXTimerEvent; *************** *** 56,62 **** FInterval : Cardinal; FInitialized : Boolean; ! ! // Event ! FOnTimer : TGLXTimerEvent; // Time --- 58,62 ---- FInterval : Cardinal; FInitialized : Boolean; ! FEventList : TList; // Time *************** *** 96,99 **** --- 96,105 ---- destructor Destroy; override; + { TGLXDraw or other objects that want to be notified by the Timer subscribe here. } + procedure Subscribe(Event:TGLXTimerEvent); + { TGLXDraw or other objects that no longer want to be notified by the Timer unsubscribe here. } + procedure UnSubscribe(Event:TGLXTimerEvent); + + { The current framerate, is weighted over the last 500 ms. } property FrameRate : Integer read FFrameRate; *************** *** 109,114 **** { This tells if the timer shall be disabled when the window loses focus. } property ActiveOnly : Boolean read FActiveOnly write SetActiveOnly; - { The main timer event, this is called with the interval in milliseconds. } - property OnTimer : TGLXTimerEvent read FOnTimer write FOnTimer; end; --- 115,118 ---- *************** *** 123,126 **** --- 127,131 ---- begin inherited Create(AOwner); + FEventList := TList.Create; FActiveOnly:= True; FActive := True; *************** *** 142,153 **** Finalize; Application.UnHookMainWindow(AppProc); inherited ; end; //------------------------------------------------------------------------------ procedure TGLXTimer.AppIdle(Sender: TObject; var Done: Boolean); ! Var FrameTime, FrameRateTime: DWord; ! var Compensate: DWord; begin Done := False; --- 147,191 ---- Finalize; Application.UnHookMainWindow(AppProc); + FEventList.Free; inherited ; end; + //------------------------------------------------------------------------------ + procedure TGLXTimer.Subscribe(Event:TGLXTimerEvent); + var + NewEvent : PGLXTimerEvent; + begin + New(NewEvent); + NewEvent^:=Event; + FEventList.Add(NewEvent); + end; + + //------------------------------------------------------------------------------ + procedure TGLXTimer.UnSubscribe(Event:TGLXTimerEvent); + var + i : Integer; + TestEvent : TGLXTimerEvent; + begin + if FEventList.Count>0 then begin + i:=0; + repeat + TestEvent:=PGLXTimerEvent(FEventList.Items[i])^; + if (@TestEvent=@Event) then begin + Dispose(PGLXTimerEvent(FEventList.Items[i])); + FEventList.Delete(i); + i := 0; + end else Inc(i); + until (i>=FEventList.Count); + end; + end; + //------------------------------------------------------------------------------ procedure TGLXTimer.AppIdle(Sender: TObject; var Done: Boolean); ! var ! FrameTime, FrameRateTime: DWord; ! Compensate: DWord; ! i: Integer; ! Event : TGLXTimerEvent; begin Done := False; *************** *** 168,172 **** end; ! if Assigned(FOnTimer) then FOnTimer(Self, (FFrameTimes + FrameTime) / 2); FFrameTimes:=FrameTime; --- 206,213 ---- end; ! for i:=0 to FEventList.Count-1 do begin ! Event:=PGLXTimerEvent(FEventList.Items[i])^; ! if Assigned(Event) then Event(Self, (FFrameTimes + FrameTime) / 2); ! end; FFrameTimes:=FrameTime; |