X Tutup
Skip to content

Move the System Map to PiGUI#4821

Merged
sturnclaw merged 2 commits intopioneerspacesim:masterfrom
Gliese852:ecraven-systemview-squashed
Apr 4, 2020
Merged

Move the System Map to PiGUI#4821
sturnclaw merged 2 commits intopioneerspacesim:masterfrom
Gliese852:ecraven-systemview-squashed

Conversation

@Gliese852
Copy link
Contributor

@Gliese852 Gliese852 commented Feb 28, 2020

The main idea of the interaction of lua side and C++ side is the same as in the worldview - the C++ View Class builds three-dimensional objects, some projected points are passed to the lua script, the lua script only works with screen coordinates.

The difference between the system view and the world view is that not all objects can have a physical body. If we examine a non-current star system, we see only system bodies that do not have physical bodies. Therefore, if for a world view you can simply create an array of physical bodies, this will not work in a system view.

To solve this problem, struct "Projectable" was created, into which you can write any point object, system body, ship, Lagrange point, apocenter, pericenter, etc. Now all these objects can be processed in a single array.

The names of the types of these objects are recorded in an enum, which is exported to a enum_table.cpp and read by the script as integers at the start. I thought it was better to avoid passing strings in such a hot place in the code. (runs for every object in every frame) Therefore,
type names are written and transmitted as integers.

All colors are now imported from lua: color index names are listed in the enum, which is exported to the enum_table.cpp. At event "onGameStart" the lua script reads these names and sends color values to the class. Now you can change colors at runtime.

Improvements/fixes:

  • Fix zooming speeds.
  • Fix ship's orbits in nonroot frame.
  • Remove unused old gui objects.
  • Landed ship are now spinning with the planet when rewinding time in a planner.
  • Now you can center the view on any object, including the player’s ship.
  • Add right-click context menu to center or set object as target. Therefore, to rotate the view, set the middle button.
  • Add indicators for navigation target and combat target.

Extra improvements/fixes (second commit):

  • Now only those orbits whose radius is less than 1% of the screen width are not shown.
  • Add smooth transition when click object.
  • Improve system bodies orbits.
  • Fix that ..apsis and lagrange points were displayed in the wrong place.
  • After rescanning enums, an error was found in the pigui/Face.h, fixed. fixes src/pigui/Face.h & src/gameui/Face.h both "export" the same enum #4801
  • Some indentations to pass clang
  • Add static_cast to Space.cpp, because it caused a warning at compilation.

Changes in the files explained:

SystemView.cpp, SystemView.h, system-view-ui.lua, lang/core/en.json

The whole thing, lots of changes. Now the system view draws only the orbits and the grid. In those places where the icons were drawn, instead of drawing, they are stored in an array, which is then requested from the lua.

LuaEngine.cpp

Add a general function that returns the value of an any enum by name from an enum_table.cpp (for calling from a lua)

Space.cpp

Add a notification for the systemview when the ship is removed from space, because it can be centered at this time, and an segmentation fault will occur.

LuaSystemBody.cpp

Add attributes to determine the shape of the icon and set the navigation target.

enum_table.cpp, enum_table.h

Rescanned enums to pass color settings and object types between Lua and C++.

LuaGame.cpp

The float does not have enough accuracy to display time up to seconds, change to double.

icons.svg, themes/default.lua

Add rotate view icon

Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

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

The indentation makes it a little difficult to review in the web UI, so I'll pull the PR locally and test it in more depth. So far, I've found a few things for you to fix, if you don't mind!

@Gliese852 Gliese852 force-pushed the ecraven-systemview-squashed branch 5 times, most recently from 5127474 to 3161c08 Compare March 4, 2020 21:33
@impaktor
Copy link
Member

impaktor commented Mar 8, 2020

@Gliese852 you need to give a shout when you feel this PR is ready for re-review

@Gliese852
Copy link
Contributor Author

Gliese852 commented Mar 8, 2020

@impaktor I fixed all the errors, tell me please how to inform about it.
EDIT: Oh, I think I get it!

