Jump to content
  • Advertisement
Sign in to follow this  
Nyap

Terrible performance on my first game

This topic is 771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm making my first game in SDL, and it performs so bad it slows down my linux pc to a crawl

Here's the code: https://github.com/Nyapp/Cell

You might want to take a look at entity::collisionDetect() first, because I feel like I'm doing it wrong

Share this post


Link to post
Share on other sites
Advertisement
How many bounding boxes are in your level? You're iterating through all of them to check for collisions every time. That's not fast, but if there's only one entity the performance hit shouldn't be too bad.

Have you tried profiling your code, or failing that commenting out sections of your code to see if disabling particular parts of your code makes your program fast again?

Share this post


Link to post
Share on other sites

I didnt look over your code in any detail, so I cant comment on your speed issues, maybe its time to start profilling and debuging :)

 

But on a design note, I did see you have a few classes that inherrit from your texture class, i.e.

 

class entity : public texture

class level  : public texture

 

This isint really correct, if you use the is-a / has-a rule here, I dont think you can correctly say

An Entity is a Texture, or a Level is a texture.

more likely:

An Entity has a Texture, a Level has a texture.

 

This shows you should be using compisition rather then inherittance in this case, I know this doesnt really answer your question, but just to note!

Share this post


Link to post
Share on other sites

Ok, I felt bad about not at least attempting to anwer your question :P - I believe Oberon is correct here; in your update call you seem to be calling your collision detection on both your x and y axis, which is fine - but your collision detection is checking everything in the game each pass. So for each update - you are checking everything twice for collision.

You should try and reduce this down, something like quadtrees or other spacial partitioning maybe the way to go depending on how complex you see your game getting, but for a simpiler quicker way, maybe just keep track of enemys that are on screen / close enough to actually collide with - and test your collisions on this subset of enemies.

You could have a broadphaze / narrowphaze collision - where you first check if an enemy is within 500 pixels of your character - if so then check for all collision types, if not ignore it

Share this post


Link to post
Share on other sites

Checking the collision for everything in a level every time will slow things down a fair amount. I think @[member='McGrane'], had a great idea in his 

where you first check if an enemy is within 500 pixels of your character

Share this post


Link to post
Share on other sites
ok so turns out that I was just being an idiot and forgot to copy the backbuffer to the frontbuffer (now that i've fixed it, it works at 3K FPS). that's also why nothing was appearing in the window
dddddddddeeeeeeeeeeeerrrrrrrrrrrrrrrppppppppppppp
I'll take all these tips into consideration though thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!