Guest User

Untitled

a guest
May 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. protected:
  2. void MoveForward(float Magnitude);
  3. void MoveRight(float Magnitude);
  4.  
  5. void MyCharacter::MoveForward(float Magnitude) {
  6. AddMovementInput(GetActorForwardVector() * Magnitude);
  7. }
  8.  
  9. void Myharacter::MoveRight(float Magnitude) {
  10. AddMovementInput(GetActorRightVector() * Magnitude);
  11. }
  12.  
  13. enum class Direction { LEFT, RIGHT, TOP, BOTTOM };
  14.  
  15. class MyCharacter {
  16. template<Direction DIR> Vector MyCharacter::getVector() const;
  17.  
  18. template<Direction DIR> void move() {
  19. AddMovementInput(getVector<Dir>() * magnitude);
  20. }
  21. }
  22.  
  23. template<> Vector MyCharacter::getVector<Direction::LEFT>() const { ... }
  24. template<> Vector MyCharacter::getVector<Direction::RIGHT>() const { ... }
  25.  
  26. float GetActorForwardVector() { return 3.0f; }
  27.  
  28. class Foo
  29. {
  30. public:
  31. template<float (*F)()> float move() { return F(); }
  32. inline float moveLeft() { return move<GetActorForwardVector>(); }
  33. };
  34.  
  35. int main()
  36. {
  37. Foo foo;
  38. std::cout << foo.moveLeft();
  39. }
  40.  
  41. void Move(int x, int y);
  42.  
  43. // Move forward
  44. Move (0, 1);
  45.  
  46. // Move right
  47. Move (1, 0);
  48.  
  49. struct MOVE_INFO
  50. {
  51. int x;
  52. int y;
  53. void (*GetVector)(void);
  54. }
  55.  
  56. void Move(MOVE_INFO mv)
  57. {
  58. ...
  59. mv.GetVector();
  60. ...
  61. }
  62.  
  63. main()
  64. {
  65. MOVE_INFO forward = {0, 1, SomeLib::GetForwardVector};
  66. MOVE_INFO right = {1, 0, SomeLib::GetRightVector};
  67.  
  68. // Move Forward
  69. Move(forward);
  70.  
  71. // Move Right
  72. Move(right);
  73. }
  74.  
  75. class Foo
  76. {
  77. protected:
  78. void MoveForward(float x) { Move(&Foo::GetActorForwardVector, x); }
  79. void MoveRight(float x) { Move(&Foo::GetActorRightVector, x); }
  80. private:
  81. template<typename GetDirectionFunc>
  82. void Move(GetDirectionFunc getDirection, float x)
  83. {
  84. AddMovementInput((this->*getDirection)() * x);
  85. }
  86. };
Add Comment
Please, Sign In to add comment