@Gliese852 Gliese852 requested a review from sturnclaw March 8, 2020 17:03
@fluffyfreak fluffyfreak requested a review from impaktor March 13, 2020 21:42
@impaktor
Copy link
Member

impaktor commented Mar 14, 2020

Add right-click context menu to center or set object as target. Therefore, to rotate the view, set the middle button.

I think this should be discussed, as it feels very strange (to me), to not have rotation on right mouse button, like it is in WorldView and SectorView. I thought it was a bug, and didn't realize there was a middle mouse button.

Could one have rotation on RMB, and move functinality on middle mouse button to someplace else? What does the rest of you think? There is logic in middle mouse button, since it's already used for zoom in/out, but having them different on different views is strange. And many people don't have middle mouse button, I suspect, if on a laptop, like me.

I haven't looked at the code (yet?), but seems to be a lot of improvements

@Gliese852
Copy link
Contributor Author

@impaktor In the worldview, the camera rotates with the middle button, and the ship rotates with the right button. In fact, I play a lot with a view from the outside, so it’s just convenient for me to rotate the camera in a worldview and in a systemview using a wheel.

In fact, I do not have a firm position, as it should be, this is a question of one line of code.

On the other hand, to play without a mouse, can it be better to make on-screen buttons to rotate the view? And maybe assign physical keys.

@bszlrd
Copy link
Contributor

bszlrd commented Mar 14, 2020

@Gliese852 I think it should be consistent with the other views.
Middle mouse sounds reasonablew for rotation to me, and having physical keys for it would be nice as well.
Rigth mouse then could be free for future right-click menu functionality similar to worldview.
I think on-screen buttons would be an overkill, and would only add clutter. But maybe in a simplified way: one button for rotation, it rotates the view when you clicked on it until you release the mouse button?

@impaktor
Copy link
Member

But maybe in a simplified way: one button for rotation, it rotates the view when you clicked on it until you release the mouse button?

Sounds like a good idea. @nozmajner maybe there should be an icon for such a button?

Either way, I think this PR probably needs to touch sectorview as well, to make rotation consistent. Sorry to expand the scope of this.

@Gliese852
Copy link
Contributor Author

@impaktor @nozmajner Maybe then do this: make one on-screen button for zoom, one on-screen button for rotation, and assign numpad keys. And do the same in the sectorview?

@Gliese852 Gliese852 requested a review from sturnclaw March 20, 2020 19:07
@Gliese852
Copy link
Contributor Author

@impaktor @nozmajner I implemented on-screen buttons for zooming and rotating in the system Map in the last commit.

@impaktor
Copy link
Member

Doesn't build on my system:

/usr/bin/ld: src/lua/libpioneer-lua.a(Lua.cpp.o): in function `Lua::InitModules()':
/home/me/usr/src/pioneer/src/lua/Lua.cpp:75: undefined reference to `LuaObject<SystemView>::RegisterClass()'
/usr/bin/ld: src/lua/libpioneer-lua.a(LuaGame.cpp.o): in function `LuaObjectBase::LuaObjectBase(char const*)':
/home/me/usr/src/pioneer/src/lua/LuaObject.h:119: undefined reference to `LuaObject<SystemView>::s_type'

@bszlrd

This comment has been minimized.

@sturnclaw
Copy link
Member

Regarding the handling of rotation/zoom mode, here are some words transcribed from IRC:

sturnclaw   Gliese852: apologies if my comment comes across a little harsh
sturnclaw   I haven't gotten time to review the lua code yet, but
            doingViewTransformation stuck out to me; please definitely don't
            touch Pi.cpp unless completely necessary
sturnclaw   The current way of manually checking SDL_MOUSE_BUTTON_LEFT to
            determine if we need to rotate a view should be considered
            deprecated, I just haven't had time to build the replacement system
sturnclaw   For now, I'd recommend you pass the mouse movement from imgui
            itself; there's a hysteresis value for tiny drags to avoid
            micromovements (e.g. single clicks addding a tiny offset)
sturnclaw   In the future, you're going to need to consume input from more than
            just the mouse movement; we'd like to be able to bind joystick axes
            and gamepad sticks and buttons etc. to rotate the view
sturnclaw   I'm definitely going to implement a "capture mode" that lets the
            input system take priority over imgui for mouse motion
