-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
Fixes and changes for functions in LuaBody/Player/Ship #5643
Fixes and changes for functions in LuaBody/Player/Ship #5643
Conversation
@Web-eWorks
These are my thoughts at the moment. I will add comments if I find something more. |
The problem here is the split between "radar altitude" and "sea level altitude" relative to the body. Altitude above terrain features (radar altitude) is only useful for bodies actually near or on trajectory to intersect the terrain, whereas bodies in high orbit shouldn't care about terrain height but use sea-level altitude instead. Not only does this better mimic what other games (e.g. KSP) do with regards to altitude handling, it's significantly better for performance because we don't have to thrash the instruction cache (
This is fine. The new method should ideally take a parameter indicating whether to return the altitude relative to terrain or sea-level (sbody radius) - I'll leave that at your discretion how best to ensure existing behavior is preserved with the new API.
This should be fixed, but be wary of existing code that implicitly depends on the old/incorrect values. |
@Web-eWorks And to correct myself here:
Missed this while I was writing this comment. |
If GetGPS can be replaced by GetGroundPosition with no loss in functionality, then by all means please drop the GetGPS function entirely! |
3730917
to
58c31bc
Compare
@Web-eWorks I listed all changes in the initial comment. Let me know if you find something unusual. |
58c31bc
to
e9d87b1
Compare
@Web-eWorks I found the cause for assertion error that I mentioned here. When ship is hyperspacing, it's not in space (in But maybe there's a more clean way to do this? Also, |
cacbd97
to
9bb464e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few concerns with the API patterns used in this PR, which are explored in more depth in the individual request comments. Otherwise I'm quite happy with the improvements this brings (especially the dynamic_cast
removal and segfault fixes!)
Thank you for your efforts in fixing these bugs and improving the code quality of Pioneer!
9bb464e
to
5317261
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the feedback! I consider this PR in a good state to merge, but I've left one new suggestion where the new code is slightly overzealous in my eyes - I don't consider addressing that a requirement to merge however.
Rewrite of GetAltitudeRelTo: 1. This function is moved to body class to support this functionality in C++ code; 2. This function is used in the LUA version of GetAltitudeRelTo, GetGroundPosition and GetGPS for consistency in calculating altitudes; 3. This function supports the choice of which height to calculate (sea level, above ground). Other change: 1. GetGPS is moved to Ship.lua to support this function for other ships, not only the player. Implementing this function in C++ is considered unnecessary because of slightly different parameter interface and because of this can be simplified a lot; 2. GetGroundPosition also supports the choice of which altitude to calculate (sea level or above terrain). Fixes for this issues: 1. GetAltitudeRelTo using player pos no matter what first argument is passed; 2. GetGroundPosition returns nil when not in the rotating frame of ref; 3. GetGPS sometimes return different height than GetAltitudeRelTo; 4. Access violation when trying to access frameBody, frameRotation and call GetGroundPosition when body doesn't have frame of ref (ex. when ship is hyperspacing). Co-Authored-By: Webster Sheets <[email protected]>
5317261
to
1cb457b
Compare
Update:
Rewrite of
GetAltitudeRelTo
:GetAltitudeRelTo
,GetGroundPosition
andGetGPS
for consistency in calculating altitudes;Other change:
GetGPS
is moved toLuaShip.cpp
to support this function for other ships, not only the player.Fixes for this issues:
GetAltitudeRelTo
using player pos no matter what first argument is passed;GetGroundPosition
returns nil when not in the rotating frame of ref;GetGPS
sometimes return different height thanGetAltitudeRelTo
;frameBody
,frameRotation
and callGetGroundPosition
when body doesn't have frame of ref (ex. when ship is hyperspacing).Update2:
static bool push_body_to_lua(Body *body)
:dynamic_cast
is changed tostatic_cast
;ModelBody
andCargoBody
had wrong template type (Body
andStar
).P.S.: Unless, there's some good reason for using templates, it can actually be changed to just
LuaObject<Body>::PushToLua(body)
.(I checked, haven't seen any oddities).
Update3:
Removed space at the start of
l_body_get_altitude_rel_to
. A lot of comments didn't show up for functions, because they had a space between function name. Deleted spaces, so comments will show up when hovering function name.Update4:
GetGPS
is moved toShip.lua
to support this function for other ships, not only the player. Implementing this function in C++ is considered unnecessary because of slightly different parameter interface and because of this can be simplified a lot;GetGroundPosition
also supports the choice of which altitude to calculate (sea level or above terrain).Old:
Fixes for this issues:
Need clarification on this:
if (!f->IsRotFrame())
) should be changed back? I deleted that, because with this, when, for example you're on the Moon, altitude will already benil
at ~6000m.Edit: to clarify second point, altitude will be different when
IsRotFrame
will be false (basically, when space particles (lines) will start to appear or when not in rotating frame).