Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / General Programming / perfomance probs with simple dx game Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
coment

March 30, 2005, 08:42 PM

hi all.

this is my first post but ill get to my question right away if that fits you.

so, im making some little game for myself mainly using the dxsprite interface. my main problem is that i cant get the fps over 50 altough my systems able to do more (amd64, radeon 9800).
I deactivated all parts of my game (heavy loops etc) but fps never changed. Only when i switch to fullscreen the fps goes up to around 70. I have some strange feeling that the prop is that i dont get enough execution time from the os, but thats over my knowledge so im not sure. And thats my question is there anything i do wrong so that i somehow cant run the game faster?

heres the source:

  1.  
  2. int WINAPI WinMain(HINSTANCE hInstance,
  3.                                    HINSTANCE hPrevInstance,
  4.                                    char* pcCommandLine,
  5.                                    int nCmdShow)
  6. {
  7.         bool R;
  8.         MSG     msg;
  9.  
  10.         ZeroMemory(&g_Crosstown,sizeof(CCrosstown));
  11.         g_Crosstown = new CCrosstown;
  12.         g_Crosstown ->load(hInstance,nCmdShow);
  13.         g_Crosstown ->init();
  14.         R = g_Crosstown ->SetState(gState_intro);
  15.         if(R == true){//we get false if SetState fails cause any loading failed
  16.                 msg = g_Crosstown->Run();
  17.         }else{
  18.                 g_Crosstown->exit();
  19.         }
  20.         return(msg.wParam);
  21. }
  22.  
  23. bool CCrosstown::load(HINSTANCE hInstance,int nCmdShow)
  24. {
  25.  
  26.         /*----------- START WINDOWS STUFF -------------*/
  27.         WNDCLASS                wc;
  28.         HRESULT                 hR;
  29.         wc.style = CS_OWNDC;
  30.         wc.lpfnWndProc = (WNDPROC) WindowProc;
  31.         wc.cbClsExtra = 0;
  32.         wc.cbWndExtra = sizeof(DWORD);
  33.         wc.hInstance = hInstance;
  34.         wc.hIcon = NULL;
  35.         wc.hCursor = NULL;
  36.         wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
  37.         wc.lpszMenuName = NULL;
  38.         wc.lpszClassName = "Crosstown Traffic v.1";
  39.  
  40.         if(!RegisterClass(&wc)){//error handler
  41.                 MessageBox(NULL, "Error Registering Class","Crosstown Traffic v.1", MB_OK);
  42.                 return false;
  43.         }
  44.  
  45.         int scrW = GetSystemMetrics(SM_CXSCREEN);
  46.         int scrH = GetSystemMetrics(SM_CYSCREEN);
  47.         HWND hWnd;
  48.  
  49.         hWnd = CreateWindow("Crosstown Traffic v.1",
  50.                                                 "Crosstown Traffic v.1",
  51.                                                 WS_VISIBLE|WS_POPUP,
  52.                                                 0,
  53.                                                 0,
  54.                                                 1024,
  55.                                                 768,
  56.                                                 NULL,
  57.                                                 NULL,
  58.                                                 hInstance,
  59.                                                 NULL);
  60.  
  61.         if(!hWnd){//if failed creation, kill app
  62.                 MessageBox(NULL, "Error Creating window", "Crosstown Traffic v.1", MB_OK);
  63.                 return false;
  64.         }
  65.  
  66.         /*----------- END WINDOWS STUFF -----------*/
  67.  
  68.         /*----------- START D3D STUFF -------------*/
  69.         if(NULL == (p_D3D = Direct3DCreate9(D3D_SDK_VERSION))){
  70.                 MessageBox(NULL, "Error Creating D3D9 Interface", "Crosstown Traffic v.1", MB_OK);
  71.                 return false;
  72.         }
  73.  
  74.         D3DPRESENT_PARAMETERS d3dpp;
  75.         ZeroMemory(&d3dpp,sizeof(d3dpp));
  76.         d3dpp.SwapEffect                = D3DSWAPEFFECT_DISCARD;
  77.         d3dpp.hDeviceWindow             = hWnd;
  78.         d3dpp.BackBufferCount   = 1;
  79.         d3dpp.Windowed          = true;
  80.         d3dpp.BackBufferWidth   = 1024;
  81.         d3dpp.BackBufferHeight  = 768;
  82.         d3dpp.BackBufferFormat  = D3DFMT_A8R8G8B8;
  83.         hR   = p_D3D -> CreateDevice(D3DADAPTER_DEFAULT,
  84.                                                                  D3DDEVTYPE_HAL,
  85.                                                                  hWnd,
  86.                                                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  87.                                                                  &d3dpp,
  88.                                                                  &p_D3DDevice);
  89.         if(FAILED(hR)){
  90.                 ErrStr = DXGetErrorDescription9(hR);
  91.                 return false;
  92.         }
  93.         D3DXCreateSprite(p_D3DDevice,&p_Sprite);
  94.         /*----------- END D3D STUFF ---------------*/
  95. //rest of game init follows here
  96. }
  97.  
  98. MSG CCrosstown::Run(){
  99.         HRESULT hR;
  100.         MSG msg;
  101.         notDone = true;
  102.  
  103.         DWORD time1;
  104.         DWORD time2;
  105.         long time3 = 5;
  106.         long fTime = 0;
  107.  
  108.         while(notDone){
  109.                 time1 = timeGetTime();
  110.                 if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
  111.                         if(msg.message == WM_QUIT){
  112.                                 notDone = false;
  113.                                 g_Crosstown->exit();
  114.                         }
  115.                         TranslateMessage(&msg);
  116.                         DispatchMessage(&msg);                 
  117.                 }
  118.                 if(fTime>time3){
  119.                         g_Crosstown->Step(fTime);
  120.                 }
  121.                 g_Crosstown->Render(fTime);
  122.                 time2 = timeGetTime();
  123.                 fTime = (long) time2 - time1;
  124.         }
  125.         return msg;
  126. }
  127.  

 
