Don't register platforms that have gone out from the bottom.

This fixes the assert occurring after a few seconds playing.
This commit is contained in:
King_DuckZ 2014-08-14 10:56:01 +02:00
parent e9253fae1f
commit d30a93bb5b

View file

@ -29,6 +29,18 @@
#include <algorithm> #include <algorithm>
namespace cloonel { namespace cloonel {
namespace {
///----------------------------------------------------------------------
///----------------------------------------------------------------------
boost::circular_buffer<Platform>::const_iterator FindFirstVisible (const boost::circular_buffer<Platform>& parPlatforms) {
auto curr = parPlatforms.begin();
while (curr != parPlatforms.end() and curr->TopLeft().y() < 0.0f) {
++curr;
}
return curr;
}
} //unnamed namespace
///-------------------------------------------------------------------------- ///--------------------------------------------------------------------------
///-------------------------------------------------------------------------- ///--------------------------------------------------------------------------
PlatformSet::PlatformSet (SDLMain* parSdl) : PlatformSet::PlatformSet (SDLMain* parSdl) :
@ -52,18 +64,24 @@ namespace cloonel {
///-------------------------------------------------------------------------- ///--------------------------------------------------------------------------
///-------------------------------------------------------------------------- ///--------------------------------------------------------------------------
void PlatformSet::CopyBars (std::vector<const HorzCollisionBar*>& parOut) const { void PlatformSet::CopyBars (std::vector<const HorzCollisionBar*>& parOut) const {
parOut.reserve(parOut.size() + m_platforms.size()); auto eleCopy = FindFirstVisible(m_platforms);
for (auto& platf : m_platforms) { const size_t count = m_platforms.end() - eleCopy;
parOut.push_back(platf.TopCollisionBar()); parOut.reserve(parOut.size() + count);
while (m_platforms.end() != eleCopy) {
parOut.push_back(eleCopy->TopCollisionBar());
++eleCopy;
} }
} }
///-------------------------------------------------------------------------- ///--------------------------------------------------------------------------
///-------------------------------------------------------------------------- ///--------------------------------------------------------------------------
void PlatformSet::CopyDrawables (std::vector<const Drawable*>& parOut) const { void PlatformSet::CopyDrawables (std::vector<const Drawable*>& parOut) const {
parOut.reserve(parOut.size() + m_platforms.size()); auto eleCopy = FindFirstVisible(m_platforms);
for (auto& platf : m_platforms) { const size_t count = m_platforms.end() - eleCopy;
parOut.push_back(&platf); parOut.reserve(parOut.size() + count);
while (m_platforms.end() != eleCopy) {
parOut.push_back(&*eleCopy);
++eleCopy;
} }
} }