Request feedback on my drawing algorithms.

Recommended Posts

Please tell me what I am doing inefficiently and wrong. The game runs properly but I think that there is some things I could improve before I move on with the game. What would you do differently? I often get bizzare slowdowns when my character moves around for a while. As far as I know I do not have any memory leaks. Are there any better ways to handle the game loop or animation? The three methods I am worried about the most are void walk_animation(int,int,int,int,int,int,int,int,int); void move_hero(); and void three_frame_animation(int,int,int,int,int,int,int,int,int,int,int); I am using C++ with ALLEGRO.

This may gain some speed as well... instead of calling .size() on each iteration, store the size before entering the loop. I say you "may" gain speed here because the compiler could be doing some optimizing on its own anyway, but it's something to try... So instead of the following...

It's faster to pass a single struct by reference then it is to pass lots of values. But with that said, you'd probably not be able to measure the optimization in this case cause your not passing large objects. Just something to keep in mind I guess.

0

Share this post

Link to post

Share on other sites

If you do that, especially when you experience the slow down, you will get nice statistics how much time is spent in each function as well as the accumulated sum of all functions called. Do profiling is very important before you start optimizing, or you may spend your time on things that have negligible effects.

Otherwise, as Nyssa stated, making copies of vectors looks inefficient.

0

Share this post

Link to post

Share on other sites

If you do that, especially when you experience the slow down, you will get nice statistics how much time is spent in each function as well as the accumulated sum of all functions called. Do profiling is very important before you start optimizing, or you may spend your time on things that have negligible effects.

Otherwise, as Nyssa stated, making copies of vectors looks inefficient.

I just got access to Visual Studio premium I think using Microsoft Dreamspark. I will profile my code soon and check which functions and methods are slowing it down.

This may gain some speed as well... instead of calling .size() on each iteration, store the size before entering the loop. I say you "may" gain speed here because the compiler could be doing some optimizing on its own anyway, but it's something to try... So instead of the following...

It's faster to pass a single struct by reference then it is to pass lots of values. But with that said, you'd probably not be able to measure the optimization in this case cause your not passing large objects. Just something to keep in mind I guess.