Trapper McFerron

March 30, 2005, 11:16 PM

it sounds like dx is waiting for the vsync w/ your monitor. to test that you can either comment out your render or add this to your present_parameters

d3dpp.PresentationInterval = D3DPRESENT_DONOTWAIT;

 
Endurion

March 31, 2005, 12:16 AM

What TrapperMcFerror really means is D3DPRESENT_INTERVAL_IMMEDIATE. D3DPRESENT_DONOTWAIT just tells Present to return immediately but will in some cases not really do the updating.

 
coment

March 31, 2005, 05:04 AM

ok thx.
it helped a bit, but im still hanging aroung 80fps.
if checked the sdk examples(they go way over 100fps), and they use callbacks to run the app. would this give some speed redoing the whole core to run with callbacks?

 
AcidChris

March 31, 2005, 06:08 AM

hi there.

it has nothing to do with vsync turned on or off, also callbacks would not solve your problem.
the most important thing you should change is from
D3DCREATE_SOFTWARE_VERTEXPROCESSING
to
D3DCREATE_HARDWARE_VERTEXPROCESSING

you should check the device caps if your graphics card supports HVP:
((devcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0)

when i ran the skinned mesh expample from the dxsdk, software vertex processing gave me around 160fps and when switching to hardware vertex processing i got around 800fps

this is done before you create the device.
make all the necessary checks, store them in a local variable and pass this variable to the CreateDevice call.

hope this helps!
regards,
christoph

 
coment

March 31, 2005, 11:10 AM

k thx alot for your help, setting the Presentation Interval and changing the main loop to

  1.  
  2. ...
  3.         while(notDone){
  4.                 time1 = timeGetTime();
  5.                 if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
  6.                         if(msg.message == WM_QUIT){
  7.                                 notDone = false;
  8.                                 g_Crosstown->exit();
  9.                         }
  10.                         TranslateMessage(&msg);
  11.                         DispatchMessage(&msg);                 
  12.                 }
  13.                 //if(fTime>time3){
  14.                         g_Crosstown->Step(fTime);
  15.                 //}
  16.                 g_Crosstown->Render(fTime);
  17.                 time2 = timeGetTime();
  18.                 fTime = (long) time2 - time1;
  19.         }
  20. ...
  21.  

solved the problem, have around 600fps now.

thx again for you help.

 
This thread contains 6 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.