diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-09 07:55:22 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-09 07:55:22 +0100 |
commit | 60072c1d8089ffd3294e76636198d14710be95b8 (patch) | |
tree | 511d459e9afe69ca58d05880eb53ce44a9a183c6 /include | |
parent | 660996bd750dbb5fcdce85845ee6b260f3ed23eb (diff) | |
download | YAGE-60072c1d8089ffd3294e76636198d14710be95b8.tar.gz YAGE-60072c1d8089ffd3294e76636198d14710be95b8.zip |
Restructuring
Diffstat (limited to 'include')
-rw-r--r-- | include/YAGE/Math/math.h | 14 | ||||
-rw-r--r-- | include/YAGE/Math/matrix.h | 424 | ||||
-rw-r--r-- | include/YAGE/Physics/README.org | 27 | ||||
-rw-r--r-- | include/YAGE/Physics/body.h | 56 | ||||
-rw-r--r-- | include/YAGE/Physics/collider.h | 43 | ||||
-rw-r--r-- | include/YAGE/Physics/collisionbody.h | 28 | ||||
-rw-r--r-- | include/YAGE/Physics/particlebody.h | 33 | ||||
-rw-r--r-- | include/YAGE/Physics/physics.h | 19 | ||||
-rw-r--r-- | include/YAGE/Physics/rectanglecollider.h | 30 | ||||
-rw-r--r-- | include/YAGE/Physics/rigidbody.h | 28 | ||||
-rw-r--r-- | include/YAGE/camera2d.h | 38 | ||||
-rw-r--r-- | include/YAGE/glslprogram.h | 52 | ||||
-rw-r--r-- | include/YAGE/imageloader.h | 27 | ||||
-rw-r--r-- | include/YAGE/inputmanager.h | 28 | ||||
-rw-r--r-- | include/YAGE/iomanager.h | 27 | ||||
-rw-r--r-- | include/YAGE/picopng.h | 20 | ||||
-rw-r--r-- | include/YAGE/resourcemanager.h | 31 | ||||
-rw-r--r-- | include/YAGE/sprite.h | 52 | ||||
-rw-r--r-- | include/YAGE/spritebatch.h | 105 | ||||
-rw-r--r-- | include/YAGE/spritesheet.h | 25 | ||||
-rw-r--r-- | include/YAGE/texture.h | 25 | ||||
-rw-r--r-- | include/YAGE/texturecache.h | 32 | ||||
-rw-r--r-- | include/YAGE/vertex.h | 84 | ||||
-rw-r--r-- | include/YAGE/window.h | 55 | ||||
-rw-r--r-- | include/YAGE/yage.h | 63 |
25 files changed, 0 insertions, 1366 deletions
diff --git a/include/YAGE/Math/math.h b/include/YAGE/Math/math.h deleted file mode 100644 index b729dbe6..00000000 --- a/include/YAGE/Math/math.h +++ /dev/null @@ -1,14 +0,0 @@ -/* ---------------------------------------------------------------------------- - * math.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_MATH_H -#define YAGE_MATH_H - -#include "matrix.h" - -#endif diff --git a/include/YAGE/Math/matrix.h b/include/YAGE/Math/matrix.h deleted file mode 100644 index 3992acfe..00000000 --- a/include/YAGE/Math/matrix.h +++ /dev/null @@ -1,424 +0,0 @@ -/* ---------------------------------------------------------------------------- - * matrix.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -/** @file - */ - -#ifndef YAGE_MATH_MATRIX_H -#define YAGE_MATH_MATRIX_H - -#include <algorithm> -#include <exception> -#include <iostream> -#include <sstream> -#include <string> -#include <vector> - -namespace yage -{ - -template <int Rows, int Cols, class Type> -class Matrix; - -/** @internal Namespace for internal details. - * - * Detail Namespace - * ================ - * - * This is the namespace used for implementation detail. - */ -namespace detail -{ - -/** @internal Internal Row class used by the Matrix class to return the - * internal data structure of the Matrix. - * - * Row - * === - * - * Internal Row class to return a value in the row of the matrix. - */ -template <int Rows, int Cols, class Type> -class Row -{ -private: - Matrix<Rows, Cols, Type> *parent_; - int index_; - -public: - Row<Rows, Cols, Type>(Matrix<Rows, Cols, Type> *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]; - } -}; - -} // namespace detail - -/** Base Matrix class used by other similar classes. - */ -template <int Rows = 4, int Cols = 4, class Type = double> -class Matrix -{ - // friended with the row class so that it can access protected member data. - friend class detail::Row<Rows, Cols, Type>; - -protected: - /// Vector containing the data of the matrix. - std::vector<Type> data_; - -public: - /// Initializes the size of the data_ vector. - Matrix<Rows, Cols, Type>() : data_(Rows * Cols) {} - Matrix<Rows, Cols, Type>(const std::vector<Type> &data) : data_(data) {} - - /// Returns the row size of the Matrix. - int rowSize() const { return Rows; } - - /// Returns the column size of the Matrix. - int colSize() const { return Cols; } - - /** Return the row specified row as a Matrix with only one row. - * - * @param row Row number to be returned. - * @return 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; - } - - /** Get a specific column in a column vector. - * - * @param col Column number to be returned. - * @return Column Matrix of the selected column. - */ - Matrix<Rows, 1, Type> getCol(int col) const - { - Matrix<Rows, 1, Type> colMatrix; - for (int i = 0; i < Rows; ++i) { - colMatrix[i][0] = data_[i][col]; - } - return colMatrix; - } - - /** Iterator support for the start. - * - * @return Iterator pointing to the start of the data. - */ - typename std::vector<Type>::iterator begin() { return data_.begin(); } - - /** Iterator support for the end. - * - * @return Iterator pointing to the end of the data. - */ - typename std::vector<Type>::iterator end() { return data_.end(); } - - /** Prints out the matrix, but can also be implemented by other classes to - * print data differently. - * - * @bug When printing certain matrices, it omits a row or column. Still - * need to determine under which conditions. - */ - 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<Rows, Cols, Type> operator[](int row) - { - return detail::Row<Rows, Cols, Type>(this, row); - } - - detail::Row<Rows, Cols, Type> operator[](int row) const - { - return detail::Row<Rows, Cols, Type>((Matrix<Rows, Cols, Type> *)this, - row); - } - - Matrix<Rows, Cols, Type> &operator+=(const Matrix<Rows, Cols, Type> &rhs) - { - std::vector<Type> 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<Rows, Cols, Type> &operator-=(const Matrix<Rows, Cols, Type> &rhs) - { - std::vector<Type> 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 <int M, int N, class T> -Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const Matrix<M, N, T> &rhs) -{ - lhs += rhs; - return lhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const Matrix<M, N, T> &rhs) -{ - lhs -= rhs; - return lhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator+(Matrix<M, N, T> lhs, const T &rhs) -{ - for (auto &data : lhs) { - data += rhs; - } - return lhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator+(const T &lhs, Matrix<M, N, T> rhs) -{ - for (auto &data : rhs) { - data += lhs; - } - return rhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator-(Matrix<M, N, T> lhs, const T &rhs) -{ - for (auto &data : lhs) { - data -= rhs; - } - return lhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator-(const T &lhs, Matrix<M, N, T> rhs) -{ - for (auto &data : rhs) { - data = lhs - data; - } - return rhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator*(Matrix<M, N, T> lhs, const T &rhs) -{ - for (auto &data : lhs) { - data *= rhs; - } - return lhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator*(const T &lhs, Matrix<M, N, T> rhs) -{ - for (auto &data : rhs) { - data *= lhs; - } - return rhs; -} - -template <int M, int N, class T> -Matrix<M, N, T> operator/(Matrix<M, N, T> lhs, const T &rhs) -{ - for (auto &data : lhs) { - data /= rhs; - } - return lhs; -} - -template <int M, int N, class T> -bool operator==(const Matrix<M, N, T> &lhs, const Matrix<M, N, T> &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 <int M, int N, class T> -std::ostream &operator<<(std::ostream &os, const Matrix<M, N, T> &mat) -{ - return os << mat.toString(); -} - -template <int Rows = 2, class Type = double> -class Vector : public Matrix<Rows, 1, Type> -{ -public: - Vector<Rows, Type>() : Matrix<Rows, 1, Type>() {} - Vector<Rows, Type>(const Matrix<Rows, 1, Type> &other) - : Matrix<Rows, 1, Type>(other) - { - } - - Vector<Rows, Type>(const std::vector<Type> &data) - : Matrix<Rows, 1, Type>(data) - { - } - - Type &operator[](int col) { return this->data_[col]; } - - const Type &operator[](int col) const { return this->data_[col]; } - - std::string toString() const override - { - 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 Type = double> -class Vector2 : public Vector<2, Type> -{ -public: - Vector2<Type>() : Vector<2, Type>() {} - Vector2<Type>(const std::vector<Type> &data) : Vector<2, Type>(data) {} - - Vector2<Type>(Type x, Type y) - { - this->data_[0] = x; - this->data_[1] = y; - } - - Vector2<Type>(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. - */ -using Vector2d = Vector2<double>; - -/** Namespace containing functions that operate on matrices. - * - * Implementations defined here are meant to operate on anything that inherits - * from the base Matrix class. - */ -namespace matrix -{ - -/** Transposes a matrix and returns the result - * - * @param m input matrix. - */ -template <int M, int N, class T> -Matrix<N, M, T> transpose(const Matrix<M, N, T> &m) -{ - Matrix<N, M, T> 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 m1,m2 Input matrices. - */ -template <int R, class T> -T dot(const Matrix<R, 1, T> &m1, const Matrix<R, 1, T> &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 m1,m2 Matrix inputs - * - * Requires the two matrices to be compatible with multiplication. - */ -template <int M, int N, int P, int Q, class T> -Matrix<M, Q, T> multiply(const Matrix<M, N, T> &m1, const Matrix<P, Q, T> &m2) -{ - /// @todo Think if this should be a static_assert. - if (N != P) { - throw std::runtime_error( - "Matrices don't have the right dimensions for multiplication"); - } - - Matrix<M, Q, T> res; - - /// Performs multiplication by getting the rows and columns, transposing - /// one of them and then doting the result. - 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; -} - -} // namespace matrix - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/README.org b/include/YAGE/Physics/README.org deleted file mode 100644 index 0620cc93..00000000 --- a/include/YAGE/Physics/README.org +++ /dev/null @@ -1,27 +0,0 @@ -#+ TITLE : README -#+ DATE : <2017 - 04 - 17 Mon> -#+ AUTHOR: -#+ EMAIL : yannherklotz @yann - arch -#+ OPTIONS : ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline -#+ OPTIONS : author : t c : nil creator : comment d : (not"LOGBOOK") date : t -#+ OPTIONS : e : t email : nil f : t inline : t num : t p : nil pri : nil stat : t -#+ OPTIONS : tags : t tasks : t tex : t timestamp : t toc : t todo : t | : t -#+ CREATOR : Emacs 25.1.1(Org mode 8.2.10) -#+ DESCRIPTION: -#+ EXCLUDE_TAGS : noexport -#+ KEYWORDS: -#+ LANGUAGE : en -#+ SELECT_TAGS : export - -*Physics Engine - - **Acceleration, - speed and position - - I have a = dv / dt; -v = dp / dt; - -I am going to use the second order runga kutta method with a = 0, b = 1, - alpha = - 1 / 2 and beta = - 1 / 2 diff --git a/include/YAGE/Physics/body.h b/include/YAGE/Physics/body.h deleted file mode 100644 index bd33a9ac..00000000 --- a/include/YAGE/Physics/body.h +++ /dev/null @@ -1,56 +0,0 @@ -/* ---------------------------------------------------------------------------- - * body.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_BODY_H -#define YAGE_PHYSICS_BODY_H - -#include <YAGE/Math/matrix.h> - -namespace yage -{ -class Body -{ -public: - // 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); - -public: - // 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; - -protected: - // protected constructor to initialize member variables - Body(Vector2d position = Vector2d(0, 0), double mass = 1, - Vector2d velocity = Vector2d(0, 0), bool gravity = false); -}; -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/collider.h b/include/YAGE/Physics/collider.h deleted file mode 100644 index 2fd2ff89..00000000 --- a/include/YAGE/Physics/collider.h +++ /dev/null @@ -1,43 +0,0 @@ -/* ---------------------------------------------------------------------------- - * collider.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_COLLIDER_H -#define YAGE_PHYSICS_COLLIDER_H - -#include <glm/glm.hpp> - -namespace yage -{ - -// The Collider class helps collision detection by providing a general shape -// for different shapes to have their own collision algorithms. -class Collider -{ -protected: - // position of the object - glm::vec2 position_; - - // size of the object - glm::vec2 size_; - -public: - 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 returns if a point is inside the shape - virtual bool inside(const glm::vec2 &point) const = 0; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/collisionbody.h b/include/YAGE/Physics/collisionbody.h deleted file mode 100644 index 715c4a54..00000000 --- a/include/YAGE/Physics/collisionbody.h +++ /dev/null @@ -1,28 +0,0 @@ -/* ---------------------------------------------------------------------------- - * collisionbody.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_COLLISION_BODY_H -#define YAGE_COLLISION_BODY_H - -#include "body.h" - -namespace yage -{ - -// a collision body will be a body that is static and not affected by gravity, -// with infinite mass -class CollisionBody : public Body -{ -public: - CollisionBody(); - virtual ~CollisionBody(); -}; - -} // yage - -#endif diff --git a/include/YAGE/Physics/particlebody.h b/include/YAGE/Physics/particlebody.h deleted file mode 100644 index a0b9bdad..00000000 --- a/include/YAGE/Physics/particlebody.h +++ /dev/null @@ -1,33 +0,0 @@ -/* ---------------------------------------------------------------------------- - * particlebody.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_PARTICLE_BODY_H -#define YAGE_PHYSICS_PARTICLE_BODY_H - -#include "body.h" - -#include <YAGE/Math/matrix.h> - -namespace yage -{ - -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 - void applyForce(const Vector2d &force) override; - void update() override; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/physics.h b/include/YAGE/Physics/physics.h deleted file mode 100644 index 900f4b6a..00000000 --- a/include/YAGE/Physics/physics.h +++ /dev/null @@ -1,19 +0,0 @@ -/* ---------------------------------------------------------------------------- - * physics.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_PHYSICS_H -#define YAGE_PHYSICS_H - -#include "body.h" -#include "collider.h" -#include "collisionbody.h" -#include "particlebody.h" -#include "rectanglecollider.h" -#include "rigidbody.h" - -#endif diff --git a/include/YAGE/Physics/rectanglecollider.h b/include/YAGE/Physics/rectanglecollider.h deleted file mode 100644 index c009f665..00000000 --- a/include/YAGE/Physics/rectanglecollider.h +++ /dev/null @@ -1,30 +0,0 @@ -/* ---------------------------------------------------------------------------- - * rectanglecollider.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_RECTANGLE_COLLIDER_H -#define YAGE_RECTANGLE_COLLIDER_H - -#include "collider.h" - -#include <glm/glm.hpp> - -namespace yage -{ - -class RectangleCollider : public Collider -{ -public: - RectangleCollider(const glm::vec2 &position, const glm::vec2 &size); - - bool collides(const Collider &collider) const override; - bool inside(const glm::vec2 &point) const override; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/Physics/rigidbody.h b/include/YAGE/Physics/rigidbody.h deleted file mode 100644 index 67ccb4ca..00000000 --- a/include/YAGE/Physics/rigidbody.h +++ /dev/null @@ -1,28 +0,0 @@ -/* ---------------------------------------------------------------------------- - * rigidbody.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_RIGID_BODY_H -#define YAGE_RIGID_BODY_H - -#include "particlebody.h" - -#include <glm/glm.hpp> - -namespace yage -{ - -class RigidBody : public ParticleBody -{ -public: - RigidBody(const Vector2d &position = Vector2d(0, 0), double mass = 1, - const Vector2d &velocity = Vector2d(0, 0), bool gravity = true); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/camera2d.h b/include/YAGE/camera2d.h deleted file mode 100644 index a60893ac..00000000 --- a/include/YAGE/camera2d.h +++ /dev/null @@ -1,38 +0,0 @@ -/* ---------------------------------------------------------------------------- - * camera2d.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_CAMERA2D_H -#define YAGE_CAMERA2D_H - -#include "glslprogram.h" - -#include <glm/glm.hpp> -#include <glm/gtc/matrix_transform.hpp> - -namespace yage -{ - -class Camera2D -{ -private: - bool update_matrix_ = 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); - - void update(GlslProgram &program); - void move(const glm::vec2 &direction); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/glslprogram.h b/include/YAGE/glslprogram.h deleted file mode 100644 index fbe5ac5c..00000000 --- a/include/YAGE/glslprogram.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ---------------------------------------------------------------------------- - * glslprogram.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef GLSL_PROGRAM_H -#define GLSL_PROGRAM_H - -#include <GL/glew.h> - -#include <string> - -namespace yage -{ - -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; - - /// compiles one shader - void compileShader(const GLuint &shader, const std::string &file_path); - -public: - GlslProgram() = default; - GlslProgram(const GlslProgram &) = delete; - GlslProgram(GlslProgram &&) = delete; - ~GlslProgram(); - - 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 linkShaders(); - void addAttribute(const std::string &attribute_name); - GLint getUniformLocation(const std::string &uniform_name); - void use(); - void unuse(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/imageloader.h b/include/YAGE/imageloader.h deleted file mode 100644 index 8d5c5cd1..00000000 --- a/include/YAGE/imageloader.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ---------------------------------------------------------------------------- - * imageloader.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef IMAGE_LOADER_H -#define IMAGE_LOADER_H - -#include "texture.h" - -#include <string> - -namespace yage -{ - -class ImageLoader -{ -public: - static Texture loadPng(const std::string &file_path); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/inputmanager.h b/include/YAGE/inputmanager.h deleted file mode 100644 index 84728fff..00000000 --- a/include/YAGE/inputmanager.h +++ /dev/null @@ -1,28 +0,0 @@ -/* ---------------------------------------------------------------------------- - * inputmanager.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef INPUT_MANAGER_H -#define INPUT_MANAGER_H - -#include <unordered_map> - -namespace yage -{ - -class InputManager -{ -private: - std::unordered_map<unsigned, bool> key_map_; - -public: - void keyPressed(unsigned key); - void keyReleased(unsigned key); - bool isKeyPressed(unsigned key) const; -}; -} // namespace yage -#endif diff --git a/include/YAGE/iomanager.h b/include/YAGE/iomanager.h deleted file mode 100644 index 95abd652..00000000 --- a/include/YAGE/iomanager.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ---------------------------------------------------------------------------- - * iomanager.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef IO_MANAGER_H -#define IO_MANAGER_H - -#include <string> -#include <vector> - -namespace yage -{ - -class IoManager -{ -public: - static bool readFileToBuffer(const std::string &file_path, - std::vector<unsigned char> &buffer); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/picopng.h b/include/YAGE/picopng.h deleted file mode 100644 index 095bf68a..00000000 --- a/include/YAGE/picopng.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ---------------------------------------------------------------------------- - * picopng.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#include <cstdlib> -#include <vector> - -namespace yage -{ - -extern int decodePNG(std::vector<unsigned char> &out_image, - unsigned long &image_width, unsigned long &image_height, - const unsigned char *in_png, size_t in_size, - bool convert_to_rgba32 = true); - -} // namespace yage diff --git a/include/YAGE/resourcemanager.h b/include/YAGE/resourcemanager.h deleted file mode 100644 index 3c5081c4..00000000 --- a/include/YAGE/resourcemanager.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ---------------------------------------------------------------------------- - * resourcemanager.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef RESOURCE_MANAGER_H -#define RESOURCE_MANAGER_H - -#include "texture.h" -#include "texturecache.h" - -#include <string> - -namespace yage -{ - -class ResourceManager -{ -private: - static TextureCache texture_cache_; - -public: - static Texture getTexture(const std::string &texture_path); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/sprite.h b/include/YAGE/sprite.h deleted file mode 100644 index 5b9baf91..00000000 --- a/include/YAGE/sprite.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ---------------------------------------------------------------------------- - * sprite.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -/** @file - */ - -#ifndef SPRITE_H -#define SPRITE_H - -#include "texture.h" - -#include <GL/glew.h> - -#include <string> - -namespace yage -{ - -/** @deprecated Use SpriteBatch instead - */ -class Sprite -{ -private: - float x_; - float y_; - float width_; - float height_; - GLuint vbo_id_ = 0; - Texture texture_; - -public: - Sprite(); - Sprite(const Sprite &) = delete; - Sprite(Sprite &&) = delete; - ~Sprite(); - - 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 draw(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/spritebatch.h b/include/YAGE/spritebatch.h deleted file mode 100644 index 7235bd25..00000000 --- a/include/YAGE/spritebatch.h +++ /dev/null @@ -1,105 +0,0 @@ -/* ---------------------------------------------------------------------------- - * spritebatch.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_SPRITE_BATCH_H -#define YAGE_SPRITE_BATCH_H - -#include "vertex.h" - -#include <GL/glew.h> -#include <glm/glm.hpp> - -#include <vector> - -namespace yage -{ - -class SpriteBatch; - -/** Glyph with information of the texture. - */ -class Glyph -{ -private: - GLuint texture_; - float depth_; - Vertex top_left_; - Vertex top_right_; - Vertex bottom_right_; - Vertex bottom_left_; - -public: - 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_; } - Vertex top_left() const { return top_left_; } - Vertex top_right() const { return top_right_; } - Vertex bottom_right() const { return bottom_right_; } - Vertex bottom_left() const { return bottom_left_; } -}; - -class RenderBatch -{ - friend SpriteBatch; - -private: - GLsizei num_vertices_; - GLint offset_; - GLuint texture_; - -public: - RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture); - - GLint offset() const { return offset_; } - GLsizei num_vertices() const { return num_vertices_; } - GLuint texture() const { return texture_; } -}; - -class SpriteBatch -{ -public: - static const int NUM_VERTICES = 6; - -private: - GLuint vbo_ = 0; - GLuint vao_ = 0; - std::vector<Glyph> glyphs_; - std::vector<Glyph *> glyph_ptrs_; - std::vector<RenderBatch> render_batches_; - -public: - SpriteBatch(); - SpriteBatch(const SpriteBatch &) = delete; - SpriteBatch(SpriteBatch &&) = delete; - ~SpriteBatch(); - - 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); - // render the batch - void render(); - -private: - void createVertexArray(); - void createRenderBatches(); - void sortGlyphs(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/spritesheet.h b/include/YAGE/spritesheet.h deleted file mode 100644 index 2b70ad8b..00000000 --- a/include/YAGE/spritesheet.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ---------------------------------------------------------------------------- - * spritesheet.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_SPRITESHEET_H -#define YAGE_SPRITESHEET_H - -#include "texture.h" - -namespace yage -{ - -class SpriteSheet -{ -private: - Texture texture_; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/texture.h b/include/YAGE/texture.h deleted file mode 100644 index d1fdcbf2..00000000 --- a/include/YAGE/texture.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ---------------------------------------------------------------------------- - * texture.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef GL_TEXTURE_H -#define GL_TEXTURE_H - -#include <GL/glew.h> - -namespace yage -{ - -struct Texture { - GLuint id; - int width; - int height; -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/texturecache.h b/include/YAGE/texturecache.h deleted file mode 100644 index 414c9ec3..00000000 --- a/include/YAGE/texturecache.h +++ /dev/null @@ -1,32 +0,0 @@ -/* ---------------------------------------------------------------------------- - * texturecache.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef TEXTURE_CACHE_H -#define TEXTURE_CACHE_H - -#include "texture.h" - -#include <unordered_map> - -namespace yage -{ - -class TextureCache -{ -private: - std::unordered_map<std::string, Texture> texture_map_; - -public: - TextureCache(); - - Texture getTexture(const std::string &texture_path); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/vertex.h b/include/YAGE/vertex.h deleted file mode 100644 index 15b46ed9..00000000 --- a/include/YAGE/vertex.h +++ /dev/null @@ -1,84 +0,0 @@ -/* ---------------------------------------------------------------------------- - * vertex.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef VERTEX_H -#define VERTEX_H - -#include <GL/glew.h> - -namespace yage -{ - -struct Position { - float x; - float y; - - Position() = default; - - Position(float x_, float y_) : x(x_), y(y_) {} -}; - -struct Color { - GLubyte r; - GLubyte g; - GLubyte b; - GLubyte a; - - Color() = default; - - Color(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_) - : r(r_), g(g_), b(b_), a(a_) - { - } -}; - -struct UV { - float u; - float v; - - UV() = default; - - UV(float u_, float v_) : u(u_), v(v_) {} -}; - -struct Vertex { - Position position; - Color color; - UV uv; - - Vertex() = default; - - 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 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; - } -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/window.h b/include/YAGE/window.h deleted file mode 100644 index 8639e075..00000000 --- a/include/YAGE/window.h +++ /dev/null @@ -1,55 +0,0 @@ -/* ---------------------------------------------------------------------------- - * window.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#ifndef WINDOW_H -#define WINDOW_H - -#include <SDL2/SDL.h> - -#include <string> - -namespace yage -{ - -// window flags that can change it's appearance -enum WindowFlags : unsigned { - SHOWN = 0x1, - HIDDEN = 0x2, - FULLSCREEN = 0x4, - BORDERLESS = 0x8, -}; - -// window wrapper around SDL_Window pointer -class Window -{ -private: - /// window handle - SDL_Window *window_ = nullptr; - -public: - Window(); - Window(const Window &) = delete; - Window(Window &&) = delete; - /// destroys the window handle - ~Window(); - - 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); - /// swap the buffer - void swapBuffer(); - /// clear buffer - void clearBuffer(); -}; - -} // namespace yage - -#endif diff --git a/include/YAGE/yage.h b/include/YAGE/yage.h deleted file mode 100644 index 6157e6bf..00000000 --- a/include/YAGE/yage.h +++ /dev/null @@ -1,63 +0,0 @@ -/* ---------------------------------------------------------------------------- - * yage.h - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -/** @file Includes all the headers in the main YAGE project. - * - * This does not include - */ - -#ifndef YAGE_YAGE_H -#define YAGE_YAGE_H - -#include "camera2d.h" -#include "glslprogram.h" -#include "imageloader.h" -#include "inputmanager.h" -#include "iomanager.h" -#include "picopng.h" -#include "resourcemanager.h" -#include "spritebatch.h" -#include "texture.h" -#include "vertex.h" -#include "window.h" - -#include <SDL2/SDL.h> - -#include <stdexcept> - -/** Project namespace. - * - * Avoids collision as all the classes and global functions are wrapped in. - * it. - */ -namespace yage -{ - -/** Initializes YAGE. - * - * This is only there to initialize SDL2. - * - * @return Returns true if the initialization was successful. - */ -bool init() -{ - return SDL_Init(SDL_INIT_VIDEO); -} - -/** Quit and cleanup YAGE - * - * SDL2 needs to clean itself up. - */ -void quit() -{ - SDL_Quit(); -} - -} // namespace yage - -#endif |