Skip to content

[Plugin] Add track progress property to vehicles#13593

Merged
IntelOrca merged 11 commits into
OpenRCT2:developfrom
Basssiiie:plugin-track-progress
Dec 29, 2020
Merged

[Plugin] Add track progress property to vehicles#13593
IntelOrca merged 11 commits into
OpenRCT2:developfrom
Basssiiie:plugin-track-progress

Conversation

@Basssiiie

@Basssiiie Basssiiie commented Dec 15, 2020

Copy link
Copy Markdown
Member

Hey all, this is my draft attempt at adding a property for track progress to vehicles for plugins. This would be very useful for my RideVehicleEditor plugin to adjust spacing between vehicles, and maybe others can find some usefulness in it as well!

  • Track progress can be read and set for Car-instances.
  • If the chosen value is beyond the maximum amount of the current track piece, the vehicle will go to the relative position on the next track piece.
  • If the chosen value is negative, the vehicle will go to the relative position on the previous track piece.

What I'm still planning to do:

  • Clamp track progress at the end of tracks (for non-complete circuits).
  • Sometimes if it jumps to the next or previous track, the position is off by 1.
  • Test it thoroughly to make sure it doesn't crash or mess up the game somehow (so far it doesn't seem to).
  • Run clang-format.

Update 21 dec:

  • After talking with Duncan, the proposed implementation has been changed to modify the vehicles 'remaining distance' instead.
  • Duncan provided the related Add individual vehicle motion update flag #13607 update flag which this implementation uses.
  • The 'track progress' setter has been removed and replaced by a 'move' method which moves the car a relative distance in either forward or backwards along the track.

A screenshot of it working ingame:
afbeelding

Right now it works surprisingly well and I haven't really found any issues so far.

I'd love to hear feedback though. This is my first pull request and I'm not even sure if this is the best approach for it. Please let me know if this is something that would fit into the source code and if there is anything I should change.

@James103

Copy link
Copy Markdown
Contributor

Have you tried running clang-format on your changes?

@Basssiiie

Copy link
Copy Markdown
Member Author

Have you tried running clang-format on your changes?

No I haven't, I was looking into how to do that after the checks failed. I'll fix that tonight. :)

@duncanspumpkin

Copy link
Copy Markdown
Contributor

This wont be able to set the correct sprite for vehicles going through reverser elements or rotate elements like log flumes, heartline.

@duncanspumpkin

duncanspumpkin commented Dec 16, 2020

Copy link
Copy Markdown
Contributor

I think it will need to hook in early to the UpdateMotion functions. The vehicle placement code uses UpdateMotion to place the vehicles and this ensures that all of the values are correct. I'm not too sure how you would achieve that though.

Edit: Possibly could work by setting the value of remaining_distance to whatever you want to update the progress with then calling UpdateMotion(nullptr);.

Something like:

vehicle->remaining_distance += trackProgress;
UpdateMotion(nullptr);

remaining_distance will understand negatives and call the appropriate items for backwards movement.

@Basssiiie

Copy link
Copy Markdown
Member Author

@duncanspumpkin Thank you for your reply. I'll give the remaining_distance a shot. What does it exactly hold? The distance to travel within this frame? Or the distance to the next track piece? Or something else?

@duncanspumpkin

Copy link
Copy Markdown
Contributor

From memory the units are the same as track progress. It's a sort of left over amount after a vehicle update when things don't quite line up

duncanspumpkin added a commit to duncanspumpkin/OpenRCT2 that referenced this pull request Dec 18, 2020
This can be used in conjuction with OpenRCT2#13593 to change the placement of vehicles on a track
Comment thread src/openrct2/scripting/ScEntity.hpp Outdated
duncanspumpkin added a commit to duncanspumpkin/OpenRCT2 that referenced this pull request Dec 20, 2020
This can be used in conjuction with OpenRCT2#13593 to change the placement of vehicles on a track
@Basssiiie

Basssiiie commented Dec 20, 2020

Copy link
Copy Markdown
Member Author

@duncanspumpkin I realise I checked in your code from #13607 here as well. Should I remove it or should it merge fine after your PR has been merged?

Comment thread distribution/openrct2.d.ts
duncanspumpkin added a commit that referenced this pull request Dec 21, 2020
This can be used in conjuction with #13593 to change the placement of vehicles on a track
@duncanspumpkin

Copy link
Copy Markdown
Contributor

@duncanspumpkin I realise I checked in your code from #13607 here as well. Should I remove it or should it merge fine after your PR has been merged?

Could you rebase now that my code has been merged.

@Basssiiie

Copy link
Copy Markdown
Member Author

Could you rebase now that my code has been merged.

Sure! I'll do that tonight or tomorrow when I have time. :)

@Basssiiie Basssiiie force-pushed the plugin-track-progress branch from 1cfaf49 to 21c20b1 Compare December 21, 2020 16:25
@Basssiiie Basssiiie marked this pull request as ready for review December 21, 2020 16:58
Comment thread src/openrct2/ride/Vehicle.cpp Outdated
UpdateTrackMotion(nullptr);
ClearUpdateFlag(VEHICLE_UPDATE_FLAG_SINGLE_CAR_POSITION);

