Advertisement

Terrible performance on my first game

Started by September 06, 2016 12:13 PM
4 comments, last by Nyap 8 years, 2 months ago

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

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?
Advertisement

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!

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

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

Developer with a bit of Kickstarter and business experience.

YouTube Channel: Hostile Viking Studio
Twitter: @Precursors_Dawn

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

This topic is closed to new replies.

Advertisement