Example #1
0
 void performDrawOpsAndCode()
 {
     // Allows us to make some assumptions.
     if (ops.empty())
     {
         for (CodeMap::iterator it = code.begin(), end = code.end(); it != end; ++it)
             it->second();
         return;
     }
     
     // Apply Z-Ordering.
     std::stable_sort(ops.begin(), ops.end());
     
     // We will loop: Drawing DrawOps, execute custom code.
     // This means if there is no code, we just draw one batch
     // of DrawOps, so no performance is sacrified.
     DrawOps::const_iterator current = ops.begin(), last = ops.begin();
     CodeMap::const_iterator it = code.begin();
     
     while (true)
     {
         if (it == code.end())
             // Last or only batch of DrawOps:
             // Just draw everything.
             last = ops.end() - 1;
         else
         {
             // There is code waiting:
             // Only draw up to this Z level.
             while (last != ops.end() - 1 && (last + 1)->z < it->first)
                 ++last;
         }
         
         if (current <= last)
         {
             // Draw DrawOps until next code is due
             RenderState renderState;
             while (current < last)
             {
                 DrawOps::const_iterator next = current + 1;
                 current->perform(renderState, &*next);
                 current = next;
             }
             last->perform(renderState, 0);
             ++current;
         }
         
         // Draw next code, or break if there is none
         if (it == code.end())
             break;
         else
         {
             it->second();
             ++it;
         }
     }
 }