Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up[WIP] Amphibious vehicles #21723
Conversation
This comment has been minimized.
This comment has been minimized.
|
I've implemented support for amphibious vehicles now; it seems to work fine, but some more testing needs to be done, since this is my first excursion into the depths of the vehicle code. Also, there's one comfort feature I haven't implemented yet: Currently, all vehicles, including boats, get "is_floating=false" during initialization, which means boats have to be manually set to 'sea' mode by the user after loading a save. I've tried to recognize boats automatically by adding a |
This comment has been minimized.
This comment has been minimized.
Most likely because the map has not yet been loaded. |
This comment has been minimized.
This comment has been minimized.
|
Most likely because the map has not yet been loaded.
Yes, I assume that's the problem. How do I avoid this, though? I
suppose I could rework vehicle_wheel_traction() to bail out gracefully
in this case.
|
This comment has been minimized.
This comment has been minimized.
|
Vehicles should dynamically (when needed) detect whether they are floating, instead of relying on a member variable. Instead of having a |
atlaua
added some commits
Aug 26, 2017
This comment has been minimized.
This comment has been minimized.
|
Vehicles should dynamically (when needed) detect whether they are
floating, instead of relying on a member variable. Instead of having
a `is_floating` variable, add a `is_floating()` function.
I've considered this, but decided against it for now. An
'is_floating()' function would have to loop over all wheels and boat
boards, and by my count, it would be called at least three times for
every single vehicle movement. That seems a bit excessive given that
the job can be easily and much more efficiently done with a variable.
|
This comment has been minimized.
This comment has been minimized.
|
Even if the internal state that's being checked is a variable, that
variable should be private and callers should check it with a method call.
|
This comment has been minimized.
This comment has been minimized.
|
Even if the internal state that's being checked is a variable, that
variable should be private and callers should check it with a method
call.
Okay, I can change that. I'd just thought that we didn't care too much
about strict encapsulation here since everything's one compilation unit
anyway. There are accesses to other classes' internal variables all
over the place, I haven't seen many accessor functions.
|
This comment has been minimized.
This comment has been minimized.
|
Looking at the code again, making 'is_floating' private with an
accessor doesn't look like a very good idea. I need to set it from
map::vehact(). Also, all the other bools in the vehicle class (other
than three cache invalidation flags), some of them quite comparable in
function to 'is_floating', are public, too.
|
This comment has been minimized.
This comment has been minimized.
Requiring an UI operation to switch land/float mode is unacceptable. It clearly shows that the implementation must be wrong or incomplete. Player must not be required to manually select the mode. You will have to set
However if For purposes of UI and the like, it is tolerable (not good, though) if it displays the last state. It may be worth saving this state to savegame json, to avoid potential weirdness on load. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the feedback! I don't like the manual mode toggling either,
and I've already lined up two changes to vehicle::thrust() that should
set the mode correctly in all cases. I'll push them as soon as I've
done some more testing.
Currently, I'm only having the code consider a switch to land mode if
it can't move at all in sea mode. I suspect your suggestion would make
for cleaner code without a considerable performance cost, so I'll look
into that.
Serializing the mode may indeed be a good idea; I've already run into
some weirdness when dialing a boat's target speed down and then
saving and reloading before it has a chance to slow down.
|
This comment has been minimized.
This comment has been minimized.
|
I bit the bullet and made is_floating a function. I would've preferred to cache the floating mode in a variable, but toggling the mode correctly in all cases was getting a bit messy. Everything seems to work fine now, but I need to test and review it more thoroughly. |
Coolthulhu
reviewed
Sep 11, 2017
| @@ -5102,7 +5103,9 @@ void vehicle::refresh() | |||
| if( vpi.has_flag( "CAMERA" ) ) { | |||
| camera_epower += vpi.epower; | |||
| } | |||
| if( vpi.has_flag( VPFLAG_FLOATS ) ) { | |||
| // The floating cache shouldn't include broken parts; | |||
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Sep 11, 2017
Contributor
refresh is called only on part addition/removal and similar. floating must necessarily contain both broken and unbroken parts.
Coolthulhu
reviewed
Sep 11, 2017
| remove_part( p ); | ||
| } | ||
|
|
||
| refresh(); |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Sep 11, 2017
Contributor
Forcing refresh here to keep that weird thing with floating not having broken parts sounds really wrong.
Instead make a can_float or something like that, which checks if there is a non-broken floating part or something like that.
Coolthulhu
reviewed
Sep 11, 2017
|
|
||
| // Otherwise, the vehicle is amphibious. We consider it | ||
| // to be floating if >2/3 of the wheels are submerged | ||
| if ( g->m.vehicle_wheel_traction( *this ) < 0 ) { |
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Sep 11, 2017
Contributor
Negative wheel traction is a hack to sink vehicles. It isn't totally wrong to use it here, but it's not right either.
Coolthulhu
reviewed
Sep 11, 2017
| @@ -6466,3 +6475,24 @@ void vehicle::calc_mass_center( bool use_precalc ) const | |||
| mass_center_no_precalc_dirty = false; | |||
| } | |||
| } | |||
|
|
|||
| bool vehicle::is_floating() const | |||
This comment has been minimized.
This comment has been minimized.
Coolthulhu
Sep 11, 2017
Contributor
If you're worried about this being called too often and becoming slow, back it up with a cached variable, just like mass is cached.
This comment has been minimized.
This comment has been minimized.
|
Is this dead @atlaua ? |
This comment has been minimized.
This comment has been minimized.
|
On Sun, 14 Jan 2018 23:40:56 -0800 BorkBorkGoesTheCode ***@***.***> wrote:
Is this dead @atlaua ?
Yep, sorry. It needs a complete rewrite, for which I unfortunately don't
have time right now.
|
This comment has been minimized.
This comment has been minimized.
|
@atlaua what about now? |
This comment has been minimized.
This comment has been minimized.
|
Closing for the time being |
atlaua commentedAug 26, 2017
As the title says, I'm working on making amphibious vehicles possible. There's no code for that yet, though; so far I've only done a minor cleanup of the boat code that I'd love to get some feedback on.