diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2013-01-15 21:15:09 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:48:53 +0300 |
commit | d95863bfcd3d306d642fdeb06552a926710037a6 (patch) | |
tree | 111a8aec2da4fb1d73ae963a775200de1b8cc12a | |
parent | 85c9b1802392d311a28ef9ae962193c5af8e49d1 (diff) |
fixed mapInfo for array of Resource::Info's
-rw-r--r-- | geometry/packer.cpp | 4 | ||||
-rw-r--r-- | graphics/geometry_batcher.cpp | 70 |
2 files changed, 40 insertions, 34 deletions
diff --git a/geometry/packer.cpp b/geometry/packer.cpp index 4cd0fb60c1..6eb77fed84 100644 --- a/geometry/packer.cpp +++ b/geometry/packer.cpp @@ -13,7 +13,7 @@ namespace m2 m_height(0), m_currentHandle(0), m_maxHandle(0), - m_invalidHandle(static_cast<uint32_t>(-1)) + m_invalidHandle(0x00FFFFFF) {} Packer::Packer(unsigned width, unsigned height, uint32_t maxHandle) @@ -24,7 +24,7 @@ namespace m2 m_height(height), m_currentHandle(0), m_maxHandle(maxHandle), - m_invalidHandle(maxHandle + 1) + m_invalidHandle(0x00FFFFFF) { } diff --git a/graphics/geometry_batcher.cpp b/graphics/geometry_batcher.cpp index d0290024d5..cc497d7ef5 100644 --- a/graphics/geometry_batcher.cpp +++ b/graphics/geometry_batcher.cpp @@ -801,47 +801,53 @@ namespace graphics uint32_t * ids, size_t count) { - int startDynamicPage = m_dynamicPage; - int cycles = 0; - - int i = 0; - - do + for (unsigned cycles = 0; cycles < 2; ++cycles) { - ids[i] = pipeline(m_dynamicPage).cache()->findInfo(*infos[i]); - - if ((ids[i] == invalidPageHandle()) - || (unpackID(ids[i]).first != m_dynamicPage)) + bool packed = true; + for (unsigned i = 0; i < count; ++i) { - /// try to pack on the currentDynamicPage - while (!pipeline(m_dynamicPage).cache()->hasRoom(*infos[i])) - { - /// no room - flush the page - flushDynamicPage(); - - if (startDynamicPage == m_dynamicPage) - cycles += 1; + ResourceCache * staticCache = pipeline(m_startStaticPage).cache().get(); + ResourceCache * dynamicCache = pipeline(m_dynamicPage).cache().get(); - /// there could be maximum 2 cycles to - /// pack the sequence as a whole. - /// second cycle is necessary as the first one - /// could possibly run on partially packed skin pages. - if (cycles == 2) - return false; + uint32_t res; + ids[i] = staticCache->findInfo(*infos[i]); - /// re-start packing - i = 0; + if (ids[i] == invalidPageHandle()) + { + ids[i] = staticCache->findInfo(infos[i]->cacheKey()); + if (ids[i] == invalidPageHandle()) + { + ids[i] = dynamicCache->findInfo(*infos[i]); + if (ids[i] == invalidPageHandle()) + { + if (dynamicCache->hasRoom(*infos[i])) + ids[i] = packID(m_dynamicPage, dynamicCache->mapInfo(*infos[i])); + else + { + packed = false; + break; + } + } + else + ids[i] = packID(m_dynamicPage, ids[i]); + } + else + { + staticCache->addParentInfo(*infos[i]); + ids[i] = packID(m_startStaticPage, ids[i]); + } } - - ids[i] = packID(m_dynamicPage, - pipeline(m_dynamicPage).cache()->mapInfo(*infos[i])); + else + ids[i] = packID(m_startStaticPage, ids[i]); } - ++i; + if (packed) + return packed; + else + flushDynamicPage(); } - while (i != count); - return true; + return false; } } // namespace graphics |