Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 4 5 [6] 7
  ignore  |  Print  
  Voxel - a start  (Read 18460 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Member


Medals: 1



« Reply #150 - Posted 2013-04-19 23: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...
Offline steg90

Senior Member


Medals: 1



« Reply #151 - Posted 2013-04-20 10: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));

      // Check ground
     if (b != null && b.IsActive()) {
         // playerSphere radius is 1
        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); // width, height, depth
        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;
         }
      }

      // Check chunk for any collisions - should have early bail out
     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); // width, height,
                                            // depth
                 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?

Offline steg90

Senior Member


Medals: 1



« Reply #152 - Posted 2013-04-21 23:53:39 »

Update:

Some collision...
Random landscape creation
Very basic trees
Random items


https://www.youtube.com/watch?v=19-0c1iGA2I


Thanks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Vermeer

JGO Coder


Medals: 16



« Reply #153 - Posted 2013-04-22 19:12:32 »

I like how that's all looking, looks good with the trees and other blocks in the landscape. Really cool Smiley
Offline steg90

Senior Member


Medals: 1



« Reply #154 - Posted 2013-04-22 21:46:05 »

Take a look at:

https://www.youtube.com/watch?v=DyAheqbhbk4

Thanks
Offline Vermeer

JGO Coder


Medals: 16



« Reply #155 - Posted 2013-04-22 22: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! Smiley
Offline steg90

Senior Member


Medals: 1



« Reply #156 - Posted 2013-04-22 22:13:53 »

Thanks pal :-)

PS - any insight into how you did the infinite landscape?
Online HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #157 - Posted 2013-04-22 23: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.

Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #158 - Posted 2013-04-23 00: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

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline Vermeer

JGO Coder


Medals: 16



« Reply #159 - Posted 2013-04-23 20: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.jpg


Chunk generation:

http://www.java-gaming.org/user-generated-content/members/167679/exp2.jpg

I 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!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Member


Medals: 1



« Reply #160 - Posted 2013-04-24 10: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?
Offline Vermeer

JGO Coder


Medals: 16



« Reply #161 - Posted 2013-04-24 14: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
Offline steg90

Senior Member


Medals: 1



« Reply #162 - Posted 2013-04-25 11: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!

Offline steg90

Senior Member


Medals: 1



« Reply #163 - Posted 2013-04-25 22:30:28 »

Update:

Frustum culling
Further field of view
Some spatial portioning
Updates to camera vectors
Few bug fixes


https://www.youtube.com/watch?v=fSp-54tGgLU



Thanks
Offline Vermeer

JGO Coder


Medals: 16



« Reply #164 - Posted 2013-04-25 22: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?
Offline steg90

Senior Member


Medals: 1



« Reply #165 - Posted 2013-04-25 22:57:28 »

Hi,

Thanks  Grin

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...



Online HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #166 - Posted 2013-04-25 23: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

Offline steg90

Senior Member


Medals: 1



« Reply #167 - Posted 2013-04-26 09: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
Offline steg90

Senior Member


Medals: 1



« Reply #168 - Posted 2013-04-26 19: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!
Offline Vermeer

JGO Coder


Medals: 16



« Reply #169 - Posted 2013-04-26 19:53:51 »

good luck, tho I'm sure you will get that sorted. Smiley

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!

Offline steg90

Senior Member


Medals: 1



« Reply #170 - Posted 2013-04-26 19: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!
Online HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #171 - Posted 2013-04-27 00: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. Grin

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.

Offline Longor1996
« Reply #172 - Posted 2013-04-27 15: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

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Member


Medals: 1



« Reply #173 - Posted 2013-04-28 18: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.
Offline Longor1996
« Reply #174 - Posted 2013-04-28 19: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

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Member


Medals: 1



« Reply #175 - Posted 2013-04-28 19: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

Offline Mike

JGO Wizard


Medals: 69
Projects: 2
Exp: 5 years


Java guru wanabee


« Reply #176 - Posted 2013-04-28 20:12:51 »

Good luck with writing it in C++. If you could post a performance comparison when finished it would be great. Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline steg90

Senior Member


Medals: 1



« Reply #177 - Posted 2013-04-28 23:19:40 »

Will do, hoping to have something up by weekend...hoping!

Offline Agro
« Reply #178 - Posted 2013-04-28 23: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! Smiley

Offline steg90

Senior Member


Medals: 1



« Reply #179 - Posted 2013-04-28 23:48:43 »

I know what you mean.

Need to find a good C++ texture loader...next mission!
Pages: 1 ... 4 5 [6] 7
  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.

xsi3rr4x (62 views)
2014-04-15 18:08:23

BurntPizza (60 views)
2014-04-15 03:46:01

UprightPath (73 views)
2014-04-14 17:39:50

UprightPath (56 views)
2014-04-14 17:35:47

Porlus (73 views)
2014-04-14 15:48:38

tom_mai78101 (99 views)
2014-04-10 04:04:31

BurntPizza (159 views)
2014-04-08 23:06:04

tom_mai78101 (254 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!