From 488c36ba2db7915c4df5e0f4593a0cc83671dd98 Mon Sep 17 00:00:00 2001 From: Six Jonathan Date: Sun, 26 Feb 2023 00:58:02 +0100 Subject: [PATCH 1/2] Fix collision debug mode --- include/Game/Game.hpp | 102 +++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 35 deletions(-) diff --git a/include/Game/Game.hpp b/include/Game/Game.hpp index 3362830..453ec5c 100644 --- a/include/Game/Game.hpp +++ b/include/Game/Game.hpp @@ -12,10 +12,10 @@ #include "Engine/SpriteSheet.hpp" #include "Engine/Texture.hpp" #include "Engine/TimeManager.hpp" +#include "Engine/Updater.hpp" #include "Engine/Utilities.hpp" #include "Engine/Vector2.hpp" #include "Engine/Window.hpp" -#include "Engine/Updater.hpp" #include #include @@ -58,10 +58,10 @@ class Game glfwSetMonitorCallback(setMonitorCallback); datas.monitors.init(); - Vec2i monitorSize = datas.monitors.getMonitorsSize(); + Vec2i monitorSize = datas.monitors.getMonitorsSize(); Vec2i monitorsSizeMM = datas.monitors.getMonitorPhysicalSize(); - datas.windowSize = {1, 1}; + datas.windowSize = {1, 1}; // Evaluate pixel distance based on dpi and monitor size datas.pixelPerMeter = {(float)monitorSize.x / (monitorsSizeMM.x * 0.001f), @@ -121,18 +121,8 @@ class Game createResources(); - Vec2i mainMonitorPosition; - Vec2i mainMonitorSize; - datas.monitors.getMainMonitorWorkingArea(mainMonitorPosition, mainMonitorSize); - - datas.windowPos = mainMonitorPosition + mainMonitorSize / 2; - datas.petPos = datas.windowPos; - glfwSetWindowPos(datas.window, datas.windowPos.x, datas.windowPos.y); - glfwShowWindow(datas.window); - glfwSetWindowUserPointer(datas.window, &datas); - glfwSetMouseButtonCallback(datas.window, mousButtonCallBack); glfwSetCursorPosCallback(datas.window, cursorPositionCallback); @@ -159,8 +149,64 @@ class Game glfwTerminate(); } + void runCollisionDetectionMode() + { + const std::function unlimitedUpdate{[&](double deltaTime) { + // poll for and process events + glfwPollEvents(); + }}; + + int frameCount = 0; + const std::function limitedUpdateDebugCollision{[&](double deltaTime) { + ++frameCount; + + // render + initDrawContext(); + + if (!(frameCount & 1) && datas.pImageGreyScale && datas.pEdgeDetectionTexture && datas.pFullScreenQuad) + { + datas.pImageGreyScale->use(); + datas.pImageGreyScale->setInt("uTexture", 0); + datas.pFullScreenQuad->use(); + datas.pEdgeDetectionTexture->use(); + datas.pFullScreenQuad->draw(); + } + + // swap front and back buffers + glfwSwapBuffers(datas.window); + + if (frameCount & 1) + { + Vec2 newPos; + physicSystem.CatpureScreenCollision(datas.windowSize, newPos); + } + }}; + + // fullscreen + Vec2i monitorSize; + datas.monitors.getMonitorSize(0, monitorSize); + datas.windowSize = monitorSize; + glfwSetWindowSize(datas.window, datas.windowSize.x, datas.windowSize.y); + glfwSetWindowPos(datas.window, 0, 0); + glfwSetWindowAttrib(datas.window, GLFW_MOUSE_PASSTHROUGH, true); + glfwSetWindowAttrib(datas.window, GLFW_TRANSPARENT_FRAMEBUFFER, true); + mainLoop.setFrameRate(1); + + mainLoop.start(); + while (!glfwWindowShouldClose(datas.window)) + { + mainLoop.update(unlimitedUpdate, limitedUpdateDebugCollision); + } + } + void run() { + if (datas.debugEdgeDetection) + { + runCollisionDetectionMode(); + return; + } + Pet pet(datas); const std::function unlimitedUpdate{[&](double deltaTime) { @@ -172,6 +218,7 @@ class Game // poll for and process events glfwPollEvents(); }}; + const std::function limitedUpdate{[&](double deltaTime) { pet.update(deltaTime); @@ -188,27 +235,12 @@ class Game } }}; - const std::function limitedUpdateDebugCollision{[&](double deltaTime) { - // fullscreen - Vec2i monitorSize = datas.monitors.getMonitorsSize(); - datas.windowSize = monitorSize; - glfwSetWindowSize(datas.window, datas.windowSize.x, datas.windowSize.y); - - // render - initDrawContext(); - - if (datas.pImageGreyScale && datas.pEdgeDetectionTexture && datas.pFullScreenQuad) - { - datas.pImageGreyScale->use(); - datas.pImageGreyScale->setInt("uTexture", 0); - datas.pFullScreenQuad->use(); - datas.pEdgeDetectionTexture->use(); - datas.pFullScreenQuad->draw(); - } - - // swap front and back buffers - glfwSwapBuffers(datas.window); - }}; + Vec2i mainMonitorPosition; + Vec2i mainMonitorSize; + datas.monitors.getMainMonitorWorkingArea(mainMonitorPosition, mainMonitorSize); + datas.windowPos = mainMonitorPosition + mainMonitorSize / 2; + datas.petPos = datas.windowPos; + glfwSetWindowPos(datas.window, datas.windowPos.x, datas.windowPos.y); mainLoop.emplaceTimer([&]() { physicSystem.update(1.f / datas.physicFrameRate); }, 1.f / datas.physicFrameRate, true); @@ -216,7 +248,7 @@ class Game mainLoop.start(); while (!glfwWindowShouldClose(datas.window)) { - mainLoop.update(unlimitedUpdate, datas.debugEdgeDetection ? limitedUpdateDebugCollision : limitedUpdate); + mainLoop.update(unlimitedUpdate, limitedUpdate); } } }; \ No newline at end of file From 1e90bdd0bd101bb4daf580857c5f54e94977d95d Mon Sep 17 00:00:00 2001 From: Six Jonathan Date: Sun, 26 Feb 2023 01:15:30 +0100 Subject: [PATCH 2/2] global balancing --- content/setting/animation.yaml | 26 +++++++++++++------------- content/setting/setting.yaml | 16 ++++++++-------- include/Engine/TimeManager.hpp | 5 +++++ include/Game/Pet.hpp | 8 ++++---- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/content/setting/animation.yaml b/content/setting/animation.yaml index 4de3d23..b4b3899 100644 --- a/content/setting/animation.yaml +++ b/content/setting/animation.yaml @@ -12,14 +12,14 @@ Nodes: sprite: idle2.png sizeFactor: 2 tileCount: 14 - framerate: 8 + framerate: 7 loop: true AnimationNode: name: sleep sprite: sleep.png sizeFactor: 2 tileCount: 6 - framerate: 6 + framerate: 4 loop: true GrabNode: name: grab @@ -75,9 +75,9 @@ Transitions: to: grab RandomDelayTransition: from: idle1 - to: [walk, jump, sleep, fly] - duration: 3000 - interval: 1000 + to: [walk, walk, jump, sleep] + duration: 4000 + interval: 2000 IsNotGroundedTransition: from: idle1 to: air @@ -86,8 +86,8 @@ Transitions: to: grab RandomDelayTransition: from: idle2 - to: [walk, jump, sleep, fly] - duration: 3000 + to: [walk, jump, jump, fly] + duration: 2000 interval: 1000 IsNotGroundedTransition: from: idle2 @@ -101,8 +101,8 @@ Transitions: RandomDelayTransition: from: walk to: [idle1, idle2] - duration: 3000 - interval: 500 + duration: 2000 + interval: 1000 TouchScreenEdgeTransition: from: fly to: [idle1, idle2] @@ -112,8 +112,8 @@ Transitions: RandomDelayTransition: from: fly to: [idle1, idle2] - duration: 5000 - interval: 1000 + duration: 6000 + interval: 2000 StartLeftClicTransition: from: jump to: grab @@ -135,5 +135,5 @@ Transitions: RandomDelayTransition: from: sleep to: [idle1, idle2] - duration: 9000 - interval: 1000 \ No newline at end of file + duration: 30000 + interval: 15000 \ No newline at end of file diff --git a/content/setting/setting.yaml b/content/setting/setting.yaml index 4872f38..ae3aa0f 100644 --- a/content/setting/setting.yaml +++ b/content/setting/setting.yaml @@ -7,19 +7,19 @@ Physic: Friction: 0.85 # [0, 1] : 0 no friction, 1 max friction GravityX: 0 GravityY: 9.81 - Bounciness: 0.7 # [0, 1] : 0 no bounciness, 1 full energie restitution + Bounciness: 0.6 # [0, 1] : 0 no bounciness, 1 full energie restitution ContinuousCollisionMaxVelocity: 40 # min 0 - FootBasementWidth: 4 # min 2 + FootBasementWidth: 6 # min 2 FootBasementHeight: 2 # min 2 CollisionPixelRatioStopMovement: 0.3 # min 0, max 1. Ratio of pixel with collision to detect a real collision IsGroundedDetection: 1.0 # min 0 - InputReleaseImpulse: 3.0 # min 0 + InputReleaseImpulse: 1.0 # min 0. Velocity factor after release the pet GamePlay: - CoyoteTimeCursorMovement: 0.1 # min 0 + CoyoteTimeCursorMovement: 0.05 # min 0. Record duration of the velocity before released the pet to preserve velocity with the mouse movement Window: ShowFrameBufferBackground: false - UseForwardWindow: true - ShowWindow: false - UseMousePassThoughWindow: true + UseForwardWindow: true # Define if the application should be displayed in forground + ShowWindow: false # Display the window edge or not + UseMousePassThoughWindow: true # Define if user can selection pet only with selected pixel or with the entire windows Debug: - ShowEdgeDetection: false \ No newline at end of file + ShowEdgeDetection: false # Debug mode to display the result of the collision alogyrthm on the entire window \ No newline at end of file diff --git a/include/Engine/TimeManager.hpp b/include/Engine/TimeManager.hpp index 5cd5c85..7c33a97 100644 --- a/include/Engine/TimeManager.hpp +++ b/include/Engine/TimeManager.hpp @@ -58,6 +58,11 @@ class TimeManager m_timerQueue.emplace(functionToExecute, delay, delay + datas.timeAcc, isLooping); } + void setFrameRate(int FPS) + { + m_fixedDeltaTime = 1. / FPS; + } + void update(std::function unlimitedUpdateFunction, std::function limitedUpdateFunction) { diff --git a/include/Game/Pet.hpp b/include/Game/Pet.hpp index 507732e..b3d3a0a 100644 --- a/include/Game/Pet.hpp +++ b/include/Game/Pet.hpp @@ -117,7 +117,7 @@ class NeedUpdator NeedUpdator(GameData& datas, DialoguePopUp& dialoguePopup, UtilitySystem& utilitySystem) : m_datas{datas}, m_dialoguePopup{dialoguePopup}, m_utilitySystem{utilitySystem} { - nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f; + nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f; } void update(float deltaTime) @@ -131,7 +131,7 @@ class NeedUpdator m_dialoguePopup.display(1.f, EPopupType::Dialogue, ENeed::Angry); displayPopupCurrentTimer = 0; lastNeed = currentNeedIndex; - nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f; + nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f; } else { @@ -140,7 +140,7 @@ class NeedUpdator if (displayPopupCurrentTimer > nexTimeDisplayPopup) { displayPopupCurrentTimer -= nexTimeDisplayPopup; - nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f; + nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f; m_dialoguePopup.display(2.f, EPopupType::Dialogue, ENeed::Angry); } } @@ -152,7 +152,7 @@ class NeedUpdator if (displayPopupCurrentTimer > nexTimeDisplayPopup) { displayPopupCurrentTimer -= nexTimeDisplayPopup; - nexTimeDisplayPopup = randNum(5000, 10000) / 1000.f; + nexTimeDisplayPopup = randNum(10000, 30000) / 1000.f; m_dialoguePopup.display(2.f, EPopupType::Dialogue, ENeed::Love); } }