Hello ... and looking for advice on mixing Java & C++

Hi, my first post, so Hello everyone! :slight_smile:

I’m new to Java, but fairly experienced with C++ and game development in general, I’ve got a new game on iPhone (should be out in a few days), and I want to jump in to Android game developent.

I’d like to get your advice on something…

My plan is, to develop an Android branch of my existing cross-platform engine (so far it’s PC / Mac / iPhone), and the idea being, that I can code all my game logic in C++, which will link to my engine layer, which sits between my game logic and the hardware.

So in short, that will mean, coding the main part of my game (all the game logic etc) in C++, and having that interface with another chunk of code (probably Java) for the purposes of accessing any OS stuff and graphics and sound (OpenGL / OpenAL).

Is that feasible? What’s the situation with mixing Java and C++? Any advice or suggestions?

Many thanks,

Hi Jamie,

basically, er, don’t. It is a world of pain. Port your code to Java. Actually no, rewrite it in Java anew.

Cas :slight_smile:

Hey Cas,

Yeh, it sounded pretty painful from what the Lemon Team chap was saying on indiegamer.

I’m not so familiar with Java, but I’m guessing it’s similar-ish to C++? Hmm, maybe I should say such things around here? I’m thinking a good option might be to run my C++ source files through some kind of processor that auto-magically converts them all to Java.

Do you know of anythig like that?

Cheers,
Jamie. :slight_smile:

It looks syntactically a bit like C++ but considerably simpler by having no macros, header files, or operator overloading. You write Java in a fairly fundamentally different way to C++ though - you won’t really be able to autoconvert it, but it’s not too onerous to port by hand.

Cas :slight_smile:

Well, if your target platform is Android, and you’ve already got your code in C++, just use the Android NDK and leave it in C++. As I understand it, you don’t need to use Java if you don’t want to.

Ah, looks like the NDK is rather “incomplete.” Sorry about the bad advice then. ::slight_smile:

Guess you’re “stuck” with Java.

One should be able to use the NDK on Android if the game engine already exists in C/C++. Obviously if the iPhone is a target it is necessary to work in C/C++. On Android each app even NDK still is tied to the Dalvik VM. There is full support for OpenGL ES in the NDK, but you have to buffer input controls (key / sensors) from the Java side to the native side. Also it is my understanding the audio has to be buffered back to the Java side as well and can’t be played on the NDK side. Overall if iPhone compatibility is required the NDK is definitely an option on Android. I’ll soon be releasing my middleware tech for Android which includes a bunch of input control configuration and virtual controller overlays for devices without a keyboard. I’m making an effort to make the input controller / virtual overlay code work with NDK apps.