apophysis/2.02g/Source/RenderThread.pas

184 lines
4.6 KiB
ObjectPascal
Raw Normal View History

2005-01-22 02:46:14 -05:00
{
Flame screensaver Copyright (C) 2002 Ronald Hordijk
Apophysis Copyright (C) 2001-2004 Mark Townsend
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
unit RenderThread;
interface
uses
Classes, windows, Messages, Graphics,
2005-02-06 04:14:17 -05:00
controlPoint, Render, Render32, Render64, RenderMM;
2005-01-22 02:46:14 -05:00
const
WM_THREAD_COMPLETE = WM_APP + 5437;
WM_THREAD_TERMINATE = WM_APP + 5438;
type
TRenderThread = class(TThread)
private
2005-01-29 06:09:50 -05:00
FRenderer: TBaseRenderer;
2005-01-22 02:46:14 -05:00
FOnProgress: TOnProgress;
FCP: TControlPoint;
2005-02-06 04:14:17 -05:00
Fcompatibility: Integer;
FMaxMem: int64;
procedure Render;
function GetNrSlices: integer;
function GetSlice: integer;
procedure Setcompatibility(const Value: Integer);
procedure SetMaxMem(const Value: int64);
2005-01-22 02:46:14 -05:00
public
TargetHandle: HWND;
2005-02-06 04:14:17 -05:00
2005-01-22 02:46:14 -05:00
constructor Create;
destructor Destroy; override;
procedure SetCP(CP: TControlPoint);
function GetImage: TBitmap;
2005-02-06 04:14:17 -05:00
procedure Execute; override;
2005-01-22 02:46:14 -05:00
procedure Terminate;
2005-01-22 02:46:14 -05:00
property OnProgress: TOnProgress
read FOnProgress
write FOnProgress;
2005-02-06 04:14:17 -05:00
property Slice: integer
read GetSlice;
property NrSlices: integer
read GetNrSlices;
property MaxMem: int64
read FMaxMem
write SetMaxMem;
property compatibility: Integer
read Fcompatibility
write Setcompatibility;
2005-01-22 02:46:14 -05:00
end;
implementation
uses
Math, Sysutils;
{ TRenderThread }
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
2005-01-22 02:46:14 -05:00
destructor TRenderThread.Destroy;
begin
if assigned(FRenderer) then
FRenderer.Free;
2005-01-22 02:46:14 -05:00
inherited;
end;
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
2005-01-22 02:46:14 -05:00
function TRenderThread.GetImage: TBitmap;
begin
Result := nil;
if assigned(FRenderer) then
Result := FRenderer.GetImage;
2005-01-22 02:46:14 -05:00
end;
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
2005-01-22 02:46:14 -05:00
procedure TRenderThread.SetCP(CP: TControlPoint);
begin
FCP := CP;
end;
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
2005-01-22 02:46:14 -05:00
constructor TRenderThread.Create;
begin
2005-02-06 04:14:17 -05:00
MaxMem := 0;
2005-01-22 02:46:14 -05:00
FreeOnTerminate := False;
inherited Create(True); // Create Suspended;
end;
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
2005-01-22 02:46:14 -05:00
procedure TRenderThread.Render;
begin
if assigned(FRenderer) then
FRenderer.Free;
2005-01-22 02:46:14 -05:00
2005-02-06 04:14:17 -05:00
if MaxMem = 0 then begin
FRenderer := TRenderer64.Create;
end else begin
FRenderer := TRendererMM64.Create;
FRenderer.MaxMem := MaxMem
end;
FRenderer.SetCP(FCP);
FRenderer.compatibility := compatibility;
FRenderer.OnProgress := FOnProgress;
Frenderer.Render;
2005-01-22 02:46:14 -05:00
end;
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
2005-01-22 02:46:14 -05:00
procedure TRenderThread.Execute;
begin
2005-02-06 04:14:17 -05:00
Render;
2005-01-22 02:46:14 -05:00
if Terminated then
PostMessage(TargetHandle, WM_THREAD_TERMINATE, 0, 0)
else
PostMessage(TargetHandle, WM_THREAD_COMPLETE, 0, 0);
end;
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
procedure TRenderThread.Terminate;
begin
inherited Terminate;
if assigned(FRenderer) then
2005-02-06 04:14:17 -05:00
FRenderer.Stop;
end;
///////////////////////////////////////////////////////////////////////////////
function TRenderThread.GetNrSlices: integer;
begin
if assigned(FRenderer) then
Result := FRenderer.Nrslices
else
Result := 1;
end;
///////////////////////////////////////////////////////////////////////////////
function TRenderThread.GetSlice: integer;
begin
if assigned(FRenderer) then
Result := FRenderer.Slice
else
Result := 1;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TRenderThread.Setcompatibility(const Value: Integer);
begin
Fcompatibility := Value;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TRenderThread.SetMaxMem(const Value: int64);
begin
FMaxMem := Value;
end;
2005-02-06 04:14:17 -05:00
///////////////////////////////////////////////////////////////////////////////
2005-01-22 02:46:14 -05:00
end.