Advertisement
code_gs

Untitled

Mar 5th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. // Assuming m_sMaterial is our material string keyfield
  2. const size_t uMaterialLen = strlen( m_sMaterial );
  3. size_t uDigitLen = 0;
  4. size_t uNextDigit = 1;
  5.  
  6. for (size_t i = 0; i < NUM_MATERIAL_HANDLES; ++i)
  7. {
  8.     if (i % uNextDigit == 0)
  9.     {
  10.         ++uDigitLen;
  11.         uNextDigit *= 10;
  12.     }
  13.  
  14.     // Allocate length of material string + length of numeral suffix + null terminator
  15.     // This is non-standard but is used around the engine already so I assume it's compiled with a dynamic stack allocation addon
  16.     const size_t uLength = uMaterialLen + uDigitLen + 1;
  17.     char str[uLength];
  18.  
  19.     // Copy the base material string
  20.     for (size_t j = 0; j < uMaterialLen; ++j)
  21.         str[j] = m_sMaterial[j];
  22.  
  23.     // Copy each digit
  24.     size_t uNum = i;
  25.  
  26.     for (size_t j = uLength - 2; j >= uMaterialLen; --j)
  27.     {
  28.         str[j] = '0' + uNum % 10;
  29.         uNum /= 10;
  30.     }
  31.    
  32.     str[uLength - 1] = 0;
  33.  
  34.     m_MaterialHandles[i] = m_ParticleEffect.FindOrAddMaterial(str);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement