Page 1 of 2
Smooth Movement?
Posted: Tue Apr 17, 2012 5:26 pm
by RandomDever
I'm already working on my next gaming project, but I finally want to tackle a problem I've had since the beginning.
When anything on the screen moves for extended periods of time, they tend to move very jumpily.
I am wondering if anyone knows how to alleviate this problem. Thank you.
Re: Smooth Movement?
Posted: Tue Apr 17, 2012 5:55 pm
by k1net1k
Memory leak, rounding error ?
Re: Smooth Movement?
Posted: Tue Apr 17, 2012 6:16 pm
by lalacomun
RandomDever wrote:I'm already working on my next gaming project, but I finally want to tackle a problem I've had since the beginning.
When anything on the screen moves for extended periods of time, they tend to move very jumpily.
I am wondering if anyone knows how to alleviate this problem. Thank you.
Smooth Movement = OpenGL render
, are you using SDL, or OpenGL for rendering??, it can be a memory lake as said before,(open your taskmanager and you can see your memory and cpu usage), or it can just be that each time you press a key you render a new image, i use to have that problem before
for example:
Code: Select all
switch( event.key.keysym.sym )
{
case SDLK_UP:
SDL_BlitSurface(playerUP,NULL,screen,&player);
break;
case SDLK_DOWN:
SDL_BlitSurface(playerDOWN,NULL,screen,&player);
break;
case SDLK_LEFT:
SDL_BlitSurface(playerLEFT,NULL,screen,&player);
break;
case SDLK_RIGHT:
SDL_BlitSurface(playerRIGHT,NULL,screen,&player);
break;
}
and here a way to regulate your FPS
http://www.youtube.com/watch?v=IXejVlRX ... MC8m7dkwc=
or
http://lazyfoo.net/SDL_tutorials/lesson14/index.php
Re: Smooth Movement?
Posted: Tue Apr 17, 2012 7:29 pm
by tappatekie
Make sure your disposing of every bitmap you are rendering after you finished using them. If your using c#, then you don't need to do this since it has a garbage collector. But otherwise, if your getting memory leaks, personal experience suggests that your not disposing of the bitmaps that are being used per frame.
Re: Smooth Movement?
Posted: Tue Apr 17, 2012 10:16 pm
by RandomDever
There is no memory leak. Unless memory leak means something other than a constant increase in allocated memory.
CPU usage stays around 10 and memory around 7,500k.
And I am using SDL for rendering because OpenGL is not supported by my engine. Yet.
Re: Smooth Movement?
Posted: Wed Apr 18, 2012 12:25 am
by dandymcgee
RandomDever wrote:There is no memory leak. Unless memory leak means something other than a constant increase in allocated memory.
A memory leak is any memory which is allocated but not deallocated. This doesn't necessarily have to happen at any certain speed, as it depends where in your code the allocation is occurring.
Re: Smooth Movement?
Posted: Wed Apr 18, 2012 5:23 am
by RandomDever
dandymcgee wrote:RandomDever wrote:There is no memory leak. Unless memory leak means something other than a constant increase in allocated memory.
A memory leak is any memory which is allocated but not deallocated. This doesn't necessarily have to happen at any certain speed, as it depends where in your code the allocation is occurring.
Well that's possible. But how the hell would I find that in the 20,000 lines of code?
I have a fairly substantial engine and finding such a leak seems virtually impossible (assuming there is one).
Re: Smooth Movement?
Posted: Wed Apr 18, 2012 6:02 am
by k1net1k
You need to narrow down your engine to the point where you can eliminate things causing it.
Start by removing textures, remove all characters, remove lighting, remove AI, slow down the game loop, use more debugging, etc. Keep going until you find the thing causing it, then drill down into that
Re: Smooth Movement?
Posted: Wed Apr 18, 2012 11:10 am
by tappatekie
If it is leaking, why not try making some sort of tester to force the engine to re-render everything every 1ms, then see if the memory it uses increases.
E.g
Re: Smooth Movement?
Posted: Wed Apr 18, 2012 11:13 am
by superLED
Are you regulating your frame rate? Like, keep it at a constant 60 fps? If not, it may be that the CPU works faster sometimes, and make it 'jump in speed', because the game loops is running faster/slower.
Re: Smooth Movement?
Posted: Wed Apr 18, 2012 7:01 pm
by RandomDever
Couldn't find any memory leaks, I don't have lighting or AI, and my FPS is capped at 60.
Any more suggestions?
Re: Smooth Movement?
Posted: Wed Apr 18, 2012 7:19 pm
by thejahooli
Could you post more detail as to what the 'jumpy' movement is. If we have a less ambiguous description of what's happening, it might be easier to isolate a cause.
Re: Smooth Movement?
Posted: Thu Apr 19, 2012 3:59 am
by RandomDever
Let's say I have a square moving at a rate of 2 pixels per second.
It will move 2 pixels one frame and the next frame it will move like 4 pixels for no reason.
Re: Smooth Movement?
Posted: Thu Apr 19, 2012 9:01 am
by lalacomun
Cap it at 100 frames
i know it sound ridiculous but belive me its not the same, i think its because you are using SDL for graphics, and its not that powerfull, i recomend you learn OpenGL belive me you will see the diference
since its hardware accelerated, my SDL(for render and input) programs always lag, not because any memory lakes just because its not powerfull enought for my needs
Re: Smooth Movement?
Posted: Thu Apr 19, 2012 11:11 am
by k1net1k
RandomDever wrote:Let's say I have a square moving at a rate of 2 pixels per second.
It will move 2 pixels one frame and the next frame it will move like 4 pixels for no reason.
Sounds like a maths/timing/calculation error rather than a performance thing. If it is a performance thing, there must be some reason for it.
Can you benchmark the performance in any way, eg. what FPS, how much CPU is being used etc ?
Can you narrow down your code to a few lines which reproduce the problem ? Maybe then someone can help you