sturnclaw   Actually, I'll try to hammer that out tomorrow so you can rework
            your PR to use it
sturnclaw   So the code flow would become if ui.IsItemClicked() then
            systemView:RotationMode(true) end
sturnclaw   and SystemView::RotationMode(bool enabled) would call
            Input::SetCaptureMouse(enabled), set m_rotateMode = enabled, and
            then the normal control handling would happen
sturnclaw   I'd caution you against using string comparisons with e.g.
            SetVisibility by the way; especially for the Rotate and Zoom modes
            you really should be using a dedicated function call rather than
            overloading a visibility mode

I've settled on implementing a "Capture Mouse" setting to the input system to unify the various methods of handling exclusive mouse input and pre-empting ImGui's mouse handling; I'll get that coded up tomorrow as I don't expect many issues with implementing it. I'd recommend you rebase your PR to remove the changes to Pi.h/Pi.cpp once that's merged (which will be very soon after I get it working).

Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

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

I've left some comments about suggested code structure; it's at your discretion whether to follow them rigidly or not, but please do take them into consideration when updating this PR.

@impaktor
Copy link
Member

impaktor commented Mar 24, 2020

Nice. I wonder if the magnify and rotate buttons could be placed somewhere else? E.g. top right corner? @nozmajner thoughts? (see screenshot below)

It's still pretty strange to use different buttons for rotation in sector view vs. system view. I'd suggest making sector view work the same way as system view, and also add magnifying glass and rotate button to top right corner.

Other than that, good work!

2020-03-25-083429_1600x900_scrot

@Gliese852
Copy link
Contributor Author

Gliese852 commented Mar 24, 2020

@impaktor Yes, I plan to add control from the numeric keypad (as in the worldview), and then, when it works well in the systemview, do the same in the sectorview.

The location of the buttons is definitely not final, it's just the way @ecraven had it in the original PR. #4380

@impaktor
Copy link
Member

I plan to add control from the numeric keypad

I was more thinking about the RMB / MMB behaving differently / opposite in system view vs. sector view.

@Gliese852
Copy link
Contributor Author

@impaktor Oh, yes, I just didn’t put it that way, I had in mind all the controls including the keyboard, mouse and on-screen buttons will be copied from systemview to sectorview.

@impaktor
Copy link
Member

OK. Sounds good. (right click menu for sectore view would be nice as well, but could be outside the scope of this PR, as long as RMB/MMB inconcistency is sorted out in this PR).

I played a bit more with this branch, and updated the screenshot in my previous post to show more features. Very nice.

@Gliese852 Gliese852 force-pushed the ecraven-systemview-squashed branch from e32068a to d9ac379 Compare March 26, 2020 18:35
@sturnclaw
Copy link
Member

...Those comments were supposed to be part of a review, but apparently Github doesn't do reviews unless you're viewing the whole PR's history and not just a single commit.

Looking good so far, just some minor changes and I'll try to get this merged in ASAP!

@Gliese852
Copy link
Contributor Author

@Web-eWorks I implemented the latest recommendations in the commit ba3bbe8

@Gliese852 Gliese852 requested a review from sturnclaw March 26, 2020 22:09
@impaktor
Copy link
Member

Looks like commit history could need some squashing, ideally

@Gliese852
Copy link
Contributor Author

@impaktor Can squash-merge solve this problem? or it should be squashed in advance for some reason?

@impaktor
Copy link
Member

Well, squash-merge makes the whole thing into a single commit, which is a but brutal on the other end, as I assume you've had to implement various titbits to make this whole PR come together, so ideally they shuld be kept as separate commits, but the small fixes you've done in the review process should be squashed into where the code they fixed was introduced.

...If we are to appeal to our perfectionsit side.

@sturnclaw sturnclaw removed the request for review from impaktor March 29, 2020 20:55
@Gliese852 Gliese852 force-pushed the ecraven-systemview-squashed branch from d413105 to 698da86 Compare April 4, 2020 08:41
The main idea of the interaction of lua side and C++ side is the same as
in the worldview - the C++ View Class builds three-dimensional objects,
some projected points are passed to the lua script, the lua script only
works with screen coordinates.

