From f7ce70d139effc5553c4ed2fa604724413b9d9b2 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 6 Aug 2017 17:03:05 +0100 Subject: Adding clang format with my style based on google --- include/YAGE/Math/matrix.hpp | 601 +++++++++++++---------------- include/YAGE/Physics/body.hpp | 68 ++-- include/YAGE/Physics/collider.hpp | 29 +- include/YAGE/Physics/collisionbody.hpp | 8 +- include/YAGE/Physics/particlebody.hpp | 23 +- include/YAGE/Physics/rectanglecollider.hpp | 14 +- include/YAGE/Physics/rigidbody.hpp | 14 +- include/YAGE/camera2d.hpp | 18 +- include/YAGE/glslprogram.hpp | 36 +- include/YAGE/imageloader.hpp | 12 +- include/YAGE/iomanager.hpp | 11 +- include/YAGE/resourcemanager.hpp | 13 +- include/YAGE/sprite.hpp | 22 +- include/YAGE/spritebatch.hpp | 43 ++- include/YAGE/texture.hpp | 10 +- include/YAGE/texturecache.hpp | 13 +- include/YAGE/vertex.hpp | 80 ++-- include/YAGE/window.hpp | 38 +- include/YAGE/yage.hpp | 21 +- 19 files changed, 475 insertions(+), 599 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 8f490b41..860a250c 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -6,18 +6,16 @@ * ---------------------------------------------------------------------------- */ - /** \file matrix.hpp Templated matrix class - * + * * Matrix * ====== * * This is a very general matrix class that can then be inherited by - * vectors and other similar data structures to minimize code + * vectors and other similar data structures to minimize code * density. */ - #ifndef YAGE_MATH_MATRIX_HPP #define YAGE_MATH_MATRIX_HPP @@ -28,21 +26,19 @@ #include #include +namespace yage { -namespace yage -{ - -template class Matrix; +template +class Matrix; /** \internal Namespace for internal details. - * + * * Detail Namespace * ================ * * This is the namespace used for implementation detail. */ -namespace detail -{ +namespace detail { /** \internal Internal Row class used by the Matrix class to return the * internal data structure of the Matrix. @@ -52,30 +48,27 @@ namespace detail * * Internal Row class to return a value in the row of the matrix. */ -template class Row -{ +template +class Row { private: - Matrix *parent_; - int index_; + Matrix* parent_; + int index_; public: - Row(Matrix *parent, int index) : - parent_(parent), index_(index) - {} - - Type& operator[](int col) - { - // the index is the y-position of the element in the matrix - return parent_->data_[index_*Cols+col]; - } - - const Type& operator[](int col) const - { - return parent_->data_[index_*Cols+col]; - } + Row(Matrix* parent, int index) + : parent_(parent), index_(index) {} + + Type& operator[](int col) { + // the index is the y-position of the element in the matrix + return parent_->data_[index_ * Cols + col]; + } + + const Type& operator[](int col) const { + return parent_->data_[index_ * Cols + col]; + } }; -} // detail +} // detail /** Base Matrix class used by other similar classes. * @@ -85,365 +78,297 @@ public: * This is the base matrix class that can be used by all the other matrix * like data structures. */ -template class Matrix -{ - // friended with the row class so that it can access protected member data - friend class detail::Row; +template +class Matrix { + // friended with the row class so that it can access protected member data + friend class detail::Row; + protected: - /// Vector containing the data of the matrix - std::vector data_; + /// Vector containing the data of the matrix + std::vector data_; public: - /// Initializes the size of the data_ vector - Matrix() : data_(Rows*Cols) {} - Matrix(const std::vector& data) : data_(data) {} - - /// Returns the row size of the Matrix - int rowSize() const - { - return Rows; - } - - /// Returns the column size of the Matrixxs - int colSize() const - { - return Cols; - } - - /** Return the row specified row as a Matrix with only one row - * - * \param[in] row Row number to be returned - * - * Returns the row that is specified by the row variables. - */ - Matrix<1, Cols, Type> getRow(int row) const - { - Matrix<1, Cols, Type> rowMatrix; - for(int i=0; i getCol(int col) const - { - Matrix colMatrix; - for(int i=0; i::iterator begin() - { - return data_.begin(); - } - - // iterator support for end - typename std::vector::iterator end() - { - return data_.end(); - } - - // prints out the matrix, but can also be implemented by other classes to print data - // differently - virtual std::string toString() const - { - std::stringstream ss; - ss<<'['; - for(int i=0; i operator[](int row) - { - return detail::Row(this, row); - } - - detail::Row operator[](int row) const - { - // TODO got to fix this - return detail::Row((Matrix*)this, row); - } - - Matrix& operator+=(const Matrix &rhs) - { - std::vector out; - out.reserve(data_.size()); - std::transform(data_.begin(), data_.end(), rhs.data_.begin(), std::back_inserter(out), - [] (Type a, Type b) { - return a+b; - }); - data_=std::move(out); - return *this; - } - - Matrix& operator-=(const Matrix &rhs) - { - std::vector out; - out.reserve(data_.size()); - std::transform(data_.begin(), data_.end(), rhs.begin(), std::back_inserter(out), - [] (Type a, Type b) { - return a-b; - }); - data_=std::move(out); - return *this; - } + /// Initializes the size of the data_ vector + Matrix() : data_(Rows * Cols) {} + Matrix(const std::vector& data) : data_(data) {} + + /// Returns the row size of the Matrix + int rowSize() const { return Rows; } + + /// Returns the column size of the Matrixxs + int colSize() const { return Cols; } + + /** Return the row specified row as a Matrix with only one row + * + * \param[in] row Row number to be returned + * + * Returns the row that is specified by the row variables. + */ + Matrix<1, Cols, Type> getRow(int row) const { + Matrix<1, Cols, Type> rowMatrix; + for (int i = 0; i < Cols; ++i) { + rowMatrix[0][i] = data_[row][i]; + } + return rowMatrix; + } + + // returns the column in a column matrix + Matrix getCol(int col) const { + Matrix colMatrix; + for (int i = 0; i < Rows; ++i) { + colMatrix[i][0] = data_[i][col]; + } + return colMatrix; + } + + // iterator support for begin + typename std::vector::iterator begin() { return data_.begin(); } + + // iterator support for end + typename std::vector::iterator end() { return data_.end(); } + + // prints out the matrix, but can also be implemented by other classes to + // print data differently + virtual std::string toString() const { + std::stringstream ss; + ss << '['; + for (int i = 0; i < Rows - 1; ++i) { + ss << '['; + for (int j = 0; j < Cols - 1; ++j) { + ss << data_[i * Cols + j] << ' '; + } + ss << data_[(Rows - 1) * Cols + Cols - 1] << "],"; + } + ss << '['; + for (int j = 0; j < Cols - 1; ++j) { + ss << data_[(Rows - 1) * Cols + j] << ' '; + } + ss << data_[(Rows - 1) * Cols + Cols - 1] << "]]"; + return ss.str(); + } + + detail::Row operator[](int row) { + return detail::Row(this, row); + } + + detail::Row operator[](int row) const { + // TODO got to fix this + return detail::Row((Matrix*)this, + row); + } + + Matrix& operator+=(const Matrix& rhs) { + std::vector out; + out.reserve(data_.size()); + std::transform(data_.begin(), data_.end(), rhs.data_.begin(), + std::back_inserter(out), + [](Type a, Type b) { return a + b; }); + data_ = std::move(out); + return *this; + } + + Matrix& operator-=(const Matrix& rhs) { + std::vector out; + out.reserve(data_.size()); + std::transform(data_.begin(), data_.end(), rhs.begin(), + std::back_inserter(out), + [](Type a, Type b) { return a - b; }); + data_ = std::move(out); + return *this; + } }; -template -Matrix operator+(Matrix lhs, const Matrix &rhs) -{ - lhs+=rhs; - return lhs; +template +Matrix operator+(Matrix lhs, const Matrix& rhs) { + lhs += rhs; + return lhs; } -template -Matrix operator-(Matrix lhs, const Matrix &rhs) -{ - lhs-=rhs; - return lhs; +template +Matrix operator-(Matrix lhs, const Matrix& rhs) { + lhs -= rhs; + return lhs; } -template -Matrix operator+(Matrix lhs, const T &rhs) -{ - for(auto &data : lhs) - { - data+=rhs; - } - return lhs; +template +Matrix operator+(Matrix lhs, const T& rhs) { + for (auto& data : lhs) { + data += rhs; + } + return lhs; } -template -Matrix operator+(const T &lhs, Matrix rhs) -{ - for(auto &data : rhs) - { - data+=lhs; - } - return rhs; +template +Matrix operator+(const T& lhs, Matrix rhs) { + for (auto& data : rhs) { + data += lhs; + } + return rhs; } -template -Matrix operator-(Matrix lhs, const T &rhs) -{ - for(auto &data : lhs) - { - data-=rhs; - } - return lhs; +template +Matrix operator-(Matrix lhs, const T& rhs) { + for (auto& data : lhs) { + data -= rhs; + } + return lhs; } -template -Matrix operator-(const T &lhs, Matrix rhs) -{ - for(auto &data : rhs) - { - data=lhs-data; - } - return rhs; +template +Matrix operator-(const T& lhs, Matrix rhs) { + for (auto& data : rhs) { + data = lhs - data; + } + return rhs; } -template -Matrix operator*(Matrix lhs, const T &rhs) -{ - for(auto &data : lhs) - { - data*=rhs; - } - return lhs; +template +Matrix operator*(Matrix lhs, const T& rhs) { + for (auto& data : lhs) { + data *= rhs; + } + return lhs; } -template -Matrix operator*(const T &lhs, Matrix rhs) { - for(auto &data : rhs) - { - data*=lhs; - } - return rhs; +template +Matrix operator*(const T& lhs, Matrix rhs) { + for (auto& data : rhs) { + data *= lhs; + } + return rhs; } -template -Matrix operator/(Matrix lhs, const T &rhs) -{ - for(auto &data : lhs) - { - data/=rhs; - } - return lhs; +template +Matrix operator/(Matrix lhs, const T& rhs) { + for (auto& data : lhs) { + data /= rhs; + } + return lhs; } -template -bool operator==(const Matrix &lhs, const Matrix &rhs) -{ - for(int i=0; i +bool operator==(const Matrix& lhs, const Matrix& rhs) { + for (int i = 0; i < M; ++i) + for (int j = 0; j < N; ++j) + if (lhs[i][j] != rhs[i][j]) return false; + return true; } -template -std::ostream& operator<<(std::ostream &os, const Matrix &mat) -{ - return os< +std::ostream& operator<<(std::ostream& os, const Matrix& mat) { + return os << mat.toString(); } -template class Vector : public Matrix -{ +template +class Vector : public Matrix { public: - Vector() : Matrix() {} - Vector(const Matrix& other) : Matrix(other) {} - Vector(const std::vector& data) : Matrix(data) {} - - Type& operator[](int col) - { - return this->data_[col]; - } - - const Type& operator[](int col) const - { - return this->data_[col]; - } - - virtual std::string toString() const - { - std::stringstream ss; - ss<<"["; - for(std::size_t i=0; idata_.size()-1; ++i) - { - ss<data_[i]<<" "; - } - ss<data_[this->data_.size()-1]<<"]"; - return ss.str(); - } + Vector() : Matrix() {} + Vector(const Matrix& other) + : Matrix(other) {} + Vector(const std::vector& data) + : Matrix(data) {} + + Type& operator[](int col) { return this->data_[col]; } + + const Type& operator[](int col) const { return this->data_[col]; } + + virtual std::string toString() const { + std::stringstream ss; + ss << "["; + for (std::size_t i = 0; i < this->data_.size() - 1; ++i) { + ss << this->data_[i] << " "; + } + ss << this->data_[this->data_.size() - 1] << "]"; + return ss.str(); + } }; /** 2D Vector class. * * Two dimensional vector class. */ -template class Vector2 : public Vector<2, Type> -{ +template +class Vector2 : public Vector<2, Type> { public: - Vector2() : Vector<2, Type>() {} - Vector2(const std::vector& data) : Vector<2, Type>(data) {} - - Vector2(Type x, Type y) - { - this->data_[0]=x; - this->data_[1]=y; - } - - Vector2(const Matrix<2, 1, Type> &other) : Vector<2, Type>(other) {} - - Type& x() - { - return this->data_[0]; - } - - const Type& x() const - { - return this->data_[0]; - } - - Type& y() - { - return this->data_[1]; - } - - const Type& y() const - { - return this->data_[1]; - } + Vector2() : Vector<2, Type>() {} + Vector2(const std::vector& data) : Vector<2, Type>(data) {} + + Vector2(Type x, Type y) { + this->data_[0] = x; + this->data_[1] = y; + } + + Vector2(const Matrix<2, 1, Type>& other) : Vector<2, Type>(other) {} + + Type& x() { return this->data_[0]; } + + const Type& x() const { return this->data_[0]; } + + Type& y() { return this->data_[1]; } + + const Type& y() const { return this->data_[1]; } }; /// Definition of a 2D vector. typedef Vector2 Vector2d; /** Namespace containing functions that operate on matrices. */ -namespace matrix -{ +namespace matrix { /** Transposes a matrix and returns the result - * - * \param[in] m input matrix. - */ -template Matrix transpose(const Matrix &m) -{ - Matrix trans; - for(int i=0; i +Matrix transpose(const Matrix& m) { + Matrix trans; + for (int i = 0; i < M; ++i) { + for (int j = 0; j < N; ++j) { + trans[j][i] = m[i][j]; + } + } + return trans; } /** Returns the dot product between two vectors - * - * \param[in] m1,m2 Input matrices. - */ -template T dot(const Matrix &m1, const Matrix &m2) -{ - T sum=0; - for(int i=0; i +T dot(const Matrix& m1, const Matrix& m2) { + T sum = 0; + for (int i = 0; i < R; ++i) { + sum += m1[i][0] * m2[i][0]; + } + return sum; } /** Multiplies two matrices together. - * - * \param[in] m1,m2 Matrix inputs - * - * Requires the two matrices to be compatible with multiplication. - */ -template -Matrix multiply(const Matrix &m1, const Matrix &m2) -{ - if(N!=P) - { - throw std::runtime_error("Matrices don't have the right dimensions for multiplication"); - } - - Matrix res; - - for(int i=0; i +Matrix multiply(const Matrix& m1, const Matrix& m2) { + if (N != P) { + throw std::runtime_error( + "Matrices don't have the right dimensions for multiplication"); + } + + Matrix res; + + for (int i = 0; i < M; ++i) { + for (int j = 0; j < Q; ++j) { + res[i][j] = dot(transpose(m1.getRow(i)), m2.getCol(j)); + } + } + + return res; } -} // matrix +} // matrix -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp index b0869779..f32b767d 100644 --- a/include/YAGE/Physics/body.hpp +++ b/include/YAGE/Physics/body.hpp @@ -11,48 +11,46 @@ #include "Math/matrix.hpp" -namespace yage -{ +namespace yage { -class Body -{ +class Body { public: - // gravity constant - static const double GRAVITY; + // gravity constant + static const double GRAVITY; + protected: - // center of mass of the object - Vector2d position_=Vector2d(0, 0); - - // mass of the object - double mass_=1; - - // current velocity of the object - Vector2d velocity_=Vector2d(0, 0); - - // boolean that defines if gravity can act on the object - bool gravity_=true; - - // current acceleration - Vector2d acceleration_=Vector2d(0, 0); - - // force acting on the body - Vector2d force_=Vector2d(0, 0); - + // center of mass of the object + Vector2d position_ = Vector2d(0, 0); + + // mass of the object + double mass_ = 1; + + // current velocity of the object + Vector2d velocity_ = Vector2d(0, 0); + + // boolean that defines if gravity can act on the object + bool gravity_ = true; + + // current acceleration + Vector2d acceleration_ = Vector2d(0, 0); + + // force acting on the body + Vector2d force_ = Vector2d(0, 0); + public: - // apply force to the object and update the velocity - virtual void applyForce(const Vector2d &force)=0; - virtual void update()=0; + // apply force to the object and update the velocity + virtual void applyForce(const Vector2d& force) = 0; + virtual void update() = 0; + + double xPosition() const; + double yPosition() const; - double xPosition() const; - double yPosition() const; protected: - // protected constructor to initialize member variables - Body(const Vector2d &position=Vector2d(0, 0), - double mass=1, - const Vector2d &velocity=Vector2d(0, 0), - bool gravity=false); + // protected constructor to initialize member variables + Body(const Vector2d& position = Vector2d(0, 0), double mass = 1, + const Vector2d& velocity = Vector2d(0, 0), bool gravity = false); }; -} // namespace yage +} // namespace yage #endif diff --git a/include/YAGE/Physics/collider.hpp b/include/YAGE/Physics/collider.hpp index 716b7d4c..92b90de2 100644 --- a/include/YAGE/Physics/collider.hpp +++ b/include/YAGE/Physics/collider.hpp @@ -11,30 +11,29 @@ #include -namespace yage -{ +namespace yage { // The Collider class helps collision detection by providing a general shape // for different shapes to have their own collision algorithms. -class Collider -{ +class Collider { protected: - // position of the object - glm::vec2 position_; + // position of the object + glm::vec2 position_; + + // size of the object + glm::vec2 size_; - // size of the object - glm::vec2 size_; - public: - Collider(const glm::vec2 &position, const glm::vec2 &size) : position_(position), size_(size) {} + Collider(const glm::vec2& position, const glm::vec2& size) + : position_(position), size_(size) {} - // function that checks if two colliders are colliding - virtual bool collides(const Collider &collider) const=0; + // function that checks if two colliders are colliding + virtual bool collides(const Collider& collider) const = 0; - // function that returns if a point is inside the shape - virtual bool inside(const glm::vec2 &point) const=0; + // function that returns if a point is inside the shape + virtual bool inside(const glm::vec2& point) const = 0; }; -} // namespace yage +} // namespace yage #endif diff --git a/include/YAGE/Physics/collisionbody.hpp b/include/YAGE/Physics/collisionbody.hpp index b7403e81..5ddacacd 100644 --- a/include/YAGE/Physics/collisionbody.hpp +++ b/include/YAGE/Physics/collisionbody.hpp @@ -11,18 +11,16 @@ #include "Physics/body.hpp" -namespace yage -{ +namespace yage { // a collision body will be a body that is static and not affected by gravity, // with infinite mass -class CollisionBody : public Body -{ +class CollisionBody : public Body { public: CollisionBody(); virtual ~CollisionBody(); }; -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp index e107cb6a..ff8b3b85 100644 --- a/include/YAGE/Physics/particlebody.hpp +++ b/include/YAGE/Physics/particlebody.hpp @@ -13,22 +13,19 @@ #include "body.hpp" -namespace yage -{ +namespace yage { -class ParticleBody : public Body -{ +class ParticleBody : public Body { public: - ParticleBody(const Vector2d &position=Vector2d(0, 0), - double mass=1, - const Vector2d &velocity=Vector2d(0, 0), - bool gravity=true); - - // apply a force to the rigid body - virtual void applyForce(const Vector2d &force); - virtual void update(); + ParticleBody(const Vector2d& position = Vector2d(0, 0), double mass = 1, + const Vector2d& velocity = Vector2d(0, 0), + bool gravity = true); + + // apply a force to the rigid body + virtual void applyForce(const Vector2d& force); + virtual void update(); }; -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/rectanglecollider.hpp b/include/YAGE/Physics/rectanglecollider.hpp index 62f11100..7f9dd7f7 100644 --- a/include/YAGE/Physics/rectanglecollider.hpp +++ b/include/YAGE/Physics/rectanglecollider.hpp @@ -13,18 +13,16 @@ #include -namespace yage -{ +namespace yage { -class RectangleCollider : public Collider -{ +class RectangleCollider : public Collider { public: - RectangleCollider(const glm::vec2 &position, const glm::vec2 &size); + RectangleCollider(const glm::vec2& position, const glm::vec2& size); - virtual bool collides(const Collider &collider) const; - virtual bool inside(const glm::vec2 &point) const; + virtual bool collides(const Collider& collider) const; + virtual bool inside(const glm::vec2& point) const; }; -} // yage +} // yage #endif diff --git a/include/YAGE/Physics/rigidbody.hpp b/include/YAGE/Physics/rigidbody.hpp index c8a2e497..fd19dc7c 100644 --- a/include/YAGE/Physics/rigidbody.hpp +++ b/include/YAGE/Physics/rigidbody.hpp @@ -13,18 +13,14 @@ #include "particlebody.hpp" -namespace yage -{ +namespace yage { -class RigidBody : public ParticleBody -{ +class RigidBody : public ParticleBody { public: - RigidBody(const Vector2d &position=Vector2d(0, 0), - double mass=1, - const Vector2d &velocity=Vector2d(0, 0), - bool gravity=true); + RigidBody(const Vector2d& position = Vector2d(0, 0), double mass = 1, + const Vector2d& velocity = Vector2d(0, 0), bool gravity = true); }; -} // yage +} // yage #endif diff --git a/include/YAGE/camera2d.hpp b/include/YAGE/camera2d.hpp index 4c44ccaf..077d0544 100644 --- a/include/YAGE/camera2d.hpp +++ b/include/YAGE/camera2d.hpp @@ -14,27 +14,25 @@ #include #include -namespace yage -{ +namespace yage { -class Camera2D -{ +class Camera2D { private: - bool matrix_needs_update_=true; - float scale_=1; + bool matrix_needs_update_ = true; + float scale_ = 1; glm::vec2 position_; glm::mat4 camera_matrix_; glm::mat4 ortho_matrix_; public: - Camera2D(int screen_width=1280, int screen_height=720); + Camera2D(int screen_width = 1280, int screen_height = 720); // update camera location - void update(GlslProgram &program); + void update(GlslProgram& program); // camera movement - void move(const glm::vec2 &direction); + void move(const glm::vec2& direction); }; -} // yage +} // yage #endif diff --git a/include/YAGE/glslprogram.hpp b/include/YAGE/glslprogram.hpp index 70f30b73..fd97c3a0 100644 --- a/include/YAGE/glslprogram.hpp +++ b/include/YAGE/glslprogram.hpp @@ -13,38 +13,38 @@ #include -namespace yage -{ +namespace yage { -class GlslProgram -{ +class GlslProgram { private: /// compiled shader program id - GLuint program_id_=0; - GLuint vertex_shader_id_=0; - GLuint fragment_shader_id_=0; - int attribute_index_=0; + GLuint program_id_ = 0; + GLuint vertex_shader_id_ = 0; + GLuint fragment_shader_id_ = 0; + int attribute_index_ = 0; /// compiles one shader - void compileShader(const GLuint &shader, const std::string &file_path); + void compileShader(const GLuint& shader, const std::string& file_path); + public: - GlslProgram()=default; - GlslProgram(const GlslProgram&)=delete; - GlslProgram(GlslProgram&&)=delete; + GlslProgram() = default; + GlslProgram(const GlslProgram&) = delete; + GlslProgram(GlslProgram&&) = delete; ~GlslProgram(); - GlslProgram& operator=(const GlslProgram&)=delete; - GlslProgram& operator=(GlslProgram&&)=delete; + GlslProgram& operator=(const GlslProgram&) = delete; + GlslProgram& operator=(GlslProgram&&) = delete; /// compiles vertex and fragment shader - void compileShaders(const std::string &vertex_shader_path, const std::string &fragment_shader_path); + void compileShaders(const std::string& vertex_shader_path, + const std::string& fragment_shader_path); void linkShaders(); - void addAttribute(const std::string &attribute_name); - GLint getUniformLocation(const std::string &uniform_name); + void addAttribute(const std::string& attribute_name); + GLint getUniformLocation(const std::string& uniform_name); void use(); void unuse(); }; -} // yage +} // yage #endif diff --git a/include/YAGE/imageloader.hpp b/include/YAGE/imageloader.hpp index 4c0b5a36..90425cab 100644 --- a/include/YAGE/imageloader.hpp +++ b/include/YAGE/imageloader.hpp @@ -13,15 +13,13 @@ #include -namespace yage -{ +namespace yage { -class ImageLoader -{ +class ImageLoader { public: - static Texture loadPng(const std::string &file_path); + static Texture loadPng(const std::string& file_path); }; - -} // yage + +} // yage #endif diff --git a/include/YAGE/iomanager.hpp b/include/YAGE/iomanager.hpp index 4295c598..3b1f5278 100644 --- a/include/YAGE/iomanager.hpp +++ b/include/YAGE/iomanager.hpp @@ -12,15 +12,14 @@ #include #include -namespace yage -{ +namespace yage { -class IoManager -{ +class IoManager { public: - static bool readFileToBuffer(const std::string &file_path, std::vector &buffer); + static bool readFileToBuffer(const std::string &file_path, + std::vector &buffer); }; - + } // yage #endif diff --git a/include/YAGE/resourcemanager.hpp b/include/YAGE/resourcemanager.hpp index 10f6cbb8..3d824d61 100644 --- a/include/YAGE/resourcemanager.hpp +++ b/include/YAGE/resourcemanager.hpp @@ -14,17 +14,16 @@ #include -namespace yage -{ +namespace yage { -class ResourceManager -{ +class ResourceManager { private: static TextureCache texture_cache_; + public: - static Texture getTexture(const std::string &texture_path); + static Texture getTexture(const std::string& texture_path); }; - -} // yage + +} // yage #endif diff --git a/include/YAGE/sprite.hpp b/include/YAGE/sprite.hpp index cddc0e26..969d0a67 100644 --- a/include/YAGE/sprite.hpp +++ b/include/YAGE/sprite.hpp @@ -15,11 +15,9 @@ #include -namespace yage -{ +namespace yage { -class Sprite -{ +class Sprite { private: float x_; float y_; @@ -27,19 +25,21 @@ private: float height_; GLuint vbo_id_ = 0; Texture texture_; + public: Sprite(); - Sprite(const Sprite&)=delete; - Sprite(Sprite&&)=delete; + Sprite(const Sprite&) = delete; + Sprite(Sprite&&) = delete; ~Sprite(); - Sprite& operator=(const Sprite&)=delete; - Sprite& operator=(Sprite&&)=delete; + Sprite& operator=(const Sprite&) = delete; + Sprite& operator=(Sprite&&) = delete; - void init(float x, float y, float width, float height, const std::string &texture_path); + void init(float x, float y, float width, float height, + const std::string& texture_path); void draw(); }; - -} // yage + +} // yage #endif diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp index a3007bbf..9446c40f 100644 --- a/include/YAGE/spritebatch.hpp +++ b/include/YAGE/spritebatch.hpp @@ -16,13 +16,11 @@ #include -namespace yage -{ +namespace yage { class SpriteBatch; -class Glyph -{ +class Glyph { // member variables private: GLuint texture_; @@ -34,7 +32,9 @@ private: // member functions public: - Glyph(GLuint texture, float depth, const Vertex &top_left, const Vertex &top_right, const Vertex &bottom_right, const Vertex &bottom_left); + Glyph(GLuint texture, float depth, const Vertex& top_left, + const Vertex& top_right, const Vertex& bottom_right, + const Vertex& bottom_left); GLuint texture() const { return texture_; } float depth() const { return depth_; } @@ -44,12 +44,11 @@ public: Vertex bottom_left() const { return bottom_left_; } }; -class RenderBatch -{ +class RenderBatch { friend SpriteBatch; // member variables private: - GLsizei num_vertices_; + GLsizei num_vertices_; GLint offset_; GLuint texture_; @@ -63,42 +62,44 @@ public: GLuint texture() const { return texture_; } }; -class SpriteBatch -{ +class SpriteBatch { // member variables public: - static const int NUM_VERTICES=6; + static const int NUM_VERTICES = 6; + private: - GLuint vbo_=0; - GLuint vao_=0; + GLuint vbo_ = 0; + GLuint vao_ = 0; std::vector glyphs_; - std::vector glyph_ptrs_; + std::vector glyph_ptrs_; std::vector render_batches_; // member functions public: SpriteBatch(); - SpriteBatch(const SpriteBatch&)=delete; - SpriteBatch(SpriteBatch&&)=delete; + SpriteBatch(const SpriteBatch&) = delete; + SpriteBatch(SpriteBatch&&) = delete; ~SpriteBatch(); - SpriteBatch& operator=(const SpriteBatch&)=delete; - SpriteBatch& operator=(SpriteBatch&&)=delete; + SpriteBatch& operator=(const SpriteBatch&) = delete; + SpriteBatch& operator=(SpriteBatch&&) = delete; // initialize vaos and vbos void init(); void begin(); void end(); // adds a sprite to the sprite batch to be rendered later - void draw(const glm::vec4 &destination_rect, const glm::vec4 &uv_rect, GLuint texture, const Color &color, float depth); + void draw(const glm::vec4& destination_rect, const glm::vec4& uv_rect, + GLuint texture, const Color& color, float depth); // render the batch void render(); + private: void createVertexArray(); void createRenderBatches(); void sortGlyphs(); }; - -} // yage + +} // yage #endif diff --git a/include/YAGE/texture.hpp b/include/YAGE/texture.hpp index 34accaca..65f3f651 100644 --- a/include/YAGE/texture.hpp +++ b/include/YAGE/texture.hpp @@ -11,16 +11,14 @@ #include -namespace yage -{ +namespace yage { -struct Texture -{ +struct Texture { GLuint id; int width; int height; }; - -} // yage + +} // yage #endif diff --git a/include/YAGE/texturecache.hpp b/include/YAGE/texturecache.hpp index ac318230..0de5c12a 100644 --- a/include/YAGE/texturecache.hpp +++ b/include/YAGE/texturecache.hpp @@ -13,19 +13,18 @@ #include -namespace yage -{ +namespace yage { -class TextureCache -{ +class TextureCache { private: std::unordered_map texture_map_; + public: TextureCache(); - Texture getTexture(const std::string &texture_path); + Texture getTexture(const std::string& texture_path); }; - -} // yage + +} // yage #endif diff --git a/include/YAGE/vertex.hpp b/include/YAGE/vertex.hpp index a3848490..d3355b11 100644 --- a/include/YAGE/vertex.hpp +++ b/include/YAGE/vertex.hpp @@ -11,84 +11,66 @@ #include -namespace yage -{ +namespace yage { -struct Position -{ +struct Position { float x; float y; - Position() - {} - - Position(float x_, float y_) : - x(x_), y(y_) - {} + Position() {} + + Position(float x_, float y_) : x(x_), y(y_) {} }; -struct Color -{ +struct Color { GLubyte r; GLubyte g; GLubyte b; GLubyte a; - Color() - {} + Color() {} - Color(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_) : - r(r_), g(g_), b(b_), a(a_) - {} + Color(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_) + : r(r_), g(g_), b(b_), a(a_) {} }; -struct UV -{ +struct UV { float u; float v; - UV() - {} + UV() {} - UV(float u_, float v_) : - u(u_), v(v_) - {} + UV(float u_, float v_) : u(u_), v(v_) {} }; -struct Vertex -{ +struct Vertex { Position position; Color color; UV uv; - Vertex() - {} + Vertex() {} - Vertex(const Position &position_, const Color &color_, const UV &uv_) : - position(position_), color(color_), uv(uv_) - {} + Vertex(const Position& position_, const Color& color_, const UV& uv_) + : position(position_), color(color_), uv(uv_) {} - void setPosition(float x, float y) - { - position.x = x; - position.y = y; + void setPosition(float x, float y) { + position.x = x; + position.y = y; } - - void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) - { - color.r = r; - color.g = g; - color.b = b; - color.a = a; + + void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) { + color.r = r; + color.g = g; + color.b = b; + color.a = a; } - - void setUv(float u, float v) - { - uv.u = u; - uv.v = v; + + void setUv(float u, float v) { + uv.u = u; + uv.v = v; } }; - -} // yage + +} // yage #endif diff --git a/include/YAGE/window.hpp b/include/YAGE/window.hpp index beefae3d..c2003a94 100644 --- a/include/YAGE/window.hpp +++ b/include/YAGE/window.hpp @@ -13,43 +13,41 @@ #include -namespace yage -{ +namespace yage { // window flags that can change it's appearance -enum WindowFlags : unsigned -{ - SHOWN=0x1, - HIDDEN=0x2, - FULLSCREEN=0x4, - BORDERLESS=0x8, +enum WindowFlags : unsigned { + SHOWN = 0x1, + HIDDEN = 0x2, + FULLSCREEN = 0x4, + BORDERLESS = 0x8, }; // window wrapper around SDL_Window pointer -class Window -{ +class Window { private: /// window handle - SDL_Window *window_=nullptr; - + SDL_Window* window_ = nullptr; + public: Window(); - Window(const Window&)=delete; - Window(Window&&)=delete; + Window(const Window&) = delete; + Window(Window&&) = delete; /// destroys the window handle - ~Window(); + ~Window(); - Window& operator=(const Window&)=delete; - Window& operator=(Window&&)=delete; + Window& operator=(const Window&) = delete; + Window& operator=(Window&&) = delete; /// create the window, initialize the handle and update the width and height - void create(const std::string &window_name, int width, int height, unsigned flags=WindowFlags::SHOWN); + void create(const std::string& window_name, int width, int height, + unsigned flags = WindowFlags::SHOWN); /// swap the buffer void swapBuffer(); /// clear buffer void clearBuffer(); }; - -} // namespace yage + +} // namespace yage #endif diff --git a/include/YAGE/yage.hpp b/include/YAGE/yage.hpp index 1045e12b..45c1c4d7 100644 --- a/include/YAGE/yage.hpp +++ b/include/YAGE/yage.hpp @@ -25,23 +25,16 @@ #include -namespace yage -{ - -bool init() -{ - if(SDL_Init(SDL_INIT_VIDEO)) - { - return false; - } - return true; -} +namespace yage { -void quit() -{ - SDL_Quit(); +bool init() { + if (SDL_Init(SDL_INIT_VIDEO)) { + return false; + } + return true; } +void quit() { SDL_Quit(); } }; #endif -- cgit