Skip to content

Commit

Permalink
Add route checker cache for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
KingfuChan committed Mar 17, 2022
1 parent 4072f64 commit 6d27291
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 20 deletions.
19 changes: 17 additions & 2 deletions MTEPlugIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ void CMTEPlugIn::OnFunctionCall(int FunctionId, const char* sItemString, POINT P
case TAG_ITEM_FUNCTION_RTE_INFO: {
if (!FlightPlan.IsValid()) break;
if (m_RouteChecker == nullptr) break;
char rc = m_RouteChecker->CheckFlightPlan(FlightPlan);
char rc = m_RouteChecker->CheckFlightPlan(FlightPlan, true); // force a refresh here to avoid error
if (rc == 'Y' || rc == ' ') break; // no need to show ok routes and cleared routes
DisplayRouteMessage(FlightPlan.GetFlightPlanData().GetOrigin(), FlightPlan.GetFlightPlanData().GetDestination());

Expand Down Expand Up @@ -694,20 +694,35 @@ void CMTEPlugIn::OnFlightPlanControllerAssignedDataUpdate(CFlightPlan FlightPlan
m_TrackedRecorder->SetCFLConfirmed(FlightPlan.GetCallsign(), false);
}
}
if (DataType == CTR_DATA_TYPE_FINAL_ALTITUDE && !FlightPlan.GetCorrelatedRadarTarget().GetPosition().GetTransponderC() && m_RouteChecker != nullptr) {
m_RouteChecker->CheckFlightPlan(FlightPlan, true);
}
if (DataType == CTR_DATA_TYPE_GROUND_STATE && m_DepartureSequence != nullptr) {
m_DepartureSequence->EditSequence(FlightPlan, 0);
}
}

void CMTEPlugIn::OnFlightPlanDisconnect(CFlightPlan FlightPlan)
{
if (!FlightPlan.IsValid()) return;
if (!FlightPlan.IsValid())
return;
if (m_RouteChecker != nullptr)
m_RouteChecker->RemoveCache(FlightPlan);
if (m_DepartureSequence != nullptr)
m_DepartureSequence->EditSequence(FlightPlan, -1);
if (FlightPlan.GetTrackingControllerIsMe())
m_TrackedRecorder->UpdateFlight(FlightPlan, false);
}

void CMTEPlugIn::OnFlightPlanFlightPlanDataUpdate(CFlightPlan FlightPlan)
{
if (!FlightPlan.IsValid())
return;
if (m_RouteChecker != nullptr) {
m_RouteChecker->CheckFlightPlan(FlightPlan, true);
}
}

void CMTEPlugIn::OnRadarTargetPositionUpdate(CRadarTarget RadarTarget)
{
if (!RadarTarget.IsValid())
Expand Down
1 change: 1 addition & 0 deletions MTEPlugIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CMTEPlugIn :
virtual void OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area);
virtual void OnFlightPlanControllerAssignedDataUpdate(CFlightPlan FlightPlan, int DataType);
virtual void OnFlightPlanDisconnect(CFlightPlan FlightPlan);
virtual void OnFlightPlanFlightPlanDataUpdate(CFlightPlan FlightPlan);
virtual void OnRadarTargetPositionUpdate(CRadarTarget RadarTarget);
virtual bool OnCompileCommand(const char* sCommandLine);

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Tag item functions:
+ **Open similar callsign list** - shows a list of all callsigns that are similar to the current one.
+ Selecting one will toggle native ***.find*** command.
+ **Restore assigned data** - restore previously assigned data for reconnected flights and start tracking.
+ Assigned data includes: *communication type, heading/DCT point, cleared altitude, final altitude, speed/Mach, rate, scratch pad*.
+ Assigned data includes: *communication type, squawk, heading/DCT point, cleared altitude, final altitude, speed/Mach, rate, scratch pad*.

Related command line functions:

Expand All @@ -159,4 +159,4 @@ All command line functions are case-insensitive, including those mentioned above

