Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster asel detection #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Aman/AmanPlugIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ AmanPlugIn::AmanPlugIn() : CPlugIn(COMPATIBILITY_CODE, "Arrival Manager", "2.1.0
loadTimelines("aman-config.json");

amanController->modelUpdated();

runAselWatcher = true;
aselWatcherThread = CreateThread(NULL, 0, AmanPlugIn::lookForNewASEL, this, 0, &aselWatcherThreadId);
}

AmanPlugIn::~AmanPlugIn() {
runAselWatcher = false;
WaitForSingleObject(aselWatcherThread, INFINITE);
}

std::set<std::string> AmanPlugIn::getAvailableIds() {
Expand Down Expand Up @@ -268,6 +273,10 @@ void AmanPlugIn::requestReload() {
amanController->modelUpdated();
}

void AmanPlugIn::onNewAsel(const std::string& asel) {
amanController->modelUpdated();
}

std::vector<std::string> AmanPlugIn::splitString(const std::string& string, const char delim) {
std::vector<std::string> output;
size_t start;
Expand Down
21 changes: 21 additions & 0 deletions Aman/AmanPlugIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class AmanPlugIn : public CPlugIn {
AmanPlugIn();
std::set<std::string> getAvailableIds();
std::shared_ptr<std::vector<std::shared_ptr<AmanTimeline>>> getTimelines(std::vector<std::string>& ids);
bool shouldRunASELWatcher() { return runAselWatcher; };

void requestReload();
void onNewAsel(const std::string& asel);
virtual ~AmanPlugIn();

private:
Expand All @@ -36,4 +38,23 @@ class AmanPlugIn : public CPlugIn {
void loadTimelines(const std::string& filename);

static std::vector<std::string> splitString(const std::string& string, const char delim);

HANDLE aselWatcherThread;
DWORD aselWatcherThreadId;
bool runAselWatcher;

// For quicker detection when ASEL changes
static DWORD WINAPI lookForNewASEL(LPVOID lpParam) {
AmanPlugIn* plugin = (AmanPlugIn*)lpParam;
std::string oldAsel = std::string(plugin->RadarTargetSelectASEL().GetCallsign());
while (plugin->shouldRunASELWatcher()) {
auto newAsel = plugin->RadarTargetSelectASEL().GetCallsign();
if (oldAsel != newAsel) {
plugin->onNewAsel(newAsel);
oldAsel = std::string(newAsel);
}
Sleep(50);
}
return 0;
};
};