From 56b5466f014d9f7c3662544713bd53670cd8e32f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 23 Aug 2017 20:33:34 +0100 Subject: Applied modernize rules and fixed build. Applied clang-tidy modernize rules and fixed the CMakeLists.txt file so that it also linked against the SDL2 library. --- CMakeLists.txt | 8 ++++---- README.md | 19 +++++++++++++++---- include/YAGE/Physics/body.hpp | 2 +- src/body.cpp | 8 +++++--- src/glslprogram.cpp | 2 +- src/picopng.cpp | 16 ++++++++-------- src/sprite.cpp | 4 ++-- src/spritebatch.cpp | 2 +- src/texturecache.cpp | 2 +- src/window.cpp | 2 +- 10 files changed, 39 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f084702c..b92ec79a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,16 +67,16 @@ endif() # find libraries find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) +include(FindPkgConfig) +pkg_search_module(SDL2 REQUIRED sdl2) # set include directory -include_directories(${YAGE_INCLUDE_DIR} - ${YAGE_INCLUDE_DIR}/Physics/ - ${YAGE_INCLUDE_DIR}/Math/) +include_directories(${YAGE_INCLUDE_DIR}) # make it a static library add_library(${PROJECT_NAME} ${YAGE_SOURCES}) -set(YAGE_LIB_DEP_L "yage;${OPENGL_LIBRARIES};${GLEW_LIBRARIES};${SDL2_LIBRAIRES}") +set(YAGE_LIB_DEP_L "yage;${OPENGL_LIBRARIES};${GLEW_LIBRARIES};${SDL2_LIBRARIES}") message("${YAGE_LIB_DEP_L}") diff --git a/README.md b/README.md index 17176786..96a0ad70 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,25 @@ YAGE ==== -YAGE stands for Yet Another Game Engine. It is a game engine that I am developing for a game called [Arider](https://github.com/ymherklotz/Arider). +Introduction +------------ -YAGE uses OpenGL and SDL2 for the window creation and management and graphics. +YAGE stands for Yet Another Game Engine. It is a game engine that I am +developing for a game called [Arider](https://github.com/ymherklotz/Arider). +It uses OpenGL and SDL2 for the window creation and management and graphics. -Installation and Usage +Installation and usage ---------------------- -To compile YAGE, create a build directory from the base directory. Then call cmake and point it to the directory containing [CMakeLists.txt](/CMakeLists.txt). +To use YAGE for your own game, you should link it as a static library and +include the [yage.hpp](/include/YAGE/yage.hpp) header in your project. + +Build and Testing +----------------- + +To compile YAGE, create a build directory from the base directory. Then call +cmake and point it to the directory containing. +[CMakeLists.txt](/CMakeLists.txt). ``` shell mkdir build diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp index fab28fc1..efeedb64 100644 --- a/include/YAGE/Physics/body.hpp +++ b/include/YAGE/Physics/body.hpp @@ -46,7 +46,7 @@ public: 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); + Body(Vector2d position = Vector2d(0, 0), double mass = 1, Vector2d velocity = Vector2d(0, 0), bool gravity = false); }; } // namespace yage diff --git a/src/body.cpp b/src/body.cpp index a17f6ee3..9c8babf1 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -6,6 +6,8 @@ * ---------------------------------------------------------------------------- */ +#include + #include "Physics/body.hpp" namespace yage { @@ -16,11 +18,11 @@ double Body::xPosition() const { return position_[0]; } double Body::yPosition() const { return position_[1]; } -Body::Body(const Vector2d& position, double mass, const Vector2d& velocity, +Body::Body(Vector2d position, double mass, Vector2d velocity, bool gravity) - : position_(position), + : position_(std::move(position)), mass_(mass), - velocity_(velocity), + velocity_(std::move(velocity)), gravity_(gravity) {} } // yage diff --git a/src/glslprogram.cpp b/src/glslprogram.cpp index a5f95ad5..6d0a60b2 100644 --- a/src/glslprogram.cpp +++ b/src/glslprogram.cpp @@ -38,7 +38,7 @@ void GlslProgram::compileShader(const GLuint& shader, // cast source to a c string to get the address of it and input it for // compilation - const GLchar* vertex_source = (const GLchar*)content.c_str(); + const auto* vertex_source = (const GLchar*)content.c_str(); glShaderSource(shader, 1, &vertex_source, nullptr); glCompileShader(shader); diff --git a/src/picopng.cpp b/src/picopng.cpp index 6fe9c1f7..f75390de 100644 --- a/src/picopng.cpp +++ b/src/picopng.cpp @@ -466,7 +466,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, void decode(std::vector& out, const unsigned char* in, size_t size, bool convert_to_rgba32) { error = 0; - if (size == 0 || in == 0) { + if (size == 0 || in == nullptr) { error = 48; return; } // the given data is empty @@ -543,7 +543,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, return; } // error: this chunk must be 2 bytes for greyscale // image - info.key_defined = 1; + info.key_defined = true; info.key_r = info.key_g = info.key_b = 256 * in[pos] + in[pos + 1]; pos += 2; @@ -552,7 +552,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, error = 41; return; } // error: this chunk must be 6 bytes for RGB image - info.key_defined = 1; + info.key_defined = true; info.key_r = 256 * in[pos] + in[pos + 1]; pos += 2; info.key_g = 256 * in[pos] + in[pos + 1]; @@ -590,7 +590,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, outlength = (info.height * info.width * bpp + 7) / 8; out.resize(outlength); // time to fill the out buffer unsigned char* out_ = - outlength ? &out[0] : 0; // use a regular pointer to the + outlength ? &out[0] : nullptr; // use a regular pointer to the // std::vector for faster code if // compiled without optimization if (info.interlaceMethod == 0) // no interlace, just filter @@ -603,7 +603,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, for (unsigned long y = 0; y < info.height; y++) { unsigned long filterType = scanlines[linestart]; const unsigned char* prevline = - (y == 0) ? 0 + (y == 0) ? nullptr : &out_[(y - 1) * info.width * bytewidth]; unFilterScanline(&out_[linestart - y], &scanlines[linestart + 1], prevline, @@ -619,7 +619,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, for (size_t y = 0, obp = 0; y < info.height; y++) { unsigned long filterType = scanlines[linestart]; const unsigned char* prevline = - (y == 0) ? 0 + (y == 0) ? nullptr : &out_[(y - 1) * info.width * bytewidth]; unFilterScanline(&templine[0], &scanlines[linestart + 1], prevline, @@ -788,7 +788,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, linelength = 1 + ((bpp * passw + 7) / 8); for (unsigned long y = 0; y < passh; y++) { unsigned char filterType = in[y * linelength], - *prevline = (y == 0) ? 0 : lineo; + *prevline = (y == 0) ? nullptr : lineo; unFilterScanline(linen, &in[y * linelength + 1], prevline, bytewidth, filterType, (w * bpp + 7) / 8); if (error) return; @@ -876,7 +876,7 @@ int decodePNG(std::vector& out_image, unsigned long& image_width, out.resize(numpixels * 4); unsigned char* out_ = out.empty() - ? 0 + ? nullptr : &out[0]; // faster if compiled without optimization if (infoIn.bitDepth == 8 && infoIn.colorType == 0) // greyscale for (size_t i = 0; i < numpixels; i++) { diff --git a/src/sprite.cpp b/src/sprite.cpp index e3d74982..4cdd2ecf 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -14,7 +14,7 @@ namespace yage { -Sprite::Sprite() {} +Sprite::Sprite() = default; Sprite::~Sprite() { if (vbo_id_ != 0) glDeleteBuffers(1, &vbo_id_); @@ -50,7 +50,7 @@ void Sprite::init(float x, float y, float width, float height, vertex_data[5].setPosition(x + width, y); vertex_data[5].setUv(1.f, 0.f); - for (int i = 0; i < 6; ++i) vertex_data[i].setColor(255, 0, 255, 255); + for (auto & i : vertex_data) i.setColor(255, 0, 255, 255); vertex_data[1].setColor(0, 255, 255, 255); vertex_data[4].setColor(255, 0, 0, 255); diff --git a/src/spritebatch.cpp b/src/spritebatch.cpp index 8e64aa5e..f4767829 100644 --- a/src/spritebatch.cpp +++ b/src/spritebatch.cpp @@ -28,7 +28,7 @@ Glyph::Glyph(GLuint texture, float depth, const Vertex& top_left, RenderBatch::RenderBatch(GLint offset, GLsizei num_vertices, GLuint texture) : num_vertices_(num_vertices), offset_(offset), texture_(texture) {} -SpriteBatch::SpriteBatch() {} +SpriteBatch::SpriteBatch() = default; SpriteBatch::~SpriteBatch() { if (vao_ != 0) glDeleteVertexArrays(1, &vao_); diff --git a/src/texturecache.cpp b/src/texturecache.cpp index 6d10b209..09ac2639 100644 --- a/src/texturecache.cpp +++ b/src/texturecache.cpp @@ -13,7 +13,7 @@ namespace yage { TextureCache::TextureCache() -{} += default; Texture TextureCache::getTexture(const std::string &texture_path) { diff --git a/src/window.cpp b/src/window.cpp index 7a00b0c9..959cacb3 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -15,7 +15,7 @@ namespace yage { -Window::Window() {} +Window::Window() = default; Window::~Window() { SDL_DestroyWindow(window_); } -- cgit