Wartime

Members
  • Content count

    14
  • Joined

  • Last visited

Community Reputation

103 Neutral

About Wartime

  • Rank
    Member
  1. I've forgot to upload the final source-code. We have got an 1.0 (excellent) for our Project. Thanks to all who helped us. Here is the final sourcecode. Feel free to use it for your own projects.
  2. Hi there, As some of you know, we are programming an MineCraft-like game. This works very well. We are allowed to flyring around, selecting blocks, etc.... Now we have a real problem. We want to add a block if somebody clicks the left mousebutton. But if we add a block we have a graphic problem. The world is divided in chunks (16*16*16 blocks). If we add a block or sometimes if we are flying around some chunks are going to dissapear. We don't know why and so we want to ask you if you can help us. I've added the complete sourcecode. Feel free to use it for your own projects if you want. [attachment=8694:Kubos.rar] [color=#ff0000]--------------------------------------------------------------------------------------------[/color] [color=#ff0000]Problem solved.[/color] [color=#ff0000]In Class "Chunks"->prepare we forgot to reset the variable "index" to "0";[/color]
  3. Hi, Thank you for help. Sry for answering so late, I attened a funeral today. I will try Bullet (I used it for another game and it was really good) again. Otherwise I try another solution i found out yesterday: Get all blocks you are sorrunded with a distance of three blocks. Do a d3dxboundingboxtest. All boxes that collide with the ray, do a d3dxintersecttri test. So i know which surface my ray is intersecting. This could work too.
  4. Hi there, As you can see here [url="http://www.gamedev.net/topic/623627-vertexbuffer-performance-issue-idea-for-a-strategy/"]http://www.gamedev.n...for-a-strategy/[/url] I'm programming a minecraft-like game. A lot of things are done. The only thing I need help with is to make a collision detection. At the moment the game allows flying around with a first person camera and i want to detect which block and which side of a block a user is facing. Have you got any ideas to realizing this? If you need some code of our game please ask. You can get the whole if you want. [attachment=8493:Kubos.rar] Thanks for help
  5. Thank you for your help. Our game is going full speed ahead. Here is the newest version: [attachment=8473:Kubos.rar]
  6. OK, Still one question: Situation: I filled the buffer until it's full. Now I draw the Vertices and flush the Buffer. Second thing is that I fill it again with other vertices (because the buffer was full) and render. If I re-render the frame (nothing has changed) i have to fill the buffer twice. Once with the first data and then with the second to redraw all vertices, or?
  7. Thank you both. If I understand you the solution is: [list=1] [*]Create the Vertex and Idexbuffer once on Startup. [*]Fill the buffers until they are full [*]Draw the Primitives [*]Clear Buffers [*]If there are more Vertices go to 2 [/list] If this ist right, I've got another question: What is if I walk around on the map. The chunks i view change permanent if I turn around or go forward for a long time. So I have to change the buffer-content all the time. How can I do this? Or is there another solution.
  8. Here is my code to create a chunk: [CODE] void WorldChunk::createChunk() { vert_count = 0; index_count = 0; index_number = 0; CUSTOMVERTEX* Vertices; int* Indices; cdevice->CreateVertexBuffer( 24 * 16 * 16 * 16 * sizeof( CUSTOMVERTEX ), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &VB, NULL ); cdevice->CreateIndexBuffer(36 * 16 * 16 * 16 *sizeof(int),D3DUSAGE_WRITEONLY,D3DFMT_INDEX32,D3DPOOL_DEFAULT,&IB,NULL); VB->Lock( 0, 0, ( void** )&Vertices, D3DLOCK_DISCARD); IB->Lock(0,0,(void **)&Indices, D3DLOCK_DISCARD); for(int x = 0; x < 16; x++) { for(int y = 0; y < 16; y++) { for(int z = 0; z < 16; z++) { //Ist da kein Block zeichnen wir den nicht... if(chunk[x][y][z] == 0) continue; block_type = chunk[x][y][z]; //Befinden wir uns am linken Rand? Dann haben wir keinen linken Nachbarn ansonsten holen wir den aus dem Chunk-Array //Dasselbe gilt für alle anderen Richtungen (Hab keine Lust, das für jede Abfrage zu wiederholen ;-) ) if(x > 0) { testblock = chunk[x-1][y][z]; }else{ testblock = 0; } if(testblock == 0) { Vertices[vert_count].position = D3DXVECTOR3(x,y,z+1); Vertices[vert_count].tu = 0.0f+((float)(block_type-1))*0.25f; Vertices[vert_count].tv = 1.0f; ver.push_back(Vertices[vert_count]); Indices[index_count] = index_number; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+1].position = D3DXVECTOR3(x,y+1,z+1); Vertices[vert_count+1].tu = 0.0f+((float)(block_type-1))*0.25f; Vertices[vert_count+1].tv = 0.0f; ver.push_back(Vertices[vert_count+1]); Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+2].position = D3DXVECTOR3(x,y,z); Vertices[vert_count+2].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+2].tv = 1.0f; ver.push_back(Vertices[vert_count+2]); Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+3].position = D3DXVECTOR3(x,y+1,z); Vertices[vert_count+3].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+3].tv = 0.0f; ver.push_back(Vertices[vert_count+3]); Indices[index_count] = index_number+3; ind.push_back(Indices[index_count]); index_count++; index_number += 4; vert_count += 4; //Erhöhe den Zähler um 6 , weil wir 6 Vertices gezeichnet haben... } if(x < 16-1) { testblock = chunk[x+1][y][z]; }else{ testblock = 0; } if(testblock == 0) { Vertices[vert_count].position = D3DXVECTOR3(x+1,y,z+1); Vertices[vert_count].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count].tv = 1.0f; ver.push_back(Vertices[vert_count]); Indices[index_count] = index_number; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+1].position = D3DXVECTOR3(x+1,y+1,z+1); Vertices[vert_count+1].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count+1].tv = 0.0f; ver.push_back(Vertices[vert_count+1]); Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+2].position = D3DXVECTOR3(x+1,y,z); Vertices[vert_count+2].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+2].tv = 1.0f; ver.push_back(Vertices[vert_count+2]); Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+3].position = D3DXVECTOR3(x+1,y+1,z); Vertices[vert_count+3].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+3].tv = 0.0f; ver.push_back(Vertices[vert_count+3]); Indices[index_count] = index_number+3; ind.push_back(Indices[index_count]); index_count++; index_number += 4; vert_count += 4; //Erhöhe den Zähler um 6 , weil wir 6 Vertices gezeichnet haben... } if(y > 0) { testblock = chunk[x][y-1][z]; }else{ testblock = 0; } if(testblock == 0) { Vertices[vert_count].position = D3DXVECTOR3(x,y,z); Vertices[vert_count].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count].tv = 1.0f; ver.push_back(Vertices[vert_count]); Indices[index_count] = index_number; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+1].position = D3DXVECTOR3(x,y,z+1); Vertices[vert_count+1].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count+1].tv = 0.0f; ver.push_back(Vertices[vert_count+1]); Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+2].position = D3DXVECTOR3(x+1,y,z); Vertices[vert_count+2].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+2].tv = 1.0f; ver.push_back(Vertices[vert_count+2]); Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+3].position = D3DXVECTOR3(x+1,y,z+1); Vertices[vert_count+3].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+3].tv = 0.0f; ver.push_back(Vertices[vert_count+3]); Indices[index_count] = index_number+3; ind.push_back(Indices[index_count]); index_count++; index_number += 4; vert_count += 4; //Erhöhe den Zähler um 6 , weil wir 6 Vertices gezeichnet haben... } if(y < 16-1) { testblock = chunk[x][y+1][z]; }else{ testblock = 0; } if(testblock == 0) { Vertices[vert_count].position = D3DXVECTOR3(x,y+1,z); Vertices[vert_count].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count].tv = 1.0f; ver.push_back(Vertices[vert_count]); Indices[index_count] = index_number; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+1].position = D3DXVECTOR3(x,y+1,z+1); Vertices[vert_count+1].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count+1].tv = 0.0f; ver.push_back(Vertices[vert_count+1]); Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+2].position = D3DXVECTOR3(x+1,y+1,z); Vertices[vert_count+2].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+2].tv = 1.0f; ver.push_back(Vertices[vert_count+2]); Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+3].position = D3DXVECTOR3(x+1,y+1,z+1); Vertices[vert_count+3].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+3].tv = 0.0f; ver.push_back(Vertices[vert_count+3]); Indices[index_count] = index_number+3; ind.push_back(Indices[index_count]); index_count++; index_number += 4; vert_count += 4; //Erhöhe den Zähler um 6 , weil wir 6 Vertices gezeichnet haben... } if(z > 0) { testblock = chunk[x][y][z-1]; }else{ testblock = 0; } if(testblock == 0) { Vertices[vert_count].position = D3DXVECTOR3(x,y,z); Vertices[vert_count].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count].tv = 1.0f; ver.push_back(Vertices[vert_count]); Indices[index_count] = index_number; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+1].position = D3DXVECTOR3(x,y+1,z); Vertices[vert_count+1].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count+1].tv = 0.0f; ver.push_back(Vertices[vert_count+1]); Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+2].position = D3DXVECTOR3(x+1,y,z); Vertices[vert_count+2].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+2].tv = 1.0f; ver.push_back(Vertices[vert_count+2]); Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+3].position = D3DXVECTOR3(x+1,y+1,z); Vertices[vert_count+3].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+3].tv = 0.0f; ver.push_back(Vertices[vert_count+3]); Indices[index_count] = index_number+3; ind.push_back(Indices[index_count]); index_count++; index_number += 4; vert_count += 4;//Erhöhe den Zähler um 6 , weil wir 6 Vertices gezeichnet haben... } if(z < 16-1) { testblock = chunk[x][y][z+1]; }else{ testblock = 0; } if(testblock == 0) { Vertices[vert_count].position = D3DXVECTOR3(x,y,z+1); Vertices[vert_count].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count].tv = 1.0f; ver.push_back(Vertices[vert_count]); Indices[index_count] = index_number; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+1].position = D3DXVECTOR3(x,y+1,z+1); Vertices[vert_count+1].tu = 0.0f+(block_type-1)*0.25f; Vertices[vert_count+1].tv = 0.0f; ver.push_back(Vertices[vert_count+1]); Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+2].position = D3DXVECTOR3(x+1,y,z+1); Vertices[vert_count+2].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+2].tv = 1.0f; ver.push_back(Vertices[vert_count+2]); Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+2; ind.push_back(Indices[index_count]); index_count++; Indices[index_count] = index_number+1; ind.push_back(Indices[index_count]); index_count++; Vertices[vert_count+3].position = D3DXVECTOR3(x+1,y+1,z+1); Vertices[vert_count+3].tu = 0.25f+(block_type-1)*0.25f; Vertices[vert_count+3].tv = 0.0f; ver.push_back(Vertices[vert_count+3]); Indices[index_count] = index_number+3; ind.push_back(Indices[index_count]); index_count++; index_number += 4; vert_count += 4; //Erhöhe den Zähler um 6 , weil wir 6 Vertices gezeichnet haben... } } } } //**************************************************************************************************************** IB->Unlock(); VB->Unlock(); [/CODE] If it's created i use the vectors to "quick fill" the buffers in the next frame (the vertices don't change) [CODE] void WorldChunk::QuickFill() { void* vv = NULL; void* ii = NULL; cdevice->CreateVertexBuffer( ver.size()*sizeof(CUSTOMVERTEX),D3DUSAGE_DYNAMIC, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &VB, NULL ); cdevice->CreateIndexBuffer(ind.size()*sizeof(int),D3DUSAGE_DYNAMIC,D3DFMT_INDEX32,D3DPOOL_DEFAULT,&IB,NULL); VB->Lock(0,(ver.size()+10)*sizeof(CUSTOMVERTEX),(void**)&vv,D3DLOCK_DISCARD); memcpy(vv,&ver[0],ver.size()*sizeof(CUSTOMVERTEX)); VB->Unlock(); IB->Lock(0,(ind.size()+10)*sizeof(int),(void**)&ii,D3DLOCK_DISCARD); memcpy(ii,&(ind[0]),ind.size()*sizeof(int)); IB->Unlock(); } [/CODE]
  9. [quote name='jischneider' timestamp='1334770261' post='4932529'] Why don’t you try first to copy only one time the buffers and see the performance? The scene will be static and won’t be any culling, of course. But if it runs fast then we have information about your bottleneck. [/quote] If I fill the Buffers once and draw draw the primitives the program runs with 60 fps. I think your right, that the bottleneck is copying the std::vectors into the buffers. Have you got any idea to fix the problem with the performance issue?
  10. I've found a bottelneck in my code. I call SetTexture for every chunk [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img] Now I'm calling it once and the performance is better. I've searched for "Dynamic Vertex Buffers", but I don't understand it.
  11. Ok, thanks. How does Dynamic Vertexbuffer work and how can I use it? Is there an example or can anybody post some example code? Thanks
  12. Not directly. I remove the faces bewteen two blocks, not chunks.... Another strategy i use (it's not in the source) is, that I calculate the Normal of the camera and where i look and compare it with the normals of the chunk. So I only fill in vertices that are visible and not behind, but it doesn't increase the performance.
  13. Hi there, I'm new in this forum. At our university we have to program a game with DirectX9. Me and some other students wanted to program a Minecraft-like game, but without unlimited terrain (don't worry [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img] ) Now we have a problem with our performance. Our strategy is, that we have a chunk with 16^3 blocks. We are going through all blocks and look if there is a neighbour above, in front, ..... If there is one we dont put the vertices and indices of this side of the cube into the buffer. This works really quick. Now we made a class for a chunk. In this class we create the buffers and put in the vertices and indices and save them in a std::vector. On rendering we fill the buffers with memcpy and draw the primitives. If i try to draw 4 chunks, everything works fine with 60 fps. But if I try to draw more chunks (e.g. 64) the performance goes down to 8 fps. I've added my source-code and wanted to ask for a strategy to improve the performance. Source: [attachment=8313:Kubos.zip] I hope you understand me (I'm german and my english isn't very well [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] )