zaksabeast / CaptureSight

Tesla Overlay to view Pokemon game info in Sword, Shield, Brilliant Diamond, Shining Pearl, and Legends Arceus!
GNU General Public License v3.0
156 stars 28 forks source link

Show loading indicator when CaptureSight is calculating raid seeds #25

Closed zaksabeast closed 4 years ago

zaksabeast commented 4 years ago

CaptureSight doesn't show any indication it's properly calculating raid seeds. Instead, it appears frozen, which isn't a good user experience.

Having the indicator animated in some way (e.g. a moving spinner or "Loading" text with "." -> ".." -> "..." -> repeat) is even better for the UX since it shows CaptureSight isn't frozen more than a static image or text would.

Update: Thanks to ulucs, the loading indicator has been added to the applet as of https://github.com/zaksabeast/CaptureSight/commit/a7e661117f5c3e65508b0fa9a08b0ff1ecff2c32.

ulucs commented 4 years ago

I finally wrapped my head around how this would work. Expect a PR soon :)

ulucs commented 4 years ago

Okay, I've added two possible implementations for running a non-blocking while loop into Utils.hpp:

template <typename T>
void while_waiting(std::future<T>* to_wait, std::function<void()> loop, int interval_ms) {
  while (to_wait->wait_for(std::chrono::milliseconds(1)) == std::future_status::timeout) {
    loop();
    std::this_thread::sleep_for(std::chrono::milliseconds(interval_ms));
  }
  return;
}

template <typename T>
bool waiting_interval(std::future<T>* to_wait, int interval_ms) {
  return to_wait->wait_for(std::chrono::milliseconds(interval_ms)) == std::future_status::timeout;
}

It appears that C++ lambdas are quite limited, so I think using a while (waiting_interval(future, interval)) will be easier to use.

However, I couldn't find a way to edit the UI in these while blocks. Neither LoadLayout nor RefreshSummaryLayout seems to work in the applet, and the overlay is always crashing. Was there a dependency update?

zaksabeast commented 4 years ago

Application::LoadLayout will tell Plutonium which layout to use, and MainApplication::RefreshSummaryLayout will update the values PokemonSummaryLayout should render, but Application::CallForRender is what actually renders the values.

Try using CallForRender in your loop and see if that fixes the issue you're seeing. :slightly_smiling_face:

As for libtesla, I'm less familiar with it and can't speak much as to how it works under the hood. When I looked, libtesla was deleting the elements and screens when it was done with them, so trying to reuse elements and screens will often mean trying to use something that no longer exists. This may not be your issue, but is something I ran into when first playing with libtesla that caused some crashes.

As far as dependencies go, none have been updated recently.

ulucs commented 4 years ago

Thanks a lot, I'll try this tomorrow