zv0n
f92a94ef01
Since textures should only be manipulated in the main thread (as well as rendering), let programmers deal with ensuring the texture is available during rendercopy
108 lines
4.0 KiB
C++
108 lines
4.0 KiB
C++
#ifndef SDLPP_HPP_RENDER_OBJECT
|
|
#define SDLPP_HPP_RENDER_OBJECT
|
|
|
|
#include "sdlpp_common.hpp"
|
|
#include "sdlpp_collision.hpp"
|
|
#include "sdlpp_renderer.hpp"
|
|
#include "sdlpp_texture.hpp"
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace SDLPP {
|
|
class SDLPPSCOPE Scene;
|
|
|
|
class SDLPPSCOPE RenderObject {
|
|
public:
|
|
RenderObject( const std::shared_ptr< Renderer > &r ) : renderer( r ) {}
|
|
virtual ~RenderObject() {}
|
|
// TODO maybe do basic render() that all descandants can inherit?
|
|
virtual void render() = 0;
|
|
virtual int leftmost() = 0;
|
|
virtual int topmost() = 0;
|
|
virtual int rightmost() = 0;
|
|
virtual int bottommost() = 0;
|
|
virtual int collisionPushX() = 0;
|
|
virtual int collisionPushY() = 0;
|
|
virtual int collisionWidth() = 0;
|
|
virtual int collisionHeight() = 0;
|
|
virtual void specialAction( int code ) = 0;
|
|
virtual std::pair< std::pair< double, double >,
|
|
std::pair< double, double > >
|
|
getDoubleRect() const = 0;
|
|
virtual void setPos( double x, double y ) = 0;
|
|
virtual void setPos( const std::pair< double, double > &pos ) = 0;
|
|
virtual std::pair< double, double > getPos() const = 0;
|
|
bool colidesWith( const RenderObject &other ) const;
|
|
template < class T > void addCollision( const T &p ) {
|
|
collisions.push_back( std::make_shared< T >( p ) );
|
|
collisions.back()->updateCollision( collisionPushX(), collisionPushY(),
|
|
collisionWidth(),
|
|
collisionHeight() );
|
|
}
|
|
bool hasCollisions() const;
|
|
const std::vector< std::shared_ptr< CollisionPolygon > > &
|
|
getCollisions() const;
|
|
virtual void setTexture( const std::shared_ptr< Texture > &t );
|
|
virtual void setTexture( const std::string &img_path );
|
|
virtual void setTexture( Font &font, const std::string &text,
|
|
const std::string &color = "FFFFFF",
|
|
const std::string &outline_color = "000000",
|
|
int outline_size = -1 );
|
|
virtual void setColor( const std::string &color ) = 0;
|
|
virtual void setOutlineColor( const std::string &color ) = 0;
|
|
virtual void unsetTexture();
|
|
virtual void unsetColor();
|
|
// per second, relative to window width
|
|
void setMovementSpeed( double speed );
|
|
void addMovement( int x, int y );
|
|
void resetMovementX();
|
|
void resetMovementY();
|
|
void clearColided();
|
|
void addColided( std::shared_ptr< RenderObject > &obj );
|
|
std::vector< std::shared_ptr< RenderObject > > &getColidedWith();
|
|
void setId( uint64_t input_id );
|
|
uint64_t getId();
|
|
void setHidden( bool hid );
|
|
bool getHidden() const;
|
|
void destroy();
|
|
bool getKilled();
|
|
void setColiderColor( const std::string &color );
|
|
virtual void move( int ticks ) = 0;
|
|
virtual void custom_move( int ticks ) = 0;
|
|
virtual void updateSizeAndPosition() = 0;
|
|
virtual SDL_Rect getRect() = 0;
|
|
void setPermanent( bool perm = true );
|
|
bool getPermanent() const;
|
|
virtual void centerX() = 0;
|
|
virtual std::shared_ptr< RenderObject > copySelf() = 0;
|
|
bool isStatic();
|
|
void setStatic( bool stat = true );
|
|
std::shared_ptr< Renderer > getRenderer() const;
|
|
|
|
protected:
|
|
virtual void copyTo( std::shared_ptr< RenderObject > other );
|
|
std::vector< std::shared_ptr< CollisionPolygon > > collisions;
|
|
std::shared_ptr< Texture > texture;
|
|
std::shared_ptr< Texture > cur_texture;
|
|
std::shared_ptr< Renderer > renderer;
|
|
std::shared_ptr< CollisionPolygon > polygon;
|
|
double movementSpeed = 0;
|
|
std::pair< int, int > movementDirection = { 0, 0 };
|
|
std::vector< std::shared_ptr< RenderObject > > colidedWith;
|
|
uint64_t id = -1;
|
|
bool hidden = false;
|
|
bool kill = false;
|
|
std::tuple< int, int, int, int > colider_color = { 0x00, 0xFF, 0xFF, 0xFF };
|
|
uint64_t scene_id = -1;
|
|
bool permanent = false;
|
|
bool is_static = true;
|
|
|
|
private:
|
|
void setSceneID( int id );
|
|
friend Scene;
|
|
};
|
|
} // end of namespace SDLPP
|
|
|
|
#endif
|