Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tilengine on Java
#11
(12-05-2020, 04:07 AM)megamarc Wrote: You picked two extreme cases Smile

In order to communicate, sometimes the binding must do data conversion before passing the arguments. In other cases, it must create and destroy elements that are needed on the Java side.

The first example is the simplest one: no conversion of any data is needed, just call the function. Done!

The second one manages the callback, the Java function that needs to be called from the native library. Callbacks are always the trickiest part of a binding. In thsi case, it requires destroying a previously allocated Java object, and creating a new one. In addition, it gets a text string, that needs explicit conversion because C and Java don't represent strings internally in the same way. That's why this function is the most complex of all.

Oh I see, is there other functions in the new version that can ask for that kind of complex conversions?
Reply
#12
Not like the callback one, sure. Any function that passes strings will need the data conversion, same as functions that pass or get structures (structs). But there are already some functions that do that, that can be used as a template. As you can see, it's repetitive work, nothing you'll have to imagine or guess.
Reply
#13
(12-05-2020, 04:32 AM)megamarc Wrote: Not like the callback one, sure. Any function that passes strings will need the data conversion, same as functions that pass or get structures (structs). But there are already some functions that do that, that can be used as a template. As you can see, it's repetitive work, nothing you'll have to imagine or guess.

Alright! I'll try to do that so.
If I do an update, I'll do a fork of the GitHub repo and if you want, I can give you my updated version if it works well!
Reply
#14
Of course, that would be welcome!

If you do that, after cloning the repo in your GitHub and do the modifications, you can do a "pull request". With this, your patch will be integrated back into the main repo and you'll appear as a contributor.

I recommend to base the modifications on the last version of the engine, this is the header at 2.8.5:
https://github.com/megamarc/Tilengine/bl...ilengine.h
Reply
#15
(12-05-2020, 05:23 PM)megamarc Wrote: Of course, that would be welcome!

If you do that, after cloning the repo in your GitHub and do the modifications, you can do a "pull request". With this, your patch will be integrated back into the main repo and you'll appear as a contributor.

I recommend to base the modifications on the last version of the engine, this is the header at 2.8.5:
https://github.com/megamarc/Tilengine/bl...ilengine.h

Cloning into my GitHub is forking, right?
Reply
#16
I have a problem.
I try to compile TilengineJNI.dll, but the jni.h header is not included in the project. Where can I find this header please? Thanks for the answer.
Reply
#17
Hi,
Required JNI header is distributed with the JDK (Java Development Kit). Please read main JTilengine README in GitHub to see how to reference it when compiling, depending on your OS, as its location is different.
Reply
#18
When I type the build command that you can find on the GitHub, the compiler says "Undefined Reference to [For all Tilengine functions], except if I put "-c" argument in the command.
I included the Tilengine.h header too. I don't know if I'm supposed to add this -c argument.

Also, when I import the dll in my Java project, Java says "[Path to file]\TilengineJNI.dll: %1 is not a valid Win32 application". Is it normal? It do that with your dll too.

Thanks for your help and I'm sorry for that bunch of questions.
Reply
#19
Hi!

What version of the OS and JDK are you using? I use Windows 10 x64 2004 and OpenJDK 1.8.22.

I've tried the commands I put on github, and they still work for me. Just a minor warning on a function because I forgot to put a type cast, but it doesn't stop compilation. I've tried gcc and tcc compilers, and both produce the resulting TilengineJNI.dll library.

You must not use the "-c" switch, because it tells gcc/tcc to just compile, but not try to link the final library. The errors you're getting are from the linker, not the compiler. That way you avoid the linker errors, but also don't get the library. You cannot import the dll if it has not been built, that's why Java complains when importing it: the library still doesn't exist.

Please attach here OS, JDK versions, the line you're using to build, and the exact output you get. Just copy and paste.
Reply
#20
(12-07-2020, 06:36 PM)megamarc Wrote: Hi!

What version of the OS and JDK are you using? I use Windows 10 x64 2004 and OpenJDK 1.8.22.

I've tried the commands I put on github, and they still work for me. Just a minor warning on a function because I forgot to put a type cast, but it doesn't stop compilation. I've tried gcc and tcc compilers, and both produce the resulting TilengineJNI.dll library.

You must not use the "-c" switch, because it tells gcc/tcc to just compile, but not try to link the final library. The errors you're getting are from the linker, not the compiler. That way you avoid the linker errors, but also don't get the library. You cannot import the dll if it has not been built, that's why Java complains when importing it: the library still doesn't exist.

Please attach here OS, JDK versions, the line you're using to build, and the exact output you get. Just copy and paste.

OS : Windows 10 2004

JDK : 1.8.0_181 (Official Java sdk)

Command used for building : gcc -shared -I"%JAVA_HOME%\include" -I"%JAVA_HOME%\include\win32" -I"../Tilengine.dll" TilengineJNI.c -o ../TilengineJNI.dll
output : Link to the Pastebin I only changed the user name and computer name for privacy reasons.

IDE in case of need : IntelliJ IDEA 2019.2.3
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)