Skip to content

Commit

Permalink
Fix SimbaPluginTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Sep 25, 2023
1 parent 29ae291 commit 8deee04
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Source/simba.target.pas
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,16 @@ procedure TSimbaTarget.SetEIOS(FileName, Args: String);

FMethods.GetDimensions := @EIOSTarget_GetDimensions;
FMethods.GetImageData := @EIOSTarget_GetImageData;

FMethods.IsValid := @EIOSTarget_IsValid;
end;

procedure TSimbaTarget.SetPlugin(FileName, Args: String);
begin
ChangeTarget(ETargetType.PLUGIN);

FTargetPlugin := LoadPluginTarget(FileName, Args);
FTarget := @FTargetPlugin;

FMethods.KeyDown := @PluginTarget_KeyDown;
FMethods.KeyUp := @PluginTarget_KeyUp;
Expand All @@ -379,6 +382,8 @@ procedure TSimbaTarget.SetPlugin(FileName, Args: String);

FMethods.GetDimensions := @PluginTarget_GetDimensions;
FMethods.GetImageData := @PluginTarget_GetImageData;

FMethods.IsValid := @PluginTarget_IsValid;
end;

procedure TSimbaTarget.SetPlugin(FileName, Args: String; out DebugImage: TSimbaExternalImage);
Expand Down
7 changes: 7 additions & 0 deletions Source/targets/simba.target_eios.pas
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ procedure EIOSTarget_MouseDown(Target: Pointer; Button: EMouseButton);
procedure EIOSTarget_MouseUp(Target: Pointer; Button: EMouseButton);
procedure EIOSTarget_MouseScroll(Target: Pointer; Scrolls: Integer);

function EIOSTarget_IsValid(Target: Pointer): Boolean;

implementation

uses
Expand Down Expand Up @@ -253,6 +255,11 @@ procedure EIOSTarget_MouseScroll(Target: Pointer; Scrolls: Integer);
end;
end;

function EIOSTarget_IsValid(Target: Pointer): Boolean;
begin
Result := True;
end;

procedure EIOSTarget_KeyDown(Target: Pointer; Key: EKeyCode);
begin
with PEIOSTarget(Target)^ do
Expand Down
75 changes: 73 additions & 2 deletions Source/targets/simba.target_plugin.pas
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ procedure PluginTarget_KeyUp(Target: Pointer; Key: EKeyCode);
procedure PluginTarget_KeySend(Target: Pointer; Key: Char; KeyDownTime, KeyUpTime, ModifierDownTime, ModifierUpTime: Integer);
function PluginTarget_KeyPressed(Target: Pointer; Key: EKeyCode): Boolean;

function PluginTarget_IsValid(Target: Pointer): Boolean;

implementation

uses
simba.env, simba.files, simba.script_pluginloader;

procedure CheckExported(const MethodName: String; const Method: Pointer); inline;
begin
if (Method = nil) then
SimbaException('SimbaPluginTarget: "' + MethodName + '" is not exported');
end;

function Load(AFileName: String): TSimbaPluginTarget;
begin
Result := Default(TSimbaPluginTarget);
Expand Down Expand Up @@ -97,85 +105,148 @@ function Load(AFileName: String): TSimbaPluginTarget;
function LoadPluginTarget(FileName, Args: String): TSimbaPluginTarget;
begin
Result := Load(FileName);
Result.Target := Result.Request(PChar(Args));
with Result do
begin
CheckExported('SimbaPluginTarget_Request', Request);

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

function LoadPluginTarget(FileName, Args: String; out DebugImage: TSimbaExternalImage): TSimbaPluginTarget;
begin
Result := Load(FileName);
Result.Target := Result.RequestWithDebugImage(PChar(Args), DebugImage);
with Result do
begin
CheckExported('SimbaPluginTarget_RequestWithDebugImage', RequestWithDebugImage);

Target := Result.RequestWithDebugImage(PChar(Args), DebugImage);
end;
end;

procedure PluginTarget_GetDimensions(Target: Pointer; out W, H: Integer);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_GetDimensions', GetDimensions);

GetDimensions(Target, W, H);
end;
end;

function PluginTarget_GetImageData(Target: Pointer; X, Y, Width, Height: Integer; var Data: PColorBGRA; var DataWidth: Integer): Boolean;
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_GetImageData', GetImageData);

Result := GetImageData(Target, X, Y, Width, Height, Data, DataWidth);
end;
end;

function PluginTarget_MousePressed(Target: Pointer; Button: EMouseButton): Boolean;
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_MousePressed', MousePressed);

Result := MousePressed(Target, Integer(Button));
end;
end;

function PluginTarget_MousePosition(Target: Pointer): TPoint;
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_MousePosition', MousePosition);

Result := MousePosition(Target);
end;
end;

procedure PluginTarget_MouseTeleport(Target: Pointer; P: TPoint);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_MouseTeleport', MouseTeleport);

MouseTeleport(Target, P);
end;
end;

procedure PluginTarget_MouseUp(Target: Pointer; Button: EMouseButton);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_MouseUp', MouseUp);

MouseUp(Target, Integer(Button));
end;
end;

procedure PluginTarget_MouseDown(Target: Pointer; Button: EMouseButton);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_MouseDown', MouseDown);

MouseDown(Target, Integer(Button));
end;
end;

procedure PluginTarget_MouseScroll(Target: Pointer; Scrolls: Integer);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_MouseScroll', MouseScroll);

MouseScroll(Target, Scrolls);
end;
end;

procedure PluginTarget_KeyDown(Target: Pointer; Key: EKeyCode);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_KeyDown', KeyDown);

KeyDown(Target, Integer(Key));
end;
end;

procedure PluginTarget_KeyUp(Target: Pointer; Key: EKeyCode);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_KeyUp', KeyUp);

KeyUp(Target, Integer(Key));
end;
end;

procedure PluginTarget_KeySend(Target: Pointer; Key: Char; KeyDownTime, KeyUpTime, ModifierDownTime, ModifierUpTime: Integer);
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_KeySend', KeySend);

KeySend(Target, Key, KeyDownTime, KeyUpTime, ModifierDownTime, ModifierUpTime);
end;
end;

function PluginTarget_KeyPressed(Target: Pointer; Key: EKeyCode): Boolean;
begin
with PSimbaPluginTarget(Target)^ do
begin
CheckExported('SimbaPluginTarget_KeyPressed', KeyPressed);

Result := KeyPressed(Target, Integer(Key));
end;
end;

function PluginTarget_IsValid(Target: Pointer): Boolean;
begin
Result := True;
end;

end.
Expand Down

0 comments on commit 8deee04

Please sign in to comment.