Skip to content

Commit

Permalink
Rename ExternalImage to ExternalCanvas (as its only drawing methods)
Browse files Browse the repository at this point in the history
Doublebuffing is now a option, rather than required.
Default is unbuffered.

DoubleBuffered means draw calls must be done between a BeginUpdate/EndUpdate after buffer will be copied to the external memory.
  • Loading branch information
ollydev committed Oct 23, 2024
1 parent 785813d commit 2b63cac
Show file tree
Hide file tree
Showing 12 changed files with 1,613 additions and 1,431 deletions.
895 changes: 895 additions & 0 deletions Source/script/imports/simba.externalcanvas.pas

Large diffs are not rendered by default.

642 changes: 642 additions & 0 deletions Source/script/imports/simba.import_externalcanvas.pas

Large diffs are not rendered by default.

653 changes: 0 additions & 653 deletions Source/script/imports/simba.import_externalimage.pas

This file was deleted.

12 changes: 6 additions & 6 deletions Source/script/imports/simba.import_target.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ implementation
TypInfo,
lptypes, lpvartypes, ffi,
simba.colormath, simba.dtm, simba.misc,
simba.image, simba.target, simba.externalimage, simba.finder_image, simba.finder_color;
simba.image, simba.target, simba.externalcanvas, simba.finder_image, simba.finder_color;

type
PMouseButton = ^EMouseButton;
Expand Down Expand Up @@ -107,14 +107,14 @@ procedure _LapeTarget_SetPlugin1(const Params: PParamArray); LAPE_WRAPPER_CALLIN
TTarget.SetPlugin
-----------------
```
procedure TTarget.SetPlugin(FileName, Args: String; out DebugImage: TSimbaExternalImage);
procedure TTarget.SetPlugin(FileName, Args: String; out DebugImage: TExternalCanvas);
```
Overloaded version that returns a external image to draw on.
Overloaded version that returns a "external canvas" to draw on.
*)
procedure _LapeTarget_SetPlugin2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
begin
PSimbaTarget(Params^[0])^.SetPlugin(PString(Params^[1])^, PString(Params^[2])^, PSimbaExternalImage(Params^[3])^);
PSimbaTarget(Params^[0])^.SetPlugin(PString(Params^[1])^, PString(Params^[2])^, TSimbaExternalCanvas(Params^[3]^));
end;

