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

Refactor the ModelViewer to use PiGui #4849

Merged
merged 9 commits into from
Apr 6, 2020

Conversation

Web-eWorks
Copy link
Member

I've re-implemented the ModelViewer in PiGui, using the GuiApplication class and the Input system to simplify a fair amount of the handling.

To accomplish this, I've done a fair amount of refactoring:

  • PiGui is now PiGui::Instance, and all of the static drawing methods have been moved out of the class, opening up the possibility to add more C++-side widgets for both Lua and C++ to use.
  • PiGui::Instance is now only responsible for handling ImGui - all Lua-side initialization is handled by PiGUI::Lua::Init() instead.
  • As an addenda, the (separate) PiGUI namespace will be merged into the (new) PiGui namespace in a future PR; I didn't do that here because I was focused on other work.
  • PiGui::Instance has its renderer dependency injected by its owner rather than relying on Pi::renderer. This actually reduced complexity a bit, because we no longer had to manually specify the SDL window every time we started an ImGui frame.
  • Input had its last ties to Pi removed, with the Config dependency injected by the owner, similarly to PiGui.
  • Of note: KeyBindings::AxisBinding and ActionBinding still depend on the Pi::input singleton variable, so there's an ugly hack in the ModelViewer to work around that. I'll address that in a later PR that refactors bindings (once again!).
  • GuiApplication now owns an Input instance and a PiGui instance, decoupling management of those two classes away from Pi.cpp. It's not as automatic as I'd like, due to oldUI's issues with label drawing, but it's 90% of the way there.
  • Input now has methods IsKeyPressed() and IsKeyReleased() to check whether a specific key was pressed or released during the current frame. This does come with some more runtime complexity, but the overall effect should be mostly negligible.

Overall, this is a 1:1 replacement of the previous ModelViewer, with only one regression: the "snap view to direction" keybindings are not currently working because they're not being fed SDL_Events to trigger the onPress callbacks. This will also be resolved in a future Input PR, but is outside of the scope of this work.

- Now LuaPiGui handles it, decoupling the PiGui implementation from lua
- Made all externally-facing symbols in LuaPiGui part of the PiGUI namespace
This will be renamed to PiGui and the class of the same name will become part of the namespace.
At the moment, the lifecycle is responsible for calling HandleEvents and rendering PiGui.
This can change once legacy code no longer depends on HandleEvents running after View::Draw3D().

Added virtual HandleEvent() call to dispatch to legacy UI code.
This is suboptimal; we need a better way that doesn't involve virtual function calls.
Use std::function or a better, lower-overhead delegate library
Make PiGui a namespace for easier method scoping, allows us to be more flexible

PiGui::Instance only has the bare minimum of methods needed to run ImGui

Move PiGui RegisterClass call to pigui/PiGuiLua - we'll further unify LuaPiGui
and PiGuiLua later.
Explicitly inject the renderer dependency, instead of relying on Pi::renderer existing
Made it Pi.cpp's responsibility to hide the mouse cursor.
Added IsKeyPressed / Released methods to track per-frame key state
Added GetMouseWheel so users don't have to track mouse wheel events themselves
Input keeps a pointer to a config instance, completely decoupling it from Pi
"Snap to Direction" keybinds don't work, due to Input not dispatching their event handlers.
Will be resolved in a later sprint on the Input system.
@impaktor
Copy link
Member

impaktor commented Apr 1, 2020

Did we find out what's happened to travis?

@Web-eWorks
Copy link
Member Author

Nope, still not sure what's going on there. The config file works fine, travis is building correctly, but it's not showing up on the repo. I think you'll have to dig around in the Travis settings to figure out what's going on.

Copy link
Contributor

@fluffyfreak fluffyfreak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, minor fixes supplied, good to go

@Web-eWorks
Copy link
Member Author

Merging this in, as I think we've caught all of the related bugs!

@Web-eWorks Web-eWorks merged commit 0838649 into pioneerspacesim:master Apr 6, 2020
@Web-eWorks Web-eWorks deleted the modelviewer-refactor branch May 21, 2020 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants