For FastDrawTransparent, will it take all of the source bitmap, and put at x,y on the target bitmap? So I need to make the first bitmap the client, do BitmapFromClient to get a section of the first bitmap to be the second bitmap, then FastDrawTransparent the whole of the second bitmap to a certain position on the third bitmap.
If I make a bitmap the target, and then do FastSetPixel on the bitmap, is the target also updated?
Edit: so I finally installed Simba etc, and made my crappy gedit code compile, and it looks like almost everything is working except FastSetPixel. Does FastSetPixel not work when bmp is target?
program new;
{$Define SMART}
{$i srl\srl.scar}
{$i Reflection\reflection.simba}
const
CTWBOn = true; //Make true to help out CTWB
color_Black = 65536;
CTWBPath = AppPath + 'CTWB\';
var
CircleOffsets: TPointArray;
//LordSaturn
{function }procedure CTWBCollectDots(Bitmap: integer);//: TPointArray;
var
SearchColors: TIntegerArray;
OtherColors: T2DIntegerArray;
i, j, Hi, x, y, leftDev, rightDev, L, LTop: Integer;
ATPA: T2DPointArray;
TPA, FoundColorsTPA: TPointArray;
begin //red white yellow
//Freeze;
SearchColors := [217, 188, 14869218, 12961221, 56797, 52428];
SetLength(OtherColors, 3);
OtherColors[0] := [3553023, 789758, 2105598, 395004, 237, 206, 65536, 217, 188]; //red
OtherColors[1] := [16711422, 15527148, 13816530, color_Black, 14869218, 12961221]; //white
OtherColors[2] := [1179390, 195836, 62965, 56797, 60909, 52428, color_Black]; //yellow
LTop := 999;
//SetLength(Result, LTop);
for i := 0 to 5 do
begin
if FindColors(TPA, SearchColors[i], 14, 14, 113, 113) then
FoundColorsTPA := CombineTPA(FoundColorsTPA, TPA); //if one color is covered, we will find the other
if (i mod 2 = 1) then
begin
ATPA := TPAtoATPAEx(FoundColorsTPA, 1, 0);
Hi := High(ATPA);
for j := 0 to Hi do
begin
//if (GetColor(ATPA[j][0].x, ATPA[j][0].y+1) = color_Black) then //it is a dot
begin //begin finding the whole dot
leftDev := 0;
if (GetColor(ATPA[j][0].x-1, ATPA[j][0].y) = color_Black) then //finding the left bound of the dot
leftDev := -1
else
if (GetColor(ATPA[j][0].x-2, ATPA[j][0].y) = color_Black) then
leftDev := -2
else
if (GetColor(ATPA[j][0].x-1, ATPA[j][0].y) = 217) then
leftDev := -1;
rightDev := 0;
if (GetColor(ATPA[j][0].x+1, ATPA[j][0].y) = color_Black) then //finding the right bound of the dot
rightDev := 1
else
if (GetColor(ATPA[j][0].x+2, ATPA[j][0].y) = color_Black) then
rightDev := 2
else
if (GetColor(ATPA[j][0].x+1, ATPA[j][0].y) = 188) then
rightDev := 1;
for x := ATPA[j][0].x + leftDev to ATPA[j][0].x + rightDev do
for y := ATPA[j][0].y - 3 to ATPA[j][0].y + 1 do
begin
if ((x = ATPA[j][0].x + leftDev) and (y = ATPA[j][0].y - 3)) or //ignore 4 corners
((x = ATPA[j][0].x + leftDev) and (y = ATPA[j][0].y + 1)) or
((x = ATPA[j][0].x + rightDev) and (y = ATPA[j][0].y - 3)) or
((x = ATPA[j][0].x + rightDev) and (y = ATPA[j][0].y + 1)) then
Continue;
if InIntArray(OtherColors[i/2], GetColor(x, y)) then
begin
if (L = LTop) then
begin
LTop := LTop*2;
//SetLength(Result, LTop);
end;
FastSetPixel(Bitmap, x, y, 0); //Result[L] := Point(x, y);
Inc(L);
end;
end;
end;
end;
SetLength(FoundColorsTPA, 0);
end;
end;
//SetLength(Result, L);
//Unfreeze;
end;
//Determines whether TPoint has at least Threshold color_BlackPoints in radius 7 around it
function CTWBIsSymbolCenter (ThePoint: TPoint; Threshold: integer): boolean;
var
i, Score: integer;
begin
result := false;
//if point is near the edge of the bitmap, doing a GetColor 7 away will result in out of range
//also, we only care about circle edge points 14 pixels in from the edges, so skip it
if (ThePoint.x < 7) or (ThePoint.x > 121) or (ThePoint.y < 7) or (ThePoint.y > 121) then
exit;
Score := 0;
for i := 0 to 39 do
begin
if GetColor(ThePoint.x + CircleOffsets[i].x, ThePoint.y + CircleOffsets[i].y) = color_Black then
begin
Inc(Score);
if Score > Threshold then
begin
result := true;
exit;
end;
end;
end;
end;
procedure CTWBMakeClean(MyTile: TPoint);
var
CAB: TBox; //CurrentAreaBox
Chunks, Corners, Corners2, BlackPixels, CircleCenters, CopiedChunks: TPointArray;
t,i, i2, i3, counter, lengthx, lengthy, Score, MainBitmap, ChunkBitmap, FragmentBitmap, NewTarget, OldTarget: integer;
CircleSliceOffsets, CircleSliceWidths: array of integer;
TmpPoint: TPoint;
TmpString: String;
Skip: Boolean;
ChunksTiles, FragmentsTiles, FragmentsPixels, FragmentsPos: TBoxArray;
begin
t := getsystemtime;
//Get tile bounds of CurrentAreaBox
CAB := IntToBox(MyTile.x - 12, MyTile.y + 12, MyTile.x + 12, MyTile.y - 12);//Make sure this does not normalize
//CurrentAreaBox is spread over 1, 2, or 4 chunks, so these arrays are set to 4
//In these arrays, [0] corresponds to the chunk that the top left corner of CAB is in,
//[1] is top right, [2] is bottom left, [3] is bottom right. This defined in Corners
Corners := [Point(CAB.x1, CAB.y1), Point(CAB.x2, CAB.y1), Point(CAB.x1, CAB.y2), Point(CAB.x2, CAB.y2)];
SetArrayLength(Chunks, 4);
SetArrayLength(ChunksTiles, 4);
SetArrayLength(FragmentsTiles, 4);
SetArrayLength(FragmentsPixels, 4);
SetArrayLength(FragmentsPos, 4);
//Contains offsets between the center and 40 outline points of circle with raidus 7 (ie a symbol)
CircleOffsets := [Point(0, 7), Point(1, 7), Point(2, 7), Point(3, 6), Point(4, 6), Point(5, 5), Point(6, 4),
Point(6, 3), Point(7, 2), Point(7, 1), Point(7, 0), Point(7, -1), Point(7, -2), Point(6, -3), Point(6, -4),
Point(5, -5), Point(4, -6), Point(3, -6), Point(2, -7), Point(1, -7), Point(0, -7), Point(-1, -7), Point(-2, -7),
Point(-3, -6), Point(-4, -6), Point(-5, -5), Point(-6, -4), Point(-6, -3), Point(-7, -2), Point(-7, -1),
Point(-7, 0), Point(-7, 1), Point(-7, 2), Point(-6, 3), Point(-6, 4), Point(-5, 5), Point(-4, 6), Point(-3, 6),
Point(-2, 7), Point(-1, 7)];
CircleSliceOffsets := [-2, -4, -5, -6, -6, -7, -7, -7];
CircleSliceWidths := [5, 9, 11, 13, 13, 15, 15, 15];
//Using these conventions when working with tiles and pixels
//Pixels have 0,0 in the top left
//Tiles have 0,0 in the bottom left
//Chunks have 0,0 in the bottom left (the are 100x100 pixels, but they deliberately start and end on tiles so that no tile
//is spread over multiple chunks (25x25 tiles), therefore, they follow the tile convention)
//X1,Y1 is always top left, X2,Y2 is always bottom right
//For pixels, Y1 is lower than Y2. For tiles and chunks, Y2 is lower than Y1
for i:= 0 to 3 do
begin
//Find the Chunk that the corresponding corner of CAB is in
Chunks[i] := Point(((Corners[i].x-2044) div 25),((Corners[i].y-861) div 25));
//Find the tile bounds of that chunk
ChunksTiles[i] := IntToBox(2044+Chunks[i].x*25, 885+Chunks[i].y*25, 2068+Chunks[i].x*25, 861+Chunks[i].y*25);//No normalize
//These are the opposite corners of Corners
Corners2 := [Point(ChunksTiles[i].x2, ChunksTiles[i].y2), Point(ChunksTiles[i].x1, ChunksTiles[i].y2), Point(ChunksTiles
[i].x2, ChunksTiles[i].y1), Point(ChunksTiles[i].x1, ChunksTiles[i].y1)]; //yes normalize
//Find the intersection of the corresponding Corner of CAB and the opposite corner of the Chunk
//that contains the Corner of CAB. Also make X1 lower than X2, and Y1 higher than Y2 (tiles start from the bottom left)
FragmentsTiles[i] := IntToBox(Min(Corners[i].x,Corners2[i].x), Max(Corners[i].y,Corners2[i].y), Max(Corners[i].x,Corners2
[i].x), Min(Corners[i].y, Corners2[i].y));
//Find the pixel bounds (on MainBitmap) of thoses tiles
FragmentsPixels[i] := IntToBox(14+(FragmentsTiles[i].x1-(MyTile.x-12))*4, 14+((MyTile.y+12)-FragmentsTiles[i].y1)*4, 112-
((MyTile.x+12)-FragmentsTiles[i].x2)*4, 112-(FragmentsTiles[i].y2-(MyTile.y-12))*4);
//Find the pixel box in Chunk that fragment will be copied to
FragmentsPos[i] := IntToBox((FragmentsTiles[i].x1-ChunksTiles[i].x1)*4, (ChunksTiles[i].y1-FragmentsTiles[i].y1)*4,
(FragmentsTiles[i].x1-ChunksTiles[i].x1)*4 + (FragmentsPixels[i].x2 - FragmentsPixels[i].x1),
(ChunksTiles[i].y1-FragmentsTiles[i].y1)*4 + (FragmentsPixels[i].y2 - FragmentsPixels[i].y1));
end;
writeln('set arrays '+inttostr(getsystemtime-t));
t:=getsystemtime;
MainBitmap := BitmapFromClient(564, 21, 691, 148);
OldTarget := GetImageTarget;
SetTargetBitmap(MainBitmap);
NewTarget := GetImageTarget;
writeln('set target '+inttostr(getsystemtime-t));
t:=getsystemtime;
//0 out the dots
CTWBCollectDots(MainBitmap);
writeln('set dots '+inttostr(getsystemtime-t));
t:=getsystemtime;
//0 out the symbols
FindColors(BlackPixels, color_Black, 0, 0, 113, 113);
for i := 0 to High(BlackPixels) do
begin
//Start-Checking if this pixel is a part of a circle we already know about
Skip := false;
for i2 := 0 to High(CircleCenters) do
begin
lengthx := (BlackPixels[i].x-CircleCenters[i2].x);
lengthy := (BlackPixels[i].y-CircleCenters[i2].y);
counter := lengthx*lengthx + lengthy*lengthy;
if (counter < 54) and (counter >44) then
begin
Skip := true;
break;
end;
end;
//End-Checking if this pixel is a part of a circle we already know about
if not Skip then
begin
//Start- Hope the top 5 pixels of the symbol are uncovered
Score := 0;
if GetColor(BlackPixels[i].x+1, BlackPixels[i].y) = color_Black then
if GetColor(BlackPixels[i].x+2, BlackPixels[i].y) = color_Black then
if GetColor(BlackPixels[i].x+3, BlackPixels[i].y) = color_Black then
if GetColor(BlackPixels[i].x+4, BlackPixels[i].y) = color_Black then //pixel is top left of group horizontal 5
begin
TmpPoint := Point(BlackPixels[i].x+2, BlackPixels[i].y+7); //Center of possible circle;
if CTWBIsSymbolCenter(TmpPoint, 20) then //TmpPoint is probably the center of a symbol
begin
CircleCenters := CombineTPA(CircleCenters, [TmpPoint]);
Skip := true;
break;
end;
end;
//End- Hope the top 5 pixels of the symbol are uncovered
//Start- Bruteforce
if not Skip then
begin
for i2 := 0 to 39 do
begin
TmpPoint := Point(BlackPixels[i].x+CircleOffsets[i2].x, BlackPixels[i].y+CircleOffsets[i2].y);
if CTWBIsSymbolCenter(TmpPoint, 20) then
begin
CircleCenters := CombineTPA(CircleCenters, [TmpPoint]);
Skip := true;
break;
end;
end;
end;
//End- Bruteforce
end;
end;
writeln('find circles '+inttostr(getsystemtime-t));
t:=getsystemtime;
//now 0 out the circles (and contents)
for i := 0 to High(CircleCenters) do
begin
for i2:= 0 to 7 do
for i3 := 0 to CircleSliceWidths[i2] do
begin
if (CircleCenters[i].x > 6) and (CircleCenters[i].x < 122) and (CircleCenters[i].y > 6) and (CircleCenters[i].y < 122) then
begin
FastSetPixel(MainBitmap, 0, CircleCenters[i].x + CircleSliceOffsets[i2] + i3, CircleCenters[i].y-7+i2);
if i2 < 7 then
FastSetPixel(MainBitmap, 0, CircleCenters[i].x + CircleSliceOffsets[i2] + i3, CircleCenters[i].y+7-i2);
end;
end;
end;
//end of setting pixels on MainBitmap
writeln('set circles '+inttostr(getsystemtime-t));
t:=getsystemtime;
SetImageTarget(OldTarget);
FreeTarget(NewTarget);
OldTarget := GetImageTarget;
SetTargetBitmap(MainBitmap);
NewTarget := GetImageTarget;
writeln('set target '+inttostr(getsystemtime-t));
t:=getsystemtime;
SetLength(CopiedChunks,1);
Counter := 0;
CopiedChunks[0] := Point(-1,-1);
for i:= 0 to 3 do
begin
Skip := false;
TmpString := 'CleanChunk'+ Padz(IntToStr(Chunks[i].x),2)+'-'+Padz(IntToStr(Chunks[i].y),2);
//bug in here making it skip when i is 2 and 3
{ for i2 := 0 to High(CopiedChunks) do
begin
if ReadINI('CleanChunksDone', TmpString, CTWBPath + 'CTWBSVN\SVNCleanChunks.INI')='DONE' then
begin
Skip := true;
break;
end;
if ReadINI('CleanChunksDone', TmpString, CTWBPath + 'UserCleanChunks.INI')='DONE' then
begin
Skip := true;
break;
end;
if (Chunks[i].x = CopiedChunks[i2].x) and (Chunks[i].x = CopiedChunks[i2].x) then
begin
Skip := true;
break;
end;
end; }
if not Skip then
begin
SetArrayLength(CopiedChunks, counter+1);
CopiedChunks[Counter] := Chunks[i];
Inc(Counter);
TmpString := CTWBPath + TmpString +'.bmp';
if FileExists(TmpString) then
ChunkBitmap := LoadBitmap(TmpString)
else
ChunkBitmap := CreateBitmap(100,100);
FragmentBitmap := BitmapFromClient(FragmentsPixels[i].x1, FragmentsPixels[i].y1,
FragmentsPixels[i].x2, FragmentsPixels[i].y2);
SetTransparentColor(FragmentBitmap, 0);
FastDrawTransparent(FragmentsPos[i].x1, FragmentsPos[i].y1, FragmentBitmap, ChunkBitmap);
FreeBitmap(FragmentBitmap);
SaveBitmap(ChunkBitmap, TmpString);
FreeBitmap(ChunkBitmap);
end;
end;
writeln('make bmps '+inttostr(getsystemtime-t));
t:=getsystemtime;
SetImageTarget(OldTarget);
FreeTarget(NewTarget);
SaveBitmap(MainBitmap, AppPath+'poop.bmp');
FreeBitmap(MainBitmap);
end;
{*******************************************************************************
function CTWBGetMyPos: TTile;
By: BenLand100
Description: Returns the global tile position of your player.
*******************************************************************************}
function CTWBGetMyPos: TPoint;
var
me: Integer;
begin
me := SmartGetFieldObject(0, hook_static_MyPlayer);
Result.x := SmartGetFieldInt(0, hook_static_BaseX) + SmartGetFieldInt(me, hook_animable_PixelX) / 512;
Result.y := SmartGetFieldInt(0, hook_static_BaseY) + SmartGetFieldInt(me, hook_animable_PixelY) / 512;
SmartFreeObject(me);
if CTWBOn then
CTWBMakeClean(Result);
end;
var mypoint:tpoint;
t:integer;
begin
Smart_Server := 152;
Smart_Members := false;
Smart_signed := true;
Smart_SuperDetail := false;
SetUpSRL;
SetUpReflection;
HowManyPlayers := 1;
CurrentPlayer := 0;
NumberOfPlayers(HowmanyPlayers);
with Players[0] do
begin
Name := '';
Pass := '';
Active := true;
end;
LoginPlayer;
writeln('go');
t:=getsystemtime;
mypoint:= CTWBGetMyPos;
writeln(inttostr(getsystemtime-t));
writeln(mypoint);
end.