Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Game development with Java


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
25 replies to this topic

#21 SimonForsman   Crossbones+   -  Reputation: 6666

Like
0Likes
Like

Posted 06 August 2013 - 04:16 AM

So would a 2D array likely have been better, even though for say [y][x] (as well as the order being somewhat confusing) creates height+1 separate arrays (and then likely requires a temp and memcpy if it ever interacts with native code, e.g. to display it)? In 3D for a block game like minecraft that seems even worse.

 

If not then I guess that is actually a good reason to suggest building stuff like Minecraft in C.

 

regardless of language you really should use a single dimensional array and access it linearly to avoid cache misses most of the time (the cost of the extra arithmetics is far smaller than the cost of cache misses for large arrays). in C and C++ 2D array will be identical to a 1D array behind the scenes though and you only have to worry about iterating over it effectivly ([x][y] vs [y][x] depending on which way you're looping for example) making those languages a bit easier to work with for such cases.

 

in Java a 2D array will not be a single block of memory and thus requires 2 dereferences per access and is far more likely to cause cache misses, since you want to iterate over the datablock linearly anyway regardless of language you should use a 1D array as often as possible (As its most cache friendly) its best to figure out where to start and stop before the loop (then Java can usually do the bounds check just once for the whole loop making it a non issue).

 

It can be quite a bit easier to write such things well using a language with low level features though. (I wouldn't use C myself as C++ provides more or less the same low level features + a whole bunch of useful high level features anyway)


Edited by SimonForsman, 06 August 2013 - 04:19 AM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Sponsor:

#22 SyncViews   Members   -  Reputation: 507

Like
0Likes
Like

Posted 06 August 2013 - 04:31 AM

I meant C++ smile.png. So basically despite all these benchmarks saying how Java is as good as C/C++, as soon as you need to deal with images, maps, etc with 2D and 3D arrays your kind of sunk in Java, since many algorithms can not work with a single linear scan, because you often need data from all adjacent cells and both [y * width + x] and [y][x] have problems in Java and java an not infer things like "array length = width * height" and the "[y * width + x]" is bounded by width and height?

 

Wonder what a profile of Minecraft looks like. Even with optimisations like avoiding a hash map to get a chunk reference many of my algorithms (e.g. building the renderer vertex arrays, lighting calculations, things like grass spreading) are pretty much 20% reading block data...


Edited by SyncViews, 06 August 2013 - 04:34 AM.


#23 TheChubu   Crossbones+   -  Reputation: 6283

Like
0Likes
Like

Posted 06 August 2013 - 10:26 AM

I'm pretty sure the JIT compiler can infer those kind of things. Once I saw a guy who showed the assembly of what the JIT compiler did to an iteration over an ArrayList, it simplified it to an iteration over a primitive array. I remind you that ArrayList is operated by accessor/mutator methods only and that it uses Iterator objects for traversing the array, so it ended up throwing all that indirection away. Bytecode tells you nothing about what will eventually get executed, the only way is to look through what the JIT compiler does to it

 

It can do other kinds of "magic" too, like inlining virtual method calls, thus no pointer hopping for calling methods of abstract classes or interfaces.

 

Some VM things are pretty neat, I'd be more worried about memory usage (which is a very documented issue) rather than performance. You can lookup Oracle's articles on object construction in HotSpot VM, which will tell you the approximate costs of doing things in Java instead of native code. IIRC, i think that avg memory costs for allocating Java objects were 30% higher on a 32 bit VM, or even more when 64 bit pointers are used.

 

The actual allocation of objects is fast (some people even say that its faster than doing a malloc() call) but its the additional overhead of metadata about the objects that creates memory (over)usage issues. Moreover, the GC doesn't likes to work on memory constrained environments, so the memory requirements of your program end up being even bigger than the actual memory usage of the program.

 

Its just a big pile of tradeoffs really :D


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#24 Eamonn Rea   Members   -  Reputation: 54

Like
0Likes
Like

Posted 07 August 2013 - 02:20 PM

So, I should use Java for game development?



#25 SyncViews   Members   -  Reputation: 507

Like
0Likes
Like

Posted 08 August 2013 - 02:01 AM

Well if you don't plan to exceed Minecraft's scale then I think Java is still the easier / more productive choice, although C++ these days is a lot easier to work with (than before, not Java), still has the learning curve.

 

On my current project going to have to say most of my problems are not really language, related, but more with designing the algorithms to achieve something,e.g. getting light calculations to work reliably with a chunked world, making use of multiple threads so I can have a larger loaded world, AI etc. So learning about those things applies to nearly any language.

 

There is the performance aspect, but thats the exceeding Minecraft bit, like supporting a view distance of 500m (256 in Minecraft?), and more persistent stuff like villages that actually do stuff.



#26 TheChubu   Crossbones+   -  Reputation: 6283

Like
1Likes
Like

Posted 08 August 2013 - 07:56 AM

So, I should use Java for game development?

Yes. Go and code something.


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS