Extract QueueManager from MusicManager
Move the playback queue + shuffle state (the queue vector, shuffled-index list, shuffle cursor, next-queue-id counter, and RNG) into a QueueManager class. To preserve the real-time playback loop's exact behavior, the design is deliberately minimal: QueueManager is a non-thread-safe data holder that exposes its containers by reference, and MusicManager keeps its single playback mutex_/cv_ and drives QueueManager under it. Every former queue_/ shuffledIndices_/shuffleIndex_/nextQueueId_/rng_ site is a 1:1 rename to the accessor with identical semantics — no logic, locking, or ordering change. Build green. Runtime behavior in the live playback loop is unverified here (no audio/TeamSpeak); this is an isolated, revertible commit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
622335260f
commit
1efdbe0771
3 files changed
+150
-100
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include "Database.hpp"
|
||||
#include "NetworkClient.hpp"
|
||||
#include "PlaylistLoader.hpp"
|
||||
#include "QueueManager.hpp"
|
||||
#include "RpcTypes.hpp"
|
||||
#include "SubscriptionManager.hpp"
|
||||
#include "YouTubeClient.hpp"
|
||||
@@ -238,7 +239,8 @@ namespace Echoion::Core
|
||||
std::unique_ptr<SubscriptionManager> subscriptionManager_;
|
||||
|
||||
Api::BotConfig config_;
|
||||
std::vector<Api::QueueEntry> queue_;
|
||||
// Playback queue + shuffle state (driven under mutex_).
|
||||
QueueManager queueMgr_;
|
||||
std::optional<Api::QueueEntry> currentTrack_;
|
||||
std::atomic<bool> isPlaying_{false};
|
||||
std::atomic<bool> isPaused_{false};
|
||||
@@ -254,11 +256,7 @@ namespace Echoion::Core
|
||||
std::atomic<float> volume_{0.5f};
|
||||
std::atomic<bool> shuffle_{false};
|
||||
std::atomic<bool> repeat_{false};
|
||||
uint64_t nextQueueId_ = 1;
|
||||
|
||||
// Shuffle state - maintains shuffled order of queue indices
|
||||
std::vector<size_t> shuffledIndices_;
|
||||
size_t shuffleIndex_ = 0;
|
||||
void rebuildShuffledIndices();
|
||||
void reshuffleRemaining();
|
||||
|
||||
@@ -279,7 +277,6 @@ namespace Echoion::Core
|
||||
ClientInfoCallback clientInfoCallback_;
|
||||
UidToClientIdCallback uidToClientIdCallback_;
|
||||
NicknameCallback nicknameCallback_;
|
||||
std::mt19937 rng_{std::random_device{}()};
|
||||
|
||||
// Position tracking for periodic event updates
|
||||
std::chrono::steady_clock::time_point lastPositionUpdate_{};
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <TrackTypes.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
// Owns the playback queue and its shuffle state. NOT thread-safe by
|
||||
// design: the owning MusicManager serializes every access under its
|
||||
// playback mutex_, so the single-lock model of the real-time loop is
|
||||
// preserved. The containers are exposed by reference so the playback loop
|
||||
// keeps operating on them with identical semantics.
|
||||
class QueueManager
|
||||
{
|
||||
public:
|
||||
|
||||
using Entry = Api::QueueEntry;
|
||||
|
||||
[[nodiscard]] std::vector<Entry>& entries() noexcept
|
||||
{
|
||||
return entries_;
|
||||
}
|
||||
[[nodiscard]] const std::vector<Entry>& entries() const noexcept
|
||||
{
|
||||
return entries_;
|
||||
}
|
||||
[[nodiscard]] std::vector<std::size_t>& shuffledIndices() noexcept
|
||||
{
|
||||
return shuffledIndices_;
|
||||
}
|
||||
[[nodiscard]] std::size_t& shuffleIndex() noexcept
|
||||
{
|
||||
return shuffleIndex_;
|
||||
}
|
||||
[[nodiscard]] std::uint64_t& nextQueueId() noexcept
|
||||
{
|
||||
return nextQueueId_;
|
||||
}
|
||||
[[nodiscard]] std::mt19937& rng() noexcept { return rng_; }
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Entry> entries_;
|
||||
std::vector<std::size_t> shuffledIndices_;
|
||||
std::size_t shuffleIndex_ = 0;
|
||||
std::uint64_t nextQueueId_ = 1;
|
||||
std::mt19937 rng_{std::random_device{}()};
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user