Sign in to follow this  
Zulfus_101080

[Solved] DirectX Load Time Question - 256 x 256 Map - no textures

Recommended Posts

Zulfus_101080    103
[b]Edit: [/b][b]RulerOfNothing was correct, I was using too many calls to cout to check all my vertice/indice values. [/b]

Hey, I've been programming a while, but pretty new to directx/win32 programming and i've finally run into something I can't really find on google, so i've decided to create an account and ask you guys! (Yay! or groan maybe? haha)

Anyway, my question is basically this; I have a basic engine going using directx/c++ that'll basically let you input a width and it'll draw a square map with that width/height. At small values it takes no time at all to load, but if I start increasing it to 50+ it starts to take a while to load, at 100x100 it takes ~30 seconds, and at 256 x 256 it takes atleast a minute (maybe 2-3 - feels like forever!) to load.

This seems pretty excessive considering I have little else, just a sky box and low poly model with a basic texture on the screen.

I assume this isn't normal based off current games loading times, I don't know much about culling & I also have some basic lighting going on?

Do I just have a poor algorithm or is there some culling option or something else I can do to get the time down?

Here's the code that draws the vertices/indicies;

This basically calculates everything & puts it in arrays;

[CODE]
void loadMap(int width){

SecureZeroMemory(arrayx, sizeof(arrayx));
SecureZeroMemory(arrayy, sizeof(arrayy));
SecureZeroMemory(arrayz, sizeof(arrayz));
SecureZeroMemory(indx, sizeof(indx));
SecureZeroMemory(indy, sizeof(indy));
SecureZeroMemory(indz, sizeof(indz));

int widthx = width;
int counter = 0;
int xtrack = 0;
int zvalue = 0;
int limit = (widthx+1) * (widthx+1);
while(counter < limit){

arrayx[counter] = xtrack;
arrayy[counter] = 0;
arrayz[counter] = zvalue;

if( xtrack > 0 && xtrack % widthx == 0)
{
xtrack = 0;
++zvalue;
} else { ++xtrack;}
++counter;
}
counter = 0;
cout << "\n x: ";
while(counter < limit){
cout << arrayx[counter];
++counter;
}
counter = 0;
cout << "\n y: ";
while(counter < limit){
cout << arrayy[counter];
++counter;
}

counter = 0;
cout << "\n z: ";
while(counter < limit){
cout << arrayz[counter];
++counter;
}

/********* indicies loop **********/
int totaltriangles = (widthx * widthx) * 2;
counter = 0;
int yoffset = widthx+1;
int zoffset = 1;
int zup = width + 2;
int xoffset = 0;
int eor = 1; //end of row
int eorMax = width * 2; //value eor resets at
while ( counter < totaltriangles){
indx[counter] = xoffset;
indy[counter] = yoffset;

if(counter % 2 == 0 || eor == eorMax ){
++xoffset;}
if(counter % 2 == 1){
indz[counter] = zup; ++zup;
++yoffset;
++zoffset;
} else {
indz[counter] = zoffset;

}

if(eor < eorMax){++eor;}
else{eor = 1; ++yoffset; ++zoffset; ++zup;}
++counter;
}
counter = 0;
cout << "\n\n Indicy Arrays: \n x:";
while(counter < totaltriangles){
cout << indx[counter];
++counter;
}
counter = 0;
cout << "\n y: ";
while(counter < totaltriangles){
cout << indy[counter];
++counter;
}
counter = 0;
cout << "\n z: ";
while(counter < totaltriangles){
cout << indz[counter];
++counter;
}
cout << "\n";
}
[/CODE]

And this sends it all to the vertex/index buffers;

[CODE]
void init_graphics(void)
{
loadMesh();
buildSkyBox();
loadMap(MAP_WIDTH); //Load map data into arrays based on map size
int counter = 0; //Generic Loop Counter
limit = (MAP_WIDTH+1) * (MAP_WIDTH+1); //Calculate number of vertices
int sizearray = sizeof(CUSTOMVERTEX) * limit; //Calculate size of array to store vertices

CUSTOMVERTEX *vertices = new CUSTOMVERTEX[limit]; //Allocate memory on the heap
while(counter < limit){ //fill vertices array with our map data

vertices[counter].x = arrayx[counter];
vertices[counter].y = arrayy[counter];
vertices[counter].z = arrayz[counter];
vertices[counter].NORMAL.x = 0.0f;
vertices[counter].NORMAL.y = 0.1f;
vertices[counter].NORMAL.z = 0.0f;

++counter;
}

// create the vertex and store the pointer into v_buffer, which is created globally
d3ddev->CreateVertexBuffer(limit*sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);
VOID* pVoid; // the void pointer
v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer
memcpy(pVoid, vertices, sizearray); // copy the vertices to the locked buffer
v_buffer->Unlock(); // unlock the vertex buffer

triangleCount = (MAP_WIDTH*MAP_WIDTH)*2; //total number of triangles we'll be using
int sizeofarrayind = triangleCount * 3; //work out how big of an array we need to store all the data
short *indices = new short[sizeofarrayind]; //allocate memory on the heap for our array
counter = 0; //Generic counter
int track = 0; //Some sort of tracker
int sizeofindices = sizeof(short) * sizeofarrayind; //calculate the memory size of our array
while(counter < triangleCount){ //fill the area with our map data
indices[track] = indx[counter];
indices[track+1] = indy[counter];
indices[track+2] = indz[counter];

track += 3;
++counter;
}
// create an index buffer interface called i_buffer
d3ddev->CreateIndexBuffer(sizeofarrayind*sizeof(short),
0,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&i_buffer,
NULL);
// lock i_buffer and load the indices into it
i_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, indices, sizeofindices);
i_buffer->Unlock();
delete[] vertices;
delete[] indices;
}
[/CODE]

Any help would be appreciated! Thanks!

Nb: I know how rough some of my code is, it'll be more rigorous later I swear [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]

Zul

Share this post


Link to post
Share on other sites
Zulfus_101080    103
Hey thanks for the response, you were absolutely right! Now it's taking around 3 seconds for a 256 map [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img] Of course it was something that simple! ha!

Much appreciated,
Zul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this