Skip to content

Commit

Permalink
PluginTarget tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Feb 24, 2024
1 parent d867860 commit c748985
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Source/script/imports/simba.import_file.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ implementation
File, Path, Directory related methods.
*)


(*
INIFileWrite
------------
> function INIFileWrite(FileName: String; Section, Key, Value: String): Boolean
*)
procedure _LapeINIFileWrite(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := INIFileWrite(PString(Params^[0])^, PString(Params^[1])^, PString(Params^[2])^, PString(Params^[3])^);
Expand All @@ -37,10 +41,6 @@ procedure _LapeINIFileWrite(const Params: PParamArray; const Result: Pointer); L
INIFileRead
-----------
> function INIFileDelete(FileName: String; Section, Key: String): Boolean
```
INIFileDelete('Hello World', 'Hello', 'World');
```
*)
procedure _LapeINIFileRead(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
Expand Down
11 changes: 6 additions & 5 deletions Source/script/simba.script_pluginmethods.pas
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface
SetArrayLength: procedure(TypeInfo: Pointer; var AVar: Pointer; NewLen: NativeInt); cdecl;
GetArrayLength: function(AVar: Pointer): NativeInt; cdecl;

ExternalImage_Create: function(FreeOnTerminate: Boolean): Pointer; cdecl;
ExternalImage_Create: function(AutoResize: Boolean): Pointer; cdecl;
ExternalImage_SetMemory: procedure(Img: Pointer; Data: PColorBGRA; AWidth, AHeight: Integer); cdecl;
ExternalImage_Resize: procedure(Img: Pointer; NewWidth, NewHeight: Integer); cdecl;
ExternalImage_SetUserData: procedure(Img: Pointer; UserData: Pointer); cdecl;
Expand Down Expand Up @@ -209,7 +209,7 @@ procedure Plugin_ReAllocateRawArray(var AVar: Pointer; AElementSize, ALen: Nativ
Inc(PtrUInt(AVar), SizeOf(SizeInt));

if (ALen > OldLen) then
FillChar(Pointer(PtrInt(AVar) + (OldLen * AElementSize))^, (ALen - OldLen) * AElementSize, 0);
FillChar(Pointer(PtrUInt(AVar) + (OldLen * AElementSize))^, (ALen - OldLen) * AElementSize, 0);
end else
begin
Dec(PtrInt(AVar^));
Expand Down Expand Up @@ -267,11 +267,12 @@ function Plugin_GetArrayLength(Arr: Pointer): NativeInt; cdecl;
Result := DynArraySize(Arr);
end;

function Plugin_ExternalImage_Create(FreeOnTerminate: Boolean): Pointer; cdecl;
function Plugin_ExternalImage_Create(AutoResize: Boolean): Pointer; cdecl;
begin
Result := TSimbaExternalImage.Create();
if FreeOnTerminate then
TSimbaExternalImage(Result).FreeOnTerminate := True;

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

procedure Plugin_ExternalImage_SetMemory(Img: Pointer; Data: PColorBGRA; AWidth, AHeight: Integer); cdecl;
Expand Down
6 changes: 6 additions & 0 deletions Source/simba.externalimage.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ TSimbaExternalImage = class(TSimbaBaseClass)
FDirty: Boolean;
FDirtyBox: TBox;

FAutoResize: Boolean;

procedure CheckInUpdate; inline;

procedure addDirty(b: TBox); inline;
Expand Down Expand Up @@ -63,6 +65,7 @@ TSimbaExternalImage = class(TSimbaBaseClass)
property Width: Integer read FWidth;
property Height: Integer read FHeight;
property UserData: Pointer read GetUserData write SetUserData;
property AutoResize: Boolean read FAutoResize write FAutoResize;

property FontName: String read GetFontName write SetFontName;
property FontSize: Single read GetFontSize write SetFontSize;
Expand Down Expand Up @@ -299,6 +302,9 @@ procedure TSimbaExternalImage.Resize(NewWidth, NewHeight: Integer);
var
Y: Integer;
begin
if (FWidth = NewWidth) and (FHeight = NewHeight) then
Exit;

BeginUpdate();
try
FWidth := NewWidth;
Expand Down
48 changes: 46 additions & 2 deletions Source/targets/simba.target_plugin.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TSimbaPluginTarget = record
Lib: TLibHandle;
FileName: String;
Target: Pointer;
DebugImageThread: TThread;

Request: function(Args: PChar): Pointer; cdecl;
RequestWithDebugImage: function(Args: PChar; out DebugImage: TSimbaExternalImage): Pointer; cdecl;
Expand Down Expand Up @@ -67,6 +68,48 @@ implementation
uses
simba.env, simba.files, simba.script_pluginloader;

type
TUpdateDebugImageThread = class(TThread)
protected
FTarget: TSimbaPluginTarget;
FImg: TSimbaExternalImage;

procedure Execute; override;
public
constructor Create(Target: TSimbaPluginTarget; Img: TSimbaExternalImage); reintroduce;
end;

procedure TUpdateDebugImageThread.Execute;
var
CurrentWidth, CurrentHeight, NewWidth, NewHeight: Integer;
begin
CurrentWidth := 0;
CurrentHeight := 0;

while (not Terminated) do
begin
FTarget.GetDimensions(FTarget.Target, NewWidth, NewHeight);

if (NewWidth <> CurrentWidth) or (NewHeight <> CurrentHeight) then
begin
CurrentWidth := NewWidth;
CurrentHeight := NewHeight;

FImg.Resize(CurrentWidth, CurrentHeight);
end;

Sleep(1000);
end;
end;

constructor TUpdateDebugImageThread.Create(Target: TSimbaPluginTarget; Img: TSimbaExternalImage);
begin
inherited Create(False, 512*512);

FTarget := Target;
FImg := Img;
end;

procedure CheckExported(const MethodName: String; const Method: Pointer); inline;
begin
if (Method = nil) then
Expand Down Expand Up @@ -116,7 +159,7 @@ function LoadPluginTarget(FileName, Args: String): TSimbaPluginTarget;
begin
CheckExported('SimbaPluginTarget_Request', Request);

Result.Target := Result.Request(PChar(Args));
Target := Result.Request(PChar(Args));
end;
end;

Expand All @@ -128,7 +171,8 @@ function LoadPluginTarget(FileName, Args: String; out DebugImage: TSimbaExternal
CheckExported('SimbaPluginTarget_RequestWithDebugImage', RequestWithDebugImage);

Target := Result.RequestWithDebugImage(PChar(Args), DebugImage);
WriteLn('Target is: ', HexStr(Target));
if Assigned(DebugImage) and DebugImage.AutoResize then
DebugImageThread := TUpdateDebugImageThread.Create(Result, DebugImage);
end;
end;

Expand Down

0 comments on commit c748985

Please sign in to comment.