SDLPP: make copySelf actually copy everything
This commit is contained in:
parent
67a56d31de
commit
20c30712b9
@ -130,4 +130,8 @@ void CircleColider::render( Renderer &renderer ) {
|
|||||||
int CircleColider::getRadius() const {
|
int CircleColider::getRadius() const {
|
||||||
return rad_;
|
return rad_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr< CollisionPolygon > CircleColider::copySelf() {
|
||||||
|
return std::make_shared< CircleColider >( *this );
|
||||||
|
}
|
||||||
} // namespace SDLPP
|
} // namespace SDLPP
|
||||||
|
@ -24,6 +24,7 @@ public:
|
|||||||
render( Renderer &renderer,
|
render( Renderer &renderer,
|
||||||
const std::tuple< int, int, int, int > &color ) override;
|
const std::tuple< int, int, int, int > &color ) override;
|
||||||
virtual void render( Renderer &renderer ) override;
|
virtual void render( Renderer &renderer ) override;
|
||||||
|
virtual std::shared_ptr<CollisionPolygon> copySelf() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int getRadius() const;
|
int getRadius() const;
|
||||||
|
@ -25,6 +25,7 @@ public:
|
|||||||
int getY() const;
|
int getY() const;
|
||||||
void setColor( const std::string &color );
|
void setColor( const std::string &color );
|
||||||
void setOutlineColor( const std::string &color );
|
void setOutlineColor( const std::string &color );
|
||||||
|
virtual std::shared_ptr<CollisionPolygon> copySelf() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double original_x;
|
double original_x;
|
||||||
|
@ -88,4 +88,9 @@ SDL_Rect RectColider::getRect() {
|
|||||||
r.h = pixel_h;
|
r.h = pixel_h;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr< CollisionPolygon > RectColider::copySelf() {
|
||||||
|
return std::make_shared< RectColider >( *this );
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace SDLPP
|
} // namespace SDLPP
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
render( Renderer &renderer,
|
render( Renderer &renderer,
|
||||||
const std::tuple< int, int, int, int > &color ) override;
|
const std::tuple< int, int, int, int > &color ) override;
|
||||||
virtual void render( Renderer &renderer ) override;
|
virtual void render( Renderer &renderer ) override;
|
||||||
|
virtual std::shared_ptr<CollisionPolygon> copySelf() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Rect getRect();
|
SDL_Rect getRect();
|
||||||
|
@ -139,9 +139,12 @@ void RectangleRender::centerX() {
|
|||||||
updateSizeAndPosition();
|
updateSizeAndPosition();
|
||||||
}
|
}
|
||||||
std::shared_ptr< RenderObject > RectangleRender::copySelf() {
|
std::shared_ptr< RenderObject > RectangleRender::copySelf() {
|
||||||
// TODO ACTUALLY copy, don't just copy pointers to textures and whatnot,
|
auto ret = std::make_shared< RectangleRender >( *this );
|
||||||
// create new textures!!!
|
copyTo(ret);
|
||||||
return std::make_shared< RectangleRender >( *this );
|
return ret;
|
||||||
|
}
|
||||||
|
void RectangleRender::copyTo(std::shared_ptr<RenderObject> other) {
|
||||||
|
RenderObject::copyTo(other);
|
||||||
}
|
}
|
||||||
std::string RectangleRender::getColor() const {
|
std::string RectangleRender::getColor() const {
|
||||||
return color;
|
return color;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "sdlpp_common.hpp"
|
#include "sdlpp_common.hpp"
|
||||||
#include "sdlpp_renderobject.hpp"
|
#include "sdlpp_renderobject.hpp"
|
||||||
#include "sdlpp_rectcolider.hpp"
|
#include "sdlpp_rectcolider.hpp"
|
||||||
|
#include "sdlpp_circlecolider.hpp"
|
||||||
|
|
||||||
namespace SDLPP {
|
namespace SDLPP {
|
||||||
class SDLPPSCOPE RectangleRender : public RenderObject {
|
class SDLPPSCOPE RectangleRender : public RenderObject {
|
||||||
@ -45,6 +46,7 @@ public:
|
|||||||
std::string getColor() const;
|
std::string getColor() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void copyTo(std::shared_ptr<RenderObject> other) override;
|
||||||
void updateXY();
|
void updateXY();
|
||||||
double og_x;
|
double og_x;
|
||||||
double og_y;
|
double og_y;
|
||||||
|
@ -104,4 +104,19 @@ std::shared_ptr< Renderer > RenderObject::getRenderer() const {
|
|||||||
void RenderObject::setSceneID( int id ) {
|
void RenderObject::setSceneID( int id ) {
|
||||||
scene_id = id;
|
scene_id = id;
|
||||||
}
|
}
|
||||||
|
void RenderObject::copyTo(std::shared_ptr<RenderObject> other) {
|
||||||
|
other->collisions.clear();
|
||||||
|
for ( auto &colider : collisions ) {
|
||||||
|
other->collisions.push_back(colider->copySelf());
|
||||||
|
}
|
||||||
|
other->texture.reset();
|
||||||
|
if ( texture ) {
|
||||||
|
other->texture = std::make_shared< Texture >( *texture );
|
||||||
|
}
|
||||||
|
other->polygon.reset();
|
||||||
|
if ( polygon ) {
|
||||||
|
other->polygon = polygon->copySelf();
|
||||||
|
}
|
||||||
|
other->colidedWith.clear();
|
||||||
|
}
|
||||||
} // namespace SDLPP
|
} // namespace SDLPP
|
||||||
|
@ -80,6 +80,7 @@ public:
|
|||||||
std::shared_ptr< Renderer > getRenderer() const;
|
std::shared_ptr< Renderer > getRenderer() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void copyTo(std::shared_ptr<RenderObject> other);
|
||||||
std::vector< std::shared_ptr< CollisionPolygon > > collisions;
|
std::vector< std::shared_ptr< CollisionPolygon > > collisions;
|
||||||
std::shared_ptr< Texture > texture;
|
std::shared_ptr< Texture > texture;
|
||||||
std::shared_ptr< Renderer > renderer;
|
std::shared_ptr< Renderer > renderer;
|
||||||
|
Loading…
Reference in New Issue
Block a user