SDLPP: formatting, make compileable on Linux

This commit is contained in:
zvon 2021-03-13 18:36:29 +01:00
parent d2cf54556e
commit 2f20661b5b
16 changed files with 118 additions and 100 deletions

View File

@ -3,7 +3,7 @@
namespace SDLPP { namespace SDLPP {
CircleColider::CircleColider( double x, double y, double rad ) CircleColider::CircleColider( double x, double y, double rad )
: CircleColider( { x, y }, rad ){}; : CircleColider( { x, y }, rad ) {}
CircleColider::CircleColider( const Vec2D< double > &center, double rad ) CircleColider::CircleColider( const Vec2D< double > &center, double rad )
: CollisionPolygon( center ), original_rad( rad ) {} : CollisionPolygon( center ), original_rad( rad ) {}

View File

@ -65,7 +65,8 @@ void CircleRender::setOutlineColor( const std::string &color ) {
std::pair< Vec2D< double >, Vec2D< double > > std::pair< Vec2D< double >, Vec2D< double > >
CircleRender::getDoubleRect() const { CircleRender::getDoubleRect() const {
return { { original.getX() - og_r, original.getY() - og_r }, { 2 * og_r, 2 * og_r } }; return { { original.getX() - og_r, original.getY() - og_r },
{ 2 * og_r, 2 * og_r } };
} }
int CircleRender::leftmost() { int CircleRender::leftmost() {

View File

@ -11,16 +11,22 @@ class SDLPPSCOPE CircleRender : public RenderObject {
public: public:
CircleRender() = delete; CircleRender() = delete;
virtual ~CircleRender(){}; virtual ~CircleRender(){};
CircleRender( double x, double y, double rad, std::shared_ptr< Renderer > &r ); CircleRender( double x, double y, double rad,
CircleRender( double x, double y, double rad, std::shared_ptr< Renderer > &r, std::shared_ptr< Renderer > &r );
CircleRender( double x, double y, double rad,
std::shared_ptr< Renderer > &r,
std::shared_ptr< Texture > &t ); std::shared_ptr< Texture > &t );
CircleRender( double x, double y, double rad, std::shared_ptr< Renderer > &r, CircleRender( double x, double y, double rad,
std::shared_ptr< Renderer > &r,
const std::string &img_or_color, bool is_polygon = false ); const std::string &img_or_color, bool is_polygon = false );
CircleRender( Vec2D<double> center, double rad, std::shared_ptr< Renderer > &r ); CircleRender( Vec2D< double > center, double rad,
CircleRender( Vec2D<double> center, double rad, std::shared_ptr< Renderer > &r, std::shared_ptr< Renderer > &r );
CircleRender( Vec2D< double > center, double rad,
std::shared_ptr< Renderer > &r,
std::shared_ptr< Texture > &t ); std::shared_ptr< Texture > &t );
CircleRender( Vec2D<double> center, double rad, std::shared_ptr< Renderer > &r, CircleRender( Vec2D< double > center, double rad,
std::shared_ptr< Renderer > &r,
const std::string &img_or_color, bool is_polygon = false ); const std::string &img_or_color, bool is_polygon = false );
virtual void setColor( const std::string &color ) override; virtual void setColor( const std::string &color ) override;
virtual void setOutlineColor( const std::string &color ) override; virtual void setOutlineColor( const std::string &color ) override;

View File

@ -54,7 +54,8 @@ bool infinityIntersection( const SDLPP::CollisionPolygon &infinite,
bool intersects( const SDLPP::CollisionPolygon &p1, bool intersects( const SDLPP::CollisionPolygon &p1,
const SDLPP::CollisionPolygon &p2 ) { const SDLPP::CollisionPolygon &p2 ) {
if(p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() || p1.bottommost() < p2.topmost() || p2.bottommost() < p1.topmost()) if ( p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() ||
p1.bottommost() < p2.topmost() || p2.bottommost() < p1.topmost() )
return false; return false;
for ( auto &line : p1.getLines() ) { for ( auto &line : p1.getLines() ) {
for ( auto &line2 : p2.getLines() ) { for ( auto &line2 : p2.getLines() ) {

View File

@ -3,6 +3,7 @@
#include "sdlpp_common.hpp" #include "sdlpp_common.hpp"
#include "sdlpp_font.hpp" #include "sdlpp_font.hpp"
#include <memory>
namespace SDLPP { namespace SDLPP {
class SDLPPSCOPE FontConfiguration { class SDLPPSCOPE FontConfiguration {

View File

@ -10,12 +10,10 @@ template<typename T>
double vecDotProduct( const Vec2D< T > &a, const Vec2D< T > &b ) { double vecDotProduct( const Vec2D< T > &a, const Vec2D< T > &b ) {
return a * b; return a * b;
} }
template<typename T> template < typename T > double vecLengthSquared( const Vec2D< T > &vec ) {
double vecLengthSquared( const Vec2D<T> &vec ) {
return vecDotProduct( vec, vec ); return vecDotProduct( vec, vec );
} }
template<typename T> template < typename T > double vecLength( const Vec2D< T > &vec ) {
double vecLength( const Vec2D<T> &vec ) {
return std::sqrt( vecLengthSquared( vec ) ); return std::sqrt( vecLengthSquared( vec ) );
} }
template < typename T > template < typename T >

View File

@ -6,8 +6,7 @@
#include <iostream> #include <iostream>
namespace SDLPP { namespace SDLPP {
template<typename T> template < typename T > class SDLPPSCOPE Line {
class SDLPPSCOPE Line {
public: public:
Line() = delete; Line() = delete;
~Line() = default; ~Line() = default;
@ -15,10 +14,11 @@ public:
: _start( start ), _end( end ) { : _start( start ), _end( end ) {
updateMost(); updateMost();
} }
Line( T x_1, T y_1, T x_2, T y_2 ) Line( T x_1, T y_1, T x_2, T y_2 ) : Line( { x_1, y_1 }, { x_2, y_2 } ) {}
: Line( { x_1, y_1 }, { x_2, y_2 } ) {}
Line( const Vec2D< T > &start, const Vec2D< T > &end, bool infinite ) Line( const Vec2D< T > &start, const Vec2D< T > &end, bool infinite )
: Line( start, end ), _infinite( infinite ) {} : Line( start, end ) {
_infinite = infinite;
}
Line( T x_1, T y_1, T x_2, T y_2, bool infinite ) Line( T x_1, T y_1, T x_2, T y_2, bool infinite )
: Line( { x_1, y_1 }, { x_2, y_2 }, infinite ) {} : Line( { x_1, y_1 }, { x_2, y_2 }, infinite ) {}
Line( const Line &input ) : Line( input.getStart(), input.getEnd() ) {} Line( const Line &input ) : Line( input.getStart(), input.getEnd() ) {}

View File

@ -151,8 +151,10 @@ void LineRenderer::updateXY() {
if ( width > height ) { if ( width > height ) {
auto multiplier = auto multiplier =
static_cast< double >( width ) / static_cast< double >( height ); static_cast< double >( width ) / static_cast< double >( height );
x1_ = original.getStart().getX() + static_cast< double >( multiplier - 1 ) / 2; x1_ = original.getStart().getX() +
x2_ = original.getEnd().getX() + static_cast< double >( multiplier - 1 ) / 2; static_cast< double >( multiplier - 1 ) / 2;
x2_ = original.getEnd().getX() +
static_cast< double >( multiplier - 1 ) / 2;
} else { } else {
x1_ = original.getStart().getX(); x1_ = original.getStart().getX();
x2_ = original.getEnd().getX(); x2_ = original.getEnd().getX();

View File

@ -139,9 +139,11 @@ void RectangleRender::updateSizeAndPosition() {
rect.x = std::round( current.getX() * dimension ); rect.x = std::round( current.getX() * dimension );
rect.y = std::round( current.getY() * dimension ); rect.y = std::round( current.getY() * dimension );
rect.w = rect.w =
std::round( ( current.getX() + original_size.getX() ) * dimension ) - rect.x; std::round( ( current.getX() + original_size.getX() ) * dimension ) -
rect.x;
rect.h = rect.h =
std::round( ( current.getY() + original_size.getY() ) * dimension ) - rect.y; std::round( ( current.getY() + original_size.getY() ) * dimension ) -
rect.y;
if ( polygon ) if ( polygon )
polygon->updateCollision( collisionPushX(), collisionPushY(), polygon->updateCollision( collisionPushX(), collisionPushY(),
collisionWidth(), collisionHeight() ); collisionWidth(), collisionHeight() );

View File

@ -32,31 +32,38 @@ public:
const std::shared_ptr< Renderer > &r, const std::shared_ptr< Renderer > &r,
const std::string &img, const SDL_Rect &source_rect ); const std::string &img, const SDL_Rect &source_rect );
RectangleRender( const Vec2D<double> &top_left, const Vec2D<double> &size, RectangleRender( const Vec2D< double > &top_left,
const Vec2D< double > &size,
const std::shared_ptr< Renderer > &r ); const std::shared_ptr< Renderer > &r );
RectangleRender( const Vec2D<double> &top_left, const Vec2D<double> &size, RectangleRender( const Vec2D< double > &top_left,
const Vec2D< double > &size,
const std::shared_ptr< Renderer > &r, const std::shared_ptr< Renderer > &r,
const std::shared_ptr< Texture > &t, int source_x, const std::shared_ptr< Texture > &t, int source_x,
int source_y, int source_width, int source_height ); int source_y, int source_width, int source_height );
RectangleRender( const Vec2D<double> &top_left, const Vec2D<double> &size, RectangleRender( const Vec2D< double > &top_left,
const Vec2D< double > &size,
const std::shared_ptr< Renderer > &r, const std::shared_ptr< Renderer > &r,
const std::shared_ptr< Texture > &t, const std::shared_ptr< Texture > &t,
const SDL_Rect &source_rect = { -1, -1, -1, -1 } ); const SDL_Rect &source_rect = { -1, -1, -1, -1 } );
RectangleRender( const Vec2D<double> &top_left, const Vec2D<double> &size, RectangleRender( const Vec2D< double > &top_left,
const Vec2D< double > &size,
const std::shared_ptr< Renderer > &r, const std::shared_ptr< Renderer > &r,
const std::string &img_or_color, bool is_polygon = false ); const std::string &img_or_color, bool is_polygon = false );
RectangleRender( const Vec2D<double> &top_left, const Vec2D<double> &size, RectangleRender( const Vec2D< double > &top_left,
const Vec2D< double > &size,
const std::shared_ptr< Renderer > &r, const std::shared_ptr< Renderer > &r,
const std::string &img, int source_x, int source_y, const std::string &img, int source_x, int source_y,
int source_width, int source_height ); int source_width, int source_height );
RectangleRender( const Vec2D<double> &top_left, const Vec2D<double> &size, RectangleRender( const Vec2D< double > &top_left,
const Vec2D< double > &size,
const std::shared_ptr< Renderer > &r, const std::shared_ptr< Renderer > &r,
const std::string &img, const SDL_Rect &source_rect ); const std::string &img, const SDL_Rect &source_rect );
virtual void setColor( const std::string &color ) override; virtual void setColor( const std::string &color ) override;
virtual void setOutlineColor( const std::string &color ) override; virtual void setOutlineColor( const std::string &color ) override;
virtual void specialAction( int /*UNUSED*/ ) override {} virtual void specialAction( int /*UNUSED*/ ) override {}
virtual void custom_move( int /*UNUSED*/ ) override {} virtual void custom_move( int /*UNUSED*/ ) override {}
virtual std::pair< Vec2D<double>, Vec2D<double> > getDoubleRect() const override; virtual std::pair< Vec2D< double >, Vec2D< double > >
getDoubleRect() const override;
virtual int leftmost() override; virtual int leftmost() override;
virtual int topmost() override; virtual int topmost() override;
virtual int rightmost() override; virtual int rightmost() override;

View File

@ -4,8 +4,7 @@
#include "sdlpp_common.hpp" #include "sdlpp_common.hpp"
namespace SDLPP { namespace SDLPP {
template<typename T> template < typename T > class SDLPPSCOPE Vec2D {
class SDLPPSCOPE Vec2D {
public: public:
Vec2D() = default; Vec2D() = default;
~Vec2D() = default; ~Vec2D() = default;
@ -39,6 +38,7 @@ public:
*this = *this - other; *this = *this - other;
return *this; return *this;
} }
private: private:
T _x = 0.0; T _x = 0.0;
T _y = 0.0; T _y = 0.0;
@ -51,6 +51,6 @@ template<typename T>
Vec2D< T > operator/( double divisor, const Vec2D< T > &vec ) { Vec2D< T > operator/( double divisor, const Vec2D< T > &vec ) {
return vec / divisor; return vec / divisor;
} }
} } // namespace SDLPP
#endif #endif