diff --git a/App/GameLayer.cpp b/App/GameLayer.cpp index d6b7e6b22f659c35ab652baf1e6a3c5a1717173a..0fd7b14b3433d8653d8fc99b8b6999acaf2fd39e 100644 --- a/App/GameLayer.cpp +++ b/App/GameLayer.cpp @@ -28,26 +28,52 @@ constexpr QPong::Particle::Properties initialParticleSettings = { .sharpness = 64.0, .startValue = 0.01, .hbar = 0.000125, - .threads = 8, - .game = true + .threads = 8 }; constexpr QPong::Particle::GameOptions initialOptions = { .potentialsEnabled = true, .absorbtionEnabled = true, - .momentumEnabled = false + .momentumEnabled = false, + .game = true }; +constexpr int pointsPerPosition { 3 }; +constexpr int indicesPerQuad { 6 }; // two triangles + QPong::GameLayer::GameLayer(int resolution, int threads) :Layer("GameLayer") - , m_arraySize{resolution} + , m_properties {initialParticleSettings} + , m_options{initialOptions} + , m_particle {nullptr} , m_leftBat(-0.8, 0.0, Key::W, Key::S) , m_rightBat(0.8, 0.0, Key::Up, Key::Down) - , m_propagate{false} - , m_options{initialOptions} - , m_properties {initialParticleSettings} - , m_speedScale{5.0f} + , m_playerOne() + , m_playerTwo() + , m_arraySize{resolution} + , m_numberOfQuads {(m_arraySize - 1) * (m_arraySize - 1)} + , m_numberOfIndices {m_numberOfQuads * indicesPerQuad} + , m_memorySize {0} + , m_shader {nullptr} + , m_vertexArray {0} + , m_pointsBuffer {0} + , m_indicesBuffer {0} + , m_colorBuffer {0} + , m_potentialBuffer {0} + , m_particleViewPositions {nullptr} + , m_momentumViewPositions {nullptr} + , m_staticBorderPotential {nullptr} + , m_dynamicPotential {nullptr} + , m_isMomentumEnabled {0} + , m_viewProjectionLocation {0} + , m_showPotentialsLocation {0} + , m_viewProjectionPosition() + , m_gameCounts {true} + , m_restart {false} + , m_propagate {false} , m_randomMomentum {true} + , m_speedScale{5.0f} + , m_openGlTimer {0.0} , m_gaming {true} { srand(time(nullptr)); @@ -56,10 +82,6 @@ QPong::GameLayer::GameLayer(int resolution, int threads) m_properties.threads = threads; m_memorySize = sizeof(fftw_complex) * m_properties.elements(); - constexpr int indicesPerQuad { 6 }; // two triangles - m_numberOfQuads = (m_arraySize - 1) * (m_arraySize - 1); - m_numberOfIndices = m_numberOfQuads * indicesPerQuad; - m_staticBorderPotential = new float[m_properties.elements()]; m_dynamicPotential = new float[m_properties.elements()]; m_particle = std::make_unique<Particle>( @@ -82,7 +104,6 @@ void QPong::GameLayer::onAttach() fragmentShaderPath); // static verticie positions - constexpr int pointsPerPosition { 3 }; m_particleViewPositions = new float[m_properties.elements() * pointsPerPosition]; calculatePointPositions(m_particleViewPositions, m_arraySize); @@ -113,7 +134,7 @@ void QPong::GameLayer::onAttach() glVertexAttribPointer(1, 2, GL_DOUBLE, GL_FALSE, sizeof(fftw_complex), 0); // Setup momentum view - m_momentumViewPositions = new float[m_properties.elements() * 3]; + m_momentumViewPositions = new float[m_properties.elements() * pointsPerPosition]; calculateMomentumViewPositions(m_momentumViewPositions, m_arraySize); glGenBuffers(1, &m_potentialBuffer); @@ -161,6 +182,9 @@ void QPong::GameLayer::reset() m_properties.momentum.y = (1.0f - (2.0f * positive)) * (1.0 + static_cast<float>(yRand) / 120.0f); } m_options.game = m_gaming; + m_options.absorbtionEnabled = m_gaming; + m_options.momentumEnabled = !m_gaming; + m_particle.reset(new Particle( m_properties, m_options, @@ -173,7 +197,8 @@ void QPong::GameLayer::reset() m_restart = false; m_gameCounts = true; - m_particle->update(0.0); + constexpr double veryLittleInitialStep(0.00025); + m_particle->update(veryLittleInitialStep); } void QPong::GameLayer::onUpdate(GuiCore::Timestep ts) @@ -210,7 +235,7 @@ void QPong::GameLayer::onUpdate(GuiCore::Timestep ts) GuiCore::Timer openGlTimer{"", false}; // Particle glBindBuffer(GL_ARRAY_BUFFER, m_pointsBuffer); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * m_properties.elements() * 3, m_particleViewPositions); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * m_properties.elements() * pointsPerPosition, m_particleViewPositions); glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer); glBufferSubData(GL_ARRAY_BUFFER, 0, m_memorySize, m_particle->getPsi()); @@ -229,7 +254,7 @@ void QPong::GameLayer::onUpdate(GuiCore::Timestep ts) if (m_options.momentumEnabled) { glBindBuffer(GL_ARRAY_BUFFER, m_pointsBuffer); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * m_properties.elements() * 3, m_momentumViewPositions); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * m_properties.elements() * pointsPerPosition, m_momentumViewPositions); glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer); glBufferSubData(GL_ARRAY_BUFFER, 0, m_memorySize, m_particle->getMomentum()); @@ -305,17 +330,17 @@ void QPong::GameLayer::onGuiRender() } ImGui::Text("Player 1: %d", m_playerOne.getTotalScore()); ImGui::SameLine(); - ImGui::Text(" | Live Score: %.1f\%%", m_playerOne.getCurrentGameScore()); + ImGui::Text(" | Live Score: %.1f%%", m_playerOne.getCurrentGameScore()); ImGui::Text("Player 2: %d", m_playerTwo.getTotalScore()); ImGui::SameLine(); - ImGui::Text(" | Live Score: %.1f\%%", m_playerTwo.getCurrentGameScore()); + ImGui::Text(" | Live Score: %.1f%%", m_playerTwo.getCurrentGameScore()); ImGui::Spacing(); ImGui::Text("FFT took %0.1lfms", m_particle->getTimeFFT()); ImGui::Text("OpenGL took %.1lfms", m_openGlTimer); - if (ImGui::Checkbox("Gaming", &m_gaming)) + if (ImGui::Checkbox("Toggle Gaming | Simulation", &m_gaming)) { m_propagate = false; m_randomMomentum = false; diff --git a/App/GameLayer.hpp b/App/GameLayer.hpp index a7d3ada33e60b4065ff1e4ea61643537a1838f34..e94e4f5f42970edd330cdc22077461f4cfd1ca6c 100644 --- a/App/GameLayer.hpp +++ b/App/GameLayer.hpp @@ -68,7 +68,7 @@ namespace QPong bool m_restart; bool m_propagate; bool m_randomMomentum; - float m_speedScale{1.0f}; + float m_speedScale; double m_openGlTimer; bool m_gaming; diff --git a/App/Window.cpp b/App/Window.cpp index fd8cadee923f9d42bcc414f7c482bb9f96206bb9..6435ae53cc9af22a69a626b1f56cab29dfdd1d5a 100644 --- a/App/Window.cpp +++ b/App/Window.cpp @@ -14,8 +14,6 @@ static bool s_GLFW_Initialized = false; static void GLFWErrorCallback(int error, const char *description) { - /// @todo add GuiCore::Logger - // GuiCore::Log::get()->error("{}", error); GuiCore::Log::get()->error("{}", description); } @@ -44,7 +42,7 @@ void Window::setup(const GuiCore::WindowProperties &properties) if (!s_GLFW_Initialized) { glfwSetErrorCallback(GLFWErrorCallback); - auto success = glfwInit(); + glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); diff --git a/CMakeLists.txt b/CMakeLists.txt index 90cce88c76b6426275311d5cd28ce11b3f2278a2..4dbc4b4e2d365b7f4dfe34e8b7d0686491fbb7f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,7 @@ project(QPong VERSION 0.0.1 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_BUILD_TYPE Release) -list(APPEND basic_flags "-O3" "-Wextra" "-Wall" "-Wshadow" "-Wold-style-cast") -list(APPEND basic_flags "-Wno-unused-variable") -list(APPEND pedantic_flags "-pedantic" "-Wpedantic") +list(APPEND basic_flags "-O3" "-Wextra" "-Wall" "-Wshadow" "-Wold-style-cast" "-pedantic" "-Wpedantic") option(LOG_DEBUG_INFO "Enable logging t console" OFF) if(LOG_DEBUG_INFO) diff --git a/GuiCore/Application.cpp b/GuiCore/Application.cpp index 816300ee00c6d9fc10610ca4b497ca3211fe2872..7d2e73782aef8b0afdfc8d30a329ad474ea139af 100644 --- a/GuiCore/Application.cpp +++ b/GuiCore/Application.cpp @@ -91,7 +91,7 @@ namespace GuiCore } } - bool Application::onWindowClose(Event &event) + bool Application::onWindowClose([[maybe_unused]] Event &event) { m_isRunnig = false; return true; diff --git a/GuiCore/ImGuiLayer.cpp b/GuiCore/ImGuiLayer.cpp index 63c044e9957b7ec791c308186ee7fca7570c51fe..ac94a7cb7560b6c5e19c62e22da27364bb7c5295 100644 --- a/GuiCore/ImGuiLayer.cpp +++ b/GuiCore/ImGuiLayer.cpp @@ -28,13 +28,8 @@ void ImGuiLayer::onAttach() GuiCore::Log::get()->trace("onAttach ImGuiLayer"); IMGUI_CHECKVERSION(); ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - - ImGui::StyleColorsDark(); - Application& app = Application::get(); - GLFWwindow *window = static_cast<GLFWwindow*>(app.getWindow().getNativeWindow()); ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 330"); @@ -67,12 +62,7 @@ void ImGuiLayer::end() ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } -void ImGuiLayer::onEvent(Event &event) +void ImGuiLayer::onEvent([[maybe_unused]] Event &event) { } - -bool ImGuiLayer::onMouseButtonPressed([[maybe_unused]] Event &event) -{ - return false; -} diff --git a/GuiCore/ImGuiLayer.hpp b/GuiCore/ImGuiLayer.hpp index 1156f8a23c81309dfc33f4ff9f36e6b3acaaf6e3..3b6ed72b91af604cfaff74ac5a406af36143b6ca 100644 --- a/GuiCore/ImGuiLayer.hpp +++ b/GuiCore/ImGuiLayer.hpp @@ -24,7 +24,6 @@ namespace GuiCore void end(); virtual void onEvent(Event &event); - bool onMouseButtonPressed(Event &event); private: float m_time = 0.0f; diff --git a/QPong/Bat.cpp b/QPong/Bat.cpp index 4d46d7f96ffc3e561a2a80ad756f84525ea40ef0..da160c7ac4a46f129b6291b694bb382a9c77d54a 100644 --- a/QPong/Bat.cpp +++ b/QPong/Bat.cpp @@ -87,4 +87,14 @@ double QPong::Bat::getPotential(double x, double y) const double QPong::Bat::getX() const { return m_x; +} + +void QPong::Bat::moveToStartingPosition() +{ + m_y = 0.0; +} + +void QPong::Bat::moveAway() +{ + m_y = 1.5; } \ No newline at end of file diff --git a/QPong/Bat.hpp b/QPong/Bat.hpp index 9ab01a2be9d0a4bbdb4b9e02b44388b5118f6254..5616b0a49930bbef810c5bc5e8ff8598b6ec7567 100644 --- a/QPong/Bat.hpp +++ b/QPong/Bat.hpp @@ -17,6 +17,8 @@ namespace QPong double getY() const; void onUpdate(GuiCore::Timestep ts); double getPotential(double x, double y) const; + void moveToStartingPosition(); + void moveAway(); private: double m_x; double m_y; diff --git a/QPong/Particle.cpp b/QPong/Particle.cpp index ae1f9ee40faa675488c99e15941679ab7c237bde..51c22d2d378f4a81d5b208f39d96481b2803565d 100644 --- a/QPong/Particle.cpp +++ b/QPong/Particle.cpp @@ -78,11 +78,15 @@ Particle::Particle(Properties properties, GameOptions &options, Player &playerOn if (options.game == true) { calculateBorderPotential(m_staticBorders, m_yAt, m_properties.elements()); + m_leftBat.moveToStartingPosition(); + m_rightBat.moveToStartingPosition(); } else { // "Simulation" calculateGaussBox(m_staticBorders, m_xAt, m_yAt, m_properties.elements()); + m_leftBat.moveAway(); + m_rightBat.moveAway(); } fftw_init_threads();