SDLPP: Scene - add visitCollisions function

This commit is contained in:
zv0n 2021-04-25 16:07:46 +02:00
parent 5b96de0d9d
commit 7206dbf7c3
5 changed files with 10 additions and 3 deletions

View File

@ -126,7 +126,7 @@ std::vector< std::shared_ptr< RenderObject > > &RenderObject::getColidedWith() {
void RenderObject::setId( uint64_t input_id ) {
id = input_id;
}
uint64_t RenderObject::getId() {
uint64_t RenderObject::getId() const {
return id;
}
void RenderObject::setHidden( bool hid ) {

View File

@ -73,7 +73,7 @@ public:
void addColided( std::shared_ptr< RenderObject > &obj );
std::vector< std::shared_ptr< RenderObject > > &getColidedWith();
void setId( uint64_t input_id );
uint64_t getId();
uint64_t getId() const;
void setHidden( bool hid );
bool getHidden() const;
void destroy();

View File

@ -107,6 +107,11 @@ Scene::getCollisions( RenderObject &r ) {
}
return ret;
}
void Scene::visitCollisions( RenderObject &r, Visitor &v ) {
for(auto &collision : getCollisions(r)) {
collision->visit(v);
}
}
std::vector< std::shared_ptr< RenderObject > >
Scene::getCollisions( RenderObject &r,
const std::unordered_set< int > &objectIDs ) {

View File

@ -9,6 +9,7 @@
#include "sdlpp_common.hpp"
#include "sdlpp_renderer.hpp"
#include "sdlpp_renderobject.hpp"
#include "sdlpp_visitor.hpp"
namespace SDLPP {
class SDLPPSCOPE Scene {
@ -28,6 +29,7 @@ public:
void updateScene();
std::vector< std::shared_ptr< RenderObject > >
getCollisions( RenderObject &r );
void visitCollisions( RenderObject &r, Visitor &v );
std::vector< std::shared_ptr< RenderObject > >
getCollisions( RenderObject &r,
const std::unordered_set< int > &objectIDs );

View File

@ -10,7 +10,7 @@ class SDLPPSCOPE RenderObject;
class SDLPPSCOPE Visitor {
public:
Visitor() {}
virtual void visit( const RenderObject &obj );
virtual void visit( const RenderObject &obj ) = 0;
};
} // namespace SDLPP