Advertisement

two questions, is stl vector very fast? and, my sprite's movement is jerky...,

Started by July 03, 2002 10:16 AM
12 comments, last by mickey 22 years, 5 months ago
hiya,

    

  
static float xpos = 0.0f, ypos = 0.0f, xvel = 1.0f, yvel = 1.0f;

cur_time = timeGetTime();
time_span=(double)(cur_time-last_time)*(double)time_factor;
last_time=cur_time;

xpos += xvel * time_span;
ypos += yvel * time_span;

spr->Begin();	
spr->SetTrans(0, xpos, ypos); 
spr->Draw(0);
  
this is my messageloop/gameloop

        

    
MSG msg;
while(1)
{	
	if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		if(msg.message == WM_QUIT)
			break;		
			TranslateMessage(&msg); 
			DispatchMessage(&msg);
		}
		GameLoop();
	}
}
    
i've already been strugglign for this for hours, i can't find a way to make the sprite move smooth, it's very jerky/blocky, also, is stl vector hyper fast? i used them, in all of D3DXSprite::Draw(...) functions, all the parameters are in stl vector, ie,

    

  
m_lpd3dxSprite->Draw(
	m_stlVecTex[id], 
	&m_stl_vec_rcFrameCur[id],
	&m_stl_vec_vScale[id],				
	&m_stl_vec_vRotCenter[id],		
	D3DXToRadian(m_stl_vec_fRot[id]), 		         &m_stl_vec_vTrans[id],			
	D3DCOLOR_ARGB(m_stl_vec_dwAlpha[id], 255, 255, 255)		);

  



thanks,


[edited by - mickey on July 3, 2002 11:18:34 AM]    
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Hi, Im not sure about the stl thing, but I guess from your code that movement is jerky because of where your GameLoop() function is. Its seems that it would only get called when there is a message sent to your window. Try putting it outside of your
if(PeekMessage(...)) block like so:
MSG msg;while(1){		    if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))    {	if(msg.message == WM_QUIT)            break;	TranslateMessage(&msg); 			DispatchMessage(&msg);    }    GameLoop();	}    
Advertisement
In a classic game, most user interactions are done using mouse and keyboard. It means that this is not a bad thing to call your game loop only if you do not have any message to process ie when you are idling.

[assuming you are using the VC++ stl]
In debug mode, the stl is just pain slow. It will eat your processor time if your try to act on very big vectors. Since it is inlined in release mode it''s clearly faster. But the VC++ stl is still slow. You should check for other implementations (say stlport, for example ; boost libs are also a must see) in order to fit your needs. Or you can try to modify the default behavior of the VC++ stl using (for example) your own allocator<> implementation.

Yours,

Emmanuel
hi, i''m sorry that was just a typo, the GameLoop() is really outside the PeekMessage(),

anyway, VC stl is slow??? really?? aren''t these standard libraries? so what did VC did? implemented their own?

many thanks,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
stlport, which is far superior to msvc stl, and boost.
---visit #directxdev on afternet <- not just for directx, despite the name
quote: Original post by mickey
anyway, VC stl is slow??? really?? aren't these standard libraries? so what did VC did? implemented their own?

Microsoft licensed the implementation for their STL from someone. Something that's 'standard' means that its overall interface and behaviour are documented and should be consistent regardless of the implementation. When I call std::vector::push_back, I know what the end result should be, but the way each implementation goes about it may differ (some may allocate extra memory for future push_backs, some may not, et cetera). The insides of some implementations are superior to others. Like IndirectX pointed out, you can use STLPort to replace the STL that ships with MSVC, which is a pretty nice implementation (STLPort, that is).



[edited by - Null and Void on July 4, 2002 3:16:16 PM]
Advertisement
okey this is what i did, i formatted my computer, and recompiled my source code., and voila, it''s smooth now

but got some more problems, if i use timeGetTime(...), there''s no hope, it''s really jumpy, does this happen to you too? so, i must use QueryPerformanceCounter(...),

and then, after letting my game run for around 30 sec, it will get jumpy again, but after a while, it''ll go back to it''s smoothness,

and last can you plz take a look at this link, and tell me if this is what they say by ''locking the frame rate'',

http://www.mvps.org/directx/articles/writing_the_game_loop.htm

many thanks and also bout the stl info,




http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
timeGetTime has a resolution of 1ms, planety for smooth animation. your look is bad. you need while(PeekMessage()) so that ALL messages are processed each frame. otherwise you will have a backed up queue and things getting funky. many ppl ignore this and is the reason why things dont work right in their game loop.

have you tried this on other system? i assume you are running fullscreen. windowed mode can sometrimes be probalamtic.

also if you have vsync on turn it off, if its off turn it on. it can be that yoru framerate is too slow, or that its so fast that the screen updates happen after the spirte has moved quite a bit so it only seems unsmooth.
aperson, do you mean this?

while(1){		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))	{		if(msg.message == WM_QUIT)			break;						TranslateMessage(&msg); 		DispatchMessage(&msg);	}	GameLoop();}


coz i won''t be able to receive any messages from windows if i did that,

also, i''m sorry, how do i turn on/off my vsync? where can i find that?

many thanks,

http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
i made another observation, am using Windows XP, MS VS.Net, now when i install DXSDK 8.1, the jerkiness movement happens so i removed the DXSDK and that solved it...,?
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,

This topic is closed to new replies.

Advertisement