diff --git a/src/Cool/Log/MessageConsole.cpp b/src/Cool/Log/MessageConsole.cpp index 0ecb5ac47..22e8d5f93 100644 --- a/src/Cool/Log/MessageConsole.cpp +++ b/src/Cool/Log/MessageConsole.cpp @@ -51,14 +51,6 @@ void MessageConsole::on_message_sent(const internal::RawMessageId& id) { _is_open = true; _message_just_sent = id; - if (_messages.underlying_container().underlying_container().size() > 999) // If there are too many messages the console starts to cause lag. - { - auto const it = std::find_if(_messages.begin(), _messages.end(), [](auto const& pair) { - return is_clearable(pair.second); - }); - if (it != _messages.end()) - _messages.underlying_container().underlying_container().erase(it); - } } void MessageConsole::remove(const MessageId& id) @@ -195,8 +187,24 @@ void MessageConsole::show_number_of_messages_of_given_severity(MessageSeverity s } } +void MessageConsole::remove_messages_to_keep_size_below(size_t max_number_of_messages) +{ + while (_messages.underlying_container().underlying_container().size() > max_number_of_messages) + { + auto const it = std::find_if(_messages.begin(), _messages.end(), [](auto const& pair) { + return is_clearable(pair.second); + }); + if (it != _messages.end()) + _messages.underlying_container().underlying_container().erase(it); + else + break; + } +} + void MessageConsole::imgui_window() { + remove_messages_to_keep_size_below(999); // If there are too many messages the console starts to cause lag. + if (_is_open) { refresh_counts_per_severity(); diff --git a/src/Cool/Log/MessageConsole.h b/src/Cool/Log/MessageConsole.h index 9e6aa91b0..c6883630f 100644 --- a/src/Cool/Log/MessageConsole.h +++ b/src/Cool/Log/MessageConsole.h @@ -45,17 +45,18 @@ class MessageConsole { void imgui_window(); private: - void remove(const internal::RawMessageId&); - void close_window_if_empty(); - void close_window(); - void on_message_sent(const internal::RawMessageId&); - void show_number_of_messages_of_given_severity(MessageSeverity); - void refresh_counts_per_severity(); - void imgui_menu_bar(); - void imgui_show_all_messages(); - auto there_are_clearable_messages() const -> bool; - auto there_are_clearable_messages(MessageSeverity) const -> bool; - auto should_show(const internal::MessageWithMetadata&) const -> bool; + void remove(const internal::RawMessageId&); + void close_window_if_empty(); + void close_window(); + void on_message_sent(const internal::RawMessageId&); + void show_number_of_messages_of_given_severity(MessageSeverity); + void refresh_counts_per_severity(); + void imgui_menu_bar(); + void imgui_show_all_messages(); + [[nodiscard]] auto there_are_clearable_messages() const -> bool; + [[nodiscard]] auto there_are_clearable_messages(MessageSeverity) const -> bool; + [[nodiscard]] auto should_show(const internal::MessageWithMetadata&) const -> bool; + void remove_messages_to_keep_size_below(size_t max_number_of_messages); class MessagesCountPerSeverity { public: