Looks very nice, great job!
I've looked at your code, I like it, it's nice and clean, though I have two tips:
1) There's almost reason to use std::bind anymore
Code like this:
std::bind(&Player::applyForce, _1, sf::Vector2f(-40.f, 0.f))
Can be easily rewritten like this in C++14:
[force = sf::Vector2f(-40.f, 0.f)]
(auto& player)
{
player.applyForce(force);
}
2) Use enum class instead of enum.
* Enum class values can't be implicitly casted
* Enum classes are scoped (simple enums "leak" their values in scope which you declared them in)
Check out "Effective Modern C++" on why lambdas are better than std::bind and why enum classes are awesome. :D
thanks Elias for your time to review the code, really i appreciate it. :)
I have two tips:
1) There's almost reason to use std::bind anymore
Code like this:
std::bind(&Player::applyForce, _1, sf::Vector2f(-40.f, 0.f))
Can be easily rewritten like this in C++14:
[force = sf::Vector2f(-40.f, 0.f)]
(auto& player)
{
player.applyForce(force);
}
2) Use enum class instead of enum.
* Enum class values can't be implicitly casted
* Enum classes are scoped (simple enums "leak" their values in scope which you declared them in)
Check out "Effective Modern C++" on why lambdas are better than std::bind and why enum classes are awesome. :D
For readability sake, i chose std::bind over lambda. of course if the performance is critical the lambda is going to be better. also, for VC++12-13 IDE has a bug with std::bind implementation, fortunately they fixed it in VC++14. i'm going to switch it to `lambda`
thanks once again to mention "Effective Modern C++" book. i almost forget that i usually mentioned all references that i was inspired by in my projects. i will add it to main post.
i have used few things from this book in this game. but i didn't get much time to complete it, definitely i will go back to read it from a cover to cover this time.
i'm totally agree with you regrading "Effective Modern C++" book and by the way, Scott Meyers has many books one of which is "Effective STL". speaking of re-read those great books. sure that true. for example, when i read "Effective STL" book for first time, particularly item 17 which is known by "swap to fit".
it is considered the most precious "trick" to gain maximum efficiency of STL containers like std::vector by calling its swap function:
std::vector<T>(v).swap(v);
I was very naive, i was thinking it reduces the capacity by changing its value just like what vector::resize do. but later i realized that is wrong. the only way for the capacity of a vector can be altered is by calling its vector::reserve when it is constructed. the swap trick actually performs copying for itself or the correct phrase "non-binding" for internal memory allocated. the aftermath the capacity will be reduced.
later in c++11. they inerduced shrink_to_fit as they stated it from The draft standard (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf) section 23.2.6.2
shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations.]