Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global balancing and fix collision display mode #61

Merged
merged 2 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions content/setting/animation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -112,8 +112,8 @@ Transitions:
RandomDelayTransition:
from: fly
to: [idle1, idle2]
duration: 5000
interval: 1000
duration: 6000
interval: 2000
StartLeftClicTransition:
from: jump
to: grab
Expand All @@ -135,5 +135,5 @@ Transitions:
RandomDelayTransition:
from: sleep
to: [idle1, idle2]
duration: 9000
interval: 1000
duration: 30000
interval: 15000
16 changes: 8 additions & 8 deletions content/setting/setting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
ShowEdgeDetection: false # Debug mode to display the result of the collision alogyrthm on the entire window
5 changes: 5 additions & 0 deletions include/Engine/TimeManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(double deltaTime)> unlimitedUpdateFunction,
std::function<void(double deltaTime)> limitedUpdateFunction)
{
Expand Down
102 changes: 67 additions & 35 deletions include/Game/Game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <GLFW/glfw3.h>
#include <glad/glad.h>
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);

Expand All @@ -159,8 +149,64 @@ class Game
glfwTerminate();
}

void runCollisionDetectionMode()
{
const std::function<void(double)> unlimitedUpdate{[&](double deltaTime) {
// poll for and process events
glfwPollEvents();
}};

int frameCount = 0;
const std::function<void(double)> 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<void(double)> unlimitedUpdate{[&](double deltaTime) {
Expand All @@ -172,6 +218,7 @@ class Game
// poll for and process events
glfwPollEvents();
}};

const std::function<void(double)> limitedUpdate{[&](double deltaTime) {
pet.update(deltaTime);

Expand All @@ -188,35 +235,20 @@ class Game
}
}};

const std::function<void(double)> 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);

mainLoop.start();
while (!glfwWindowShouldClose(datas.window))
{
mainLoop.update(unlimitedUpdate, datas.debugEdgeDetection ? limitedUpdateDebugCollision : limitedUpdate);
mainLoop.update(unlimitedUpdate, limitedUpdate);
}
}
};
8 changes: 4 additions & 4 deletions include/Game/Pet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
{
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down