steg90
|
 |
«
Reply #150 - Posted
2013-04-19 21:40:59 » |
|
Just used it to store chunks, then I loop through this hashmap to render them.
Having problems getting the profile tab to appear in visualvm...
|
|
|
|
steg90
|
 |
«
Reply #151 - Posted
2013-04-20 08:54:34 » |
|
This code is causing the issue on the Dell: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| private CollisionType isCollision(int dir) {
Vector3f v = this.camera.getCameraPosition();
float tempx = (v.x) / BLOCKWIDTH * BLOCKHEIGHT; int tempX = (int) tempx;
float tempz = (v.z) / BLOCKWIDTH * BLOCKHEIGHT; int tempZ = (int) tempz;
float tempy = (v.y) / BLOCKWIDTH * BLOCKHEIGHT; int tempY = (int) tempy;
int bx = (int) tempX; int by = (int) tempY; int bz = (int) tempZ;
bx = bx % BLOCKWIDTH; bz = bz % BLOCKHEIGHT; by = by % BLOCKHEIGHT;
int zchunk = Math.abs(tempZ / Chunk.CHUNK_SIZE) * WORLDWIDTH; int xchunk = Math.abs(tempX / Chunk.CHUNK_SIZE); int chunktoget = zchunk + xchunk;
CollisionType collisionType = CollisionType.NONE;
Block b = null; b = ChunkManager.getInstance().getBlockInChunk(chunktoget, Math.abs(bx), (int) Math.abs(by), Math.abs(bz));
if (b != null && b.IsActive()) { Vector playerPosition = new Vector(); playerPosition.x = Math.abs(v.x); playerPosition.y = Math.abs(v.y); playerPosition.z = Math.abs(v.z); playerSphere.update(playerPosition, 1.0f);
AABB voxel = new AABB(1f, 1f, 1f); Vector voxelPosition = new Vector(); voxelPosition.x = Math.abs(bx); voxelPosition.y = Math.abs(by); voxelPosition.z = Math.abs(bz); voxel.update(voxelPosition);
if (CollisionLibrary.testCircleAABB(playerSphere, voxel)) { collisionType = CollisionType.GROUND; groundLevel = (int) voxelPosition.y; } }
for (int x = 0; x < Chunk.CHUNK_SIZE; x++) { for (int y = 2; y < Chunk.CHUNK_SIZE; y++) { for (int z = 0; z < Chunk.CHUNK_SIZE; z++) { b = ChunkManager.getInstance().getBlockInChunk(chunktoget, x, y, z);
if (b != null && b.IsActive()) {
Vector playerPosition = new Vector(); playerPosition.x = Math.abs(v.x); playerPosition.y = Math.abs(v.y); playerPosition.z = Math.abs(v.z); playerSphere.update(playerPosition, .8f);
AABB voxel = new AABB(1f, 1f, 1f); Vector voxelPosition = new Vector(); voxelPosition.x = x; voxelPosition.y = y; voxelPosition.z = z; voxel.update(voxelPosition);
if (CollisionLibrary .testCircleAABB(playerSphere, voxel)) { if (direction == 0) { collisionType = CollisionType.FRONT; } if (direction == 1) { collisionType = CollisionType.BACK; } if (direction == 2) { collisionType = CollisionType.LEFT; } if (direction == 3) { collisionType = CollisionType.RIGHT; } return collisionType; } } } } }
return collisionType; } |
Not calling, the game is fine - but the above is fine on my mac?
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Vermeer
|
 |
«
Reply #153 - Posted
2013-04-22 17:12:32 » |
|
I like how that's all looking, looks good with the trees and other blocks in the landscape. Really cool 
|
|
|
|
steg90
|
 |
«
Reply #154 - Posted
2013-04-22 19:46:05 » |
|
|
|
|
|
Vermeer
|
 |
«
Reply #155 - Posted
2013-04-22 20:12:36 » |
|
The domes look great. Add a surreal feel to the landscape. It's really looking like a world now, an interesting place to look around! 
|
|
|
|
steg90
|
 |
«
Reply #156 - Posted
2013-04-22 20:13:53 » |
|
Thanks pal :-)
PS - any insight into how you did the infinite landscape?
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #157 - Posted
2013-04-22 21:57:55 » |
|
Thanks pal :-)
PS - any insight into how you did the infinite landscape?
To have infinite terrain generation you need 3 things, dynamic storage of world, procedural generation, and chunk loading/unloading. The first can be achieved by storing chunks in a HashMap The second I believe you already have, but it might need some adjusting depending on how you did it. The third is two parts: - Loading chunks: You need to loop through all the places a chunk could be in a certain area, then add those positions to and arraylist if a) there isn't a chunk there, and b) they aren't already in that list, or the generating list. Then you take chunk positions out of that list, add them to a generating list, and put them in a chunk generation thread. Then every frame, you take complete chunks out of the generating list, and add them to the world. - Unloading chunks. Loop through all the loaded chunks, and if they are too far away, unload them.
|
|
|
|
Mike
|
 |
