Guest User

Untitled

a guest
Mar 26th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. before:
  2. class GameObject {
  3.   float m_Pos[2];
  4.   float m_Velocity[2];
  5.   char m_Name[32];
  6.   Model* m_Model;
  7.   // ... other members ...
  8.   float m_Foo;
  9.  
  10.   void UpdateFoo(float f)
  11.   {
  12.     floag mag = sqrtf(
  13.       m_Velocity[0] * m_Velocity[0] +
  14.       m_Velocity[1] * m_Velocity[1]);
  15.       m_Foo += mag * f;
  16.   }
  17.  
  18.  
  19.  
  20.  
  21. after:
  22. struct FooUpdateIn {
  23.   float m_Velocity[2];
  24.   float m_Foo;
  25. };
  26.  
  27. struct FooUpdateOut {
  28.   float m_Foo;
  29. }
  30.  
  31. // update value depending on time passed and velocity
  32. void UpdateFoos(const FooUpdateIn* in, size_t count, FooUpdateOut* out, float f) {
  33.   for (size_t = 0; i < count; ++i) {
  34.     float mag = sqrtf(
  35.       in[i].m_Velocity[0] * in[i].m_Velocity[0] +
  36.       in[i].m_Velocity[1] * in[i].m_Velocity[1]));
  37.       out[i].m_Foo = in[i].m_Foo + mag * f;
  38.   }
  39. }
Add Comment
Please, Sign In to add comment