Closed DivFord closed 8 years ago
I found a major bottleneck: on line 45 of Skeleton.hpp there was a call to getConstant<Vector>("TILE_DIM")
which was getting called a lot. To work around this I created a member of Skeleton called tileDim_ that basically just caches the tile dimension Vector so that function calls be removed. This seems to improve performance quite a bit. I'll push it in a moment.
That actually makes it run at 100% all of the time on my laptop! I wouldn't have thought it'd've made that big a difference. I guess that's one of the things I just literally translated over from consts.
Well there's quite a bit of crunching to do underneath getConstant
: the Config class contains an unordered_map
pairing strings to pointers, so there'll be some overhead in computing the hash of the string. The values are also accessed using unordered_map::at
(operator[]
is not const), which checks whether the key exists and throws std::out_of_range
if it doesn't. So if this is in an inner loop it's going to end up using a fair bit of CPU time. What's more, I'm not sure the compiler is smart enough to optimize calls to this function, so I don't think turning on the optimisation flags would help much in this case.
EDIT: I should add that the trade-off is that each Skeleton now contains a Vector instance, so we use more memory, but given each Vector is just two floats (so four bytes total size on your average CPU) I don't think this is a big deal.
Hitboxes are in, and I believe I've ironed out all kinks in it, so I'm closing this. New issues should probably have their own threads anyway.
While talking about enemies, we mentioned hit-boxes. I thought it could do with its own issue.
I believe my thinking on hit-boxes stems from this article: http://devmag.org.za/2011/01/18/11-tips-for-making-a-fun-platformer/
Basically, if the player wants to hit something, make it easy to hit, otherwise, make it hard to hit.