Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / PlugIns and passing pointers into functions

Author
Message
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 17th Aug 2023 07:57
Hi All,

Couldn't find any info on how to pass a pointer into a new plugin function.

Anyone have experience with this or could 'point' me in the right direction?

Was thinking of CreateMemblock from an outside ref as a workaround, maybe there is an easier way.

Thanks!

Aidan
User Banned
Posted: 17th Aug 2023 08:19
You need to do "ref as" in AppGameKit so I assume your using tier 2 or AGk studio which the c++ language isn't available for studio only AppGameKit classic

To confirm Is it correct your doing it for tier 2 c++

Please have a read of this

https://www.tutorialspoint.com/cplusplus/cpp_passing_pointers_to_functions.htm

Unless others know but hope this helps for now

Aidan
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 17th Aug 2023 18:34
You might have some issues passing pointers to and from AGK.
Now from a basic standpoint AppGameKit doesn't support Pointers... while, yes Version 2 and Studio saw the introduction of the "Ref" Operator to allow R/W References to the Parent Object rather than a Copied Object only Scoped to a Function; this is still being done via the Interop Runtime for the Scripting Language... so, like Java or Python those Entities don't exist in "Memory" the same way a C/C++/C# Object does.
Instead they're being accessed through a Template Entity Class, which automatically handles the Data; and so are not compatible with C Language.

Yes, things like the Arrays (i.e. ToJson and such) give the impression of such functionality, this is all handled as a blackbox function within the Interpreter Runtime; consider it "Hardcoded" Behaviour.

Unfortunately this is a downside to AppGameKit being an Interpreted Scripting Language, as opposed to being a Compiled Language (like Dark Basic Professional is).

The second issue is said Template Entity Class automatically converting Data Types., will always Default output to a Signed 32bit Integer.
This means that you can't use 64bit Pointers; so you're limited to 4GB Address Space but more than this is values above the Sign (i.e. 32 ^ 2 / 2) will not map correctly... it's why in C Languages you avoid (where you can) casting Address values between Signed and Unsigned Integers.

As such you _can_ run into issues regarding addressing memory addresses above 2GB IF you're passing the Pointer to and from AppGameKit between Plugins.
Your better option is instead to write your plugins with Headers and a Library; so that they can access each other directly, rather than using AppGameKit as a go between.

Now personally I'd recommend using a function as part of the Library Header that will pass a Reference to the In-Flight Class you're using in that Library.
It might seem a little "Old School" but tends to be the most robust approach.
Yeshu777
4
Years of Service
User Offline
Joined: 26th Feb 2020
Location: Cymru
Posted: 18th Aug 2023 03:20
Hey!

Thanks for all the feedback & comments, much appreciated.

At present I'm sticking with Tier 1, wrapping some of my low level embedded C++ code to make it accessible in game.

I'm looking as to what to leave within the DLL and what to pass out as new commands ( if that makes any sense ).

I think as a workaround I'm looking at Creating a MemBlock in the DLL, get the ID, pass the ID back into the DLL to extract the required data.

eg.

AGK -> Plugin.CreateTXPacket -> { DLL -> agk:: CreateMemBlock } -> return the ID.

AGK -> Plugin.SetTXPacketHeader -> { DLL -> agk:: SetMemBlockByte }

AGK -> Plugin.SetTXPacketData -> { DLL -> agk:: SetMemBlockByte }

AGK -> Plugin.SendTXPacket

or along those lines at least.. time to experiment.

Are there any issues in using Memblocks to and from Plugins?

Diolch!

Yeshu777





MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 18th Aug 2023 06:37
In my Nuklear plugin I took a similar route.
I didn't notice any problems except maybe the 64bit issue that Raven mentioned.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.

Login to post a reply

Server time is: 2024-05-02 15:31:46
Your offset time is: 2024-05-02 15:31:46