timing calc for longer sleep in host program
This commit is contained in:
parent
2b73d76f93
commit
6a48ace06f
@ -27,7 +27,9 @@ ZoxNGCHistorySync::ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProvider
|
|||||||
subscribeToEvents();
|
subscribeToEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoxNGCHistorySync::tick(float delta) {
|
float ZoxNGCHistorySync::tick(float delta) {
|
||||||
|
float min_interval {_delay_next_request_min*60.f};
|
||||||
|
|
||||||
// send queued requests
|
// send queued requests
|
||||||
for (auto it = _request_queue.begin(); it != _request_queue.end();) {
|
for (auto it = _request_queue.begin(); it != _request_queue.end();) {
|
||||||
it->second.timer += delta;
|
it->second.timer += delta;
|
||||||
@ -57,7 +59,11 @@ void ZoxNGCHistorySync::tick(float delta) {
|
|||||||
// on failure, assume disconnected
|
// on failure, assume disconnected
|
||||||
it = _request_queue.erase(it);
|
it = _request_queue.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// just choose something small, since we expect a response might arrive soon
|
||||||
|
min_interval = std::min(min_interval, _delay_between_syncs_min);
|
||||||
} else {
|
} else {
|
||||||
|
min_interval = std::min(min_interval, it->second.delay - it->second.timer);
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +72,8 @@ void ZoxNGCHistorySync::tick(float delta) {
|
|||||||
it->second.timer += delta;
|
it->second.timer += delta;
|
||||||
if (it->second.timer >= it->second.delay) {
|
if (it->second.timer >= it->second.delay) {
|
||||||
it->second.timer = 0.f;
|
it->second.timer = 0.f;
|
||||||
|
// TODO: set min_interval?
|
||||||
|
|
||||||
Message3 msg_e = it->second.ents.front();
|
Message3 msg_e = it->second.ents.front();
|
||||||
it->second.ents.pop();
|
it->second.ents.pop();
|
||||||
|
|
||||||
@ -119,10 +127,14 @@ void ZoxNGCHistorySync::tick(float delta) {
|
|||||||
it = _sync_queue.erase(it);
|
it = _sync_queue.erase(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
min_interval = std::min(min_interval, it->second.delay - it->second.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return min_interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoxNGCHistorySync::sendRequest(
|
bool ZoxNGCHistorySync::sendRequest(
|
||||||
|
@ -69,7 +69,7 @@ class ZoxNGCHistorySync : public ToxEventI, public ZoxNGCEventI {
|
|||||||
public:
|
public:
|
||||||
ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProviderI& zngcepi, ToxI& t, Contact3Registry& cr, ToxContactModel2& tcm, RegistryMessageModel& rmm);
|
ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProviderI& zngcepi, ToxI& t, Contact3Registry& cr, ToxContactModel2& tcm, RegistryMessageModel& rmm);
|
||||||
|
|
||||||
void tick(float delta);
|
float tick(float delta);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// always private
|
// always private
|
||||||
|
Loading…
Reference in New Issue
Block a user