From e0f3266926f10ca157e986deed1ca353bc7e5a36 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sat, 6 Jan 2024 19:21:20 +0700 Subject: [PATCH 001/126] refactor(gameplayscene): revamp drawcombo logic --- Game/src/Scenes/GameplayScene.cpp | 45 +++++++++++-------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index cde9b389..7ac70f57 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -220,37 +220,30 @@ void GameplayScene::Render(double delta) } if (m_drawCombo && std::get<7>(scores) > 0) { - m_amplitude = 30.0; - m_wiggleTime = 60 * m_comboTimer; + const double amplitudeStart = 30.0; // Constants + const double decrement = 1.0; + const double animationSpeed = 60.0; - double decrement = 6.0; // Calculate the decrement for each frame - double totalDecrement = decrement * m_wiggleTime; // Calculate the total decrement based on the current frame/time - - double currentAmplitude = m_amplitude - totalDecrement; // Adjust the amplitude based on the total decrement - - if (currentAmplitude < 0.0) { - currentAmplitude = 0.0; // Stopper like this due compiler issues - } - - if (m_comboTimer > 1.0) { // Check if the previous animation hasn't finished - m_comboTimer = 0.0; // Reset the timer - m_amplitude += decrement; // Increase the starting amplitude for the next animation + if (m_comboTimer >= 1.0) { // Animation finished, reset parameters for the next animation + m_comboTimer = 0.0; + m_amplitude = amplitudeStart; + m_drawCombo = false; } + else { + double targetAmplitude = amplitudeStart - decrement * m_comboTimer * animationSpeed * 6; + double currentAmplitude = (targetAmplitude > 0.0) ? targetAmplitude : 0.0; - m_comboLogo->Position2 = UDim2::fromOffset(0, currentAmplitude / 3.0); - m_comboLogo->Draw(delta); + m_comboLogo->Position2 = UDim2::fromOffset(0, currentAmplitude / 3.0); // Update position based on amplitude + m_comboNum->Position2 = UDim2::fromOffset(0, currentAmplitude); - m_comboNum->Position2 = UDim2::fromOffset(0, currentAmplitude); - m_comboNum->DrawNumber(std::get<7>(scores)); + m_comboLogo->Draw(delta); + m_comboNum->DrawNumber(std::get<7>(scores)); - m_comboTimer += delta; - if (m_comboTimer > 1.0) { - m_comboTimer = 0.0; - m_drawCombo = false; + m_comboTimer += delta; } } - if (m_drawLN && std::get<9>(scores) > 0) { // Same Animation logic like DrawCombo + if (m_drawLN && std::get<9>(scores) > 0) { // Same Animation logic like DrawCombo m_amplitude = 5.0; m_wiggleTime = 60 * m_lnTimer; @@ -263,11 +256,6 @@ void GameplayScene::Render(double delta) currentAmplitude = 0.0; } - if (m_lnTimer > 1.0) { - m_lnTimer = 0.0; - m_amplitude += decrement; - } - m_lnLogo->Position2 = UDim2::fromOffset(0, currentAmplitude); m_lnLogo->Draw(delta); @@ -279,7 +267,6 @@ void GameplayScene::Render(double delta) if (m_lnTimer > 1.0) { m_lnTimer = 0.0; m_drawLN = false; - m_lnLogo->Reset(); } } From c343bed0083545c5f0b3433eea97966b749f6642 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:36:08 +0700 Subject: [PATCH 002/126] fix(game): fix thread synchronization, removed sdl_delay --- Engine/include/Game.h | 3 +++ Engine/src/Game.cpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Engine/include/Game.h b/Engine/include/Game.h index 4c259f58..7a74cfb1 100644 --- a/Engine/include/Game.h +++ b/Engine/include/Game.h @@ -87,4 +87,7 @@ class Game GameThread mRenderThread; GameThread mAudioThread; GameThread mLocalThread; + + std::mutex m_mutex; + std::condition_variable m_conditionVariable; }; \ No newline at end of file diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index 8194d65a..71c80fff 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -79,18 +79,19 @@ Game::~Game() if (m_running) { Stop(); - // Wait for threads to finish - // TODO: Figure a way to do this without using sleep - while (m_notify) { - SDL_Delay(500); + // Properly wait for threads to finish using synchronization, get rid SDL_Delay since it's not good + if (m_notify) { + std::unique_lock lock(m_mutex); + m_conditionVariable.wait(lock, [this] { return !m_notify; }); } } - SceneManager::Release(); - AudioManager::Release(); - InputManager::Release(); - Renderer::Release(); + // Release resources in reverse order of initialization GameWindow::Release(); + Renderer::Release(); + InputManager::Release(); + AudioManager::Release(); + SceneManager::Release(); DeInitSDL(); } From 12c53a48fcfcaa11babb149fd8cdc9e2b941c63f Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 9 Jan 2024 22:44:35 +0700 Subject: [PATCH 003/126] fix(game): forgot to implement stop() notify --- Engine/src/Game.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index 71c80fff..5b3e90c3 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -368,7 +368,16 @@ void Game::CheckFont() void Game::Stop() { - m_running = false; + if (m_running) { + m_running = false; + + // Notify condition variable to indicate that the threads should finish + { + std::lock_guard lock(m_mutex); + m_notify = false; + } + m_conditionVariable.notify_all(); + } } void Game::SetThreadMode(ThreadMode mode) From 4deb60eedaa4d1799f3081d195214c403042fd36 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 9 Jan 2024 22:52:39 +0700 Subject: [PATCH 004/126] Updated Game.cpp --- Engine/src/Game.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index 5b3e90c3..8c6bc4ec 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -86,12 +86,11 @@ Game::~Game() } } - // Release resources in reverse order of initialization - GameWindow::Release(); - Renderer::Release(); InputManager::Release(); AudioManager::Release(); SceneManager::Release(); + Renderer::Release(); + GameWindow::Release(); DeInitSDL(); } @@ -376,7 +375,7 @@ void Game::Stop() std::lock_guard lock(m_mutex); m_notify = false; } - m_conditionVariable.notify_all(); + m_conditionVariable.notify_one(); } } From 209aca834fb5d6d312f876ba8e36a1f16520e145 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Thu, 11 Jan 2024 18:43:04 +0700 Subject: [PATCH 005/126] fix(game): condition variable has false wake-ups --- Engine/src/Game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index 8c6bc4ec..cbbcb45d 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -79,7 +79,7 @@ Game::~Game() if (m_running) { Stop(); - // Properly wait for threads to finish using synchronization, get rid SDL_Delay since it's not good + // Properly wait for threads to finish using synchronization, get rid of SDL_Delay since it's not good if (m_notify) { std::unique_lock lock(m_mutex); m_conditionVariable.wait(lock, [this] { return !m_notify; }); @@ -373,7 +373,7 @@ void Game::Stop() // Notify condition variable to indicate that the threads should finish { std::lock_guard lock(m_mutex); - m_notify = false; + m_notify = true; // This should be true } m_conditionVariable.notify_one(); } From a25d8dd8c14d3dda146060fd2c6a63faaf262829 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:29:58 +0700 Subject: [PATCH 006/126] Update Game.cpp --- Engine/src/Game.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index cbbcb45d..0b64773c 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -86,9 +86,9 @@ Game::~Game() } } - InputManager::Release(); - AudioManager::Release(); SceneManager::Release(); + AudioManager::Release(); + InputManager::Release(); Renderer::Release(); GameWindow::Release(); From 5c06e19827659523d846537cc3fdc3e6abd692dc Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:46:52 +0700 Subject: [PATCH 007/126] feat: fix chart logger, improve combo animation --- Engine/src/Game.cpp | 4 ++-- Game/src/Data/Chart.cpp | 4 ++-- Game/src/Scenes/GameplayScene.cpp | 33 ++++++++++++++++++++----------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index cbbcb45d..cd55a0b3 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -79,7 +79,7 @@ Game::~Game() if (m_running) { Stop(); - // Properly wait for threads to finish using synchronization, get rid of SDL_Delay since it's not good + // Properly wait for threads to finish using synchronization if (m_notify) { std::unique_lock lock(m_mutex); m_conditionVariable.wait(lock, [this] { return !m_notify; }); @@ -372,7 +372,7 @@ void Game::Stop() // Notify condition variable to indicate that the threads should finish { - std::lock_guard lock(m_mutex); + std::lock_guard lock(m_mutex); // TODO: Fix game does not properly exit while crash (if not just revert back to SDL_Delay Sleep) m_notify = true; // This should be true } m_conditionVariable.notify_one(); diff --git a/Game/src/Data/Chart.cpp b/Game/src/Data/Chart.cpp index 2f98fd57..74970e28 100644 --- a/Game/src/Data/Chart.cpp +++ b/Game/src/Data/Chart.cpp @@ -223,7 +223,7 @@ Chart::Chart(BMS::BMSFile &file) // check if overlap lastTime if (info.StartTime < lastTime[info.LaneIndex]) { - Logs::Puts("[Chart] overlapped note found at %.2f ms and conflict with %.2f ms", info.StartTime, lastTime[info.LaneIndex]); + Logs::Puts("[Chart] Overlapped note found on file %d at %.2f ms and conflict with %.2f ms", m_beatmapDirectory, info.StartTime, lastTime[info.LaneIndex]); if (note.SampleIndex != -1) { AutoSample sm = {}; @@ -341,7 +341,7 @@ Chart::Chart(O2::OJN &file, int diffIndex) // check if overlap lastTime if (info.StartTime < lastTime[info.LaneIndex]) { - Logs::Puts("[Chart] overlapped note found at %.2f ms and conflict with %.2f ms", info.StartTime, lastTime[info.LaneIndex]); + Logs::Puts("[Chart] Overlapped note found on FileID: o2ma%d on %.2f ms and conflict with %.2f ms", O2JamId, info.StartTime, lastTime[info.LaneIndex]); if (note.SampleRefId != -1) { AutoSample sm = {}; diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 7ac70f57..9c9a7053 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -35,6 +35,10 @@ struct MissInfo float time; }; +double lerp(double a, double b, double t) { + return a + t * (b - a); +} + bool CheckSkinComponent(std::filesystem::path x) { return std::filesystem::exists(x); @@ -178,16 +182,16 @@ void GameplayScene::Render(double delta) curLifeTex->CalculateSize(); Rect rc = {}; - rc.left = (int)curLifeTex->AbsolutePosition.X; - rc.top = (int)curLifeTex->AbsolutePosition.Y; - rc.right = rc.left + (int)curLifeTex->AbsoluteSize.X; - rc.bottom = rc.top + (int)curLifeTex->AbsoluteSize.Y + 5; // Need to add + value because wiggle effect =w= + rc.left = static_cast(curLifeTex->AbsolutePosition.X); + rc.top = static_cast(curLifeTex->AbsolutePosition.Y); + rc.right = static_cast(rc.left + curLifeTex->AbsoluteSize.X); + rc.bottom = static_cast(rc.top + curLifeTex->AbsoluteSize.Y + 10); // Add + value because of the wiggle effect float alpha = (float)(kMaxLife - m_game->GetScoreManager()->GetLife()) / kMaxLife; // Add wiggle effect float yOffset = 0.0f; // Wiggle effect after the first second - yOffset = sinf((float)m_game->GetElapsedTime() * 75.0f) * 5.0f; + yOffset = sinf((float)m_game->GetElapsedTime() * 75.0f) * 10.0f; int topCur = (int)::round((1.0f - alpha) * rc.top + alpha * rc.bottom); rc.top = topCur + static_cast(::round(yOffset)); @@ -202,7 +206,7 @@ void GameplayScene::Render(double delta) m_judgement[m_judgeIndex]->AnchorPoint = { 0.5, 0.5 }; m_judgement[m_judgeIndex]->Draw(); - m_judgeSize = std::clamp(m_judgeSize + (delta * 6), 0.5, 1.0); // Nice + m_judgeSize = std::clamp(m_judgeSize + (delta * 7), 0.5, 1.0); // Nice if ((m_judgeTimer += delta) > 0.60) { m_drawJudge = false; } @@ -221,20 +225,25 @@ void GameplayScene::Render(double delta) if (m_drawCombo && std::get<7>(scores) > 0) { const double amplitudeStart = 30.0; // Constants - const double decrement = 1.0; + const double decrement = 6.0; const double animationSpeed = 60.0; if (m_comboTimer >= 1.0) { // Animation finished, reset parameters for the next animation m_comboTimer = 0.0; - m_amplitude = amplitudeStart; m_drawCombo = false; } else { - double targetAmplitude = amplitudeStart - decrement * m_comboTimer * animationSpeed * 6; + double targetAmplitude = amplitudeStart - decrement * m_comboTimer * animationSpeed; double currentAmplitude = (targetAmplitude > 0.0) ? targetAmplitude : 0.0; - m_comboLogo->Position2 = UDim2::fromOffset(0, currentAmplitude / 3.0); // Update position based on amplitude - m_comboNum->Position2 = UDim2::fromOffset(0, currentAmplitude); + // Wiggle effect + if (currentAmplitude > 0.0 && currentAmplitude > decrement && m_comboTimer <= 0.005) { + double wiggleAmount = decrement * m_comboTimer * animationSpeed; + currentAmplitude -= wiggleAmount; + } + + m_comboLogo->Position2 = UDim2::fromOffset(0, lerp(m_comboLogo->Position2.Y.Offset, currentAmplitude / 3.0, 0.2)); + m_comboNum->Position2 = UDim2::fromOffset(0, lerp(m_comboNum->Position2.Y.Offset, currentAmplitude, 0.2)); m_comboLogo->Draw(delta); m_comboNum->DrawNumber(std::get<7>(scores)); @@ -243,7 +252,7 @@ void GameplayScene::Render(double delta) } } - if (m_drawLN && std::get<9>(scores) > 0) { // Same Animation logic like DrawCombo + if (m_drawLN && std::get<9>(scores) > 0) { m_amplitude = 5.0; m_wiggleTime = 60 * m_lnTimer; From 40ba895674ee22bbe3d99ce997eb398131e9a862 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:21:56 +0700 Subject: [PATCH 008/126] Update Chart.cpp Fix --- Game/src/Data/Chart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game/src/Data/Chart.cpp b/Game/src/Data/Chart.cpp index 74970e28..41c8c522 100644 --- a/Game/src/Data/Chart.cpp +++ b/Game/src/Data/Chart.cpp @@ -341,7 +341,7 @@ Chart::Chart(O2::OJN &file, int diffIndex) // check if overlap lastTime if (info.StartTime < lastTime[info.LaneIndex]) { - Logs::Puts("[Chart] Overlapped note found on FileID: o2ma%d on %.2f ms and conflict with %.2f ms", O2JamId, info.StartTime, lastTime[info.LaneIndex]); + Logs::Puts("[Chart] Overlapped note found on file o2ma%d at %.2f ms and conflict with %.2f ms", O2JamId, info.StartTime, lastTime[info.LaneIndex]); if (note.SampleRefId != -1) { AutoSample sm = {}; From 0724c8f7cb027f71f9c7471b07952973c7096564 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:41:47 +0700 Subject: [PATCH 009/126] feat: slighly performance improvement --- Game/src/Engine/BGMPreview.cpp | 4 ++-- Game/src/Engine/DrawableNote.cpp | 6 +++--- Game/src/Engine/FrameTimer.cpp | 8 ++++---- Game/src/Engine/GameTrack.cpp | 6 +++--- Game/src/Engine/O2NumericTexture.cpp | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Game/src/Engine/BGMPreview.cpp b/Game/src/Engine/BGMPreview.cpp index 5d9adc0b..979889fd 100644 --- a/Game/src/Engine/BGMPreview.cpp +++ b/Game/src/Engine/BGMPreview.cpp @@ -71,7 +71,7 @@ void BGMPreview::Load() m_autoSamples.clear(); for (auto &sample : m_currentChart->m_autoSamples) { - m_autoSamples.push_back(sample); + m_autoSamples.emplace_back(sample); } for (auto ¬e : m_currentChart->m_notes) { @@ -82,7 +82,7 @@ void BGMPreview::Load() sm.Volume = note.Volume; sm.Pan = note.Pan; - m_autoSamples.push_back(sm); + m_autoSamples.emplace_back(sm); } } diff --git a/Game/src/Engine/DrawableNote.cpp b/Game/src/Engine/DrawableNote.cpp index 4b36fffb..34762b46 100644 --- a/Game/src/Engine/DrawableNote.cpp +++ b/Game/src/Engine/DrawableNote.cpp @@ -9,11 +9,11 @@ DrawableNote::DrawableNote(NoteImage *frame) : FrameTimer::FrameTimer() if (Renderer::GetInstance()->IsVulkan()) { for (auto &frame : frame->VulkanTexture) { - m_frames.push_back(new Texture2D(frame)); + m_frames.emplace_back(new Texture2D(frame)); } } else { for (auto &frame : frame->Texture) { - m_frames.push_back(new Texture2D(frame)); + m_frames.emplace_back(new Texture2D(frame)); } } @@ -23,5 +23,5 @@ DrawableNote::DrawableNote(NoteImage *frame) : FrameTimer::FrameTimer() _frame->SetOriginalRECT(frame->TextureRect); } - SetFPS(30); + SetFPS(30); //TODO: Fix animation render glitch, i can't figure it out } diff --git a/Game/src/Engine/FrameTimer.cpp b/Game/src/Engine/FrameTimer.cpp index 246d455c..710c66fd 100644 --- a/Game/src/Engine/FrameTimer.cpp +++ b/Game/src/Engine/FrameTimer.cpp @@ -22,7 +22,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer::FrameTimer { m_frames = std::vector(); for (auto frame : frames) { - m_frames.push_back(new Texture2D(frame)); + m_frames.emplace_back(new Texture2D(frame)); } } @@ -30,7 +30,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer:: { m_frames = std::vector(); for (auto frame : frames) { - m_frames.push_back(new Texture2D(frame)); + m_frames.emplace_back(new Texture2D(frame)); } } @@ -38,7 +38,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer::FrameTim { m_frames = std::vector(); for (auto frame : frames) { - m_frames.push_back(new Texture2D(frame)); + m_frames.emplace_back(new Texture2D(frame)); } } @@ -46,7 +46,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer::Fra { m_frames = std::vector(); for (auto frame : frames) { - m_frames.push_back(new Texture2D(frame)); + m_frames.emplace_back(new Texture2D(frame)); } } diff --git a/Game/src/Engine/GameTrack.cpp b/Game/src/Engine/GameTrack.cpp index 7b83c4c3..12a3e84b 100644 --- a/Game/src/Engine/GameTrack.cpp +++ b/Game/src/Engine/GameTrack.cpp @@ -42,7 +42,7 @@ void GameTrack::Update(double delta) auto ¬e = *_note; if (note->IsPassed()) { - m_inactive_notes.push_back(note); + m_inactive_notes.emplace_back(note); _note = m_notes.erase(_note); } else { if (!note->IsDrawable()) { @@ -71,7 +71,7 @@ void GameTrack::Update(double delta) if (note->IsRemoveable()) { note->Release(); - m_noteCaches.push_back(note); + m_noteCaches.emplace_back(note); _note = m_inactive_notes.erase(_note); } else { note->Update(delta); @@ -212,7 +212,7 @@ void GameTrack::AddNote(NoteInfoDesc *desc) m_keySound = note->GetKeysoundId(); } - m_notes.push_back(std::move(note)); + m_notes.emplace_back(std::move(note)); } void GameTrack::ListenEvent(std::function callback) diff --git a/Game/src/Engine/O2NumericTexture.cpp b/Game/src/Engine/O2NumericTexture.cpp index a2251acd..3233076b 100644 --- a/Game/src/Engine/O2NumericTexture.cpp +++ b/Game/src/Engine/O2NumericTexture.cpp @@ -15,7 +15,7 @@ O2NumericTexture::O2NumericTexture(OJS *ojs) auto frame = ojs->Frames[i].get(); auto tex = new O2Texture(frame); - m_numericsTexture.push_back(tex); + m_numericsTexture.emplace_back(tex); m_numbericsWidth[i] = tex->GetOriginalRECT(); } } \ No newline at end of file From 5a945c009960c9d7c3798e49cc1da27f381871a7 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 4 Feb 2024 14:37:38 +0700 Subject: [PATCH 010/126] feat: improved framelimiter and combo animation --- Engine/include/Game.h | 1 + Engine/src/Game.cpp | 103 +++++++++++++++--------------- Game/src/Scenes/GameplayScene.cpp | 29 +++++---- Game/src/Scenes/GameplayScene.h | 2 +- 4 files changed, 70 insertions(+), 65 deletions(-) diff --git a/Engine/include/Game.h b/Engine/include/Game.h index 7a74cfb1..81aca661 100644 --- a/Engine/include/Game.h +++ b/Engine/include/Game.h @@ -5,6 +5,7 @@ #include "Rendering/Threading/GameThread.h" #include "SceneManager.h" #include +#include enum class ThreadMode { SINGLE_THREAD, diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index 3d4faf48..6da2100b 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -19,6 +19,9 @@ constexpr auto kMenuDefaultRate = 60.0; constexpr auto kAudioDefaultRate = 24.0; namespace { + + constexpr double FixedDeltaTime = 1.0 / 60.0; + bool InitSDL() { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { @@ -39,21 +42,22 @@ namespace { double FrameLimit(double MaxFrameRate) { + const double targetFrameTime = 1000.0 / MaxFrameRate; + double newTick = SDL_GetTicks(); - double targetTick = lastTick + 1000.0 / MaxFrameRate; + double frameTime = newTick - curTick; - // If the frame rate is too high, wait to avoid shaky animations - if (newTick < targetTick) { - double delayTicks = targetTick - newTick; - SDL_Delay(static_cast(delayTicks)); - newTick += delayTicks; + if (frameTime < targetFrameTime) + { + double delayTime = targetFrameTime - frameTime; + SDL_Delay(static_cast(delayTime)); + newTick += delayTime; } double delta = (newTick - curTick) / 1000.0; - curTick = newTick; - // Update lastTick for the next frame lastTick = curTick; + curTick = newTick; return delta; } @@ -79,7 +83,6 @@ Game::~Game() if (m_running) { Stop(); - // Properly wait for threads to finish using synchronization if (m_notify) { std::unique_lock lock(m_mutex); m_conditionVariable.wait(lock, [this] { return !m_notify; }); @@ -153,8 +156,8 @@ void Game::Run() mAudioThread.Run([&] { double delta = FrameLimit(kAudioDefaultRate); AudioManager::GetInstance()->Update(delta); - }, - true); + }, + true); std::mutex m1, m2; @@ -169,7 +172,7 @@ void Game::Run() switch (m_frameLimitMode) { case FrameLimitMode::GAME: { - delta = FrameLimit(m_frameLimit); + delta = FrameLimit(m_frameLimit); break; } @@ -180,34 +183,34 @@ void Game::Run() } } - CheckFont(); + CheckFont(); - Update(delta); + Update(delta); - UpdateFade(delta); + UpdateFade(delta); - if (!m_minimized && m_renderer->BeginRender()) { - if (frameWithoutSwapchain > 0) { - Logs::Puts("[Game] Game iterate %d times without swap chain", frameWithoutSwapchain); - frameWithoutSwapchain = 0; - } + if (!m_minimized && m_renderer->BeginRender()) { + if (frameWithoutSwapchain > 0) { + Logs::Puts("[Game] Game iterate %d times without swap chain", frameWithoutSwapchain); + frameWithoutSwapchain = 0; + } - std::lock_guard lock(m1); + std::lock_guard lock(m1); - Render(delta); - MsgBox::Draw(); - DrawFade(delta); + Render(delta); + MsgBox::Draw(); + DrawFade(delta); - DrawConsole(); - m_renderer->EndRender(); + DrawConsole(); + m_renderer->EndRender(); - frames++; + frames++; } else { - frameWithoutSwapchain++; - } + frameWithoutSwapchain++; + } } else { - FrameLimit(15.0f); - } + FrameLimit(15.0f); + } }, true); @@ -217,7 +220,7 @@ void Game::Run() } else { m_sceneManager->OnKeyUp(state); } - }); + }); m_inputManager->ListenMouseEvent([&](const MouseState &state) { if (state.isDown) { @@ -225,23 +228,23 @@ void Game::Run() } else { m_sceneManager->OnMouseUp(state); } - }); + }); m_minimized = false; mLocalThread.Run([&] { double delta = 0; switch (m_frameLimitMode) { - case FrameLimitMode::GAME: - { - delta = FrameLimit(m_threadMode == ThreadMode::MULTI_THREAD ? kInputDefaultRate : m_frameLimit); - break; - } + case FrameLimitMode::GAME: + { + delta = FrameLimit(m_threadMode == ThreadMode::MULTI_THREAD ? kInputDefaultRate : m_frameLimit); + break; + } - case FrameLimitMode::MENU: - { - delta = FrameLimit(kMenuDefaultRate); - break; - } + case FrameLimitMode::MENU: + { + delta = FrameLimit(kMenuDefaultRate); + break; + } } m_imguiInterval += delta; @@ -249,9 +252,9 @@ void Game::Run() SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { - case SDL_QUIT: - MsgBox::Show("Quit", "Quit confirmation", "Are you sure you want to quit?", MsgBoxType::YESNO); - break; + case SDL_QUIT: + MsgBox::Show("Quit", "Quit confirmation", "Are you sure you want to quit?", MsgBoxType::YESNO); + break; } m_minimized = SDL_GetWindowFlags(m_window->GetWindow()) & SDL_WINDOW_MINIMIZED; @@ -305,8 +308,8 @@ void Game::Run() frames = 0; time = 0; } - }, - false); + }, + false); while (m_running) { mLocalThread.Update(); @@ -370,15 +373,15 @@ void Game::Stop() if (m_running) { m_running = false; - // Notify condition variable to indicate that the threads should finish { std::lock_guard lock(m_mutex); // TODO: Fix game does not properly exit while crash (if not just revert back to SDL_Delay Sleep) - m_notify = true; // This should be true + m_notify = true; } m_conditionVariable.notify_one(); } } + void Game::SetThreadMode(ThreadMode mode) { m_threadMode = mode; diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 9c9a7053..a4c717af 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -224,26 +224,27 @@ void GameplayScene::Render(double delta) } if (m_drawCombo && std::get<7>(scores) > 0) { - const double amplitudeStart = 30.0; // Constants + const double positionStart = 30.0; // Constants const double decrement = 6.0; - const double animationSpeed = 60.0; + double animationSpeed = 60.0; if (m_comboTimer >= 1.0) { // Animation finished, reset parameters for the next animation m_comboTimer = 0.0; m_drawCombo = false; } else { - double targetAmplitude = amplitudeStart - decrement * m_comboTimer * animationSpeed; - double currentAmplitude = (targetAmplitude > 0.0) ? targetAmplitude : 0.0; + double targetposition = positionStart - decrement * m_comboTimer * animationSpeed; + double currentposition = (targetposition > 0.0) ? targetposition : 0.0; // Wiggle effect - if (currentAmplitude > 0.0 && currentAmplitude > decrement && m_comboTimer <= 0.005) { + if (currentposition > 0.0 && currentposition > decrement && m_comboTimer <= 0.01667) { double wiggleAmount = decrement * m_comboTimer * animationSpeed; - currentAmplitude -= wiggleAmount; + currentposition -= wiggleAmount; } - m_comboLogo->Position2 = UDim2::fromOffset(0, lerp(m_comboLogo->Position2.Y.Offset, currentAmplitude / 3.0, 0.2)); - m_comboNum->Position2 = UDim2::fromOffset(0, lerp(m_comboNum->Position2.Y.Offset, currentAmplitude, 0.2)); + // Directly decrement positions + m_comboLogo->Position2 = UDim2::fromOffset(0, lerp(m_comboLogo->Position2.Y.Offset, currentposition / 3.0, 0.2)); + m_comboNum->Position2 = UDim2::fromOffset(0, lerp(m_comboNum->Position2.Y.Offset, currentposition, 0.2)); m_comboLogo->Draw(delta); m_comboNum->DrawNumber(std::get<7>(scores)); @@ -253,22 +254,22 @@ void GameplayScene::Render(double delta) } if (m_drawLN && std::get<9>(scores) > 0) { - m_amplitude = 5.0; + m_position = 5.0; m_wiggleTime = 60 * m_lnTimer; double decrement = 1.0; double totalDecrement = decrement * m_wiggleTime; - double currentAmplitude = m_amplitude - totalDecrement; + double currentposition = m_position - totalDecrement; - if (currentAmplitude < 0.0) { - currentAmplitude = 0.0; + if (currentposition < 0.0) { + currentposition = 0.0; } - m_lnLogo->Position2 = UDim2::fromOffset(0, currentAmplitude); + m_lnLogo->Position2 = UDim2::fromOffset(0, currentposition); m_lnLogo->Draw(delta); - m_lnComboNum->Position2 = UDim2::fromOffset(0, currentAmplitude); + m_lnComboNum->Position2 = UDim2::fromOffset(0, currentposition); m_lnComboNum->DrawNumber(std::get<9>(scores)); m_lnTimer += delta; diff --git a/Game/src/Scenes/GameplayScene.h b/Game/src/Scenes/GameplayScene.h index 2d4a4404..9e821289 100644 --- a/Game/src/Scenes/GameplayScene.h +++ b/Game/src/Scenes/GameplayScene.h @@ -104,7 +104,7 @@ class GameplayScene : public Scene /* Fixed Animation*/ double m_wiggleTime; double m_wiggleOffset; - double m_amplitude; + double m_position; /* button */ bool m_drawExitButton; From 064065e5e34950d4a1229e6919a3e2e7b6085f14 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 4 Feb 2024 14:39:21 +0700 Subject: [PATCH 011/126] Update Game.h --- Engine/include/Game.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Engine/include/Game.h b/Engine/include/Game.h index 81aca661..4e764017 100644 --- a/Engine/include/Game.h +++ b/Engine/include/Game.h @@ -5,7 +5,6 @@ #include "Rendering/Threading/GameThread.h" #include "SceneManager.h" #include -#include enum class ThreadMode { SINGLE_THREAD, @@ -91,4 +90,4 @@ class Game std::mutex m_mutex; std::condition_variable m_conditionVariable; -}; \ No newline at end of file +}; From e7dea28dd33b688858f592721e46731f9037ecac Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 4 Feb 2024 14:39:34 +0700 Subject: [PATCH 012/126] Update Game.cpp --- Engine/src/Game.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Engine/src/Game.cpp b/Engine/src/Game.cpp index 6da2100b..cad829e1 100644 --- a/Engine/src/Game.cpp +++ b/Engine/src/Game.cpp @@ -20,8 +20,6 @@ constexpr auto kAudioDefaultRate = 24.0; namespace { - constexpr double FixedDeltaTime = 1.0 / 60.0; - bool InitSDL() { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { From ae7c9792ef69909f35f5feae4c41098b053c415c Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:56:20 +0700 Subject: [PATCH 013/126] feat(gameplayscene): Draw Image for Mods --- Game/src/Scenes/GameplayScene.cpp | 62 +++++++++++++++++++++++++++++++ Game/src/Scenes/GameplayScene.h | 2 + 2 files changed, 64 insertions(+) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index a4c717af..cd521dc4 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -137,6 +137,15 @@ void GameplayScene::Render(double delta) m_Playfooter->Draw(); m_Playfield->Draw(); + + // Draw Mods + if (m_noteMod) { // Fix Crash + m_noteMod->Draw(); + } + if (m_visualMod) { // Fix Crash + m_visualMod->Draw(); + } + if (!is_flhd_enabled) { m_targetBar->Draw(delta); } @@ -924,6 +933,9 @@ bool GameplayScene::Attach() bool IsHD = EnvironmentSetup::GetInt("Hidden") == 1; bool IsFL = EnvironmentSetup::GetInt("Flashlight") == 1; + bool IsRD = EnvironmentSetup::GetInt("Random") == 1; + bool IsMR = EnvironmentSetup::GetInt("Mirror") == 1; + if (IsHD || IsFL) { std::vector segments; @@ -956,6 +968,53 @@ bool GameplayScene::Attach() m_laneHideImage->Size = UDim2::fromOffset(imageWidth, imageHeight); } + bool areNoteModsActive = IsMR || IsRD; // Check if any of the NoteMods are active (Mirror or Random) + bool areVisualModsActive = IsHD || IsFL; // Check if any of the VisualMods are active (Hidden or Flashlight) + // I don't put throw error if any file below doesn't exist maybe you can put it if necessary + if (areVisualModsActive) { // Draw VisualMods (Hidden and Flashlight) + if (IsHD) { + std::string VisualModImage = "Hidden.png"; + auto VisualModfilename = playingPath / VisualModImage; + + auto visualModPos = manager->GetPosition(SkinGroup::Playing, "VisualMods").front(); + m_visualMod = std::make_unique(VisualModfilename); + m_visualMod->Position = UDim2::fromOffset(visualModPos.X, visualModPos.Y); + m_visualMod->AnchorPoint = { visualModPos.AnchorPointX, visualModPos.AnchorPointY }; + } + + if (IsFL) { + std::string VisualModImage = "Flashlight.png"; + auto VisualModfilename = playingPath / VisualModImage; + + auto visualModPos = manager->GetPosition(SkinGroup::Playing, "VisualMods").front(); + m_visualMod = std::make_unique(VisualModfilename); + m_visualMod->Position = UDim2::fromOffset(visualModPos.X, visualModPos.Y); + m_visualMod->AnchorPoint = { visualModPos.AnchorPointX, visualModPos.AnchorPointY }; + } + } + + if (areNoteModsActive) { // Draw NoteMods (Mirror and Random) + if (IsMR) { + std::string NoteModImage = "Mirror.png"; + auto NoteModfilename = playingPath / NoteModImage; + + auto noteModPos = manager->GetPosition(SkinGroup::Playing, "NoteMods").front(); + m_noteMod = std::make_unique(NoteModfilename); + m_noteMod->Position = UDim2::fromOffset(noteModPos.X, noteModPos.Y); + m_noteMod->AnchorPoint = { noteModPos.AnchorPointX, noteModPos.AnchorPointY }; + } + + if (IsRD) { + std::string NoteModImage = "Random.png"; + auto NoteModfilename = playingPath / NoteModImage; + + auto noteModPos = manager->GetPosition(SkinGroup::Playing, "NoteMods").front(); + m_noteMod = std::make_unique(NoteModfilename); + m_noteMod->Position = UDim2::fromOffset(noteModPos.X, noteModPos.Y); + m_noteMod->AnchorPoint = { noteModPos.AnchorPointX, noteModPos.AnchorPointY }; + } + } + auto OnHitEvent = [&](NoteHitInfo info) { m_scoreTimer = 0; m_judgeTimer = 0; @@ -1032,6 +1091,9 @@ bool GameplayScene::Detach() m_Playfooter.reset(); m_exitBtn.reset(); + m_noteMod.reset(); + m_visualMod.reset(); + m_jamGauge.reset(); m_waveGage.reset(); m_jamLogo.reset(); diff --git a/Game/src/Scenes/GameplayScene.h b/Game/src/Scenes/GameplayScene.h index 9e821289..b1f8ee01 100644 --- a/Game/src/Scenes/GameplayScene.h +++ b/Game/src/Scenes/GameplayScene.h @@ -50,6 +50,8 @@ class GameplayScene : public Scene std::unique_ptr m_Playfield; std::unique_ptr m_PlayBG; std::unique_ptr m_Playfooter; + std::unique_ptr m_noteMod; + std::unique_ptr m_visualMod; std::unique_ptr m_jamGauge; std::unique_ptr m_waveGage; From 6ada3486708696cc241f338b29a66638bb6bb6b6 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:39:49 +0700 Subject: [PATCH 014/126] refactor(gameplay): swap playfield and playfooter --- Game/src/Scenes/GameplayScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index cd521dc4..5b0b9c46 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -135,8 +135,8 @@ void GameplayScene::Render(double delta) } } - m_Playfooter->Draw(); m_Playfield->Draw(); + m_Playfooter->Draw(); // Draw Mods if (m_noteMod) { // Fix Crash From dd6056504b6a819c86dc7c081d611e9468bfe218 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 13 Feb 2024 19:02:05 +0700 Subject: [PATCH 015/126] refactor(gameplay): better filename --- Game/src/Scenes/GameplayScene.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 5b0b9c46..129f5a8d 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -973,7 +973,7 @@ bool GameplayScene::Attach() // I don't put throw error if any file below doesn't exist maybe you can put it if necessary if (areVisualModsActive) { // Draw VisualMods (Hidden and Flashlight) if (IsHD) { - std::string VisualModImage = "Hidden.png"; + std::string VisualModImage = "ModHidden.png"; auto VisualModfilename = playingPath / VisualModImage; auto visualModPos = manager->GetPosition(SkinGroup::Playing, "VisualMods").front(); @@ -983,7 +983,7 @@ bool GameplayScene::Attach() } if (IsFL) { - std::string VisualModImage = "Flashlight.png"; + std::string VisualModImage = "ModFlashlight.png"; auto VisualModfilename = playingPath / VisualModImage; auto visualModPos = manager->GetPosition(SkinGroup::Playing, "VisualMods").front(); @@ -995,7 +995,7 @@ bool GameplayScene::Attach() if (areNoteModsActive) { // Draw NoteMods (Mirror and Random) if (IsMR) { - std::string NoteModImage = "Mirror.png"; + std::string NoteModImage = "ModMirror.png"; auto NoteModfilename = playingPath / NoteModImage; auto noteModPos = manager->GetPosition(SkinGroup::Playing, "NoteMods").front(); @@ -1005,7 +1005,7 @@ bool GameplayScene::Attach() } if (IsRD) { - std::string NoteModImage = "Random.png"; + std::string NoteModImage = "ModRandom.png"; auto NoteModfilename = playingPath / NoteModImage; auto noteModPos = manager->GetPosition(SkinGroup::Playing, "NoteMods").front(); From d2047fa5ee6e06d852f85066d28066bdb5a23780 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 13 Feb 2024 20:05:12 +0700 Subject: [PATCH 016/126] feat(gameplay): add modifier logger --- Game/src/Scenes/GameplayScene.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 129f5a8d..4427d7c2 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Configuration.h" #include "Game.h" @@ -1015,6 +1016,21 @@ bool GameplayScene::Attach() } } + std::string modSelected; + + if (IsHD) modSelected += "Hidden, "; + if (IsFL) modSelected += "Flashlight, "; + if (IsRD) modSelected += "Random, "; + if (IsMR) modSelected += "Mirror, "; + + if (!modSelected.empty()) { + modSelected.erase(modSelected.size() - 2); + Logs::Puts(("[Gameplay] Using modifier " + modSelected).c_str()); + } + else { + Logs::Puts("[Gameplay] Not using any modifier"); + } + auto OnHitEvent = [&](NoteHitInfo info) { m_scoreTimer = 0; m_judgeTimer = 0; From ae837d93987dea53d8e14e7175035e0c9ea3c8da Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Fri, 16 Feb 2024 02:12:04 +0700 Subject: [PATCH 017/126] feat: add new modifier --- Game/src/Scenes/GameplayScene.cpp | 85 +++++++++++++++++++++-------- Game/src/Scenes/ResultScene.cpp | 2 +- Game/src/Scenes/SongSelectScene.cpp | 65 ++++++++++------------ 3 files changed, 92 insertions(+), 60 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 4427d7c2..df142a6f 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -146,24 +146,32 @@ void GameplayScene::Render(double delta) if (m_visualMod) { // Fix Crash m_visualMod->Draw(); } - + // Maybe u decided below if (!is_flhd_enabled) { - m_targetBar->Draw(delta); - } - - for (auto &[lane, pressed] : m_keyState) { - if (pressed) { - m_keyLighting[lane]->AlphaBlend = true; - m_keyLighting[lane]->Draw(); - m_keyButtons[lane]->Draw(); + for (auto& [lane, pressed] : m_keyState) { + if (pressed) { + m_keyLighting[lane]->AlphaBlend = true; + m_keyLighting[lane]->Draw(); + m_keyButtons[lane]->Draw(); + } } + m_targetBar->Draw(delta); + m_targetBar->AlphaBlend = true; // Fix for some cases (Resource updated) + m_game->Render(delta); } - m_game->Render(delta); - if (is_flhd_enabled) { + m_game->Render(delta); m_laneHideImage->Draw(); m_targetBar->Draw(delta); + m_targetBar->AlphaBlend = true; // Fix for some cases (Resource updated) + for (auto& [lane, pressed] : m_keyState) { + if (pressed) { + m_keyLighting[lane]->AlphaBlend = true; + m_keyLighting[lane]->Draw(); + m_keyButtons[lane]->Draw(); + } + } } auto scores = m_game->GetScoreManager()->GetScore(); @@ -934,13 +942,26 @@ bool GameplayScene::Attach() bool IsHD = EnvironmentSetup::GetInt("Hidden") == 1; bool IsFL = EnvironmentSetup::GetInt("Flashlight") == 1; + bool IsSD = EnvironmentSetup::GetInt("Sudden") == 1; bool IsRD = EnvironmentSetup::GetInt("Random") == 1; bool IsMR = EnvironmentSetup::GetInt("Mirror") == 1; + bool IsPC = EnvironmentSetup::GetInt("Panic") == 1; // Requested - if (IsHD || IsFL) { + if (IsHD || IsFL || IsSD) { std::vector segments; - if (IsFL) { + if (IsHD) { + segments = { + //{ 0.00f, 0.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } }, + //{ 0.00f, 0.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 0 } }, + //{ 0.00f, 0.45f, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, + //{ 0.45f, 0.50f, { 0, 0, 0, 0 }, { 0, 0, 0, 255 } }, + //{ 0.50f, 1.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } } + { 0.00f, 0.45f, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, + { 0.45f, 0.50f, { 0, 0, 0, 0 }, { 0, 0, 0, 255 } }, + { 0.50f, 1.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } } + }; + } if (IsFL) { segments = { { 0.00f, 0.20f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } }, { 0.33f, 0.38f, { 0, 0, 0, 255 }, { 0, 0, 0, 0 } }, @@ -948,13 +969,11 @@ bool GameplayScene::Attach() { 0.61f, 0.67f, { 0, 0, 0, 0 }, { 0, 0, 0, 255 } }, { 0.67f, 1.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } } }; - } else { + } if (IsSD) { segments = { - { 0.00f, 0.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } }, - { 0.00f, 0.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 0 } }, - { 0.00f, 0.45f, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, - { 0.45f, 0.50f, { 0, 0, 0, 0 }, { 0, 0, 0, 255 } }, - { 0.50f, 1.00f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } } + { 0.00f, 0.50f, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } }, + { 0.50f, 0.55f, { 0, 0, 0, 255 }, { 0, 0, 0, 0 } }, + { 0.55f, 1.00f, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } } }; } @@ -969,10 +988,10 @@ bool GameplayScene::Attach() m_laneHideImage->Size = UDim2::fromOffset(imageWidth, imageHeight); } - bool areNoteModsActive = IsMR || IsRD; // Check if any of the NoteMods are active (Mirror or Random) - bool areVisualModsActive = IsHD || IsFL; // Check if any of the VisualMods are active (Hidden or Flashlight) + bool areVisualModsActive = IsHD || IsFL || IsSD; // Check if any of the VisualMods are active (Hidden or Flashlight) + bool areNoteModsActive = IsMR || IsRD || IsPC; // Check if any of the NoteMods are active (Mirror or Random) // I don't put throw error if any file below doesn't exist maybe you can put it if necessary - if (areVisualModsActive) { // Draw VisualMods (Hidden and Flashlight) + if (areVisualModsActive) { // Draw VisualMods (Hidden, Flashlight, and Sudden) if (IsHD) { std::string VisualModImage = "ModHidden.png"; auto VisualModfilename = playingPath / VisualModImage; @@ -987,6 +1006,15 @@ bool GameplayScene::Attach() std::string VisualModImage = "ModFlashlight.png"; auto VisualModfilename = playingPath / VisualModImage; + auto visualModPos = manager->GetPosition(SkinGroup::Playing, "VisualMods").front(); + m_visualMod = std::make_unique(VisualModfilename); + m_visualMod->Position = UDim2::fromOffset(visualModPos.X, visualModPos.Y); + m_visualMod->AnchorPoint = { visualModPos.AnchorPointX, visualModPos.AnchorPointY }; + } + if (IsSD) { + std::string VisualModImage = "ModSudden.png"; + auto VisualModfilename = playingPath / VisualModImage; + auto visualModPos = manager->GetPosition(SkinGroup::Playing, "VisualMods").front(); m_visualMod = std::make_unique(VisualModfilename); m_visualMod->Position = UDim2::fromOffset(visualModPos.X, visualModPos.Y); @@ -994,7 +1022,7 @@ bool GameplayScene::Attach() } } - if (areNoteModsActive) { // Draw NoteMods (Mirror and Random) + if (areNoteModsActive) { // Draw NoteMods (Mirror, Random, and Panic) if (IsMR) { std::string NoteModImage = "ModMirror.png"; auto NoteModfilename = playingPath / NoteModImage; @@ -1009,6 +1037,15 @@ bool GameplayScene::Attach() std::string NoteModImage = "ModRandom.png"; auto NoteModfilename = playingPath / NoteModImage; + auto noteModPos = manager->GetPosition(SkinGroup::Playing, "NoteMods").front(); + m_noteMod = std::make_unique(NoteModfilename); + m_noteMod->Position = UDim2::fromOffset(noteModPos.X, noteModPos.Y); + m_noteMod->AnchorPoint = { noteModPos.AnchorPointX, noteModPos.AnchorPointY }; + } + if (IsPC) { + std::string NoteModImage = "ModPanic.png"; + auto NoteModfilename = playingPath / NoteModImage; + auto noteModPos = manager->GetPosition(SkinGroup::Playing, "NoteMods").front(); m_noteMod = std::make_unique(NoteModfilename); m_noteMod->Position = UDim2::fromOffset(noteModPos.X, noteModPos.Y); @@ -1020,8 +1057,10 @@ bool GameplayScene::Attach() if (IsHD) modSelected += "Hidden, "; if (IsFL) modSelected += "Flashlight, "; + if (IsSD) modSelected += "Sudden, "; if (IsRD) modSelected += "Random, "; if (IsMR) modSelected += "Mirror, "; + if (IsPC) modSelected += "Panic, "; if (!modSelected.empty()) { modSelected.erase(modSelected.size() - 2); diff --git a/Game/src/Scenes/ResultScene.cpp b/Game/src/Scenes/ResultScene.cpp index 269cb796..bf3271df 100644 --- a/Game/src/Scenes/ResultScene.cpp +++ b/Game/src/Scenes/ResultScene.cpp @@ -19,7 +19,7 @@ #include "../EnvironmentSetup.hpp" #include "../GameScenes.h" -static std::array Mods = { "Mirror", "Random", "Rearrange", "Autoplay", "Hidden", "Flashlight" }; +static std::array Mods = { "Mirror", "Random", "Panic", "Rearrange", "Autoplay", "Hidden", "Flashlight", "Sudden" }; ResultScene::ResultScene() { diff --git a/Game/src/Scenes/SongSelectScene.cpp b/Game/src/Scenes/SongSelectScene.cpp index 93baba68..defc15ea 100644 --- a/Game/src/Scenes/SongSelectScene.cpp +++ b/Game/src/Scenes/SongSelectScene.cpp @@ -28,7 +28,7 @@ #include "../Data/Chart.hpp" #include "../Data/Util/Util.hpp" -static std::array Mods = { "Mirror", "Random", "Rearrange", "Autoplay", "Hidden", "Flashlight" }; +static std::array Mods = { "Mirror", "Random", "Panic", "Rearrange", "Autoplay", "Hidden", "Flashlight", "Sudden" }; static std::array Arena = { "Music Background", "Random", "Arena 1", "Arena 2", "Arena 3", "Arena 4", "Arena 5", "Arena 6", "Arena 7", "Arena 8", "Arena 9", "Arena 10", "Arena 11", "Arena 12" }; @@ -489,41 +489,34 @@ void SongSelectScene::OnGameSelectMusic(double delta) if (ImGui::Button(mod.c_str(), MathUtil::ScaleVec2(ImVec2(80, 0)))) { EnvironmentSetup::SetInt(mod, value == 1 ? 0 : 1); - switch (i) { - case 0: - { - EnvironmentSetup::SetInt(Mods[1], 0); - EnvironmentSetup::SetInt(Mods[2], 0); - break; - } - - case 1: - { - EnvironmentSetup::SetInt(Mods[0], 0); - EnvironmentSetup::SetInt(Mods[2], 0); - break; - } - - case 2: - { - bOpenRearrange = EnvironmentSetup::GetInt(Mods[2]) == 1; - - EnvironmentSetup::SetInt(Mods[0], 0); - EnvironmentSetup::SetInt(Mods[1], 0); - break; - } - - case 4: - { - EnvironmentSetup::SetInt(Mods[5], 0); - break; - } - - case 5: - { - EnvironmentSetup::SetInt(Mods[4], 0); - break; - } + switch (i) { // New Modifier + case 0: // Mirror + EnvironmentSetup::SetInt(Mods[1], 0); // Random + EnvironmentSetup::SetInt(Mods[2], 0); // Panic + break; + case 1: // Random + EnvironmentSetup::SetInt(Mods[0], 0); // Mirror + EnvironmentSetup::SetInt(Mods[2], 0); // Panic + break; + case 2: // Panic + EnvironmentSetup::SetInt(Mods[0], 0); // Mirror + EnvironmentSetup::SetInt(Mods[1], 0); // Random + break; + case 3: // Rearrange + bOpenRearrange = EnvironmentSetup::GetInt(Mods[3]) == 1; + break; + case 5: // Hidden + EnvironmentSetup::SetInt(Mods[6], 0); // Flashlight + EnvironmentSetup::SetInt(Mods[7], 0); // Sudden + break; + case 6: // Flashlight + EnvironmentSetup::SetInt(Mods[5], 0); // Hidden + EnvironmentSetup::SetInt(Mods[7], 0); // Sudden + break; + case 7: // Sudden + EnvironmentSetup::SetInt(Mods[5], 0); // Hidden + EnvironmentSetup::SetInt(Mods[6], 0); // Flashlight + break; } } From c378acb584d740deba3c91f697df91524023e23f Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Fri, 16 Feb 2024 02:26:27 +0700 Subject: [PATCH 018/126] refactor(gameplayscene): move few code --- Game/src/Scenes/GameplayScene.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index df142a6f..f896b41d 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -161,10 +161,6 @@ void GameplayScene::Render(double delta) } if (is_flhd_enabled) { - m_game->Render(delta); - m_laneHideImage->Draw(); - m_targetBar->Draw(delta); - m_targetBar->AlphaBlend = true; // Fix for some cases (Resource updated) for (auto& [lane, pressed] : m_keyState) { if (pressed) { m_keyLighting[lane]->AlphaBlend = true; @@ -172,6 +168,11 @@ void GameplayScene::Render(double delta) m_keyButtons[lane]->Draw(); } } + m_game->Render(delta); + m_laneHideImage->Draw(); + m_targetBar->Draw(delta); + m_targetBar->AlphaBlend = true; // Fix for some cases (Resource updated) + } auto scores = m_game->GetScoreManager()->GetScore(); From 2c68f099439c87eef7973ee8e019ca898d71897f Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Fri, 16 Feb 2024 18:50:37 +0700 Subject: [PATCH 019/126] fix(songselectscene): rearrange should not selected if random,mirror,panic enable --- Game/src/Scenes/SongSelectScene.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Game/src/Scenes/SongSelectScene.cpp b/Game/src/Scenes/SongSelectScene.cpp index defc15ea..ea18eff0 100644 --- a/Game/src/Scenes/SongSelectScene.cpp +++ b/Game/src/Scenes/SongSelectScene.cpp @@ -493,17 +493,23 @@ void SongSelectScene::OnGameSelectMusic(double delta) case 0: // Mirror EnvironmentSetup::SetInt(Mods[1], 0); // Random EnvironmentSetup::SetInt(Mods[2], 0); // Panic + EnvironmentSetup::SetInt(Mods[3], 0); // Rearrange break; case 1: // Random EnvironmentSetup::SetInt(Mods[0], 0); // Mirror EnvironmentSetup::SetInt(Mods[2], 0); // Panic + EnvironmentSetup::SetInt(Mods[3], 0); // Rearrange break; case 2: // Panic EnvironmentSetup::SetInt(Mods[0], 0); // Mirror EnvironmentSetup::SetInt(Mods[1], 0); // Random + EnvironmentSetup::SetInt(Mods[3], 0); // Rearrange break; case 3: // Rearrange - bOpenRearrange = EnvironmentSetup::GetInt(Mods[3]) == 1; + EnvironmentSetup::SetInt(Mods[0], 0); // Mirror + EnvironmentSetup::SetInt(Mods[1], 0); // Random + EnvironmentSetup::SetInt(Mods[2], 0); // Panic + bOpenRearrange = true; // Open Rearrange Window break; case 5: // Hidden EnvironmentSetup::SetInt(Mods[6], 0); // Flashlight From 81a5283d716b25df993c078524334c73ff5d27dc Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Fri, 16 Feb 2024 23:53:07 +0700 Subject: [PATCH 020/126] refactor(gameplayscene): fix duplicate code --- Game/src/Scenes/GameplayScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index f896b41d..8d37e60e 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -1074,7 +1074,6 @@ bool GameplayScene::Attach() auto OnHitEvent = [&](NoteHitInfo info) { m_scoreTimer = 0; m_judgeTimer = 0; - m_comboTimer = 0; m_judgeSize = 0.5; m_drawCombo = true; @@ -1098,6 +1097,7 @@ bool GameplayScene::Attach() auto OnLongComboEvent = [&] { m_lnTimer = 0; m_drawLN = true; + m_lnLogo->Reset(); }; m_game->GetScoreManager()->ListenLongNote(OnLongComboEvent); From 61bde3fe07caeb24302a2df1c9644155e912566f Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sat, 17 Feb 2024 18:21:28 +0700 Subject: [PATCH 021/126] feat: small changes, remove unnecessary code --- Game/src/Engine/BGMPreview.cpp | 4 ++-- Game/src/Engine/DrawableNote.cpp | 4 ++-- Game/src/Engine/FrameTimer.cpp | 8 ++++---- Game/src/Engine/GameTrack.cpp | 2 +- Game/src/Scenes/GameplayScene.cpp | 8 ++------ 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Game/src/Engine/BGMPreview.cpp b/Game/src/Engine/BGMPreview.cpp index 979889fd..5d9adc0b 100644 --- a/Game/src/Engine/BGMPreview.cpp +++ b/Game/src/Engine/BGMPreview.cpp @@ -71,7 +71,7 @@ void BGMPreview::Load() m_autoSamples.clear(); for (auto &sample : m_currentChart->m_autoSamples) { - m_autoSamples.emplace_back(sample); + m_autoSamples.push_back(sample); } for (auto ¬e : m_currentChart->m_notes) { @@ -82,7 +82,7 @@ void BGMPreview::Load() sm.Volume = note.Volume; sm.Pan = note.Pan; - m_autoSamples.emplace_back(sm); + m_autoSamples.push_back(sm); } } diff --git a/Game/src/Engine/DrawableNote.cpp b/Game/src/Engine/DrawableNote.cpp index 34762b46..65996500 100644 --- a/Game/src/Engine/DrawableNote.cpp +++ b/Game/src/Engine/DrawableNote.cpp @@ -9,11 +9,11 @@ DrawableNote::DrawableNote(NoteImage *frame) : FrameTimer::FrameTimer() if (Renderer::GetInstance()->IsVulkan()) { for (auto &frame : frame->VulkanTexture) { - m_frames.emplace_back(new Texture2D(frame)); + m_frames.push_back(new Texture2D(frame)); } } else { for (auto &frame : frame->Texture) { - m_frames.emplace_back(new Texture2D(frame)); + m_frames.push_back(new Texture2D(frame)); } } diff --git a/Game/src/Engine/FrameTimer.cpp b/Game/src/Engine/FrameTimer.cpp index 710c66fd..246d455c 100644 --- a/Game/src/Engine/FrameTimer.cpp +++ b/Game/src/Engine/FrameTimer.cpp @@ -22,7 +22,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer::FrameTimer { m_frames = std::vector(); for (auto frame : frames) { - m_frames.emplace_back(new Texture2D(frame)); + m_frames.push_back(new Texture2D(frame)); } } @@ -30,7 +30,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer:: { m_frames = std::vector(); for (auto frame : frames) { - m_frames.emplace_back(new Texture2D(frame)); + m_frames.push_back(new Texture2D(frame)); } } @@ -38,7 +38,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer::FrameTim { m_frames = std::vector(); for (auto frame : frames) { - m_frames.emplace_back(new Texture2D(frame)); + m_frames.push_back(new Texture2D(frame)); } } @@ -46,7 +46,7 @@ FrameTimer::FrameTimer(std::vector frames) : FrameTimer::Fra { m_frames = std::vector(); for (auto frame : frames) { - m_frames.emplace_back(new Texture2D(frame)); + m_frames.push_back(new Texture2D(frame)); } } diff --git a/Game/src/Engine/GameTrack.cpp b/Game/src/Engine/GameTrack.cpp index 12a3e84b..b03396b1 100644 --- a/Game/src/Engine/GameTrack.cpp +++ b/Game/src/Engine/GameTrack.cpp @@ -71,7 +71,7 @@ void GameTrack::Update(double delta) if (note->IsRemoveable()) { note->Release(); - m_noteCaches.emplace_back(note); + m_noteCaches.push_back(note); _note = m_inactive_notes.erase(_note); } else { note->Update(delta); diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 8d37e60e..a09ab2d7 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -36,10 +36,6 @@ struct MissInfo float time; }; -double lerp(double a, double b, double t) { - return a + t * (b - a); -} - bool CheckSkinComponent(std::filesystem::path x) { return std::filesystem::exists(x); @@ -262,8 +258,8 @@ void GameplayScene::Render(double delta) } // Directly decrement positions - m_comboLogo->Position2 = UDim2::fromOffset(0, lerp(m_comboLogo->Position2.Y.Offset, currentposition / 3.0, 0.2)); - m_comboNum->Position2 = UDim2::fromOffset(0, lerp(m_comboNum->Position2.Y.Offset, currentposition, 0.2)); + m_comboLogo->Position2 = UDim2::fromOffset(0, std::lerp(m_comboLogo->Position2.Y.Offset, currentposition / 3.0, 0.2)); + m_comboNum->Position2 = UDim2::fromOffset(0, std::lerp(m_comboNum->Position2.Y.Offset, currentposition, 0.2)); m_comboLogo->Draw(delta); m_comboNum->DrawNumber(std::get<7>(scores)); From 4a9755758c995958b2c2afcf6c4a6127a724b461 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sat, 17 Feb 2024 22:17:11 +0700 Subject: [PATCH 022/126] refactor(gameplayscene): lerp removed, optimize combo animation --- Game/src/Scenes/GameplayScene.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index a09ab2d7..b28a17cc 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -239,11 +239,11 @@ void GameplayScene::Render(double delta) } if (m_drawCombo && std::get<7>(scores) > 0) { - const double positionStart = 30.0; // Constants + const double positionStart = 30.0; const double decrement = 6.0; double animationSpeed = 60.0; - if (m_comboTimer >= 1.0) { // Animation finished, reset parameters for the next animation + if (m_comboTimer >= 1.0) { m_comboTimer = 0.0; m_drawCombo = false; } @@ -252,14 +252,19 @@ void GameplayScene::Render(double delta) double currentposition = (targetposition > 0.0) ? targetposition : 0.0; // Wiggle effect - if (currentposition > 0.0 && currentposition > decrement && m_comboTimer <= 0.01667) { + if (currentposition > 0.0 && currentposition > decrement && m_comboTimer <= 0.001) { double wiggleAmount = decrement * m_comboTimer * animationSpeed; - currentposition -= wiggleAmount; + if (currentposition > positionStart - decrement) { + currentposition = positionStart; + } + else { + currentposition -= wiggleAmount; + } } - // Directly decrement positions - m_comboLogo->Position2 = UDim2::fromOffset(0, std::lerp(m_comboLogo->Position2.Y.Offset, currentposition / 3.0, 0.2)); - m_comboNum->Position2 = UDim2::fromOffset(0, std::lerp(m_comboNum->Position2.Y.Offset, currentposition, 0.2)); + /// Directly decrement position + m_comboLogo->Position2 = UDim2::fromOffset(0, currentposition / 3.0); + m_comboNum->Position2 = UDim2::fromOffset(0, currentposition); m_comboLogo->Draw(delta); m_comboNum->DrawNumber(std::get<7>(scores)); From da6e032127ae7081b664e9c9f49f8b3e3a056572 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:42:46 +0700 Subject: [PATCH 023/126] refactor(gameplayscene): remove useless code --- Game/src/Scenes/GameplayScene.cpp | 35 ++++++++++--------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index b28a17cc..08543f56 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -243,33 +243,20 @@ void GameplayScene::Render(double delta) const double decrement = 6.0; double animationSpeed = 60.0; - if (m_comboTimer >= 1.0) { - m_comboTimer = 0.0; - m_drawCombo = false; - } - else { - double targetposition = positionStart - decrement * m_comboTimer * animationSpeed; - double currentposition = (targetposition > 0.0) ? targetposition : 0.0; - - // Wiggle effect - if (currentposition > 0.0 && currentposition > decrement && m_comboTimer <= 0.001) { - double wiggleAmount = decrement * m_comboTimer * animationSpeed; - if (currentposition > positionStart - decrement) { - currentposition = positionStart; - } - else { - currentposition -= wiggleAmount; - } - } + double targetposition = positionStart - decrement * m_comboTimer * animationSpeed; + double currentposition = (targetposition > 0.0) ? targetposition : 0.0; + + m_comboLogo->Position2 = UDim2::fromOffset(0, currentposition / 3.0); + m_comboNum->Position2 = UDim2::fromOffset(0, currentposition); - /// Directly decrement position - m_comboLogo->Position2 = UDim2::fromOffset(0, currentposition / 3.0); - m_comboNum->Position2 = UDim2::fromOffset(0, currentposition); + m_comboLogo->Draw(delta); + m_comboNum->DrawNumber(std::get<7>(scores)); - m_comboLogo->Draw(delta); - m_comboNum->DrawNumber(std::get<7>(scores)); + m_comboTimer += delta; - m_comboTimer += delta; + if (m_comboTimer >= 1.0) { + m_comboTimer = 0.0; + m_drawCombo = false; } } From 010587266997eceb231cda0e9503ee8c5ba436c0 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:07:22 +0700 Subject: [PATCH 024/126] refactor(gameplayscene): clean few codes --- Game/src/Scenes/GameplayScene.cpp | 23 ++++++++--------------- Game/src/Scenes/GameplayScene.h | 5 ----- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 08543f56..07fb163b 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -48,8 +48,6 @@ GameplayScene::GameplayScene() : Scene::Scene() m_keyState = {}; m_game = nullptr; m_drawJam = false; - m_wiggleTime = 0; - m_wiggleOffset = 0; } void GameplayScene::Update(double delta) @@ -221,7 +219,7 @@ void GameplayScene::Render(double delta) m_judgement[m_judgeIndex]->AnchorPoint = { 0.5, 0.5 }; m_judgement[m_judgeIndex]->Draw(); - m_judgeSize = std::clamp(m_judgeSize + (delta * 7), 0.5, 1.0); // Nice + m_judgeSize = std::clamp(m_judgeSize + (delta * 6), 0.7, 1.0); // Nice if ((m_judgeTimer += delta) > 0.60) { m_drawJudge = false; } @@ -238,13 +236,13 @@ void GameplayScene::Render(double delta) } } - if (m_drawCombo && std::get<7>(scores) > 0) { + if (m_drawCombo && std::get<7>(scores) > 0) { // This should be O2Jam Replication const double positionStart = 30.0; const double decrement = 6.0; double animationSpeed = 60.0; double targetposition = positionStart - decrement * m_comboTimer * animationSpeed; - double currentposition = (targetposition > 0.0) ? targetposition : 0.0; + double currentposition = (targetposition > 0.0) ? targetposition : 0.0; //TODO: 1px wiggle if combo update too frequently (MAT) m_comboLogo->Position2 = UDim2::fromOffset(0, currentposition / 3.0); m_comboNum->Position2 = UDim2::fromOffset(0, currentposition); @@ -261,17 +259,11 @@ void GameplayScene::Render(double delta) } if (m_drawLN && std::get<9>(scores) > 0) { - m_position = 5.0; - m_wiggleTime = 60 * m_lnTimer; - - double decrement = 1.0; - double totalDecrement = decrement * m_wiggleTime; - - double currentposition = m_position - totalDecrement; + const double positionStart = 5.0; + double animationSpeed = 60.0; - if (currentposition < 0.0) { - currentposition = 0.0; - } + double targetposition = positionStart - m_lnTimer * animationSpeed; + double currentposition = (targetposition > 0.0) ? targetposition : 0.0; m_lnLogo->Position2 = UDim2::fromOffset(0, currentposition); m_lnLogo->Draw(delta); @@ -287,6 +279,7 @@ void GameplayScene::Render(double delta) } } + float gaugeVal = (float)m_game->GetScoreManager()->GetJamGauge() / kMaxJamGauge; if (gaugeVal > 0) { m_jamGauge->CalculateSize(); diff --git a/Game/src/Scenes/GameplayScene.h b/Game/src/Scenes/GameplayScene.h index b1f8ee01..7377f0dc 100644 --- a/Game/src/Scenes/GameplayScene.h +++ b/Game/src/Scenes/GameplayScene.h @@ -103,11 +103,6 @@ class GameplayScene : public Scene bool m_drawHold[7]; bool m_drawHit[7]; - /* Fixed Animation*/ - double m_wiggleTime; - double m_wiggleOffset; - double m_position; - /* button */ bool m_drawExitButton; bool m_doExit; From 99b9a920e33fb17cafb33068f68b16dd4be45b5a Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:00:29 +0700 Subject: [PATCH 025/126] --- Game/src/Scenes/GameplayScene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 07fb163b..d0f94d7e 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -219,7 +219,7 @@ void GameplayScene::Render(double delta) m_judgement[m_judgeIndex]->AnchorPoint = { 0.5, 0.5 }; m_judgement[m_judgeIndex]->Draw(); - m_judgeSize = std::clamp(m_judgeSize + (delta * 6), 0.7, 1.0); // Nice + m_judgeSize = std::clamp(m_judgeSize + (delta * 6), 0.6, 1.0); // Nice if ((m_judgeTimer += delta) > 0.60) { m_drawJudge = false; } @@ -1055,7 +1055,7 @@ bool GameplayScene::Attach() auto OnHitEvent = [&](NoteHitInfo info) { m_scoreTimer = 0; m_judgeTimer = 0; - m_judgeSize = 0.5; + m_judgeSize = 0.6; m_drawCombo = true; m_drawJudge = true; From 2a1406bd2a20c7eaac2577210e5d2658c5bcadb1 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 18 Feb 2024 14:36:07 +0700 Subject: [PATCH 026/126] feat: sprite now can play once or stop on last frame --- Engine/include/Texture/Sprite2D.h | 6 ++- Engine/src/Texture/Sprite2D.cpp | 89 ++++++++++++++++++++++++++++--- Game/src/Scenes/GameplayScene.cpp | 2 +- 3 files changed, 87 insertions(+), 10 deletions(-) diff --git a/Engine/include/Texture/Sprite2D.h b/Engine/include/Texture/Sprite2D.h index 82ec986c..479f2435 100644 --- a/Engine/include/Texture/Sprite2D.h +++ b/Engine/include/Texture/Sprite2D.h @@ -33,15 +33,19 @@ class Sprite2D void Draw(double delta, bool manual = false); void Draw(double delta, Rect *rect, bool manual = false); + void DrawStop(double delta, bool manual = false); + void DrawOnce(double delta, bool manual = false); Texture2D *GetTexture(); void SetFPS(float fps); void Reset(); private: - double m_delay = 1.0; + double m_spritespeed = 1.0; float m_currentTime = 0; int m_currentIndex = 0; + bool m_drawOnce = false; + std::vector m_textures; }; diff --git a/Engine/src/Texture/Sprite2D.cpp b/Engine/src/Texture/Sprite2D.cpp index 8b014825..c18e661e 100644 --- a/Engine/src/Texture/Sprite2D.cpp +++ b/Engine/src/Texture/Sprite2D.cpp @@ -5,7 +5,7 @@ Sprite2D::Sprite2D(std::vector textures, float delay) : Sprite2D::Sprite2D() { m_textures = textures; - m_delay = delay; + m_spritespeed = delay; m_currentTime = 0.0f; m_currentIndex = 0; @@ -16,7 +16,7 @@ Sprite2D::Sprite2D(std::vector textures, float delay) : Sprite2D::S Sprite2D::Sprite2D(std::vector textures, float delay) : Sprite2D::Sprite2D() { - m_delay = delay; + m_spritespeed = delay; Size = UDim2::fromScale(1, 1); Position = UDim2::fromOffset(0, 0); AnchorPoint = { 0, 0 }; @@ -28,7 +28,7 @@ Sprite2D::Sprite2D(std::vector textures, float delay) : Sprite2D::S Sprite2D::Sprite2D(std::vector textures, float delay) : Sprite2D::Sprite2D() { - m_delay = delay; + m_spritespeed = delay; Size = UDim2::fromScale(1, 1); Position = UDim2::fromOffset(0, 0); AnchorPoint = { 0, 0 }; @@ -42,7 +42,7 @@ Sprite2D::Sprite2D(std::vector textures, float delay) : S Sprite2D::Sprite2D(std::vector textures, float delay) : Sprite2D::Sprite2D() { - m_delay = delay; + m_spritespeed = delay; Size = UDim2::fromScale(1, 1); Position = UDim2::fromOffset(0, 0); AnchorPoint = { 0, 0 }; @@ -64,7 +64,7 @@ void Sprite2D::Draw(double delta, bool manual) Draw(delta, nullptr, manual); } -void Sprite2D::Draw(double delta, Rect *rect, bool manual) +void Sprite2D::Draw(double delta, Rect *rect, bool manual) // Original code, play image sprite loop { auto tex = m_textures[m_currentIndex]; GameWindow *window = GameWindow::GetInstance(); @@ -84,15 +84,88 @@ void Sprite2D::Draw(double delta, Rect *rect, bool manual) tex->AnchorPoint = AnchorPoint; tex->Draw(rect, manual ? false : true); - if (m_delay > 0.0f) { + if (m_spritespeed > 0.0f) { m_currentTime += static_cast(delta); - if (m_currentTime >= m_delay) { + if (m_currentTime >= m_spritespeed) { m_currentTime = 0.0f; m_currentIndex = (m_currentIndex + 1) % m_textures.size(); } } } +void Sprite2D::DrawOnce(double delta, bool manual) { // Play whole image sprite once + if (m_currentIndex >= m_textures.size()) { + return; + } + + auto tex = m_textures[m_currentIndex]; + GameWindow* window = GameWindow::GetInstance(); + + double xPos = (window->GetBufferWidth() * Position.X.Scale) + (Position.X.Offset); + double yPos = (window->GetBufferHeight() * Position.Y.Scale) + (Position.Y.Offset); + + double xMPos = (window->GetBufferWidth() * Position2.X.Scale) + (Position2.X.Offset); + double yMPos = (window->GetBufferHeight() * Position2.Y.Scale) + (Position2.Y.Offset); + + xPos += xMPos; + yPos += yMPos; + + tex->Position = UDim2::fromOffset(xPos, yPos); + tex->AlphaBlend = AlphaBlend; + tex->Size = Size; + tex->AnchorPoint = AnchorPoint; + tex->Draw(); + + if (m_spritespeed > 0.0f) { + m_currentTime += static_cast(delta); + if (m_currentTime >= m_spritespeed) { + m_currentTime = 0.0f; + m_currentIndex++; + + if (m_currentIndex == m_textures.size() && m_drawOnce) { + return; + } + } + } +} + +void Sprite2D::DrawStop(double delta, bool manual) { // Play image sprite once and stop on last frame + if (m_currentIndex >= m_textures.size()) { + m_currentIndex = static_cast(m_textures.size()) - 1; + } + + auto tex = m_textures[m_currentIndex]; + GameWindow* window = GameWindow::GetInstance(); + + double xPos = (window->GetBufferWidth() * Position.X.Scale) + (Position.X.Offset); + double yPos = (window->GetBufferHeight() * Position.Y.Scale) + (Position.Y.Offset); + + double xMPos = (window->GetBufferWidth() * Position2.X.Scale) + (Position2.X.Offset); + double yMPos = (window->GetBufferHeight() * Position2.Y.Scale) + (Position2.Y.Offset); + + xPos += xMPos; + yPos += yMPos; + + tex->Position = UDim2::fromOffset(xPos, yPos); + tex->AlphaBlend = AlphaBlend; + tex->Size = Size; + tex->AnchorPoint = AnchorPoint; + tex->Draw(); + + if (m_spritespeed > 0.0f) { + m_currentTime += static_cast(delta); + if (m_currentTime >= m_spritespeed) { + m_currentTime = 0.0f; + m_currentIndex++; + + if (m_currentIndex == m_textures.size() && m_drawOnce) { + return; + } + } + } +} + + void Sprite2D::Reset() { m_currentIndex = 0; @@ -111,5 +184,5 @@ Texture2D *Sprite2D::GetTexture() void Sprite2D::SetFPS(float fps) { - m_delay = 1.0f / fps; + m_spritespeed = 1.0f / fps; } \ No newline at end of file diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index d0f94d7e..7d8cc93a 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -228,7 +228,7 @@ void GameplayScene::Render(double delta) if (m_drawJam) { if (std::get<5>(scores) > 0) { m_jamNum->DrawNumber(std::get<5>(scores)); - m_jamLogo->Draw(delta); + m_jamLogo->DrawStop(delta); // Example for DrawStop } if ((m_jamTimer += delta) > 0.60) { From ee16279393dc4eca9122e1904fec0a185faedcd3 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 18 Feb 2024 16:13:03 +0700 Subject: [PATCH 027/126] refactor(gameplayscene): fix for visual modifier --- Game/src/Scenes/GameplayScene.cpp | 46 ++++++++++--------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 7d8cc93a..cb5a7570 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -117,8 +117,6 @@ void GameplayScene::Render(double delta) ImguiUtil::NewFrame(); - bool is_flhd_enabled = m_laneHideImage.get() != nullptr; - int arena = EnvironmentSetup::GetInt("Arena"); if (arena != -1) { @@ -133,40 +131,26 @@ void GameplayScene::Render(double delta) m_Playfield->Draw(); m_Playfooter->Draw(); + m_targetBar->Draw(delta); + + for (auto& [lane, pressed] : m_keyState) { + if (pressed) { + m_keyLighting[lane]->AlphaBlend = true; + m_keyLighting[lane]->Draw(); + m_keyButtons[lane]->Draw(); + } + } + + m_game->Render(delta); + // Draw Mods - if (m_noteMod) { // Fix Crash + if (m_noteMod) { m_noteMod->Draw(); } - if (m_visualMod) { // Fix Crash + if (m_visualMod) { m_visualMod->Draw(); - } - // Maybe u decided below - if (!is_flhd_enabled) { - for (auto& [lane, pressed] : m_keyState) { - if (pressed) { - m_keyLighting[lane]->AlphaBlend = true; - m_keyLighting[lane]->Draw(); - m_keyButtons[lane]->Draw(); - } - } - m_targetBar->Draw(delta); - m_targetBar->AlphaBlend = true; // Fix for some cases (Resource updated) - m_game->Render(delta); - } - - if (is_flhd_enabled) { - for (auto& [lane, pressed] : m_keyState) { - if (pressed) { - m_keyLighting[lane]->AlphaBlend = true; - m_keyLighting[lane]->Draw(); - m_keyButtons[lane]->Draw(); - } - } - m_game->Render(delta); + m_laneHideImage.get(); m_laneHideImage->Draw(); - m_targetBar->Draw(delta); - m_targetBar->AlphaBlend = true; // Fix for some cases (Resource updated) - } auto scores = m_game->GetScoreManager()->GetScore(); From 44ef4166fb49cf8672e49030c1f2139fa7815d3b Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 18 Feb 2024 19:42:30 +0700 Subject: [PATCH 028/126] refactor(gameplayscene): remove unused code --- Game/src/Scenes/GameplayScene.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index cb5a7570..640304f0 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -149,7 +149,6 @@ void GameplayScene::Render(double delta) } if (m_visualMod) { m_visualMod->Draw(); - m_laneHideImage.get(); m_laneHideImage->Draw(); } From 4d74bc4ee9186b72309fbb998f6bd93fa8206298 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 20 Feb 2024 20:02:13 +0700 Subject: [PATCH 029/126] feat: fix thread and performance overtime --- .../include/Rendering/Threading/GameThread.h | 3 + Engine/src/Threading/GameThread.cpp | 61 +++++++++++++------ Game/src/Scenes/Overlays/Settings.cpp | 2 +- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/Engine/include/Rendering/Threading/GameThread.h b/Engine/include/Rendering/Threading/GameThread.h index 8b61218c..e15a4378 100644 --- a/Engine/include/Rendering/Threading/GameThread.h +++ b/Engine/include/Rendering/Threading/GameThread.h @@ -2,6 +2,7 @@ #include #include #include +#include class GameThread { @@ -19,6 +20,8 @@ class GameThread bool m_run; bool m_background; + std::mutex m_mutex; + std::thread m_thread; std::function m_main_cb; diff --git a/Engine/src/Threading/GameThread.cpp b/Engine/src/Threading/GameThread.cpp index e60f32ab..522abb31 100644 --- a/Engine/src/Threading/GameThread.cpp +++ b/Engine/src/Threading/GameThread.cpp @@ -20,39 +20,62 @@ void GameThread::Run(std::function callback, bool background) m_background = background; if (background) { - m_thread = std::thread([&] { + m_thread = std::thread([this] { while (m_run) { - m_main_cb(); - - if (m_queue_cb.size()) { - std::function queue_cb = m_queue_cb.back(); - m_queue_cb.pop_back(); + std::function main_cb; + { + std::lock_guard lock(m_mutex); + main_cb = m_main_cb; + } + if (main_cb) { + main_cb(); + } + std::function queue_cb; + { + std::lock_guard lock(m_mutex); + if (!m_queue_cb.empty()) { + queue_cb = m_queue_cb.front(); + m_queue_cb.pop_back(); + } + } + if (queue_cb) { queue_cb(); } } - }); + }); } } void GameThread::Update() { - if (m_background) { - return; - } - - m_main_cb(); + if (!m_background) { + std::function main_cb; + { + std::lock_guard lock(m_mutex); + main_cb = m_main_cb; + } + if (main_cb) { + main_cb(); + } - if (m_queue_cb.size()) { - std::function queue_cb = m_queue_cb.back(); - m_queue_cb.pop_back(); - - queue_cb(); + std::function queue_cb; + { + std::lock_guard lock(m_mutex); + if (!m_queue_cb.empty()) { + queue_cb = m_queue_cb.back(); + m_queue_cb.pop_back(); + } + } + if (queue_cb) { + queue_cb(); + } } } void GameThread::QueueAction(std::function callback) { + std::lock_guard lock(m_mutex); m_queue_cb.push_back(callback); } @@ -60,6 +83,8 @@ void GameThread::Stop() { if (m_background) { m_run = false; - m_thread.join(); + if (m_thread.joinable()) { + m_thread.join(); + } } } diff --git a/Game/src/Scenes/Overlays/Settings.cpp b/Game/src/Scenes/Overlays/Settings.cpp index c41e218a..81d74ad6 100644 --- a/Game/src/Scenes/Overlays/Settings.cpp +++ b/Game/src/Scenes/Overlays/Settings.cpp @@ -453,7 +453,7 @@ void SettingsOverlay::LoadConfiguration() auto fps = m_fps[currentFPSIndex]; if (fps == *(m_fps.end() - 1)) { - fps = "9999"; + fps = "-1"; // Unlimited } SceneManager::GetInstance()->SetFrameLimit(std::atof(fps.c_str())); From 35c07b460b711e39a95930381438226b21c1aa61 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 20 Feb 2024 20:05:41 +0700 Subject: [PATCH 030/126] refactor(drawablenote): temporary fix render on note --- Game/src/Engine/DrawableNote.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Game/src/Engine/DrawableNote.cpp b/Game/src/Engine/DrawableNote.cpp index 65996500..00112263 100644 --- a/Game/src/Engine/DrawableNote.cpp +++ b/Game/src/Engine/DrawableNote.cpp @@ -23,5 +23,4 @@ DrawableNote::DrawableNote(NoteImage *frame) : FrameTimer::FrameTimer() _frame->SetOriginalRECT(frame->TextureRect); } - SetFPS(30); //TODO: Fix animation render glitch, i can't figure it out -} + SetFPS(1000); // FIXME: i had to use this value otherwise it has glitch From 8e21d1a7a23210518688a0d56f876a978679c9b6 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 20 Feb 2024 22:20:43 +0700 Subject: [PATCH 031/126] refactor(gameplayscene): TargetBar AlphaBlend --- Game/src/Scenes/GameplayScene.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 640304f0..ce84021b 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -132,6 +132,7 @@ void GameplayScene::Render(double delta) m_Playfooter->Draw(); m_targetBar->Draw(delta); + m_targetBar->AlphaBlend = true; for (auto& [lane, pressed] : m_keyState) { if (pressed) { From 8e32379252a70e5e6bd63c965c2d8d6a5c579683 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 20 Feb 2024 22:33:49 +0700 Subject: [PATCH 032/126] typo --- Game/src/Engine/DrawableNote.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Game/src/Engine/DrawableNote.cpp b/Game/src/Engine/DrawableNote.cpp index 00112263..cb3b4e12 100644 --- a/Game/src/Engine/DrawableNote.cpp +++ b/Game/src/Engine/DrawableNote.cpp @@ -3,24 +3,26 @@ #include "Rendering/Renderer.h" #include "Texture/Texture2D.h" -DrawableNote::DrawableNote(NoteImage *frame) : FrameTimer::FrameTimer() +DrawableNote::DrawableNote(NoteImage* frame) : FrameTimer::FrameTimer() { - m_frames = std::vector(); + m_frames = std::vector(); if (Renderer::GetInstance()->IsVulkan()) { - for (auto &frame : frame->VulkanTexture) { + for (auto& frame : frame->VulkanTexture) { m_frames.push_back(new Texture2D(frame)); } - } else { - for (auto &frame : frame->Texture) { + } + else { + for (auto& frame : frame->Texture) { m_frames.push_back(new Texture2D(frame)); } } AnchorPoint = { 0.0, 1.0 }; - for (auto &_frame : m_frames) { + for (auto& _frame : m_frames) { _frame->SetOriginalRECT(frame->TextureRect); } SetFPS(1000); // FIXME: i had to use this value otherwise it has glitch +} \ No newline at end of file From c24e1851bea674d9d749e62d011d286c92b36070 Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:53:23 +0700 Subject: [PATCH 033/126] feat: better implementation song bg --- Game/src/Scenes/GameplayScene.cpp | 15 +++++++++++---- Game/src/Scenes/SongSelectScene.cpp | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index ce84021b..1aeb9f9f 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -119,14 +119,21 @@ void GameplayScene::Render(double delta) int arena = EnvironmentSetup::GetInt("Arena"); - if (arena != -1) { - m_PlayBG->Draw(); - } else { - auto songBG = (Texture2D *)EnvironmentSetup::GetObj("SongBackground"); + bool useSongBG = EnvironmentSetup::GetInt("Song BG") == 1; + bool blackBG = EnvironmentSetup::GetInt("Black BG") == 1; + + if (useSongBG) { + auto songBG = (Texture2D*)EnvironmentSetup::GetObj("SongBackground"); if (songBG) { songBG->Draw(); } } + else if (blackBG) { + // Do nothing + } + else { + m_PlayBG->Draw(); + } m_Playfield->Draw(); m_Playfooter->Draw(); diff --git a/Game/src/Scenes/SongSelectScene.cpp b/Game/src/Scenes/SongSelectScene.cpp index ea18eff0..514db7c9 100644 --- a/Game/src/Scenes/SongSelectScene.cpp +++ b/Game/src/Scenes/SongSelectScene.cpp @@ -28,8 +28,8 @@ #include "../Data/Chart.hpp" #include "../Data/Util/Util.hpp" -static std::array Mods = { "Mirror", "Random", "Panic", "Rearrange", "Autoplay", "Hidden", "Flashlight", "Sudden" }; -static std::array Arena = { "Music Background", "Random", +static std::array Mods = { "Mirror", "Random", "Panic (FixMe)", "Rearrange", "Autoplay", "Hidden", "Flashlight", "Sudden", "Song BG", "Black BG" }; +static std::array Arena = { "Random", "Arena 1", "Arena 2", "Arena 3", "Arena 4", "Arena 5", "Arena 6", "Arena 7", "Arena 8", "Arena 9", "Arena 10", "Arena 11", "Arena 12" }; SongSelectScene::SongSelectScene() @@ -459,7 +459,7 @@ void SongSelectScene::OnGameSelectMusic(double delta) ImGui::Spacing(); ImGui::PushItemWidth(ImGui::GetCurrentWindow()->Size.x - 15); - ImGui::Text("Notespeed"); + ImGui::Text("Note speed"); { ImGui::InputFloat("###NoteSpeed", ¤tSpeed, 0.05f, 0.1f, "%.2f"); currentSpeed = std::clamp(currentSpeed, 0.1f, 4.0f); @@ -473,7 +473,7 @@ void SongSelectScene::OnGameSelectMusic(double delta) ImGui::PopItemWidth(); - ImGui::Text("Mods"); + ImGui::Text("Modifier"); for (int i = 0; i < Mods.size(); i++) { auto &mod = Mods[i]; @@ -523,6 +523,12 @@ void SongSelectScene::OnGameSelectMusic(double delta) EnvironmentSetup::SetInt(Mods[5], 0); // Hidden EnvironmentSetup::SetInt(Mods[6], 0); // Flashlight break; + case 8: // Song Background + EnvironmentSetup::SetInt(Mods[9], 0); // Black Background + break; + case 9: // Black Background + EnvironmentSetup::SetInt(Mods[8], 0); // Song Background + break; } } @@ -543,12 +549,12 @@ void SongSelectScene::OnGameSelectMusic(double delta) ImGui::Text("Arena"); // select - int value = EnvironmentSetup::GetInt("Arena") + 1; + int value = EnvironmentSetup::GetInt("Arena"); if (ImGui::BeginCombo("###ComboBox1Arena", Arena[value].c_str(), 0)) { for (int i = 0; i < Arena.size(); i++) { bool is_selected = i == value; if (ImGui::Selectable(Arena[i].c_str(), is_selected)) { - EnvironmentSetup::SetInt("Arena", i - 1); + EnvironmentSetup::SetInt("Arena", i); } } From a3554e2b5327d620c687d87f0667126ae862f23b Mon Sep 17 00:00:00 2001 From: Albert Frengki <75172149+AlberttFrgk@users.noreply.github.com> Date: Sun, 25 Feb 2024 12:09:04 +0700 Subject: [PATCH 034/126] refactor(gameplayscene): move some code and clean things --- Game/src/Scenes/GameplayScene.cpp | 71 ++++++++++++++++--------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/Game/src/Scenes/GameplayScene.cpp b/Game/src/Scenes/GameplayScene.cpp index 1aeb9f9f..1db5234e 100644 --- a/Game/src/Scenes/GameplayScene.cpp +++ b/Game/src/Scenes/GameplayScene.cpp @@ -57,7 +57,8 @@ void GameplayScene::Update(double delta) if (EnvironmentSetup::GetInt("Key") >= 0) { m_ended = true; SceneManager::ChangeScene(GameScene::SONGSELECT); - } else { + } + else { if (MsgBox::GetResult("GameplayError") == 4) { m_ended = true; SceneManager::GetInstance()->StopGame(); @@ -77,7 +78,7 @@ void GameplayScene::Update(double delta) m_ended = true; SceneManager::DisplayFade(100, [] { SceneManager::ChangeScene(GameScene::RESULT); - }); + }); } int difficulty = EnvironmentSetup::GetInt("Difficulty"); @@ -97,11 +98,12 @@ void GameplayScene::Update(double delta) if (std::get<1>(scores) != 0 || std::get<2>(scores) != 0 || std::get<3>(scores) != 0 || std::get<4>(scores) != 0) { SceneManager::DisplayFade(100, [] { SceneManager::ChangeScene(GameScene::RESULT); - }); - } else { + }); + } + else { SceneManager::DisplayFade(100, [] { SceneManager::ChangeScene(GameScene::SONGSELECT); - }); + }); } } @@ -125,6 +127,7 @@ void GameplayScene::Render(double delta) if (useSongBG) { auto songBG = (Texture2D*)EnvironmentSetup::GetObj("SongBackground"); if (songBG) { + songBG->TintColor = Color3::FromRGB(128, 128, 128); songBG->Draw(); } } @@ -287,7 +290,8 @@ void GameplayScene::Render(double delta) }; m_jamGauge->Draw(&rc); - } else { + } + else { // Fill from left to right lerp = static_cast(std::lerp(0.0, m_jamGauge->AbsoluteSize.X, gaugeVal)); Rect rc = { @@ -354,7 +358,8 @@ void GameplayScene::Render(double delta) int idx = 2; try { idx = std::stoi(Configuration::Load("Game", "GuideLine")); - } catch (const std::invalid_argument &) { + } + catch (const std::invalid_argument&) { idx = 2; } @@ -369,7 +374,7 @@ void GameplayScene::Input(double delta) m_game->Input(delta); } -void GameplayScene::OnKeyDown(const KeyState &state) +void GameplayScene::OnKeyDown(const KeyState& state) { if (m_resourceFucked) return; @@ -377,7 +382,7 @@ void GameplayScene::OnKeyDown(const KeyState &state) m_game->OnKeyDown(state); } -void GameplayScene::OnKeyUp(const KeyState &state) +void GameplayScene::OnKeyUp(const KeyState& state) { if (m_resourceFucked) return; @@ -385,7 +390,7 @@ void GameplayScene::OnKeyUp(const KeyState &state) m_game->OnKeyUp(state); } -void GameplayScene::OnMouseDown(const MouseState &state) +void GameplayScene::OnMouseDown(const MouseState& state) { } @@ -410,7 +415,8 @@ bool GameplayScene::Attach() try { LaneOffset = std::stoi(manager->GetSkinProp("Game", "LaneOffset", "5")); HitPos = std::stoi(manager->GetSkinProp("Game", "HitPos", "480")); - } catch (const std::invalid_argument &) { + } + catch (const std::invalid_argument&) { throw std::runtime_error("Invalid parameter on Skin::Game::LaneOffset or Skin::Game::HitPos"); } @@ -669,11 +675,11 @@ bool GameplayScene::Attach() auto OnButtonHover = [&](int state) { m_drawExitButton = state; - }; + }; auto OnButtonClick = [&]() { m_doExit = true; - }; + }; m_exitButtonFunc = std::make_unique