Jump to content
  • Advertisement
Sign in to follow this  
Jnz86

Strange performance problems [partially solved]

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am writing a 2D game, and i am suprised by VERY bad performance. I am drawing only 2 triangles(NO TEXTURES), and some lines(bullets). The thing is that fps is around 80 and after 5 or so seconds it drops to 15, then again for some time is ok(~80fps) and then it drops again to 15 and so on... I tried on my friend computers and it's the same only worse. (The funny thing is that my system specs are much lower than his and i am getting better fps!) Here's exe, take a look. Here's initilization code: (i am running in windowed mode)
WNDCLASSEX wc = 
			{
			sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0, 0, GetModuleHandle(NULL),
				0,0,0,0, "SolarCombat",0
			};

		RECT rec;
		
		rec.top = rec.left = 0;
		rec.right = 1024;
		rec.bottom = 768;
		
		AdjustWindowRect(&rec,WS_OVERLAPPEDWINDOW,false);		

		RegisterClassEx(&wc);

		hWnd = CreateWindow("SolarCombat", "Solar Combat", WS_OVERLAPPEDWINDOW,
			0,0,rec.right,rec.bottom, GetDesktopWindow(),0,wc.hInstance,0);	


		//D3D stuff from here!

		D3DPRESENT_PARAMETERS d3dpp; 
		ZeroMemory( &d3dpp, sizeof(d3dpp) );
		d3dpp.Windowed = true;
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

		g_D3D = Direct3DCreate9(D3D_SDK_VERSION);

		if(!g_D3D)
			return;

		if ( FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_D3DDevice)))
			if ( FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,	D3DCREATE_MIXED_VERTEXPROCESSING,&d3dpp,&g_D3DDevice)))
				if ( FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_D3DDevice)))
					return ;


By the way i draw all my primitives using DrawPrimitiveUP() function, i dont use vertex buffers. (I am using June 2005 SDK) Any ideas? [Edited by - Jnz86 on August 28, 2005 10:51:10 AM]

Share this post


Link to post
Share on other sites
Advertisement
Give us the rest of the code as well (especially the rendering code). Everything looks good in that code from what I can tell.

Share this post


Link to post
Share on other sites
Ok, here's rendering code:

/*
======================
namespace d3d9debug
======================
*/

LPD3DXLINE Line = NULL;

namespace d3d9debug
{
void DrawLineD(D3DXVECTOR2 p_Start,D3DXVECTOR2 p_End,D3DCOLOR p_Color = D3DCOLOR_XRGB(255,255,255))
{
if(!Line)
D3DXCreateLine(g_D3DDevice,&Line);

D3DXVECTOR2 list[2];
list[0] = p_Start;
list[1] = p_End;


g_D3DDevice->BeginScene();

Line->Draw((D3DXVECTOR2*)&list, 2, p_Color);

g_D3DDevice->EndScene();
}

void DrawTriangleD(D3DXVECTOR4& p_V1,D3DXVECTOR4& p_V2,D3DXVECTOR4& p_V3)
{
vertex_t data[] =
{
{p_V1.x,p_V1.y,0.5f,1,0xff000000},
{p_V2.x,p_V2.y,0.5f,1,0xffffffff},
{p_V3.x,p_V3.y,0.5f,1,0xff000000},

};

g_D3DDevice->BeginScene();

g_D3DDevice->SetFVF(D3DFVF_VERTEX_T);
g_D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,&data,sizeof(vertex_t));

g_D3DDevice->EndScene();

}

void DrawWTriangleD(const Triangle_t &p_Tri)
{
vertex_t data[]=
{
{p_Tri.Vert[0].x,p_Tri.Vert[0].y,0.5f,1,0x40000000},
{p_Tri.Vert[1].x,p_Tri.Vert[1].y,0.5f,1,0x40000000},
{p_Tri.Vert[2].x,p_Tri.Vert[2].y,0.5f,1,0x40000000},
};


g_D3DDevice->BeginScene();

g_D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
g_D3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
g_D3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

g_D3DDevice->SetFVF(D3DFVF_VERTEX_T);
g_D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST,3,&data,sizeof(vertex_t));

g_D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);

g_D3DDevice->EndScene();
}

void DrawPlaneD(const Plane_t &p_Plane)
{
D3DXVECTOR2 right;



float p_Angle = D3DXToRadian(90);
float x,y;
x= p_Plane.Normal.x;
y= p_Plane.Normal.y;

right.y = sin(p_Angle)*x + cos(p_Angle)*y;
right.x = cos(p_Angle)*x - sin(p_Angle)*y;

D3DXVECTOR2 V1,V2;

V1 = right*10000 - p_Plane.d*p_Plane.Normal;
V2 = right*(-10000) - p_Plane.d*p_Plane.Normal;

DrawLine(V1,V2,D3DCOLOR_XRGB(255,255,255));

}



Any ideas?

Share this post


Link to post
Share on other sites
You should only use beginscene and endscene once per render, I believe.

That may be your problem.

So.. remove all of the beginscenes and endscenes from your functions, and then put them at the part where yuo start drawing, and the part you end drawing. That might fix it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Adams555
You should only use beginscene and endscene once per render, I believe.

That may be your problem.

So.. remove all of the beginscenes and endscenes from your functions, and then put them at the part where yuo start drawing, and the part you end drawing. That might fix it.


I haven't recoded my app to what you suggested, but this be the problem, here's what i found on msdn:
Quote:

There should be at most one IDirect3DDevice9::BeginScene/IDirect3DDevice9::EndScene pair between any successive calls to present (either IDirect3DDevice9::Present or IDirect3DSwapChain9::Present). IDirect3DDevice9::BeginScene should be called once before any rendering is performed, and IDirect3DDevice9::EndScene should be called once after all rendering for a frame has been submitted to the runtime. To enable maximal parallelism between the CPU and the graphics accelerator, it is advantageous to call IDirect3DDevice9::EndScene as far ahead of calling present as possible.

Hell, i don't like it. I was used to OpenGL with these glBegin/glEnd calls.I will have to change a lot in my app.
Well, back to coding, will reply if it did helped...

Share this post


Link to post
Share on other sites
You only need to call begin and end once a frame, so the change is very small. So right before you begin render call BeginScene, and when you are finished rendering call EndScene.

// Main game loop
while(true)
{
// Update the objects
scene.update( );

// Clear the back buffer
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0.0f, 0.0f, 0.0f), 1.0f, 0);

// Now begine scene
m_pD3DDevice->BeginScene( );

// Render the scene
scene.render( );

// We are finished so end the scene
m_pD3DDevice->EndScene( );

// Render to the screen
m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}

Matt Hughson

Share this post


Link to post
Share on other sites
Quote:
Original post by matthughson
Can you post the workspace?

Matt Hughson


Sorry, i didn't understood you. Workspace of what?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jnz86
Quote:
Original post by matthughson
Can you post the workspace?

Matt Hughson


Sorry, i didn't understood you. Workspace of what?


Sorry, that's Visual Studio 6.0 talk. I mean can you post the entire project so we can compile it ourselves and check things out?

Matt Hughson

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!