From 80b7608bf5991f57d84bb78cf4120a8b914b3232 Mon Sep 17 00:00:00 2001 From: Armin Co <armin.co@hs-bochum.de> Date: Sat, 25 Apr 2020 17:09:17 +0200 Subject: [PATCH] QPong core is now in the QPong namespace. All core QPong code is in a namespace now. --- CMakeLists.txt | 10 ++++------ gtk_qpong_app/ParticleImage.cpp | 2 ++ gtk_qpong_app/ParticleImage.hpp | 3 ++- gtk_qpong_app/QWindow.cpp | 2 +- gtk_qpong_app/QWindow.hpp | 4 ++-- qpong_core/CMakeLists.txt | 11 +++-------- qpong_core/Common.hpp | 2 +- qpong_core/ImageBuffer.cpp | 2 ++ qpong_core/ImageBuffer.hpp | 17 +++++++++-------- qpong_core/Particle.cpp | 2 ++ qpong_core/Particle.hpp | 3 +++ qpong_core/Player.cpp | 2 +- qpong_core/Player.hpp | 3 +++ 13 files changed, 35 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acd22c9..8f3c5d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,15 @@ -## CMake file for the Q-Pong game. -## -project(QuantumPong) +# CMake file for the QPong project. +project(QPong) cmake_minimum_required(VERSION 3.2) -## Options +# Options option(create_test "Build all tests." OFF) option(release_type "Set the type of the releas (Debug/Release)." Release) -## Use modern C++! +# Use modern C++! set(CMAKE_CXX_STANDARD 17) -set(CMAKE_BUILD_TYPE Release) ## PkgConfig diff --git a/gtk_qpong_app/ParticleImage.cpp b/gtk_qpong_app/ParticleImage.cpp index 0dde648..e51aa72 100644 --- a/gtk_qpong_app/ParticleImage.cpp +++ b/gtk_qpong_app/ParticleImage.cpp @@ -6,6 +6,8 @@ #include "ParticleImage.hpp" #include "Common.hpp" +using namespace QPong; + constexpr int bytesPerPixel = 3; constexpr int bitsPerSample = 8; diff --git a/gtk_qpong_app/ParticleImage.hpp b/gtk_qpong_app/ParticleImage.hpp index 5e48185..8d8ab97 100644 --- a/gtk_qpong_app/ParticleImage.hpp +++ b/gtk_qpong_app/ParticleImage.hpp @@ -13,10 +13,11 @@ #include "ImageBuffer.hpp" + /// @brief Wraps an one dimensional array. /// Values can be accessed as in 2D. /// -class ParticleImage : public ImageBuffer +class ParticleImage : public QPong::ImageBuffer { public: ParticleImage(); diff --git a/gtk_qpong_app/QWindow.cpp b/gtk_qpong_app/QWindow.cpp index 2943cbe..16d7a97 100644 --- a/gtk_qpong_app/QWindow.cpp +++ b/gtk_qpong_app/QWindow.cpp @@ -4,7 +4,7 @@ #include "QWindow.hpp" -// #include "Profiler.hpp" +using namespace QPong; bool propagating = true; int propRate = 0; diff --git a/gtk_qpong_app/QWindow.hpp b/gtk_qpong_app/QWindow.hpp index f9c3133..b9a610d 100644 --- a/gtk_qpong_app/QWindow.hpp +++ b/gtk_qpong_app/QWindow.hpp @@ -72,13 +72,13 @@ private: QDrawingArea m_positionArea; QDrawingArea m_momentumArea; - Particle *m_particle; + QPong::Particle *m_particle; std::thread m_propagatingThread; ParticleImage *m_momentum; ParticleImage *m_position; ParticleImage *m_obstacle; - std::map<Player::Id, std::shared_ptr<Player>> m_players; + std::map<QPong::Player::Id, std::shared_ptr<QPong::Player>> m_players; }; #endif \ No newline at end of file diff --git a/qpong_core/CMakeLists.txt b/qpong_core/CMakeLists.txt index 4c14ed2..b6f2974 100644 --- a/qpong_core/CMakeLists.txt +++ b/qpong_core/CMakeLists.txt @@ -1,12 +1,7 @@ +# Add macOS specific include path. if(APPLE) include_directories(/usr/local/include) endif() -## library for the app should be GTK independent -## -add_library( - qpong_core - Particle.cpp - ImageBuffer.cpp - Player.cpp -) +# Core QPong library +add_library(qpong_core Particle.cpp ImageBuffer.cpp Player.cpp) \ No newline at end of file diff --git a/qpong_core/Common.hpp b/qpong_core/Common.hpp index 61b8638..095bddf 100644 --- a/qpong_core/Common.hpp +++ b/qpong_core/Common.hpp @@ -17,7 +17,6 @@ constexpr unsigned arraySize = arrayWidth * arrayHeight; static_assert(arraySize % numberOfThreads == 0, "Number of threads and array size doesn't match!"); -} /// @brief Calc square of a number. /// @@ -27,4 +26,5 @@ const T sqr(const T n) return n * n; } +} #endif \ No newline at end of file diff --git a/qpong_core/ImageBuffer.cpp b/qpong_core/ImageBuffer.cpp index f4c5288..b4a524b 100644 --- a/qpong_core/ImageBuffer.cpp +++ b/qpong_core/ImageBuffer.cpp @@ -5,6 +5,8 @@ #include "Common.hpp" #include "ImageBuffer.hpp" +using namespace QPong; + ImageBuffer::ImageBuffer() { m_potbuf = new double[QPong::arraySize]; diff --git a/qpong_core/ImageBuffer.hpp b/qpong_core/ImageBuffer.hpp index fcbb81e..d7b58e9 100644 --- a/qpong_core/ImageBuffer.hpp +++ b/qpong_core/ImageBuffer.hpp @@ -9,16 +9,18 @@ #include <complex> +namespace QPong +{ + /// @brief Convinient conatiner to store a RGB value. /// {r, g, b} struct QColor { - float r = 0; - float g = 0; - float b = 0; + float r = 0.0f; + float g = 0.0f; + float b = 0.0f; }; - /// @brief Class ImageBuffer /// class ImageBuffer @@ -28,23 +30,22 @@ public: /// ImageBuffer(); - /// @brief Update the buffer at the given position. /// @param index Index of the value that should be changed. /// @param v The value as a complex number which will be interpreted as a color. /// @param pot Potential at position. - /// + /// void updateAt(unsigned index, std::complex<double> v, double pot); - /// @return Get color value from particle at array index. /// const QColor getValue(unsigned index); - private: double *m_potbuf; std::complex<double> *m_complexBuffer; }; +} // namespace QPong + #endif diff --git a/qpong_core/Particle.cpp b/qpong_core/Particle.cpp index a019f41..9e714e2 100644 --- a/qpong_core/Particle.cpp +++ b/qpong_core/Particle.cpp @@ -12,6 +12,8 @@ #include "Common.hpp" #include "Particle.hpp" +using namespace QPong; + /// @brief Planck constant. /// constexpr double hbar = 0.0002; diff --git a/qpong_core/Particle.hpp b/qpong_core/Particle.hpp index 3af6f5a..0477612 100644 --- a/qpong_core/Particle.hpp +++ b/qpong_core/Particle.hpp @@ -17,6 +17,7 @@ #include "ImageBuffer.hpp" #include "Player.hpp" +namespace QPong { class Particle { @@ -87,4 +88,6 @@ private: Particle() = delete; }; +} // namespace QPong + #endif \ No newline at end of file diff --git a/qpong_core/Player.cpp b/qpong_core/Player.cpp index 5076bc2..31db213 100644 --- a/qpong_core/Player.cpp +++ b/qpong_core/Player.cpp @@ -7,6 +7,7 @@ #include <mutex> #include "Player.hpp" +using namespace QPong; constexpr double speedStepSize = 0.0005; @@ -16,7 +17,6 @@ Player::Player(Player::Id pl, Player::Position pos) , m_x {pos.x} , m_y {pos.y} { - } diff --git a/qpong_core/Player.hpp b/qpong_core/Player.hpp index dcc7e8f..7154bc9 100644 --- a/qpong_core/Player.hpp +++ b/qpong_core/Player.hpp @@ -8,6 +8,7 @@ #ifndef QPONG_QPLAYER_HPP #define QPONG_QPLAYER_HPP +namespace QPong { /// @brief Class wraps all values of one Player. /// @@ -52,4 +53,6 @@ private: double m_score = 0; }; +} // namespace QPong + #endif \ No newline at end of file -- GitLab