The difference between the system view and the world view is that not
all objects can have a physical body. If we examine a non-current star
system, we see only system bodies that do not have physical bodies.
Therefore, if for a world view you can simply create an array of
physical bodies, this will not work in a system view.

To solve this problem, struct "Projectable" was created, into which you
can write any point object, system body, ship, Lagrange point,
apocenter, pericenter, etc. Now all these objects can be processed in a
single array.

The names of the types of these objects are recorded in an enum, which
is exported to a enum_table.cpp and read by the script as integers at
the start. I thought it was better to avoid passing strings in such a
hot place in the code. (runs for every object in every frame) Therefore,
type names are written and transmitted as integers.

All colors are now imported from lua: color index names are listed in
the enum, which is exported to the enum_table.cpp. At event
"onGameStart" the lua script reads these names and sends color values to
the class. Now you can change colors at runtime.

* Improvements/fixes: *

- Fix zooming speeds.
- Fix ship's orbits in nonroot frame.
- Remove unused old gui objects.
- Landed ship are now spinning with the planet when rewinding time in a
    planner.
- Now you can center the view on any object, including the player’s ship.
- Add right-click context menu to center or set object as target.
    Therefore, to rotate the view, set the middle button.
- Add indicators for navigation target and combat target.

* Changes in the files explained *

    SystemView.cpp, SystemView.h, system-view-ui.lua, lang/core/en.json

The whole thing, lots of changes. Now the system view draws only the
orbits and the grid. In those places where the icons were drawn, instead
of drawing, they are stored in an array, which is then requested from
the lua.

    LuaEngine.cpp

Add a general function that returns the value of an any enum by name
from an enum_table.cpp (for calling from a lua)

    Space.cpp

Added a notification for the systemview when the ship is removed from
space, because it can be centered at this time, and an segmentation
fault will occur.

    LuaSystemBody.cpp

Added attributes to determine the shape of the icon and set the
navigation target.

    enum_table.cpp, enum_table.h

Rescanned enums to pass color settings and object types between Lua and
C++.

    LuaGame.cpp

The float does not have enough accuracy to display time up to seconds,
change to double.

    icons.svg, themes/default.lua

Add rotate view icon
@Gliese852 Gliese852 force-pushed the ecraven-systemview-squashed branch from 698da86 to 12d0b6c Compare April 4, 2020 08:56
@Gliese852 Gliese852 requested a review from sturnclaw April 4, 2020 09:05
@impaktor
Copy link
Member

impaktor commented Apr 4, 2020

Hmm, this PR is showing the Travis build, so only new PRs lack it? (general statement)

@Gliese852 Gliese852 force-pushed the ecraven-systemview-squashed branch from 12d0b6c to aea0134 Compare April 4, 2020 13:26
- Now only those orbits whose radius is less than 1% of the screen width are not shown.
- Add smooth transition when click object.
- Improve system bodies orbits.
- Fix that ..apsis and lagrange points were displayed in the wrong place.

- After rescanning enums, an error was found in the pigui/Face.h, fixed. fixes pioneerspacesim#4801
- Some indentations to pass clang
- Added static_cast to Space.cpp, because it caused a warning at compilation.
@Gliese852 Gliese852 force-pushed the ecraven-systemview-squashed branch from aea0134 to ac7e982 Compare April 4, 2020 13:28
@impaktor
Copy link
Member

impaktor commented Apr 4, 2020

Just to repeat what I wrote in IRC, tested it, very nice, but I have the following suggestions:

  • Grid is a bit (or a lot) too dark, maybe use same colors as in sector view?
  • Would it be possible to (as separate commit) make middle mouse in sector view behave the same as in this new system view, for consistency?
  • Maybe here, or in another PR, add the rotation icon/function to sector view?

@Gliese852
Copy link
Contributor Author

@impaktor I planned to do a sector view in another PR (next)

@sturnclaw sturnclaw merged commit 8e31d16 into pioneerspacesim:master Apr 4, 2020
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.

src/pigui/Face.h & src/gameui/Face.h both "export" the same enum

4 participants

X Tutup