Archived

This topic is now archived and is closed to further replies.

Erratic frames per second =|

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

Recommended Posts

The frames per second on my game, aside from being low as it is (averages between 30-60) is very erratic and I don''t know why it can''t keep up a steady rate. Here is the code for my RenderAll() function:

HRESULT RenderAll()
{

CHAR	InfoText[255];

// Input

if(FAILED(XInput->UpdateInputData())) return E_FAIL;
if(SUCCEEDED(XInput->IsKeyDown(DIK_ESCAPE))) return E_FAIL;
if(SUCCEEDED(XInput->IsKeyDown(DIK_A))) XView->MoveCamera(D3DXVECTOR3((1.2f*XFrameRate->speedfactor),0.0f,0.0f));
if(SUCCEEDED(XInput->IsKeyDown(DIK_D))) XView->MoveCamera(D3DXVECTOR3((-1.2f*XFrameRate->speedfactor),0.0f,0.0f));

// Camera

if(FAILED(XView->UpdateCamera())) return E_FAIL;

// Stuff

sprintf(InfoText,"X:%ld Y:%ld Z:%ld B0:%d B1:%d B2:%d Fps:%d SF:%d",XInput->MouseX,XInput->MouseY,XInput->MouseZ,XInput->MouseB[0],XInput->MouseB[1],XInput->MouseB[2],(INT)XTimer->TimeFpsReal,XFrameRate->speedfactor);

// Clear

if(FAILED(lpD3DDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(20,26,70),1.0f,0))) return E_FAIL;

// RENDER

if(FAILED(lpD3DDevice->BeginScene())) return E_FAIL;
XFrameRate->SetSpeedFactor();
// Meshes with given Tex and Cull Test

XTexture[0]->SetActive();
if(!XView->TestCulling(XMesh[0]->BBox.vMin,XMesh[0]->BBox.vMax))
if(FAILED(XMesh[0]->RenderMesh())) return E_FAIL;

// General store

XTexture[2]->SetActive();
if(!XView->TestCulling(XMesh[1]->BBox.vMin,XMesh[1]->BBox.vMax))
if(FAILED(XMesh[1]->RenderMesh())) return E_FAIL;
// Weapons shop

XTexture[1]->SetActive();
if(!XView->TestCulling(XMesh[2]->BBox.vMin,XMesh[2]->BBox.vMax))
if(FAILED(XMesh[2]->RenderMesh())) return E_FAIL;
// Crate

XTexture[3]->SetActive();
if(!XView->TestCulling(XMesh[4]->BBox.vMin,XMesh[4]->BBox.vMax))
if(FAILED(XMesh[4]->RenderMesh())) return E_FAIL;
// Sky-box

XTexture[4]->SetActive();
if(!XView->TestCulling(XMesh[6]->BBox.vMin,XMesh[6]->BBox.vMax))
if(FAILED(XMesh[6]->RenderMesh())) return E_FAIL;
// Hospital

XTexture[5]->SetActive();
if(!XView->TestCulling(XMesh[3]->BBox.vMin,XMesh[3]->BBox.vMax))
if(FAILED(XMesh[3]->RenderMesh())) return E_FAIL;
// House

XTexture[6]->SetActive();
if(!XView->TestCulling(XMesh[5]->BBox.vMin,XMesh[5]->BBox.vMax))
if(FAILED(XMesh[5]->RenderMesh())) return E_FAIL;

if(FAILED(lpD3DDevice->EndScene())) return E_FAIL;

XSprite[1]->Render();
XSprite[0]->Render();
XSprite[2]->Render();

// Text

if(FAILED(XFont->RenderText(InfoText,0,0,300,20,D3DCOLOR_ARGB(255,0,0,0)))) return E_FAIL;

// Mouse Pointer

if(FAILED(XInput->RenderMouseCursor(D3DCOLOR_ARGB(180,255,255,255)))) return E_FAIL;

// Show

if(FAILED(lpD3DDevice->Present(NULL,NULL,NULL,NULL))) return E_FAIL;

// Timer

XTimer->WaitNextFrame(TRUE);

return S_OK;
}

I don''t know whether you''d be able to tell from this code but perhaps it will help Thanks

Share on other sites
G''day!

I would guess that your erratic FPS may have to do with:
XTimer->WaitNextFrame(TRUE);

Are you trying to cap your frame rate with this? Wait is it doing internally?

Share on other sites
The problem is that you are trying to get the time between 2 consecutive frames, and the time varies a lot. What you have to do is update your framerate only once per second. Maybe this code helpes (it works, i''m using it):

DWORD Time_Elapsed,Time_Last,Time_First;
DWORD Time_Frames;
float Time_FPS;
float Time_Elapsed_Sec;

void Time_Init()
{
Time_Last=Time_First=timeGetTime();
Time_FPS=1;
Time_Frames=1;
}
void Time_Update()
{
DWORD fTime=timeGetTime();
Time_Frames++;

Time_Elapsed=fTime-Time_Last;
Time_Elapsed_Sec=Time_Elapsed/1000.0;
Time_Last=fTime;

if (fTime-Time_First>1000)
{
Time_FPS=(float)Time_Frames/(float)(fTime-Time_First)*1000.0;
// Time_FPS=1000.0*Time_Frames/(fTime-Time_First);
Time_First=fTime;
Time_Frames=0;
}
}

Before the first frame, you use Time_Init() to initialize all the variables. Then in each frame you call Time_Update(), then you display on the screen Time_FPS.

I hope it works for you too!

Share on other sites
<ignoreme>crap, I thought this was about erotic frames...</ignoreme>

Share on other sites
I am having a bit of trouble understanding that last bit of code:
quote:

if (fTime-Time_First>1000)
{
Time_FPS=(float)Time_Frames/(float)(fTime-Time_First)*1000.0;
// Time_FPS=1000.0*Time_Frames/(fTime-Time_First);
Time_First=fTime;
Time_Frames=0;
}

Maybe I am just tired, but what exactly is happening here?

Moe''s site

Share on other sites
if you want to smooth out your framerate, keep a buffer of the time for the last X frames and take an average

********

A Problem Worthy of Attack
Proves It''s Worth by Fighting Back