From ddd26ed83d3ac0335562f762ced273a1d62bd959 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 23 Dec 2017 01:37:09 +0000 Subject: [Style] Updated style in files. --- tests/active/test.cpp | 2 +- tests/log/test.cpp | 2 +- tests/matrix/test.cpp | 2 +- tests/particlebody/test.cpp | 4 ++-- tests/spritesheet/test.cpp | 2 +- tests/struct/test.cpp | 2 +- tests/syncqueue/test.cpp | 2 +- tests/thread/test.cpp | 2 +- tests/vector3/test.cpp | 10 +++++----- tests/vector4/test.cpp | 10 +++++----- tests/window/test.cpp | 2 +- tests/yage/test.cpp | 2 +- yage/core/camera.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++ yage/core/camera.h | 37 +++++++++++++++++++++++++++++++++++ yage/core/camera2d.cpp | 46 -------------------------------------------- yage/core/camera2d.h | 38 ------------------------------------ yage/core/glslprogram.h | 10 +++++----- yage/core/input.h | 8 ++++++++ yage/core/inputmanager.cpp | 33 ------------------------------- yage/core/inputmanager.h | 30 ----------------------------- yage/core/logger.cpp | 2 +- yage/core/logsink.cpp | 4 ++-- yage/core/logsink.h | 2 +- yage/core/sprite.cpp | 8 ++++---- yage/core/sprite.h | 4 ++-- yage/core/spritebatch.h | 2 +- yage/core/spritesheet.cpp | 2 +- yage/core/window.h | 6 +++--- yage/physics/body.h | 2 +- yage/physics/particlebody.h | 2 +- yage/util/syncqueue.h | 2 +- yage/yage.h | 4 ++-- 32 files changed, 138 insertions(+), 193 deletions(-) create mode 100644 yage/core/camera.cpp create mode 100644 yage/core/camera.h delete mode 100644 yage/core/camera2d.cpp delete mode 100644 yage/core/camera2d.h delete mode 100644 yage/core/inputmanager.cpp delete mode 100644 yage/core/inputmanager.h diff --git a/tests/active/test.cpp b/tests/active/test.cpp index 3d561283..d907a1cc 100644 --- a/tests/active/test.cpp +++ b/tests/active/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: activetest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/log/test.cpp b/tests/log/test.cpp index e1010754..53c2894b 100644 --- a/tests/log/test.cpp +++ b/tests/log/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: logtest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/matrix/test.cpp b/tests/matrix/test.cpp index 1e316502..022775af 100644 --- a/tests/matrix/test.cpp +++ b/tests/matrix/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: matrixtest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/particlebody/test.cpp b/tests/particlebody/test.cpp index 09277826..65c26d5d 100644 --- a/tests/particlebody/test.cpp +++ b/tests/particlebody/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: particlebodytest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -26,7 +26,7 @@ double gravityAcceleration(int iterations) TEST(ParticleBody, Gravity) { - int randomItr = rand() % 10; + int randomItr = rand() % 10; double idealPosition = 0.5 * -9.81 * std::pow(randomItr, 2); ASSERT_GE(idealPosition * 0.95, gravityAcceleration(randomItr)); diff --git a/tests/spritesheet/test.cpp b/tests/spritesheet/test.cpp index fcfc842c..4d4cc1a4 100644 --- a/tests/spritesheet/test.cpp +++ b/tests/spritesheet/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: spritesheettest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/struct/test.cpp b/tests/struct/test.cpp index 99752abb..0288f06b 100644 --- a/tests/struct/test.cpp +++ b/tests/struct/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: structtest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/syncqueue/test.cpp b/tests/syncqueue/test.cpp index 1d7d8037..f5c7d7c3 100644 --- a/tests/syncqueue/test.cpp +++ b/tests/syncqueue/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: syncqueuetest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/thread/test.cpp b/tests/thread/test.cpp index 0527665a..c9178abd 100644 --- a/tests/thread/test.cpp +++ b/tests/thread/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: threadtest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/vector3/test.cpp b/tests/vector3/test.cpp index 570a5c10..e65d29f1 100644 --- a/tests/vector3/test.cpp +++ b/tests/vector3/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: vector3test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -7,7 +7,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector3test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -15,7 +15,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector3test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -23,7 +23,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector3test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -31,7 +31,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector3test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/vector4/test.cpp b/tests/vector4/test.cpp index 53554a25..6ef5462d 100644 --- a/tests/vector4/test.cpp +++ b/tests/vector4/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: vector4test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -7,7 +7,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector4test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -15,7 +15,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector4test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -23,7 +23,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector4test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. @@ -31,7 +31,7 @@ */ /** --------------------------------------------------------------------------- - * @file: vector4test.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/window/test.cpp b/tests/window/test.cpp index 40b7e664..d9402d49 100644 --- a/tests/window/test.cpp +++ b/tests/window/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: windowtest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/tests/yage/test.cpp b/tests/yage/test.cpp index a599eba2..8129306b 100644 --- a/tests/yage/test.cpp +++ b/tests/yage/test.cpp @@ -1,5 +1,5 @@ /** --------------------------------------------------------------------------- - * @file: yagetest.cpp + * @file: test.cpp * * Copyright (c) 2017 Yann Herklotz Grave * MIT License, see LICENSE file for more details. diff --git a/yage/core/camera.cpp b/yage/core/camera.cpp new file mode 100644 index 00000000..71938cbb --- /dev/null +++ b/yage/core/camera.cpp @@ -0,0 +1,47 @@ +/** --------------------------------------------------------------------------- + * @file: camera.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include "camera.h" +#include "glslprogram.h" + +#include +#include + +namespace yage +{ + +Camera::Camera(int screen_width, int screen_height) + : position_(0.f, 0.f), camera_matrix_(1.f), + ortho_matrix_( + glm::ortho(0.f, (float)screen_width, 0.f, (float)screen_height)) +{ +} + +void Camera::update(GlslProgram &program) +{ + if (update_matrix_) { + glm::vec3 translate(-position_.x, -position_.y, 0.f); + glm::vec3 scale(scale_, scale_, 0.f); + + camera_matrix_ = glm::translate(ortho_matrix_, translate); + camera_matrix_ = glm::scale(glm::mat4(1.f), scale) * camera_matrix_; + + update_matrix_ = false; + } + + GLint matrix_location = program.getUniformLocation("P"); + glUniformMatrix4fv(matrix_location, 1, GL_FALSE, &(camera_matrix_[0][0])); +} + +void Camera::move(const glm::vec2 &direction) +{ + position_ += direction; + update_matrix_ = true; +} + +} // namespace yage diff --git a/yage/core/camera.h b/yage/core/camera.h new file mode 100644 index 00000000..8ebe5d2a --- /dev/null +++ b/yage/core/camera.h @@ -0,0 +1,37 @@ +/** --------------------------------------------------------------------------- + * @file: camera.h + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#ifndef YAGE_CAMERA2D_H +#define YAGE_CAMERA2D_H + +#include + +namespace yage +{ + +class GlslProgram; + +class Camera +{ +private: + bool update_matrix_ = true; + float scale_ = 1; + glm::vec2 position_; + glm::mat4 camera_matrix_; + glm::mat4 ortho_matrix_; + +public: + Camera(int screen_width = 1280, int screen_height = 720); + + void update(GlslProgram &program); + void move(const glm::vec2 &direction); +}; + +} // namespace yage + +#endif diff --git a/yage/core/camera2d.cpp b/yage/core/camera2d.cpp deleted file mode 100644 index 463dd0d2..00000000 --- a/yage/core/camera2d.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: camera2d.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include "camera2d.h" -#include "glslprogram.h" - -#include - -namespace yage -{ - -Camera::Camera(int screen_width, int screen_height) - : position_(0.f, 0.f), camera_matrix_(1.f), - ortho_matrix_( - glm::ortho(0.f, (float)screen_width, 0.f, (float)screen_height)) -{ -} - -void Camera::update(GlslProgram &program) -{ - if (update_matrix_) { - glm::vec3 translate(-position_.x, -position_.y, 0.f); - glm::vec3 scale(scale_, scale_, 0.f); - - camera_matrix_ = glm::translate(ortho_matrix_, translate); - camera_matrix_ = glm::scale(glm::mat4(1.f), scale) * camera_matrix_; - - update_matrix_ = false; - } - - GLint matrix_location = program.getUniformLocation("P"); - glUniformMatrix4fv(matrix_location, 1, GL_FALSE, &(camera_matrix_[0][0])); -} - -void Camera::move(const glm::vec2 &direction) -{ - position_ += direction; - update_matrix_ = true; -} - -} // namespace yage diff --git a/yage/core/camera2d.h b/yage/core/camera2d.h deleted file mode 100644 index 109333d6..00000000 --- a/yage/core/camera2d.h +++ /dev/null @@ -1,38 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: camera2d.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef YAGE_CAMERA2D_H -#define YAGE_CAMERA2D_H - -#include -#include - -namespace yage -{ - -class GlslProgram; - -class Camera -{ -private: - bool update_matrix_ = true; - float scale_ = 1; - glm::vec2 position_; - glm::mat4 camera_matrix_; - glm::mat4 ortho_matrix_; - -public: - Camera(int screen_width = 1280, int screen_height = 720); - - void update(GlslProgram &program); - void move(const glm::vec2 &direction); -}; - -} // namespace yage - -#endif diff --git a/yage/core/glslprogram.h b/yage/core/glslprogram.h index 9e49d329..0617bc1e 100644 --- a/yage/core/glslprogram.h +++ b/yage/core/glslprogram.h @@ -19,9 +19,9 @@ namespace yage class GlslProgram { public: - GlslProgram() = default; + GlslProgram() = default; GlslProgram(const GlslProgram &) = delete; - GlslProgram(GlslProgram &&) = delete; + GlslProgram(GlslProgram &&) = delete; ~GlslProgram(); GlslProgram &operator=(const GlslProgram &) = delete; @@ -42,10 +42,10 @@ public: private: /// compiled shader program id - GLuint program_id_ = 0; - GLuint vertex_shader_id_ = 0; + GLuint program_id_ = 0; + GLuint vertex_shader_id_ = 0; GLuint fragment_shader_id_ = 0; - int attribute_index_ = 0; + int attribute_index_ = 0; /// compiles one shader void compileShader(GLuint shader, const std::string &shaderContent); diff --git a/yage/core/input.h b/yage/core/input.h index 3882e11c..125f4296 100644 --- a/yage/core/input.h +++ b/yage/core/input.h @@ -1,3 +1,11 @@ +/** --------------------------------------------------------------------------- + * @file: input.h + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + #ifndef YAGE_CORE_INPUT_H #define YAGE_CORE_INPUT_H diff --git a/yage/core/inputmanager.cpp b/yage/core/inputmanager.cpp deleted file mode 100644 index 1f324b9e..00000000 --- a/yage/core/inputmanager.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: inputmanager.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#include - -namespace yage -{ - -void InputManager::keyPressed(unsigned key) -{ - key_map_[key] = true; -} - -void InputManager::keyReleased(unsigned key) -{ - key_map_[key] = false; -} - -bool InputManager::isKeyPressed(unsigned key) const -{ - auto key_index = key_map_.find(key); - if (key_index != key_map_.end()) { - return key_index->second; - } - return false; -} - -} // namespace yage diff --git a/yage/core/inputmanager.h b/yage/core/inputmanager.h deleted file mode 100644 index e8dd153a..00000000 --- a/yage/core/inputmanager.h +++ /dev/null @@ -1,30 +0,0 @@ -/** --------------------------------------------------------------------------- - * @file: inputmanager.h - * - * Copyright (c) 2017 Yann Herklotz Grave - * MIT License, see LICENSE file for more details. - * ---------------------------------------------------------------------------- - */ - -#ifndef INPUT_MANAGER_H -#define INPUT_MANAGER_H - -#include - -namespace yage -{ - -class InputManager -{ -private: - std::unordered_map key_map_; - -public: - void keyPressed(unsigned key); - void keyReleased(unsigned key); - bool isKeyPressed(unsigned key) const; -}; - -} // namespace yage - -#endif diff --git a/yage/core/logger.cpp b/yage/core/logger.cpp index 4690fadc..f661e826 100644 --- a/yage/core/logger.cpp +++ b/yage/core/logger.cpp @@ -35,7 +35,7 @@ void Logger::flush(const LogMessage *msg) std::string asString(msg->buffer_.str()); auto &&sinks = sinks_; - auto &&meta = msg->meta_; + auto &&meta = msg->meta_; active_->send([=] { for (auto &&sink : sinks) { diff --git a/yage/core/logsink.cpp b/yage/core/logsink.cpp index 36d7038b..6680c773 100644 --- a/yage/core/logsink.cpp +++ b/yage/core/logsink.cpp @@ -78,8 +78,8 @@ public: { using namespace std::chrono; - auto now = system_clock::now(); - auto time_t = system_clock::to_time_t(now); + auto now = system_clock::now(); + auto time_t = system_clock::to_time_t(now); auto local_time = std::localtime(&time_t); (*fileHandle_) << std::put_time(local_time, "[%H:%M:%S] ") << msg diff --git a/yage/core/logsink.h b/yage/core/logsink.h index 63f95655..16812b16 100644 --- a/yage/core/logsink.h +++ b/yage/core/logsink.h @@ -39,7 +39,7 @@ private: struct Concept { virtual ~Concept() = default; - virtual Concept *clone() const = 0; + virtual Concept *clone() const = 0; virtual void write(const LogMessage::Meta &meta, const std::string &msg) const = 0; }; diff --git a/yage/core/sprite.cpp b/yage/core/sprite.cpp index a663c379..6862f910 100644 --- a/yage/core/sprite.cpp +++ b/yage/core/sprite.cpp @@ -25,10 +25,10 @@ Sprite::~Sprite() void Sprite::init(float x, float y, float width, float height, const std::string &texture_path) { - x_ = x; - y_ = y; - width_ = width; - height_ = height; + x_ = x; + y_ = y; + width_ = width; + height_ = height; texture_ = ResourceManager::getTexture(texture_path); if (vbo_id_ == 0) { diff --git a/yage/core/sprite.h b/yage/core/sprite.h index 35997195..852f4f28 100644 --- a/yage/core/sprite.h +++ b/yage/core/sprite.h @@ -31,9 +31,9 @@ private: Texture texture_; public: - Sprite() = default; + Sprite() = default; Sprite(const Sprite &) = delete; - Sprite(Sprite &&) = delete; + Sprite(Sprite &&) = delete; ~Sprite(); Sprite &operator=(const Sprite &) = delete; diff --git a/yage/core/spritebatch.h b/yage/core/spritebatch.h index fa93c5cb..c16b44f6 100644 --- a/yage/core/spritebatch.h +++ b/yage/core/spritebatch.h @@ -82,7 +82,7 @@ private: public: SpriteBatch(); SpriteBatch(const SpriteBatch &) = delete; - SpriteBatch(SpriteBatch &&) = delete; + SpriteBatch(SpriteBatch &&) = delete; ~SpriteBatch(); SpriteBatch &operator=(const SpriteBatch &) = delete; diff --git a/yage/core/spritesheet.cpp b/yage/core/spritesheet.cpp index 7fbd19e9..4ecdcf71 100644 --- a/yage/core/spritesheet.cpp +++ b/yage/core/spritesheet.cpp @@ -55,7 +55,7 @@ SpriteMap SpriteSheet::parseJson(int &width, int &height, Document jsonAtlas; jsonAtlas.Parse(jsonContent.c_str()); - width = jsonAtlas["width"].GetInt(); + width = jsonAtlas["width"].GetInt(); height = jsonAtlas["height"].GetInt(); for (auto &texture : jsonAtlas["sprites"].GetObject()) { diff --git a/yage/core/window.h b/yage/core/window.h index c350955e..5c16c172 100644 --- a/yage/core/window.h +++ b/yage/core/window.h @@ -23,8 +23,8 @@ namespace yage // window flags that can change it's appearance enum WindowFlags : unsigned { - SHOWN = 0x1, - HIDDEN = 0x2, + SHOWN = 0x1, + HIDDEN = 0x2, FULLSCREEN = 0x4, BORDERLESS = 0x8, }; @@ -39,7 +39,7 @@ private: public: Window(); Window(const Window &) = delete; - Window(Window &&) = delete; + Window(Window &&) = delete; /// destroys the window handle ~Window(); diff --git a/yage/physics/body.h b/yage/physics/body.h index 0a6bbe42..62173987 100644 --- a/yage/physics/body.h +++ b/yage/physics/body.h @@ -42,7 +42,7 @@ protected: public: // apply force to the object and update the velocity virtual void applyForce(const Vector2d &force) = 0; - virtual void update() = 0; + virtual void update() = 0; double xPosition() const; double yPosition() const; diff --git a/yage/physics/particlebody.h b/yage/physics/particlebody.h index 3978da77..d4380695 100644 --- a/yage/physics/particlebody.h +++ b/yage/physics/particlebody.h @@ -20,7 +20,7 @@ class ParticleBody : public Body public: ParticleBody(const Vector2d &position = Vector2d(0, 0), double mass = 1, const Vector2d &velocity = Vector2d(0, 0), - bool gravity = true); + bool gravity = true); // apply a force to the rigid body void applyForce(const Vector2d &force) override; diff --git a/yage/util/syncqueue.h b/yage/util/syncqueue.h index f1c7d65d..7b5e5680 100644 --- a/yage/util/syncqueue.h +++ b/yage/util/syncqueue.h @@ -20,7 +20,7 @@ template class SyncQueue { public: - SyncQueue() = default; + SyncQueue() = default; SyncQueue(const SyncQueue &) = delete; SyncQueue &operator=(const SyncQueue &) = delete; diff --git a/yage/yage.h b/yage/yage.h index 3e8ac47b..de6864eb 100644 --- a/yage/yage.h +++ b/yage/yage.h @@ -9,10 +9,10 @@ #ifndef YAGE_YAGE_H #define YAGE_YAGE_H -#include "core/camera2d.h" +#include "core/camera.h" #include "core/glslprogram.h" #include "core/imageloader.h" -#include "core/inputmanager.h" +#include "core/input.h" #include "core/iomanager.h" #include "core/logger.h" #include "core/logmessage.h" -- cgit