Smooth Movement?

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Smooth Movement?

Post 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.
User avatar
k1net1k
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 563
Joined: Sun Nov 07, 2010 2:58 pm
Contact:

Re: Smooth Movement?

Post by k1net1k »

Memory leak, rounding error ?
User avatar
lalacomun
VS Setup Wizard
VS Setup Wizard
Posts: 114
Joined: Wed Dec 28, 2011 10:18 pm
Favorite Gaming Platforms: psx, nintendo ds, gameboy advance, xbox 360, ps2
Programming Language of Choice: C++
Location: Argentina
Contact:

Re: Smooth Movement?

Post 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 8-) , 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
Image
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Smooth Movement?

Post 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.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: Smooth Movement?

Post 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.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Smooth Movement?

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: Smooth Movement?

Post 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).
User avatar
k1net1k
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 563
Joined: Sun Nov 07, 2010 2:58 pm
Contact:

Re: Smooth Movement?

Post 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
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Smooth Movement?

Post 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

Code: Select all

while(true) { engine.Draw(); }
User avatar
superLED
Chaos Rift Junior
Chaos Rift Junior
Posts: 303
Joined: Sun Nov 21, 2010 10:56 am
Current Project: Engine
Favorite Gaming Platforms: N64
Programming Language of Choice: C++, PHP
Location: Norway

Re: Smooth Movement?

Post 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.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: Smooth Movement?

Post 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?
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: Smooth Movement?

Post 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.
I'll make your software hardware.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: Smooth Movement?

Post 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.
User avatar
lalacomun
VS Setup Wizard
VS Setup Wizard
Posts: 114
Joined: Wed Dec 28, 2011 10:18 pm
Favorite Gaming Platforms: psx, nintendo ds, gameboy advance, xbox 360, ps2
Programming Language of Choice: C++
Location: Argentina
Contact:

Re: Smooth Movement?

Post 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 :mrgreen: 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 8-)
Image
User avatar
k1net1k
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 563
Joined: Sun Nov 07, 2010 2:58 pm
Contact:

Re: Smooth Movement?

Post 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
Post Reply