Thread overview
I made a specific yet advanced game playing AI but I want to bring it to D to make it cross platform
Dec 31, 2015
Gan
Dec 31, 2015
Rikki Cattermole
Dec 31, 2015
Gan
Jan 01, 2016
Rikki Cattermole
December 31, 2015
I've written an AI to play a game in Objective-C on Mac. The AI bits are mostly C++ code for performance. I want to make the AI cross platform because the game has a huge windows user base. My hope is to get other programmers interested in helping out because it is very time consuming to make perfect screen detection and AI decisions.

My question is, to write the Mac and Windows specific code in their respective languages(C# and Obj-C) for UI, screen capture and input simulation; can I have that code be usable from D? I don't know much about shared libraries or importing DLLs so I have no knowledge on the possibility. I would like to write all the AI code in D but have all the OS specific code written in their own languages that I can call from D. I am very familiar with writing C#, Obj-C and even D code. I just don't know how to make them all play nice. Maybe there's a way to compile the OS specific code in libraries and D can call them depending on which OS the D code gets compiled to?

Would anyone know how to do this? Or have basic examples?
To start I'd just like to write a D program that can call some specific already compiled C# or Obj-C code that will create a UI window but maintain full control in D such that D could issue further already compiled commands. Also receive input, like a button is clicked and that button sends an event notifier back to D.

Is this plausible?
December 31, 2015
On 31/12/15 11:20 PM, Gan wrote:
> I've written an AI to play a game in Objective-C on Mac. The AI bits are
> mostly C++ code for performance. I want to make the AI cross platform
> because the game has a huge windows user base. My hope is to get other
> programmers interested in helping out because it is very time consuming
> to make perfect screen detection and AI decisions.
>
> My question is, to write the Mac and Windows specific code in their
> respective languages(C# and Obj-C) for UI, screen capture and input
> simulation; can I have that code be usable from D? I don't know much
> about shared libraries or importing DLLs so I have no knowledge on the
> possibility. I would like to write all the AI code in D but have all the
> OS specific code written in their own languages that I can call from D.
> I am very familiar with writing C#, Obj-C and even D code. I just don't
> know how to make them all play nice. Maybe there's a way to compile the
> OS specific code in libraries and D can call them depending on which OS
> the D code gets compiled to?
>
> Would anyone know how to do this? Or have basic examples?
> To start I'd just like to write a D program that can call some specific
> already compiled C# or Obj-C code that will create a UI window but
> maintain full control in D such that D could issue further already
> compiled commands. Also receive input, like a button is clicked and that
> button sends an event notifier back to D.
>
> Is this plausible?

I'll start out by saying, this is more appropriate for D.learn not the main D Newsgroup.
What you have here is two separate issues.

- Interacting with Objective-C which over the next few years will become very easy (WIP currently). Otherwise you can interact with it via extern(C).
- Interacting with C#. This will be a good deal harder, but still do-able with the help of extern(C). You'll need to get good at interacting with unmanaged code from there, which I cannot help with since it is C# specific.

One thing to remember D is a native language meaning an exe cannot be ran on Linux and vice versa.
It won't be as simple as compiling as a shared library once and using it everywhere.
December 31, 2015
On Thursday, 31 December 2015 at 10:29:42 UTC, Rikki Cattermole wrote:
> On 31/12/15 11:20 PM, Gan wrote:
>> [...]
>
> I'll start out by saying, this is more appropriate for D.learn not the main D Newsgroup.
> What you have here is two separate issues.
>
> - Interacting with Objective-C which over the next few years will become very easy (WIP currently). Otherwise you can interact with it via extern(C).
> - Interacting with C#. This will be a good deal harder, but still do-able with the help of extern(C). You'll need to get good at interacting with unmanaged code from there, which I cannot help with since it is C# specific.
>
> One thing to remember D is a native language meaning an exe cannot be ran on Linux and vice versa.
> It won't be as simple as compiling as a shared library once and using it everywhere.

The shared library wouldn't be cross platform. I'd have to write one for each platform I target.

So what I got from this is that in theory it's possible but is there a lack of resources about the process?
January 01, 2016
On 01/01/16 10:15 AM, Gan wrote:
> On Thursday, 31 December 2015 at 10:29:42 UTC, Rikki Cattermole wrote:
>> On 31/12/15 11:20 PM, Gan wrote:
>>> [...]
>>
>> I'll start out by saying, this is more appropriate for D.learn not the
>> main D Newsgroup.
>> What you have here is two separate issues.
>>
>> - Interacting with Objective-C which over the next few years will
>> become very easy (WIP currently). Otherwise you can interact with it
>> via extern(C).
>> - Interacting with C#. This will be a good deal harder, but still
>> do-able with the help of extern(C). You'll need to get good at
>> interacting with unmanaged code from there, which I cannot help with
>> since it is C# specific.
>>
>> One thing to remember D is a native language meaning an exe cannot be
>> ran on Linux and vice versa.
>> It won't be as simple as compiling as a shared library once and using
>> it everywhere.
>
> The shared library wouldn't be cross platform. I'd have to write one for
> each platform I target.
>
> So what I got from this is that in theory it's possible but is there a
> lack of resources about the process?

Not really.
Since you'll be going over extern(C) you won't have any trouble.
It may just be a bit big the bindings.