fallback for no file mod events
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Failing after 21s
ContinuousIntegration / linux (push) Successful in 21s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled

This commit is contained in:
Green Sky 2024-06-12 22:24:47 +02:00
parent a91b4d41dd
commit 4c6beb592c
No known key found for this signature in database
2 changed files with 32 additions and 14 deletions

View File

@ -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<std::string>(event), static_cast<std::string>(params)});

View File

@ -94,6 +94,8 @@ class FactorioLogParser : public FactorioLogParserEventProviderI {
std::queue<EventEntry> _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);