I am making a voxel-based game where large structures made of voxels can collide with each other. The game runs smoothly until two structures get to close to each other where it quickly drops to about 3 updates/second.
My current solution to adding these colliders to JBullet is by using a compound shape and using a greedy-meshing algorithm to make larger colliders out of adjacent blocks. While this is a drastic improvement over each voxel having its own collider, it still isn't fast enough to simulate large structures colliding.
I did a bunch of research and it seems that octrees are the only way to make this run in real time, but can't figure out how to add support for them in JBullet.
Related
I'm using Java2D in conjunction with apache batik to draw some fairly large svg images.
So far it is working quite nicely, but i am frustrated with the performance of areas. In particular, i have three things i want to accomplish:
merge a bunch of colliding shapes to one large area
removing a bunch of shapes from one large area
checking for colliding shapes
naively, point 1 and 2 can be accomplished with Area.add and Area.subtract.
This works, but can easily take up to twenty minutes in an average use case.
Point 3 can be accomplished by subtracting the areas from each other and checking the remaing area. Still slow, but can be sped up to be usable by using some prior spatial hashing or something similar.
Is there a better and faster way to merge/subtract Java2D areas?
If not, is there another library which can do this sort of thing faster?
unfortunately, libraries like JOGL or LWJGL do not work on a resolution independent space like svg-paths or the Java2D Paths.
You can try this: AreaX
According to the author:
The AreaX class is intended to achieve exactly the same visual results as the Area class. However several possible optimizations have been carefully implemented to reach those results faster.
I have been working on a voxel game for some time now, but all that I have really accomplished was the main menu and an Item system. Now its time to make the voxel engine. I have been searching for a while now to find some tutorials or an ebook that will teach me such, but the best i could find were someones tutorials in c++, but I am making mine in Java. I have dabbled in c++ and c# in the past but it was too difficult to translate i.e. it relied on a class that java doesn't have. What I know is that there are different methods for voxel engines, they all begin with rendering a single cube, and Perlin and Simplex noise can be used to randomize terrain generation.
If anyone could point me in the correct direction, most appreciated.
I will be checking back at least once a hour incase someone feels this thread is dead.
I'm not entirely sure what you are asking, if you are asking how to make simplex noise, implement it in a voxel engine or how to start making a voxel engine.
If you are asking how to start making a voxel engine I would recommend practising with quads first (2D version) and focus on getting an understanding for the theory. Once you are happy with your understanding you should focus on the voxel class (one cube) - it is very important to learn as much as you can from it, and then add more so you can optimize rendering as much as you can, such that hidden faces are not rendered and even vertices are shared, voxel engines can be the most wasteful renderers if not optimized!
EDIT:
Optimization can be done through many methods, The first and most important is hidden face removal, this involves removing the faces of voxels that are touching which will mean you will need to check of a voxel exists on any given side of any voxel before rendering that face (e.g before rendering the left face, check if there isn't a block to the left). Next is the rendering method, do not render each face or each group individually, group them so they can be rendered faster, this can be done by using display-lists or the more technical VBOs, these ensure the data is in the GPU or the data can be given to the GPU faster, For example Minecraft groups them in chunks of huge 16x16x128 groups and uses display lists. If you really want to reduce every single vertex in memory you can also consider using strip drawing methods (in OpenGL), these will require you to define certain vertices at a certain time in rendering but allow you to reuse a vertex for multiple faces.
Next would be understanding simplex noise, I can relate to there not being much material online for noise generation algorithms, unfortunately I cannot link material that I used as that was years ago. You can implement your noise algorithm in the 2D version to prove it works in a simpler environment and then copy it to the voxel version. Typical usage would be to use the values as heights in the terrain (e.g white=255 = 255 high).
I would recommend using Unity. The engine is already made and you can add menus and titles with just a few lines of code. All of the game creation is either in C# or Javascript which shouldn't be any huge change from C++. Good luck!
I'm busy coding Conways Game of Life and I'm trying to optimise it using some data structure that records which cells should be checked on each life cycle.
I'm using an arrayList as a dynamic data structure to keep a record of all living cells and their neighbours. Is there a better data structure or way of keeping a shorter list that will increase the games speed?
I ask this because often many cells are checked but not changed so I feel like my implementation could be improved.
I believe that the Hashlife algorithm could help you.
It gives the idea of using a quadtree (tree data structure in which each internal node has exactly four children) to keep the data, and then it uses hash tables to store the nodes of the quadtree.
For further reading, this post, written by Eric Burnett, gives a great insight about how Hashlife works, it's performance and implementation (although in Python). It's worth a read.
I built a Life engine that operated on 256x512 bit grids directly mapped to screen pixels back in the 1970s, using a 2Mhz 6800 8 bit computer. I did it directly on the display pixels (they were one-bit on/off white/black) because I wanted to see the results and didn't see the point in copying the Life image to the display.
Its fundamental trick was to treat the problem as one of evaluating a Boolean logic formula for "this cell is on" based on rules of Life, rather than counting live neighbors as is usual. This formula is pretty easy to figure out, so left as a homework exercise. What made it fast was that the Boolean formula was computed on a per-bit basis, doing 8 bits at a time. If you sweep down the screen and across rows, you can in essence evaluate N bits at once (8 on the 6800, 64 on modern PCs) with very low overhead. If you go nuts, you can likely use the SIMD vector extensions and do 256 bits or more at "once". Over the top would be doing this with a GPU.
The 6800 version would process a complete screen in about .5 second; you could watch the update ripple down the screen from top to bottom (60 Hz refresh). On a modern CPU with 1000x the clock rate (1 GHz is pretty easy to get) and 64 bits at a time, it should be able to produce thousands of frames per second. So fast you can't watch it run :-{
A useful observation is that much of the Life world is dead (blank) and processing that part mostly produces more dead cells. This suggests using a sparse representation. Another poster suggested quadtrees, which I think is a very good suggestion. Your quadtree regions don't have to be square, either.
Combining the two ideas, quadtrees for non-blank regions with bit-level processing for blocks of bits designated by the quadtrees is likely to give an astonishingly fast Life algorithm.
I'm trying to make a fully-automated game engine which needs to be working based on the events. The problem I'm facing is that I've made a map class and it's initialized in the game class. It's almost static and only one map exists for a game. New maps are loaded by clearing the objects in the current map and adding new maps. You can see the source of the map class here.
http://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/map/Map.java
The main problems comes in the collision detection, where I'm using the brute-force collision detection where I should not. This slows down the game a lot and I wanna check the collisions only for objects which are nearer to the object. I've been using the MapLoader interface to construct the maps. I'm thinking that calling the collision() method of the objects in another thread might help. How-ever it all the map objects are updated in the Game class.
Here's the game class if in case it might help
http://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/core/Game.java
There's another problem that some-times, the objects aren't destroyed. I'm calling the map's removeObject() method but it takes a 1-second delay and some times wont remove at-all.
It gives me 48-64 fps in a platform game with 158 objects in the game. But in a space-invaders style game, it gives me only 20-30 fps. Any advice on optimization is greatly appreciated...
If anybody could get me a tutorial for binary spacing etc., I would be thankful.
Two suggestions by looking at your code: first thing is that you should try to minimize object allocation in collision detection, don't create new Rectangles, work on data you already have by writing directly the collision detection algorithm.
Second an more important thing: a collision detection engine should work by using two levels:
a coarse level of collision already excludes objects that are surely too far to collide (you can use many techniques here, like a binary spatial partition algorithm of big colliding blobs, or hierarchical structure of objects)
a fine level which will compute specific details for the collision that can occur, with more precise algorithms
I'm being really ambitious and working on a 2D Shoot 'em Up game that will have, hopefully, hundreds of entities running around.
What I'm having trouble wrapping my brain around, is how the bullet will detect when it makes a collision with an object, without it checking for every object on the map. The reason is that I feel that if I have four dozen bullets on the screen, each checking for collision with every entity on the map, every cycle, I will see some fairly significant performance loss.
So what would be the best way to detect for collisions without checking every single entity?
I can handle the collision algorithm when I have my two objects, I just can't seem to find a way to get those two object to see each other without checking everyone else first.
I'm working in Java and OpenGL with (soon to be textured) QUADS.
You should investigate quadtrees; they're often used for efficient 2D lookup.