Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected:
- void MoveForward(float Magnitude);
- void MoveRight(float Magnitude);
- void MyCharacter::MoveForward(float Magnitude) {
- AddMovementInput(GetActorForwardVector() * Magnitude);
- }
- void Myharacter::MoveRight(float Magnitude) {
- AddMovementInput(GetActorRightVector() * Magnitude);
- }
- enum class Direction { LEFT, RIGHT, TOP, BOTTOM };
- class MyCharacter {
- template<Direction DIR> Vector MyCharacter::getVector() const;
- template<Direction DIR> void move() {
- AddMovementInput(getVector<Dir>() * magnitude);
- }
- }
- template<> Vector MyCharacter::getVector<Direction::LEFT>() const { ... }
- template<> Vector MyCharacter::getVector<Direction::RIGHT>() const { ... }
- float GetActorForwardVector() { return 3.0f; }
- class Foo
- {
- public:
- template<float (*F)()> float move() { return F(); }
- inline float moveLeft() { return move<GetActorForwardVector>(); }
- };
- int main()
- {
- Foo foo;
- std::cout << foo.moveLeft();
- }
- void Move(int x, int y);
- // Move forward
- Move (0, 1);
- // Move right
- Move (1, 0);
- struct MOVE_INFO
- {
- int x;
- int y;
- void (*GetVector)(void);
- }
- void Move(MOVE_INFO mv)
- {
- ...
- mv.GetVector();
- ...
- }
- main()
- {
- MOVE_INFO forward = {0, 1, SomeLib::GetForwardVector};
- MOVE_INFO right = {1, 0, SomeLib::GetRightVector};
- // Move Forward
- Move(forward);
- // Move Right
- Move(right);
- }
- class Foo
- {
- protected:
- void MoveForward(float x) { Move(&Foo::GetActorForwardVector, x); }
- void MoveRight(float x) { Move(&Foo::GetActorRightVector, x); }
- private:
- template<typename GetDirectionFunc>
- void Move(GetDirectionFunc getDirection, float x)
- {
- AddMovementInput((this->*getDirection)() * x);
- }
- };
Add Comment
Please, Sign In to add comment