«
Reply #158 - Posted
2013-04-22 22:09:40 » |
|
The first can be achieved by storing chunks in a HashMap
Seeing as there will be a LOT of methods that read data out of the chunks I prefer to use a fixed size array for it for performance reasons. Just add a couple of shift functions so you can move the relative position of the array when you load/unload data and you're good to go. Mike
|
|
|
|
Vermeer
|
 |
«
Reply #159 - Posted
2013-04-23 18:03:49 » |
|
I used a fixed array of chunks. When you walk into a new chunk the direction indicates that chunks in the distance needs to be loaded. If it is on disk it overwrites the chunks in the array which would be behind you. This way you only need a fixed amount of chunks. If the chunks don't exist, I create a new row of them. I used a very basic diamond star idea. The chunk is then saved. http://www.java-gaming.org/user-generated-content/members/167679/exp1.jpgChunk generation: http://www.java-gaming.org/user-generated-content/members/167679/exp2.jpgI have tried to illustrate the concept. Please note that it is scaled down and not a full implementation of it! Adjust as needed for walking in other directions. Please ask if I have not covered it very well!
|
|
|
|
Games published by our own members! Check 'em out!
|
|
steg90
|
 |
«
Reply #160 - Posted
2013-04-24 08:34:03 » |
|
Interesting concept :-)
So you have max of 16 chunks? Static array of chunks:
chunksLoaded[16];
Where the array above stores chunks world location and I take it this is used for the filenames on disk? Example:
chunk3_3 - chunk at world offset 3,3?
Thanks
PS - do you do the loading in a separate thread?
|
|
|
|
Vermeer
|
 |
«
Reply #161 - Posted
2013-04-24 12:06:51 » |
|
@steg
I currently have an array of chunks[64] and this can be scaled. Each row needs 8 chunks.
Yes file names are calculated with ascii character based on world loaction - not stricty numbers....but are converted into the value of the char. But yes chunk1232_8829 would work the same! I havent moved that far away yet, but i was thinking of say every 256 chunks to put them in folders. I think MC did this AA AB AC where A =0 ;
if in the CF folder and the chunk3_78 would mean 3+(2*256) , 78+(5*256) world position
|
|
|
|
steg90
|
 |
«
Reply #162 - Posted
2013-04-25 09:40:03 » |
|
Thanks again @Vermeer
I'm going to try and look at implementing something like this over the weekend if I get any time!
|
|
|
|
|
Vermeer
|
 |
«
Reply #164 - Posted
2013-04-25 20:38:36 » |
|
That looks to be running really well, and the further draw distance give a better sense of space. Looking cool.
What are your plans to do next? Are you planning a GUI or any game play elements?
|
|
|
|
steg90
|
 |
«
Reply #165 - Posted
2013-04-25 20:57:28 » |
|
Hi, Thanks Dynamic loading has to be next to keep the memory stamp down and the fps up, at the moment you are seeing 16^3 chunks with a draw distance of 200. This consumes around 170mb ram and 48% CPU on average - hence need dynamic loading of chunks if wanting more. May put water in soon. Wouldn't mind looking at some perlin 3d noise stuff so can get caves...
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #166 - Posted
2013-04-25 21:30:33 » |
|
Dynamic loading has to be next to keep the memory stamp down and the fps up, at the moment you are seeing 16^3 chunks with a draw distance of 200. This consumes around 170mb ram and 48% CPU on average - hence need dynamic loading of chunks if wanting more.
I had the opposite problem with my voxel engine. 3-4% CPU & 600MB RAM with 192x192x192
|
|
|
|
steg90
|
 |
«
Reply #167 - Posted
2013-04-26 07:31:23 » |
|
3-4% CPU, what GPU was that running with?
How did you manage to get so many chunks running? I'm struggling with 16x16x16!
Regards, Steve
|
|
|
|
steg90
|
 |
«
Reply #168 - Posted
2013-04-26 17:41:36 » |
|
Think I'm going to next do:
1. Convert display lists to VBO's 2. Use triangles instead of quads 3. Switch to programmable pipeline...
Wish me luck!
|
|
|
|
Vermeer
|
 |
«
Reply #169 - Posted
2013-04-26 17:53:51 » |
|
good luck, tho I'm sure you will get that sorted.  Initially used triangles and found little difference with VBO's from quads. Though I believe quads are converted to triangles, so it makes sense to use triangles!
|
|
|
|
steg90
|
 |
