Guest User

Untitled

a guest
Jul 18th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. ...
  2.  
  3. #define INLINE __inline__
  4. #define RESTRICT __restrict__
  5. #define FORCEINLINE __attribute__((always_inline))
  6. #define ALIGN(x) __attribute__((aligned(x)))
  7.  
  8. typedef struct {
  9.   float x,y,z,w;
  10. } ALIGN(16) vector4_t;
  11.  
  12. ...
  13.  
  14. #define RIGIDBODY_SIZE 64
  15.  
  16. typedef struct {
  17.   size_t size;
  18.   vector4_t position[RIGIDBODY_SIZE];
  19.   vector4_t velocity[RIGIDBODY_SIZE];
  20. } rigidbody_t;
  21.  
  22. ...
  23.  
  24. void physics_integrate(rigidbody_t *RESTRICT rigidbody) {
  25.  
  26.   // Load
  27.   size_t index = rigidbody->size;
  28.   vector4_t *RESTRICT positions = rigidbody->position;
  29.   vector4_t *RESTRICT velocities = rigidbody->velocity;
  30.  
  31.   // Transform
  32.   while(index--) {
  33.  
  34.     // Load
  35.     vector4_t position = positions[index];
  36.     vector4_t velocity = velocities[index];
  37.    
  38.     // Transform
  39.     vector4_t result = vector4_add(position, velocity);
  40.    
  41.     // Store
  42.     positions[index] = result;
  43.  
  44.   }
  45.  
  46.   // Store
  47.  
  48. }
  49.  
  50. ...
Advertisement
Add Comment
Please, Sign In to add comment