1
0
mirror of https://github.com/moparisthebest/Simba synced 2025-02-07 02:30:19 -05:00

Fixed #83 relating to bitmap targets. Created a new TTarget extension

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@500 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
BenLand100 2010-01-30 17:01:28 +00:00
parent 78a354ecea
commit 92ff79e17c
2 changed files with 54 additions and 4 deletions

View File

@ -315,10 +315,10 @@ begin
//writeln('d1:'+inttostr(length(maze)));
//writeln('d2:'+inttostr(length(maze[0])));
writeln('preparing to solve maze');
//thin(input,start.x,start.y,finish.x,finish.y,length(input),length(input[0]));
thin(input,start.x,start.y,finish.x,finish.y,length(input),length(input[0]));
writeln('thinned the maze');
//writeln('start: (' + inttostr(start.x) + ',' + inttostr(start.y) + ') finish: (' + inttostr(finish.x) + ',' + inttostr(finish.y) + ')');
//all_paths:= flood(input,start.x,start.y,finish.x,finish.y,length(input),length(input[0]));
all_paths:= flood(input,start.x,start.y,finish.x,finish.y,length(input),length(input[0]));
writeln('found all possible paths');
jills_routes:= Length(all_paths) - 1;
max_pos:= 0;

View File

@ -75,11 +75,23 @@ interface
procedure GetTargetDimensions(var w, h: integer); override;
function ReturnData(xs, ys, width, height: Integer): TRetData; override;
private
protected
rgb: prgb32;
freedata : boolean;
w,h: integer;
end;
TBitmapTarget = class(TTarget)
public
constructor Create(bitmap: TMufasaBitmap);
destructor Destroy; override;
procedure GetTargetDimensions(var w, h: integer); override;
function ReturnData(xs, ys, width, height: Integer): TRetData; override;
protected
bitmap: TMufasaBitmap;
end;
{ Implements a target that is a Window in the operating system. This class is abstract, i.e.,
| the actual os-specific Implementation of TWindow is in one of the os units. }
@ -216,6 +228,7 @@ interface
function SetTarget(bmp : TMufasaBitmap) : integer; overload;
function SetTarget(name: string; initargs: pointer): integer; overload;
function TargetValid: Boolean;
procedure BitmapDestroyed(Bitmap : TMufasaBitmap);
function GetColor(x,y : integer) : TColor;
function ReturnData(xs, ys, width, height: Integer): TRetData;
@ -428,9 +441,19 @@ function TIOManager_Abstract.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer;
begin
result:= SetImageTarget(TRawTarget.Create(ArrPtr,Size.X,Size.Y));
end;
//Only checks the current image target, not targets that might be in the indexes...
procedure TIOManager_Abstract.BitmapDestroyed(Bitmap : TMufasaBitmap);
begin
if image is TBitmapTarget then
if TBitmapTarget(image).bitmap = Bitmap then
raise Exception.Create('Target bitmap was destroyed!');
end;
function TIOManager_Abstract.SetTarget(bmp : TMufasaBitmap) : integer;
begin
result:= SetImageTarget(TRawTarget.Create(bmp.FData,bmp.width,bmp.height));
result:= SetImageTarget(TBitmapTarget.Create(bmp));
bmp.OnDestroy:= @BitmapDestroyed;
end;
function TIOManager_Abstract.SetTarget(name: string; initargs: pointer): integer;
@ -710,6 +733,33 @@ begin
Inc(result.Ptr, ys * result.RowLen + xs);
end;
//***implementation*** TBitmapTarget
constructor TBitmapTarget.Create(bitmap: TMufasaBitmap);
begin
inherited Create;
self.bitmap:= bitmap;
end;
destructor TBitmapTarget.Destroy;
begin
inherited Destroy;
end;
procedure TBitmapTarget.GetTargetDimensions(var w, h: integer);
begin
h:= bitmap.Height;
w:= bitmap.Width;
end;
function TBitmapTarget.ReturnData(xs, ys, width, height: Integer): TRetData;
begin
result.Ptr := bitmap.FData;
result.RowLen:= bitmap.Width;
result.IncPtrWith:= result.RowLen - width;
Inc(result.Ptr, ys * result.RowLen + xs);
end;
//***implementation*** TEIOS_Controller
constructor TEIOS_Controller.Create();