From d30a93bb5bb20b9d3a486f0972dd041488f88f64 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 14 Aug 2014 10:56:01 +0200 Subject: [PATCH] Don't register platforms that have gone out from the bottom. This fixes the assert occurring after a few seconds playing. --- src/platformset.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/platformset.cpp b/src/platformset.cpp index 76887d1..5c86129 100644 --- a/src/platformset.cpp +++ b/src/platformset.cpp @@ -29,6 +29,18 @@ #include namespace cloonel { + namespace { + ///---------------------------------------------------------------------- + ///---------------------------------------------------------------------- + boost::circular_buffer::const_iterator FindFirstVisible (const boost::circular_buffer& parPlatforms) { + auto curr = parPlatforms.begin(); + while (curr != parPlatforms.end() and curr->TopLeft().y() < 0.0f) { + ++curr; + } + return curr; + } + } //unnamed namespace + ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- PlatformSet::PlatformSet (SDLMain* parSdl) : @@ -52,18 +64,24 @@ namespace cloonel { ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- void PlatformSet::CopyBars (std::vector& parOut) const { - parOut.reserve(parOut.size() + m_platforms.size()); - for (auto& platf : m_platforms) { - parOut.push_back(platf.TopCollisionBar()); + auto eleCopy = FindFirstVisible(m_platforms); + const size_t count = m_platforms.end() - eleCopy; + parOut.reserve(parOut.size() + count); + while (m_platforms.end() != eleCopy) { + parOut.push_back(eleCopy->TopCollisionBar()); + ++eleCopy; } } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- void PlatformSet::CopyDrawables (std::vector& parOut) const { - parOut.reserve(parOut.size() + m_platforms.size()); - for (auto& platf : m_platforms) { - parOut.push_back(&platf); + auto eleCopy = FindFirstVisible(m_platforms); + const size_t count = m_platforms.end() - eleCopy; + parOut.reserve(parOut.size() + count); + while (m_platforms.end() != eleCopy) { + parOut.push_back(&*eleCopy); + ++eleCopy; } }