0
\$\begingroup\$

I'm writing a game that is mostly in Java (because that's the language I'm most comfortable with) while the graphics are in C++ (because of speed, and because the Vulkan API is hard enough to learn when I'm not using a third-party language binding). I start a thread in Java and have it create a Swing window, it then runs a native method that takes the HWND handle from the window and some other information as parameters. Once in native code it binds the window to a Vulkan surface and from their the graphics engine is it's own independent thread, if possible I don't want to make any more JNI calls (performance concerns).

My issue is, I handle server-client connectivity on the Java end, and my server is responsible for sending the client models and textures when the player needs them. The obvious solution would be to pass these textures and models over JNI so that the graphics engine can make use of them but I'd REALLY like to not do that.

I've considered using memory mapped files but that would require using boost since there otherwise isn't a cross-platform mmap library, and it also seemed silly to me that I'd get the data over the network, it'd then be stored in RAM, and then I'd allocate it a different area of RAM so that it can be accessed in native.

Other than JNI and memory mapping I, with my limited experience, cannot think of any other possible solution to this problem and am hoping to find some suggestions or perhaps some inspiration. This question isn't strictly related to game development and I considered asking it over at Stackoverflow but their community is really doo doo.

\$\endgroup\$
  • 2
    \$\begingroup\$ I don't really see the point of binding C++ and Java for creating a game; You say you don't want to use JNI calls, because of performance issues; another way would be to setup a web service using MTOM or mapping. I would personally suggest to either use Java or C++, not both at the same time. Using two languages, one for speed and one because of preference, on the same thread and process, seems a bit like a waste of time and resources to me.. \$\endgroup\$ – Gabriele Vierti Dec 24 '18 at 23:15
  • \$\begingroup\$ @GabrieleVierti the only JNI call I had to make was when I initiated the graphics engine and bound the window, and the only problem I've ran into with my method is the one described in my post. If push comes to shove then I'll just use memory mapped files (which from what I've heard are definitely fast) and I can't imagine any other issues. Writing the graphics portion in c++ for speed is a no-brainer but besides personal prefrence I also chose to right the rest in java because then I'd have to use fewer 3rd party libraries and I can guarantee the rest of my code is cross-platform. \$\endgroup\$ – Semper Ambroscus Dec 25 '18 at 3:27
  • \$\begingroup\$ @GabrieleVierti at the very least Java has already saved me the hassle of having to install GLFW to create the window, and java has a built-in vector math library to boot \$\endgroup\$ – Semper Ambroscus Dec 25 '18 at 3:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.