1. **.MTEP FR24 ICAO / .MTEP VARI ICAO** - opens [Flightradar24](https://www.flightradar24.com/) / [飞常准ADS-B](https://flightadsb.variflight.com/) in web browser and centers the map on the given **ICAO** airport. Only works with airports within sector file.
2. **.MTEP CURSOR ON/OFF** - turns mouse cursor into Topsky or Eurocat style; may conflict with other plugins. This setting will be saved in your EuroScope plugin settings.
3. **.MTEP NUM 0123456789** - sets custom number mapping to replace corresponding 0-9 characters, which will be used in **Actual altitude (m)** if below transition level (Tips: use with custom font, e.g. number underscores). Note that not all characters are available, use at own risk of crashing EuroScope (offline setting recommended). This setting will be saved in your EuroScope plugin settings.
3. **.MTEP NUM 0123456789** - sets custom number mapping to replace corresponding 0-9 characters, which will be used in **Actual altitude (m)** if below transition level (Tips: use with custom font, e.g. number underscores). Use at own risk of crashing EuroScope (offline setting recommended). This setting will be saved in your EuroScope plugin settings. Note that not all characters are available through command line, in which case a direct modification in settings should work.
44 changes: 30 additions & 14 deletions RouteChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,52 @@ list<string> RouteChecker::GetRouteInfo(string departure, string arrival)
return res;
}

char RouteChecker::CheckFlightPlan(EuroScopePlugIn::CFlightPlan FlightPlan)
char RouteChecker::CheckFlightPlan(EuroScopePlugIn::CFlightPlan FlightPlan, bool refresh)
{
// ? - no route for OD pair
// Y - route and alt ok
// L - route ok, alt not
// X - route not ok
// space - clearance received flag set
// pass refresh=true to force refresh, otherwise will look up in record
if (FlightPlan.GetClearenceFlag())
return ' ';
if (!refresh) {
auto r = m_Cache.find(FlightPlan.GetCallsign());
if (r != m_Cache.end()) {
return r->second;
}
}
char res;
EuroScopePlugIn::CFlightPlanData fpd = FlightPlan.GetFlightPlanData();
string od = string(fpd.GetOrigin()) + string(fpd.GetDestination());
list<RouteData> routes;
try {
routes = m_Data.at(od);
}
catch (out_of_range e) {
return '?';
auto rteit = m_Data.find(od);
if (rteit == m_Data.end()) {
res = '?';
}
char res = 'X';
for (auto& rd : routes) {
if (IsRouteValid(fpd.GetRoute(), rd.m_Route)) {
if (IsLevelValid(FlightPlan.GetFinalAltitude(), rd.m_EvenO, rd.m_FixAltStr, rd.m_MinAlt))
return 'Y';
else
res = 'L';
else {
res = 'X';
for (auto& rd : rteit->second) {
if (IsRouteValid(fpd.GetRoute(), rd.m_Route)) {
if (IsLevelValid(FlightPlan.GetFinalAltitude(), rd.m_EvenO, rd.m_FixAltStr, rd.m_MinAlt)) {
res = 'Y';
break;
}
else {
res = 'L';
}
}
}
}
m_Cache[FlightPlan.GetCallsign()] = res;
return res;
}

void RouteChecker::RemoveCache(EuroScopePlugIn::CFlightPlan FlightPlan)
{
m_Cache.erase(FlightPlan.GetCallsign());
}

bool RouteChecker::IsRouteValid(string planroute, string realroute)
{
string temproute = planroute;
Expand Down
4 changes: 3 additions & 1 deletion RouteChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class RouteChecker
~RouteChecker(void);

list<string> GetRouteInfo(string departure, string arrival); // for string display
char CheckFlightPlan(EuroScopePlugIn::CFlightPlan FlightPlan);
char CheckFlightPlan(EuroScopePlugIn::CFlightPlan FlightPlan, bool refresh = false);
void RemoveCache(EuroScopePlugIn::CFlightPlan FlightPlan);

private:
struct RouteData {
Expand All @@ -35,6 +36,7 @@ class RouteChecker
};

unordered_map<string, list<RouteData>> m_Data; // map string store: "ZSSSZGGG" OD pair
unordered_map<string, char> m_Cache; // callsign -> check result

bool IsRouteValid(string planroute, string realroute);
bool IsLevelValid(int planalt, string evenodd, string fixalt, string minalt);
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define VERSION_MAJOR 3
#define VERSION_MINOR 1
#define VERSION_REVISION 4
#define VERSION_BUILD 319
#define VERSION_BUILD 320

#define VERSION_FILE VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION
#define VERSION_FILE_STR \
Expand Down

0 comments on commit 6d27291

Please sign in to comment.