Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Path-finding for an Android TD - A* in JNI?  (Read 1058 times)
0 Members and 1 Guest are viewing this topic.
Offline DeanMSands3

Junior Newbie




C/C++ Dev learning Android


« Posted 2012-10-20 05:08:09 »

I'm looking to make a Tower Defense on Android for a university class final project. For this, I will need to use a Path-Finding algorithm (A*, D*, D*-lite, etc.). Path-finding tends to be time-consuming, and I want this to work on 2.3.3 era phones. Also, one of the requirements for the project is I need to use OpenGL. That means more time-consumption.
So I'm thinking... Native Code for the path-finding. I'm really a C/C++ dev anyway. And it would NOT be my first multiple code-language or multiple-architecture project (embedded firmware development makes me cry, but it also makes me money; I spend a lot of time crying.)

I'm looking at a blog post on JNI here: http://www.integratingstuff.com/2010/12/12/calling-native-c-code-through-jni-in-android-applications/ and it seems straight-forward enough.

Anyone have input on their JNI experiences?

BTW, first post, glad to be here, etc., etc.
-DeanMSands3

Embedded firmware development makes me cry. It also makes me money. I spend a lot of time crying.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-10-20 09:49:41 »

The overhead of JNI on Android is pretty damn gigantic, so whatever you do should be staying in native code for a while and not crossing back and forth with java willy-nilly.  Consider also that the constrained display of a phone is not likely to present a large field to be pathfinding over, and it isn't really that clear whether the native code approach will actually pay off. 

Obviously it depends on how complex your pathfinding actually is, and more obviously the only real answer is the one you actually measure.
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2012-10-20 09:55:13 »

Android's easily fast enough to run A* in Dalvik.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pitbuller
« Reply #3 - Posted 2012-10-20 11:18:44 »

The overhead of JNI on Android is pretty damn gigantic, so whatever you do should be staying in native code for a while and not crossing back and forth with java willy-nilly.  Consider also that the constrained display of a phone is not likely to present a large field to be pathfinding over, and it isn't really that clear whether the native code approach will actually pay off. 

Obviously it depends on how complex your pathfinding actually is, and more obviously the only real answer is the one you actually measure.
Quite not true. Libgdx use JNI at many places and many those are really small things like Matrix math and such. The overhead are there but older android versions dalvik is such crap that JNI version is usually much faster.

I still recommend first make pure java A* version and profile it. JNI can be such a hassle that make sure it's worth it.
Offline DrHalfway
« Reply #4 - Posted 2012-10-20 12:20:38 »

Surely for a TD game you wouldn't need to run the A* algorithm every frame iteration or even on a set update, could improvise and pre-calculate the path on a wave-wave basis?

And just because something is written in native code dos not make it better or faster than java/dalvik code. Profile first, and if its too slow, then think about going native. You'll find most optimization can be done at an algorithm/design level.

Offline DeanMSands3

Junior Newbie




C/C++ Dev learning Android


« Reply #5 - Posted 2012-10-20 20:08:32 »

OK, so the forum consensus is "No, but maybe." (I still think I'll try it.Wink) Duly noted. But that does leave me curious. Supposing I get started with libGDX and decide to work on a game. Are there any instances where JNI would be worthwhile?

Embedded firmware development makes me cry. It also makes me money. I spend a lot of time crying.
Offline EgonOlsen
« Reply #6 - Posted 2012-10-20 21:01:25 »

Supposing I get started with libGDX and decide to work on a game. Are there any instances where JNI would be worthwhile?
Depends on the game, but you can do pretty complex stuff in Java/on Dalvik if you aren't scared of doing some micro optimization of your most performance critical code sections.
For example, this uses pure Java and runs fine on an older Galaxy S class device: http://www.youtube.com/watch?v=olxPQ6zjNEA. But it required some optimizations to get there. Without them, it would run at maybe 60% the speed.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!