Original Post
This function sometimes takes over 100ms to run through. I use this function in my game to render frames. It's a tile based game so I have to draw the tiles all over the map. I'm using a second tile layer for my buildings/objects. But since "mapsize" is only 32 I thought it shouldn't cause any lag but I guess I'm wrong. Can anyone help me get rid of the lag? tile based games have existed for years and even the computers back then managed to draw the tiles without lag. So why can't my modern computer do it properly. btw I'm 100% sure this is the only function causing the lag because I've been timing it.
void render_frame(void)
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);
d3ddev->BeginScene();
d3dspt->Begin(NULL);
for (int i=0;i<mapsize;i++)
{
for (int j=0;j<mapsize*4;j++)
{
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f); // center at the upper-left corner
int PlotX=i*imagesize+(j % 2)*(imagesize/2)-l;
int PlotY=j*(imagesize/4)-m-imagesize;
D3DXVECTOR3 position(PlotX,PlotY, 0.5f);
d3dspt->Draw(tile[j].spri, NULL, ¢er, &position, D3DCOLOR_XRGB(255, 255, 255));
}
}
for (int j=0;j<mapsize*4;j++)
{
for (int i=0;i<mapsize;i++)
{
int PlotX=i*imagesize+(j % 2)*(imagesize/2)-l;
int PlotY=j*(imagesize/4)-m-imagesize;
D3DXVECTOR3 position(PlotX,PlotY, 1.0/float(j));
D3DXVECTOR3 center(tile2[j].occ.x,tile2[j].occ.y, 0.0f);
d3dspt->Draw(tile2[j].occ.spri, NULL, ¢er, &position, D3DCOLOR_XRGB(255, 255, 255));
}
}
if(starteddragging==true && cantbuildroad==false)
{
for (int i=0;i<a;i++)
{
int PlotX=roadpath.inumber*imagesize+(roadpath.jnumber % 2)*(imagesize/2)-l;
int PlotY=roadpath.jnumber*(imagesize/4)-m-imagesize;
D3DXVECTOR3 position(PlotX,PlotY, 0);
D3DXVECTOR3 center(0,0, 0.0f);
d3dspt->Draw(roadpath.spri, NULL, ¢er, &position, D3DCOLOR_ARGB(127, 0, 255,0));
}
}
if(roadbuilding==true)
{
uppertile[xbuilding][ybuilding].occ=startbuilding;
int PlotX=xbuilding*imagesize+(ybuilding % 2)*(imagesize/2)-l;
int PlotY=ybuilding*(imagesize/4)-m-imagesize;
D3DXVECTOR3 position(PlotX,PlotY,0);
D3DXVECTOR3 center(startbuilding.x,startbuilding.y, 0.0f);
if(checkavailableland(startbuilding)==true ||(tile2[xbuilding][ybuilding].parent->occ.btype==road &&startbuilding.btype==road))
d3dspt->Draw(uppertile[xbuilding][ybuilding].occ.spri, NULL, ¢er, &position, D3DCOLOR_ARGB(127, 0, 255, 0));
else
d3dspt->Draw(uppertile[xbuilding][ybuilding].occ.spri, NULL, ¢er, &position, D3DCOLOR_ARGB(127, 255, 0, 0));
}
//draw interface
D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 position(0,0,0);
//
d3dspt->Draw(inter, NULL, ¢er, &position, D3DCOLOR_XRGB(255, 255, 255));
d3dspt->End();
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
return;
}