From c74898537bff49cf53ae63513db90ca2e8abb118 Mon Sep 17 00:00:00 2001 From: Olly Date: Sat, 24 Feb 2024 02:03:32 +0000 Subject: [PATCH] PluginTarget tweaks --- Source/script/imports/simba.import_file.pas | 10 ++-- Source/script/simba.script_pluginmethods.pas | 11 +++-- Source/simba.externalimage.pas | 6 +++ Source/targets/simba.target_plugin.pas | 48 +++++++++++++++++++- 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/Source/script/imports/simba.import_file.pas b/Source/script/imports/simba.import_file.pas index 7be14a214..65fd6425a 100644 --- a/Source/script/imports/simba.import_file.pas +++ b/Source/script/imports/simba.import_file.pas @@ -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])^); @@ -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 diff --git a/Source/script/simba.script_pluginmethods.pas b/Source/script/simba.script_pluginmethods.pas index 8e1536507..c141f2d56 100644 --- a/Source/script/simba.script_pluginmethods.pas +++ b/Source/script/simba.script_pluginmethods.pas @@ -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; @@ -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^)); @@ -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; diff --git a/Source/simba.externalimage.pas b/Source/simba.externalimage.pas index 6e47f9c16..92662a0e6 100644 --- a/Source/simba.externalimage.pas +++ b/Source/simba.externalimage.pas @@ -33,6 +33,8 @@ TSimbaExternalImage = class(TSimbaBaseClass) FDirty: Boolean; FDirtyBox: TBox; + FAutoResize: Boolean; + procedure CheckInUpdate; inline; procedure addDirty(b: TBox); inline; @@ -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; @@ -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; diff --git a/Source/targets/simba.target_plugin.pas b/Source/targets/simba.target_plugin.pas index bcdf65fbc..ac34d9521 100644 --- a/Source/targets/simba.target_plugin.pas +++ b/Source/targets/simba.target_plugin.pas @@ -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; @@ -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 @@ -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; @@ -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;