«
Reply #170 - Posted
2013-04-26 17:56:24 » |
|
Yeah, quads are depreciated like most things in GL 3.2+
Think VBO's should give speed increase and is way to go with modern hardware, same as using the programmable pipeline. Luckily I have some experience with this with using Direct3D!
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #171 - Posted
2013-04-26 22:07:38 » |
|
3-4% CPU, what GPU was that running with?
How did you manage to get so many chunks running? I'm struggling with 16x16x16!
Regards, Steve
192 blocks, not chunks. I wish I could get it running with 192^3 chunks.  Anyway, I rewrote my world code, and now have 192x192x192 (blocks) in a static array using 200-300MB and taking up 10-20% CPU (it goes up when loading chunks), with infinite loading and the occasional 2-3 fps drop when loading. It still keeps overallocating memory whenever I'm loading chunks, but at least it's not as extreme as before. Unfortunately, I can't find where the 'memory leak' is now that I've fixed the one with chunks. Not a memory leak, the garbage collector is a second too late and it bumps up the permgen. The memory usage is actually ~200MB.
|
|
|
|
Longor1996
|
 |
«
Reply #172 - Posted
2013-04-27 13:54:34 » |
|
Hello everyone. It seems like (to me) that all of you have problems with Memory usage and Render distances. Is it that hard to make 16³ big chunks and have ~8192 of them rendered with a render distance of nearly 0.5 Km and a RAM usage of 240 Mb? (240 Mb because of Server/Client world chaching, the client alone only has a RAM usage of ~100 MB) Here is a tip on how to speed up your voxel engine like heck-no-what: Use 1 Dimensional Arrays and Integer ID's + MetaData for your blocks. This way here, is slow and memory comsuming: 1 2 3 4 5 6 7 8 9 10
| class Block { boolean isVisible; } class BlockGrass extends Block{ int GrassType; }
class Chunk{ Block[][][] contents; } |
Do this instead: 1 2 3
| class Chunk{ int[] blockData; } |
And use singleton classes to code the behavior of the blocks. Like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class Block{ abstract void onRightClick(World world,int x,int y,int z); abstract void onNeighborBlockChange(World world,int x,int y,int z); }
class Button{ void onRightClick(World world,int x,int y,int z){ world.setBlockID(x,y,z,BID_BUTTON_ON); } void onNeighborBlockChange(World world,int x,int y,int z){ if(checkIfButtonCanStayHere(world,x,y,z)){ dropBlockAsItem(world,x,y,z); } } } |
If you didn't understand something just ask as many questions as you wan't. - Longor1996
|
The cake is probably a lie... but it's a delicious lie!
|
|
|
steg90
|
 |
«
Reply #173 - Posted
2013-04-28 16:22:16 » |
|
Thanks Longor,
I'm changing mine now to be coded in C++ and using Shaders...
Will take on board what you have said and try the 1d array, I've heard that does speed things up a lot on other forums.
Not so sure about using a singleton pattern for blocks though...as there are many of these.
|
|
|
|
Longor1996
|
 |
«
Reply #174 - Posted
2013-04-28 17:12:06 » |
|
Thanks Longor,
I'm changing mine now to be coded in C++ and using Shaders...
Will take on board what you have said and try the 1d array, I've heard that does speed things up a lot on other forums.
Not so sure about using a singleton pattern for blocks though...as there are many of these.
Here's another tip: Don't switch the programming language to C++. Why? Writing a Voxel Engine in C++ is incredible hard because of memory-management. Also, you won't get any big speed improvements in C++, because Java is as fast as C++ with JIT, Runtime-Optimization etc.etc (i heard so). The biggest problem in C++ are the memory leaks. Java has them too (i heard so), but they aren't very big (i heard so too). Oh, and you can use Shaders in Java too. If you rewrite your Engine in C++, good luck! - Longor1996
|
The cake is probably a lie... but it's a delicious lie!
|
|
|
steg90
|
 |
«
Reply #175 - Posted
2013-04-28 17:44:11 » |
|
Thanks again Longor,
I'm fine with C++ though, been coding in it for 16 years ;-)
Not sure myself if Java is as fast, what with the JVM and all.
Ive started writing it in C++ now, just basically porting my java code to it. Got my chunk class and block class sorted. I'm using FreeGLUT and FreeGLEW and OGL 3.2 (that is the highest my gfx card supports).
Thanks
|
|
|
|
Mike
|
 |
«
Reply #176 - Posted
2013-04-28 18:12:51 » |
|
Good luck with writing it in C++. If you could post a performance comparison when finished it would be great.  Mike
|
|
|
|
steg90
|
 |
«
Reply #177 - Posted
2013-04-28 21:19:40 » |
|
Will do, hoping to have something up by weekend...hoping!
|
|
|
|
Agro
|
 |
«
Reply #178 - Posted
2013-04-28 21:31:30 » |
|
Good luck with C++! You're sort of lucky since you get more direct control with memory. Its important with something huge like this because if you don't do it right, bad stuff will happen, but if you do do it right, then results will be outstanding! 
|
|
|
|
steg90
|
 |
«
Reply #179 - Posted
2013-04-28 21:48:43 » |
|
I know what you mean.
Need to find a good C++ texture loader...next mission!
|
|
|
|
|