mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 13:53:37 +00:00
[traffic] Properly process message replacement
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -639,6 +639,13 @@ void TrafficManager::DecodeFirstMessage()
|
|||||||
|
|
||||||
// store message in cache
|
// store message in cache
|
||||||
m_messageCache.insert_or_assign(message.m_id, message);
|
m_messageCache.insert_or_assign(message.m_id, message);
|
||||||
|
|
||||||
|
for (auto & replaced : message.m_replaces)
|
||||||
|
{
|
||||||
|
auto it = m_messageCache.find(replaced);
|
||||||
|
if (it != m_messageCache.cend())
|
||||||
|
m_messageCache.erase(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* TODO detect if we can do a quick update:
|
* TODO detect if we can do a quick update:
|
||||||
|
|||||||
@@ -210,29 +210,43 @@ void TraffDecoder::DecodeMessage(traffxml::TraffMessage & message)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
traffxml::MultiMwmColoring decoded;
|
traffxml::MultiMwmColoring decoded;
|
||||||
|
bool isDecoded = false;
|
||||||
|
|
||||||
auto it = m_messageCache.find(message.m_id);
|
std::vector<std::string> ids = message.m_replaces;
|
||||||
if ((it != m_messageCache.end())
|
ids.insert(ids.begin(), message.m_id);
|
||||||
&& !it->second.m_decoded.empty()
|
|
||||||
&& (it->second.m_location == message.m_location))
|
for (auto & id : ids)
|
||||||
{
|
{
|
||||||
// cache already has a message with reusable location
|
auto it = m_messageCache.find(id);
|
||||||
|
if ((it != m_messageCache.end())
|
||||||
LOG(LINFO, (" Location for message", message.m_id, "can be reused from cache"));
|
&& !it->second.m_decoded.empty()
|
||||||
|
&& (it->second.m_location == message.m_location))
|
||||||
std::optional<traffxml::TrafficImpact> cachedImpact = it->second.GetTrafficImpact();
|
|
||||||
if (cachedImpact.has_value() && cachedImpact.value() == impact.value())
|
|
||||||
{
|
{
|
||||||
LOG(LINFO, (" Impact for message", message.m_id, "unchanged, reusing cached coloring"));
|
// cache already has a message with reusable location
|
||||||
|
|
||||||
// same impact, m_decoded can be reused altogether
|
LOG(LINFO, (" Location for message", message.m_id, "can be reused from cache"));
|
||||||
message.m_decoded = it->second.m_decoded;
|
|
||||||
return;
|
std::optional<traffxml::TrafficImpact> cachedImpact = it->second.GetTrafficImpact();
|
||||||
|
if (cachedImpact.has_value() && cachedImpact.value() == impact.value())
|
||||||
|
{
|
||||||
|
LOG(LINFO, (" Impact for message", message.m_id, "unchanged, reusing cached coloring"));
|
||||||
|
|
||||||
|
// same impact, m_decoded can be reused altogether
|
||||||
|
message.m_decoded = it->second.m_decoded;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (!isDecoded)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* populate only on first occurrence but continue searching, we might find a matching
|
||||||
|
* location with matching impact
|
||||||
|
*/
|
||||||
|
decoded = it->second.m_decoded;
|
||||||
|
isDecoded = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
decoded = it->second.m_decoded;
|
|
||||||
}
|
}
|
||||||
else
|
if (!isDecoded)
|
||||||
DecodeLocation(message, decoded);
|
DecodeLocation(message, decoded);
|
||||||
|
|
||||||
if (impact)
|
if (impact)
|
||||||
|
|||||||
Reference in New Issue
Block a user