#pragma once #include "sys/sys.hpp" #include "ui/DialogBox.hpp" #include "ui/PopMessage.hpp" #include #include #include namespace ui { class PopMessageManager final { public: // No copying. PopMessageManager(const PopMessageManager &) = delete; PopMessageManager(PopMessageManager &&) = delete; PopMessageManager &operator=(const PopMessageManager &) = delete; PopMessageManager &operator=(PopMessageManager &&) = delete; /// @brief Updates and processes message queue. static void update(); /// @brief Renders messages to screen. static void render(); /// @brief Pushes a new message to the queue for processing. static void push_message(int displayTicks, std::string_view message); /// @brief Move version of above. static void push_message(int displayTicks, std::string &message); /// @brief The default duration of ticks for messages to be shown. static constexpr int DEFAULT_TICKS = 2500; private: // Only one instance allowed. PopMessageManager() = default; // Returns the only instance. static PopMessageManager &get_instance() { static PopMessageManager manager; return manager; } // The queue for processing. SDL can't handle things being rendered in multiple threads. std::vector> m_messageQueue{}; // Actual vector of messages std::vector m_messages{}; // Mutex to attempt to make this thread safe. std::mutex m_messageMutex{}; std::mutex m_queueMutex{}; }; } // namespace ui