const Ride* curRide = GetRide();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure you don't need to do any of this moveInfo changes. UpdateTrackMotion should take care of it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes you're right, I'll remove it. :)

Comment thread src/openrct2/ride/Vehicle.cpp Outdated
bool Vehicle::UpdateMotionCollisionDetection(const CoordsXYZ& loc, uint16_t* otherVehicleIndex)
{
if (HasUpdateFlag(VEHICLE_UPDATE_FLAG_COLLISION_DISABLED))
if (HasUpdateFlag(VEHICLE_UPDATE_FLAG_COLLISION_DISABLED) || HasUpdateFlag(VEHICLE_UPDATE_FLAG_SINGLE_CAR_POSITION))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason you are doing this rather than just setting VEHICLE_UPDATE_FLAG_COLLISION_DISABLED as well as VEHICLE_UPDATE_FLAG_SINGLE_CAR_POSITION

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can do that yes, that sounds like a better idea. Will it not interfere with any other code if I clear the VEHICLE_UPDATE_FLAG_COLLISION_DISABLED-flag again after UpdateTrackMotion? I am not sure when and where this flag is used elsewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know it's used for vehicle placement (which is not an issue). Have a look see if it's set for anything else

@Basssiiie Basssiiie Dec 22, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The only case I can find is the Giga Coaster cablelift, where it is enabled permanently. I don't think UpdateMotionCollisionDetection is called for the cablelift though, so it seems safe to clear it. :)

In all other cases where the flag is set (when vehicles are created), it is immediately cleared afterwards already.

Comment thread src/openrct2/scripting/ScEntity.hpp Outdated
@duncanspumpkin

Copy link
Copy Markdown
Contributor

This looks reasonable. Assuming it all works fine on your plugin I've no issues with it. @IntelOrca do you have anything to add?

@Basssiiie

Basssiiie commented Dec 28, 2020

Copy link
Copy Markdown
Member Author

This looks reasonable. Assuming it all works fine on your plugin I've no issues with it. @IntelOrca do you have anything to add?

Yes it works perfect in my plugin. :) Only quirk I could find is that modifying a car on a slope sometimes moves other vehicles on the train as well. (Like I mentioned on Discord.)

Other than that I tested a lot of special rides like Reverser Coaster, Chairlift, Giga Coaster, Lift, Go Karts, Heartline Twister, Log Flume reversers etc. as well and they all work perfectly. (And no crashes or freezes either.)

If you guys wanna test it as well with the plugin, just let me know and I can send over the *.js file for it!

@IntelOrca

Copy link
Copy Markdown
Contributor

Just wondering whether move is the best name for the method in both the source code and the plugin API. Maybe it should be moveBy or travel or travelBy.

@Basssiiie

Basssiiie commented Dec 28, 2020

Copy link
Copy Markdown
Member Author

Just wondering whether move is the best name for the method in both the source code and the plugin API. Maybe it should be moveBy or travel or travelBy.

I can change it to moveBy if that is preferred. That'd also make it more in line with Viewport.moveTo().

travel and travelBy sounds a bit more unconventional, but that's just my personal feeling. I'd not be against it if it's the final verdict.

Who wants to make the final choice? 😃

@Broxzier

Copy link
Copy Markdown
Member

Just move doesn't really explain what the function does, especially since it only takes one argument. travelBy would make it more clear that it has to do with the track, though something even more verbose like moveAlongTrack would be even better IMO.

@IntelOrca

Copy link
Copy Markdown
Contributor

Yeah, my thoughts are that move is likely to mean, move by a coordinate relative to the map rather than an amount relative to the track. So I think it should just have a different name in case we have another function called moveBy or moveTo which move it by an x, y, z axis.

@Basssiiie

Copy link
Copy Markdown
Member Author

So travelBy is the final decision?

@IntelOrca

Copy link
Copy Markdown
Contributor

@duncanspumpkin any personal suggestions?

@duncanspumpkin

Copy link
Copy Markdown
Contributor

No opinions here

@Basssiiie

Copy link
Copy Markdown
Member Author

The move method is now renamed to travelBy. :)

@IntelOrca

Copy link
Copy Markdown
Contributor

Okay finally, you just need to increment the plugin API version number and add this to the changelog. Sorry, I should have mentioned that previously.

@IntelOrca IntelOrca added the pending rebase PR needs to be rebased. label Dec 29, 2020
@Basssiiie Basssiiie force-pushed the plugin-track-progress branch from c30bfef to 918bd01 Compare December 29, 2020 14:50
@Basssiiie

Copy link
Copy Markdown
Member Author

Great, no worries! I think it should be properly rebased now? And the plugin API version and changelog have been updated. :)

@IntelOrca IntelOrca merged commit ce2319f into OpenRCT2:develop Dec 29, 2020
@tupaschoal tupaschoal added this to the v0.3.3 milestone Dec 29, 2020
@Basssiiie Basssiiie deleted the plugin-track-progress branch November 26, 2021 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending rebase PR needs to be rebased.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants