BVB Source Codes

CRYENGINE Show CompactSpanGrid.cpp Source code

Return Download CRYENGINE: download CompactSpanGrid.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "CompactSpanGrid.h"
  5. #include "DynamicSpanGrid.h"
  6.  
  7. namespace MNM
  8. {
  9. void CompactSpanGrid::Swap(CompactSpanGrid& other)
  10. {
  11.         std::swap(m_width, other.m_width);
  12.         std::swap(m_height, other.m_height);
  13.  
  14.         m_cells.swap(other.m_cells);
  15.         m_spans.swap(other.m_spans);
  16. }
  17.  
  18. void CompactSpanGrid::Clear()
  19. {
  20.         m_width = 0;
  21.         m_height = 0;
  22.         m_cells.clear();
  23.         m_spans.clear();
  24. }
  25.  
  26. void CompactSpanGrid::BuildFrom(const DynamicSpanGrid& dynGrid)
  27. {
  28.         const size_t cellCount = dynGrid.GetWidth() * dynGrid.GetHeight();
  29.         const size_t spanCount = dynGrid.GetCount();
  30.  
  31.         m_width = dynGrid.GetWidth();
  32.         m_height = dynGrid.GetHeight();
  33.  
  34.         m_cells.resize(cellCount);
  35.         m_spans.resize(spanCount);
  36.  
  37.         size_t spanIndex = 0;
  38.  
  39.         for (size_t i = 0; i < cellCount; ++i)
  40.         {
  41.                 if (const DynamicSpanGrid::Element* span = dynGrid[i])
  42.                 {
  43.                         const size_t index = spanIndex;
  44.                         m_cells[i].index = index;
  45.                         m_spans[spanIndex++] = Span(span->bottom, span->top - span->bottom, span->depth, span->backface);
  46.  
  47.                         for (span = span->next; span; span = span->next)
  48.                                 m_spans[spanIndex++] = Span(span->bottom, span->top - span->bottom, span->depth, span->backface);
  49.  
  50.                         const size_t count = spanIndex - index;
  51.  
  52.                         assert(count <= Cell::MaxSpanCount);
  53.  
  54.                         m_cells[i].count = count & 0xff;
  55.                 }
  56.         }
  57. }
  58.  
  59. void CompactSpanGrid::CompactExcluding(const CompactSpanGrid& spanGrid, size_t flags, size_t newSpanCount)
  60. {
  61.         const size_t cellCount = spanGrid.GetWidth() * spanGrid.GetHeight();
  62.  
  63.         m_width = spanGrid.GetWidth();
  64.         m_height = spanGrid.GetHeight();
  65.  
  66.         m_cells.resize(cellCount);
  67.         m_spans.resize(newSpanCount);
  68.  
  69.         size_t spanIndex = 0;
  70.  
  71.         for (size_t i = 0; i < cellCount; ++i)
  72.         {
  73.                 if (const Cell cell = spanGrid[i])
  74.                 {
  75.                         size_t ncount = 0;
  76.                         const size_t nindex = spanIndex;
  77.  
  78.                         const size_t count = cell.count;
  79.                         const size_t index = cell.index;
  80.  
  81.                         for (size_t s = 0; s < count; ++s)
  82.                         {
  83.                                 const Span& span = spanGrid.GetSpan(index + s);
  84.  
  85.                                 if (span.flags & flags)
  86.                                         continue;
  87.  
  88.                                 ++ncount;
  89.                                 m_spans[spanIndex++] = span;
  90.                         }
  91.  
  92.                         m_cells[i] = Cell(ncount ? nindex : 0, ncount);
  93.                 }
  94.         }
  95. }
  96. }
  97.  
downloadCompactSpanGrid.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top