diff --git a/App/CMakeLists.txt b/App/CMakeLists.txt index e42fbe0db72cfc1f2543dc806bce673688f0c96f..af3f7e2a1ca26c20a83e22ece6224d9f231c8260 100644 --- a/App/CMakeLists.txt +++ b/App/CMakeLists.txt @@ -5,7 +5,6 @@ add_executable( QPongGame MainMenuLayer.cpp QPongApp.cpp Window.cpp - Utils.cpp ) target_include_directories( QPong PUBLIC diff --git a/App/GameLayer.cpp b/App/GameLayer.cpp index a01442d7fa0322000d5a420a05a7152c56b767db..c7a867724c27550b602a2eff5fc5e088e7913209 100644 --- a/App/GameLayer.cpp +++ b/App/GameLayer.cpp @@ -17,7 +17,7 @@ #include "GameLayer.hpp" #include "Log.hpp" -#include "Utils.hpp" +#include <QPong/Utils.hpp> #include <string> #include <thread> @@ -50,6 +50,7 @@ QPong::GameLayer::GameLayer(int resolution, int threads) , m_properties {initialParticleSettings} , m_speedScale{5.0f} , m_randomMomentum {true} + , m_gaming {true} { m_properties.size = resolution; m_properties.threads = threads; @@ -122,7 +123,6 @@ void QPong::GameLayer::onAttach() m_viewProjectionLocation = glGetUniformLocation(m_shader->getRendererID(), "u_viewProjection"); m_showPotentialsLocation = glGetUniformLocation(m_shader->getRendererID(), "u_showPotential"); m_isMomentumEnabled = glGetUniformLocation(m_shader->getRendererID(), "u_isMomentumEnabled"); - reset(); } @@ -154,6 +154,7 @@ void QPong::GameLayer::reset() positive = rand() % 2; m_properties.momentum.y = (1.0f - (2.0f * positive)) * (1.0 + (float)yRand / 120.0f); } + m_options.game = m_gaming; m_particle.reset(new Particle(m_properties, m_options, m_playerOne, m_playerTwo, m_leftBat, m_rightBat, m_staticBorderPotential, m_dynamicPotential)); m_restart = false; @@ -225,9 +226,12 @@ void QPong::GameLayer::onUpdate(GuiCore::Timestep ts) glDrawElements(GL_TRIANGLES, m_numberOfIndices, GL_UNSIGNED_INT, nullptr); } m_openGlTimer = openGlTimer.stop(); - std::stringstream totalScore; - totalScore << m_playerOne.getTotalScore() << " : " << m_playerTwo.getTotalScore(); - GuiCore::Glyphs::renderText(totalScore.str(), -0.32f, 1.45f, 0.0075f, {1.0, 1.0, 1.0}); + if (m_gaming) + { + std::stringstream totalScore; + totalScore << m_playerOne.getTotalScore() << " : " << m_playerTwo.getTotalScore(); + GuiCore::Glyphs::renderText(totalScore.str(), -0.32f, 1.45f, 0.0075f, {1.0, 1.0, 1.0}); + } } void QPong::GameLayer::onGuiRender() @@ -235,6 +239,8 @@ void QPong::GameLayer::onGuiRender() // GUI settings for the particle ImGui::Begin("Particle Settings"); + ImGui::DragFloat2("Start Position", glm::value_ptr(m_properties.position), 0.01f, -1.0f, 1.0f); + // Select initial momentum for particle at restart ImGui::DragFloat2("Momentum [x,y]", glm::value_ptr(m_properties.momentum), 0.01f, -3.0f, 3.0f); ImGui::Checkbox("Random Momentum", &m_randomMomentum); @@ -294,5 +300,14 @@ void QPong::GameLayer::onGuiRender() ImGui::Text("FFT took %0.1lfms", m_particle->getTimeFFT()); ImGui::Text("OpenGL took %.1lfms", m_openGlTimer); + if (ImGui::Checkbox("Gaming", &m_gaming)) + { + m_propagate = false; + m_randomMomentum = false; + m_options.absorbtionEnabled = false; + m_options.momentumEnabled = true; + m_restart = true; + } + ImGui::End(); } \ No newline at end of file diff --git a/App/GameLayer.hpp b/App/GameLayer.hpp index d92521f35a11a240f3ba0c4e722cdd2e00063fab..a7d3ada33e60b4065ff1e4ea61643537a1838f34 100644 --- a/App/GameLayer.hpp +++ b/App/GameLayer.hpp @@ -71,6 +71,7 @@ namespace QPong float m_speedScale{1.0f}; double m_openGlTimer; + bool m_gaming; }; } #endif \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 80f22469d91e52ede093515e988ceec899e21b95..1112d31a038de22782cbf28942d7de72405b18fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(QPong VERSION 0.0.1 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_BUILD_TYPE Release) -set(CMAKE_CXX_FLAGS "-Ofast -flto") +set(CMAKE_CXX_FLAGS "-Ofast") option(LOG_DEBUG_INFO "Enable logging t console" OFF) if(LOG_DEBUG_INFO) diff --git a/QPong/CMakeLists.txt b/QPong/CMakeLists.txt index 2dcd81edf0d6b1b99203f2d30345ed73644f7419..eb417d3768a8c3e2b542fc28dbf8b55155cc42e3 100644 --- a/QPong/CMakeLists.txt +++ b/QPong/CMakeLists.txt @@ -2,6 +2,7 @@ add_library(QPong Bat.cpp Particle.cpp Workers.cpp + Utils.cpp ) target_include_directories(QPong PUBLIC diff --git a/QPong/Particle.cpp b/QPong/Particle.cpp index ccf96e18ef9f022114ec2439bef7954ee1ad72ce..71bb4a3823826b55dd8218d972e94f8663a89823 100644 --- a/QPong/Particle.cpp +++ b/QPong/Particle.cpp @@ -30,7 +30,7 @@ double QPong::yAtIndex(int i, int arraySize) return posAt(i / arraySize, arraySize); } -double QPong::potentialAt(int pos, int arraySize, double hbar) +double QPong::potentialAt(int pos, const int arraySize, const double hbar) { if (pos > arraySize / 2) { @@ -76,7 +76,16 @@ Particle::Particle(Properties properties, GameOptions &options, Player &playerOn m_psi = static_cast<std::complex<double> *>(fftw_malloc(memorySize)); m_momentum = static_cast<std::complex<double> *>(fftw_malloc(memorySize)); initialiseParticleMomentum(); - calculateBorderPotential(m_staticBorders, m_yAt, m_properties.elements()); + + if (options.game == true) + { + calculateBorderPotential(m_staticBorders, m_yAt, m_properties.elements()); + } + else + { + // "Simulation" + calculateSchroedingerPotential(m_staticBorders, m_xAt, m_yAt, m_properties.elements()); + } fftw_init_threads(); fftw_plan_with_nthreads(m_properties.threads); diff --git a/QPong/Particle.hpp b/QPong/Particle.hpp index f5340eaf7e4df6c7588fa25f3304cd46d30b3d7a..9c7c8c806b00512375fbccad5cd0e3ff453b36bd 100644 --- a/QPong/Particle.hpp +++ b/QPong/Particle.hpp @@ -45,6 +45,7 @@ namespace QPong bool potentialsEnabled; bool absorbtionEnabled; bool momentumEnabled; + bool game; }; Particle(Properties properties, GameOptions &options, Player &m_playerOne, Player &m_playerTwo ,Bat &leftBat, Bat &rightBat, float *staticBorders, float *dynamicPotential); diff --git a/App/Utils.cpp b/QPong/Utils.cpp similarity index 91% rename from App/Utils.cpp rename to QPong/Utils.cpp index 139ad7ae5e49f4e1e4a1bd7293fb41ff28d02fee..2586bcff21c4d71cc0db050ff3a09c3a7119e313 100644 --- a/App/Utils.cpp +++ b/QPong/Utils.cpp @@ -3,6 +3,7 @@ /// #include "Utils.hpp" +#include <cmath> void calculatePointPositions(float *positions, int arraySize) { @@ -82,4 +83,12 @@ void calculateBorderPotential(float *potential, double *yAt, int arrayElements) float pot = pow2(y) * pow2(y) * pow2(y) * pow2(y) * pow2(y) * pow2(y) * pow2(y) * 0.02; potential[i] = pot; } +} + +void calculateSchroedingerPotential(float *potential, double *xAt, double *yAt, int arrayElements) +{ + for (int i {0}; i < arrayElements; ++i) + { + potential[i] = ( pow2(pow2(xAt[i]) + pow2(yAt[i])) ) / 200.0; + } } \ No newline at end of file diff --git a/App/Utils.hpp b/QPong/Utils.hpp similarity index 82% rename from App/Utils.hpp rename to QPong/Utils.hpp index 93767da92f9c60adc80fc07cca81fe667128db1d..35a069ce4f549f47e38bde6b0e2a2b28db017b56 100644 --- a/App/Utils.hpp +++ b/QPong/Utils.hpp @@ -17,5 +17,6 @@ void calculatePointPositions(float *points, int arraySize); void calculateMomentumViewPositions(float *points, int arraySize); void calculateTriangleIndices(uint32_t *indices, int arraySize); void calculateBorderPotential(float *potential, double *yAt, int arrayElements); +void calculateSchroedingerPotential(float *potential, double *xAt, double *yAt, int arrayElements); #endif \ No newline at end of file