(*
Expand Down Expand Up @@ -1160,7 +1160,7 @@ procedure ImportTarget(Compiler: TSimbaScript_Compiler);
addGlobalFunc('procedure TTarget.SetWindow(Window: TWindowHandle)', @_LapeTarget_SetWindow);
addGlobalFunc('procedure TTarget.SetEIOS(Plugin, Args: String)', @_LapeTarget_SetEIOS);
addGlobalFunc('procedure TTarget.SetPlugin(Plugin, Args: String); overload', @_LapeTarget_SetPlugin1);
addGlobalFunc('procedure TTarget.SetPlugin(Plugin, Args: String; out DebugImage: TExternalImage); overload', @_LapeTarget_SetPlugin2);
addGlobalFunc('procedure TTarget.SetPlugin(Plugin, Args: String; out DebugImage: TExternalCanvas); overload', @_LapeTarget_SetPlugin2);

addGlobalFunc('function TTarget.AddTargetChangeEvent(Event: TTargetEvent): TTargetEvent', @_Lape_Target_AddTargetChangeEvent);
addGlobalFunc('function TTarget.AddTargetInvalidEvent(Event: TTargetEvent): TTargetEvent', @_Lape_Target_AddTargetInvalidEvent);
Expand Down Expand Up @@ -1307,4 +1307,4 @@ procedure ImportTarget(Compiler: TSimbaScript_Compiler);
end;
end;

end.
end.
4 changes: 2 additions & 2 deletions Source/script/simba.script_imports.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ implementation
simba.import_pointbuffer, simba.import_async,

// Simba classes
simba.import_image, simba.import_externalimage, simba.import_dtm, simba.import_matchtemplate,
simba.import_image, simba.import_externalcanvas, simba.import_dtm, simba.import_matchtemplate,
simba.import_json, simba.import_imagebox, simba.import_shapebox,

// LCL
Expand Down Expand Up @@ -58,7 +58,7 @@ procedure AddSimbaImports(Compiler: TSimbaScript_Compiler);

ImportDTM(Compiler);
ImportSimbaImage(Compiler);
ImportSimbaExternalImage(Compiler);
ImportExternalCanvas(Compiler);
ImportMatchTemplate(Compiler);
ImportJSON(Compiler);

Expand Down
18 changes: 9 additions & 9 deletions Source/script/simba.script_pluginmethods.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface

uses
Classes, SysUtils,
simba.base, simba.externalimage,
simba.base, simba.externalcanvas,
lpcompiler;

type
Expand Down Expand Up @@ -270,35 +270,35 @@ function Plugin_GetArrayLength(Arr: Pointer): NativeInt; cdecl;

function Plugin_ExternalImage_Create(AutoResize: Boolean): Pointer; cdecl;
begin
Result := TSimbaExternalImage.Create();
Result := TSimbaExternalCanvas.Create();

TSimbaExternalImage(Result).FreeOnTerminate := True;
TSimbaExternalImage(Result).AutoResize := AutoResize;
TSimbaExternalCanvas(Result).AutoResize := AutoResize;
TSimbaExternalCanvas(Result).FreeOnTerminate := True;
end;

procedure Plugin_ExternalImage_SetMemory(Img: Pointer; Data: PColorBGRA; AWidth, AHeight: Integer); cdecl;
begin
TSimbaExternalImage(Img).SetMemory(Data, AWidth, AHeight);
TSimbaExternalCanvas(Img).SetMemory(Data, AWidth, AHeight);
end;

procedure Plugin_ExternalImage_Resize(Img: Pointer; NewWidth, NewHeight: Integer); cdecl;
begin
TSimbaExternalImage(Img).Resize(NewWidth, NewHeight);
TSimbaExternalCanvas(Img).Resize(NewWidth, NewHeight);
end;

procedure Plugin_ExternalImage_SetUserData(Img: Pointer; UserData: Pointer); cdecl;
begin
TSimbaExternalImage(Img).UserData := UserData;
TSimbaExternalCanvas(Img).UserData := UserData;
end;

function Plugin_ExternalImage_GetUserData(Img: Pointer): Pointer; cdecl;
begin
Result := TSimbaExternalImage(Img).UserData;
Result := TSimbaExternalCanvas(Img).UserData;
end;

procedure Plugin_ExternalImage_SetName(Img: Pointer; Name: PChar); cdecl;
begin
TSimbaExternalImage(Img).Name := Name;
TSimbaExternalCanvas(Img).Name := Name;
end;

initialization
Expand Down
56 changes: 19 additions & 37 deletions Source/simba.baseclass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,22 @@ implementation
procedure PrintUnfreedObjects;
var
NeedHeader: Boolean = True;
I: Integer;
begin
TrackedObjects.Lock();
try
for I := 0 to TrackedObjects.Count - 1 do
if not TrackedObjects[I].FreeOnTerminate then
while (TrackedObjects.Count > 0) do
begin
if not TrackedObjects.First.FreeOnTerminate then
begin
if NeedHeader then
DebugLn([EDebugLn.YELLOW], 'The following objects were not freed:');
NeedHeader := False;

TrackedObjects[I].NotifyUnfreed();
TrackedObjects.First.NotifyUnfreed();
end;

TrackedObjects.First.Free();
end;
finally
TrackedObjects.Unlock();
end;
Expand Down Expand Up @@ -104,19 +107,25 @@ procedure PrintUnfinishedThreads;
procedure PrintUnfreedThreads;
var
NeedHeader: Boolean = True;
I: Integer;
begin
TrackedThreads.Lock();
try
for I := 0 to TrackedThreads.Count - 1 do
if TrackedThreads[I].Finished and (not TrackedThreads[I].FreeOnTerminate) then
while (TrackedThreads.Count > 0) do
begin
if TrackedThreads.First.Finished and (not TrackedThreads.First.FreeOnTerminate) then
begin
if NeedHeader then
DebugLn([EDebugLn.YELLOW], 'The following threads were not freed:');
NeedHeader := False;

TrackedThreads[I].NotifyUnfreed();
TrackedThreads.First.NotifyUnfreed();
end;

if TrackedThreads.First.FreeOnTerminate then
TrackedThreads.Delete(TrackedThreads.First)
else
TrackedThreads.First.Free();
end;
finally
TrackedThreads.Unlock();
end;
Expand Down Expand Up @@ -179,40 +188,13 @@ destructor TSimbaBaseThread.Destroy;
TrackedThreads.Delete(Self);
end;

procedure FreeObjects;
var
List: TTrackedObjects;
Thread: TSimbaBaseThread;
I: Integer;
begin
List := TrackedObjects;
TrackedObjects := nil;
for I := 0 to List.Count - 1 do
List[I].Free();
end;

procedure FreeThreads;
var
List: TTrackedThreads;
Thread: TSimbaBaseThread;
I: Integer;
begin
List := TrackedThreads;
TrackedThreads := nil;
for I := 0 to List.Count - 1 do
if List[I].FreeOnTerminate then
List[I].Terminate()
else
List[I].Free();
end;

initialization
TrackedObjects := TTrackedObjects.Create();
TrackedThreads := TTrackedThreads.Create();

finalization
FreeObjects();
FreeThreads();
while (TrackedObjects.Count > 0) do
TrackedObjects.First.Free();

end.

Loading

0 comments on commit 2b63cac

Please sign in to comment.