diff --git a/src/factorio_log_parser.cpp b/src/factorio_log_parser.cpp index af32beb..c3b3ae3 100644 --- a/src/factorio_log_parser.cpp +++ b/src/factorio_log_parser.cpp @@ -14,7 +14,17 @@ FactorioLogParser::FactorioLogParser(ConfigModelI& conf) : FactorioLogParser::~FactorioLogParser(void) { } -float FactorioLogParser::tick(float) { +float FactorioLogParser::tick(float delta) { + { // making sure, incase mod events dont work + _manual_timer += delta; + if (_manual_timer >= 10.f) { + _manual_timer = 0.f; + if (_log_file.is_open()) { + readLines(); + } + } + } + std::lock_guard lg{_event_queue_mutex}; while (!_event_queue.empty()) { dispatchRaw(_event_queue.front().event, _event_queue.front().params); @@ -36,19 +46,7 @@ void FactorioLogParser::onFileEvent(const std::string& path, const filewatch::Ev std::cerr << "FLP: modified file not open!\n"; //resetLogFile(); } else { - std::string line; - while (std::getline(_log_file, line).good()) { - if (line.empty()) { - std::cerr << "FLP error: getline empty??\n"; - continue; - } - - const auto parse_res = log_parse_line(line); - if (parse_res.has_value()) { - queueRaw(parse_res.value().event, parse_res.value().params); - } - } - _log_file.clear(); // reset eof and fail bits + readLines(); } } } @@ -65,6 +63,22 @@ void FactorioLogParser::resetLogFile(void) { } } +void FactorioLogParser::readLines(void) { + std::string line; + while (std::getline(_log_file, line).good()) { + if (line.empty()) { + std::cerr << "FLP error: getline empty??\n"; + continue; + } + + const auto parse_res = log_parse_line(line); + if (parse_res.has_value()) { + queueRaw(parse_res.value().event, parse_res.value().params); + } + } + _log_file.clear(); // reset eof and fail bits +} + void FactorioLogParser::queueRaw(std::string_view event, std::string_view params) { std::lock_guard lg{_event_queue_mutex}; _event_queue.push(EventEntry{static_cast(event), static_cast(params)}); diff --git a/src/factorio_log_parser.hpp b/src/factorio_log_parser.hpp index 5fdc6f3..0a2eecc 100644 --- a/src/factorio_log_parser.hpp +++ b/src/factorio_log_parser.hpp @@ -94,6 +94,8 @@ class FactorioLogParser : public FactorioLogParserEventProviderI { std::queue _event_queue; std::mutex _event_queue_mutex; + float _manual_timer {1.f}; + public: FactorioLogParser(ConfigModelI& conf); virtual ~FactorioLogParser(void); @@ -103,6 +105,8 @@ class FactorioLogParser : public FactorioLogParserEventProviderI { protected: void onFileEvent(const std::string& path, const filewatch::Event change_type); void resetLogFile(void); + // assumes file is open! + void readLines(void); protected: void queueRaw(std::string_view event, std::string_view params);