SDLPP: Visitor pattern

This commit is contained in:
zv0n 2021-04-25 13:57:33 +02:00
parent ee82430f82
commit 87970bfc4b
3 changed files with 25 additions and 2 deletions

View File

@ -105,7 +105,7 @@ void RenderObject::addMovement( double x, double y ) {
void RenderObject::setMovement( double x, double y ) { void RenderObject::setMovement( double x, double y ) {
movementDirection = { x, y }; movementDirection = { x, y };
} }
Vec2D<double> RenderObject::getMovement() { Vec2D< double > RenderObject::getMovement() {
return movementDirection; return movementDirection;
} }
void RenderObject::resetMovementX() { void RenderObject::resetMovementX() {
@ -237,4 +237,7 @@ void RenderObject::setAnimationSpeed( const double fps ) {
animation_fps = fps; animation_fps = fps;
animation_next_frame = animation_next_frame_base = 1000 / fps; animation_next_frame = animation_next_frame_base = 1000 / fps;
} }
void RenderObject::visit( Visitor &visitor ) {
visitor.visit( *this );
}
} // namespace SDLPP } // namespace SDLPP

View File

@ -6,6 +6,7 @@
#include "sdlpp_renderer.hpp" #include "sdlpp_renderer.hpp"
#include "sdlpp_texture.hpp" #include "sdlpp_texture.hpp"
#include "sdlpp_vector.hpp" #include "sdlpp_vector.hpp"
#include "sdlpp_visitor.hpp"
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -65,7 +66,7 @@ public:
void setMovementSpeed( double speed ); void setMovementSpeed( double speed );
void addMovement( double x, double y ); void addMovement( double x, double y );
void setMovement( double x, double y ); void setMovement( double x, double y );
Vec2D<double> getMovement(); Vec2D< double > getMovement();
void resetMovementX(); void resetMovementX();
void resetMovementY(); void resetMovementY();
void clearColided(); void clearColided();
@ -101,6 +102,7 @@ public:
void resumeAnimation(); void resumeAnimation();
void removeAnimation(); void removeAnimation();
void animate( int ticks ); void animate( int ticks );
void visit( Visitor &visitor );
protected: protected:
virtual void copyTo( std::shared_ptr< RenderObject > other ); virtual void copyTo( std::shared_ptr< RenderObject > other );

18
sdlpp/sdlpp_visitor.hpp Normal file
View File

@ -0,0 +1,18 @@
#ifndef SDLPP_HPP_VISITOR
#define SDLPP_HPP_VISITOR
#include "sdlpp_common.hpp"
namespace SDLPP {
class SDLPPSCOPE RenderObject;
class SDLPPSCOPE Visitor {
public:
Visitor() {}
virtual void visit( const RenderObject &obj );
};
} // namespace SDLPP
#endif