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
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:
parent
a91b4d41dd
commit
4c6beb592c
@ -14,7 +14,17 @@ FactorioLogParser::FactorioLogParser(ConfigModelI& conf) :
|
|||||||
FactorioLogParser::~FactorioLogParser(void) {
|
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};
|
std::lock_guard lg{_event_queue_mutex};
|
||||||
while (!_event_queue.empty()) {
|
while (!_event_queue.empty()) {
|
||||||
dispatchRaw(_event_queue.front().event, _event_queue.front().params);
|
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";
|
std::cerr << "FLP: modified file not open!\n";
|
||||||
//resetLogFile();
|
//resetLogFile();
|
||||||
} else {
|
} else {
|
||||||
std::string line;
|
readLines();
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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) {
|
void FactorioLogParser::queueRaw(std::string_view event, std::string_view params) {
|
||||||
std::lock_guard lg{_event_queue_mutex};
|
std::lock_guard lg{_event_queue_mutex};
|
||||||
_event_queue.push(EventEntry{static_cast<std::string>(event), static_cast<std::string>(params)});
|
_event_queue.push(EventEntry{static_cast<std::string>(event), static_cast<std::string>(params)});
|
||||||
|
@ -94,6 +94,8 @@ class FactorioLogParser : public FactorioLogParserEventProviderI {
|
|||||||
std::queue<EventEntry> _event_queue;
|
std::queue<EventEntry> _event_queue;
|
||||||
std::mutex _event_queue_mutex;
|
std::mutex _event_queue_mutex;
|
||||||
|
|
||||||
|
float _manual_timer {1.f};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FactorioLogParser(ConfigModelI& conf);
|
FactorioLogParser(ConfigModelI& conf);
|
||||||
virtual ~FactorioLogParser(void);
|
virtual ~FactorioLogParser(void);
|
||||||
@ -103,6 +105,8 @@ class FactorioLogParser : public FactorioLogParserEventProviderI {
|
|||||||
protected:
|
protected:
|
||||||
void onFileEvent(const std::string& path, const filewatch::Event change_type);
|
void onFileEvent(const std::string& path, const filewatch::Event change_type);
|
||||||
void resetLogFile(void);
|
void resetLogFile(void);
|
||||||
|
// assumes file is open!
|
||||||
|
void readLines(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void queueRaw(std::string_view event, std::string_view params);
|
void queueRaw(std::string_view event, std::string_view params);
|
||||||
|
Loading…
Reference in New Issue
Block a user