Jump to content

  • Log In with Google      Sign In   
  • Create Account

Shanee

Member Since 31 May 2010
Offline Last Active Feb 25 2014 04:45 AM

#5119646 Android NDK Development - Would like feedback

Posted by Shanee on 28 December 2013 - 05:51 AM

Had a really busy month so I didn't finish the next page yet but I have started working on a slightly different take for this and was wondering if someone could give it a try and lend me some feedback.

 

I decided to try and simplify or better handle the NativeActivity state handling and events and compiled a small and simple library for use as a C++ source. It is still very much WIP but if anyone wants to give it a go I will appreciate it.

 

The library can be found here:

https://github.com/Lunarsong/NativeActivity/

 

And an example project to use it is here:

https://github.com/Lunarsong/NativeExample/

 

Currently it handles letting you know when the window is hidden (and you should stop drawing then), application is paused and key/touch data. You can also call the keyboard from Native.

 

Next I will be adding simple access to assets and then either leave it there or extend the BaseGameUtils for Google Play Services.

 

I want to keep it as slim as possible so it is just bare bones but also help exposing Android APIs to C++ with it.




#5114001 Android NDK Development - Would like feedback

Posted by Shanee on 03 December 2013 - 06:13 AM

This is a good start. Most of my feedback would relate to grammar and not technical issues.

 

I generally find the NDK to be a mostly useless addition to Android.  I love C++ and would rather use that language all the time, but in the hands of the most experienced developer, switching to C++ improves performance by less than 1/2 of a generation of devices. In other words, if you are writing something very peculiar and "cutting edge," and only want it to work on the latest devices, you may need C++.  Otherwise, if you are writing a commercial application and want wide device support, you will get far more payoff from learning how to write efficient Java than from switching to C++ (and inviting the compatibility issues that can arise as a consequence).

 

Hi HScottH,

 

Thank you for the reply. The case is that I am not a native English speaker and still need to work on my writing so if you have any suggestions they will be warmly accepted.

 

As for using C++, the main reasons are performancecross-platform and convenience. I do agree performance for most applications will not be an issue and it will even be easier to create the whole program in Java with the tools given by Google, yet for more demanding applications - games for example, it is still highly beneficial to use C++.

 

In-fact many of the games out this day prove this is the case. An office I have been at had problems with things as simple as rendering smooth UI animations with the Java classes on devices such as the Galaxy S2, switching drawing and logic to C++ resolved the issue. It might be worth to note I am not familiar with the Java implementation which was at the time.

 

As for cross-platform: most games these days are out for iPhone before they are for Android and some are out on PC and then converted (FTL for example). This means there is an established code-base in C++ or Objective-C which could lead to a game being easily adapted for Android. In-fact, just the option to write games in C++ alone would influence people to choose it over Objective-C so their game can be played on both platforms.

 

As for convenience it is a simple matter, many programmers (myself included) are used to C++ and have some libraries they worked on. So added to the benefit of not having to write different code for different platforms (except for the application initialisation and some lifecycle events), the programmer will feel most comfortable using their "natural" language.

 

This is at least the case as I see it. I hope I made a good case for it ;)




#5113943 Android NDK Development - Would like feedback

Posted by Shanee on 02 December 2013 - 10:35 PM

I released Part III last night. You can find it here:

http://shaneenishry.com/android-ndk-programming-part-iii/

 

I might go over and give it a small edit still but I think it will not be anything major ;)




#5113494 Android NDK Development - Would like feedback

Posted by Shanee on 01 December 2013 - 09:27 AM

As for EGL and multi-threading for rendering. As far as I remember, and I will look into it again in the coming days/week: You can create the context on your C++ side and you can create multiple contexts for multi-threaded use.

 

The first half of the statement I know is 100% true. The second part I am pretty sure to be true except for Vertex Array Objects. I will try to get definitive answer by next week.

 

Thanks for the lovely feedback!




#5113492 Android NDK Development - Would like feedback

Posted by Shanee on 01 December 2013 - 09:21 AM

I just remembered there is an important subject I forgot to mention, the JNI_OnLoad. I will try to put it on the next article.
 

jint JNI_OnLoad( JavaVM* pJavaVM, void* pReserved )
{
    JNIEnv* pEnv;
    if ( pJavaVM->GetEnv(reinterpret_cast<void**>( &pEnv ), JNI_VERSION_1_6) != JNI_OK )
    {
        return -1;
    }
 
    // Get jclass with pJavaVM->FindClass.
    // Register methods with pJavaVM->RegisterNatives.
    ...
 
    return JNI_VERSION_1_6;
}



#5113407 Android NDK Development - Would like feedback

Posted by Shanee on 30 November 2013 - 09:31 PM

Hi Grimsaw,

 

Thank you again for your feedback.

 

I know I still didn't get to the "meat" of things, I wanted to avoid making the article twice the size it is already.

 

I am with you on "what's the point of using it" if you already decided to inherit the Java class. As for the OpenGL Context, the next chapter I will show how you create it on C++ even without the NativeActivity by using EGL.

 

As for performance, as far as I know both approaches are limited by frame rate, therefore I suspect there shouldn't be any difference in performance using native callbacks over having a ful C++ thread. That will at least prevent having to sync the threads and unpleasant JNI code. That's my opinion anyway.




#5113361 Android NDK Development - Would like feedback

Posted by Shanee on 30 November 2013 - 04:37 PM

Hi Grimshaw,

 

Thank you  for your feedback, it is really helpful. I am still somewhat torn between NativeActivity inherited and non NativeActivity and I am currently leaning toward the non NativeActivity.

 

I have worked all Saturday on this and finally it is here:

http://shaneenishry.com/android-ndk-programming-part-ii/

 

As for the advantages and disadvantages of the two, I am still working this out myself. The NativeActivity generally creates a thread and runs C++ from there, queueing events to the thread. I am not yet sure if there is performance gained from that although it is possible. The new article explains this, as well as why it is important to keep Java accessible (and therefore not use a fully NativeActivity implementation).

 

I am also wondering if it is worth having a new thread for complicating the use of Google APIs with the application. That is why I have decided to use the Java native calls route for now.

 

Hope you enjoy it and again, will love all feedback.

 

Thanks,

~ Shanee




#5113042 Android NDK Development - Would like feedback

Posted by Shanee on 29 November 2013 - 01:57 PM

Hi everyone,

 

I am working on a series of Android NDK Development articles for my blog and would love your feedback. 

 

The first article can be found here: http://shaneenishry.com/android-ndk-programming-part-i/

 

If they are found useful I will consider re-creating them using the Articles tools.

 

Thanks smile.png

 




PARTNERS