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 SpeedLimit struct #438

Closed
9 tasks done
VictorPhilipp opened this issue Jul 19, 2019 · 0 comments · Fixed by #475
Closed
9 tasks done

Refactor SpeedLimit struct #438

VictorPhilipp opened this issue Jul 19, 2019 · 0 comments · Fixed by #475
Assignees
Labels
code cleanup Refactor code, remove old code, improve maintainability
Milestone

Comments

@VictorPhilipp
Copy link
Collaborator

VictorPhilipp commented Jul 19, 2019

The struct is currently located in the TrafficManager.Traffic.Data namespace. This namespace been moved to the TMPE.API project to allow for reuse in other mods.

However, the SpeedLimit struct does not hold any information - it is merely used as a utility class and only consists of static methods which should be avoided (see #211). It also mixes UI and game logic.

Tasks:

  • Move all constants (The decision should be based on where the constant is used)
    • either to SpeedLimitManager
    • or to a UI related class (SpeedLimitsTool?)
  • Move methods EnumerateSpeedLimits, ToMphPreciseString, ToKmphPreciseString, ToMphRounded, ToMphPrecise, ToKmphPrecise, ToKmphRounded, GetPrevious, GetNext, GetVerticalTextureScale to a UI related class (SpeedLimitsTool?)
  • Move NearlyEqual and IsZero to a (new?) utility class, e.g. FloatUtils
  • Move IsValidRange to SpeedLimitManager
  • Modify VehicleBehaviorManager.FindBestLane() such that the variable optImprovementSpeed stores velocitiy in game units (and not in km/h).
  • Modify member variables MinMinSafeSpeedImprovement and MaxMinSafeSpeedImprovement in DynamicLaneSelection such that they hold velocities in game units (and not in km/h).
  • If required, add two members velocity (float) and unit (SpeedUnit) to the SpeedLimit struct and update UI code to use it properly (as a composite value). If not required, remove the struct entirely.
@VictorPhilipp VictorPhilipp added the code cleanup Refactor code, remove old code, improve maintainability label Jul 19, 2019
@originalfoo originalfoo added this to the 11.0 milestone Jul 19, 2019
@kvakvs kvakvs self-assigned this Jul 22, 2019
kvakvs added a commit to kvakvs/TMPE that referenced this issue Aug 1, 2019
@kvakvs kvakvs mentioned this issue Aug 1, 2019
9 tasks
kvakvs added a commit that referenced this issue Aug 2, 2019
* Moved SpeedLimit class and its contents; New SpeedValue, KmphValue and MphValue structs
* #438 Use speed values with units; Remove SpeedLimit class
* Add xmldoc to SpeedValue
* FloatUtil is marked as static
* SpeedValue, Mph and KmphValue are now readonly
* Speed value structs are readonly now. Added operator + (K|mphValue, ushort) for convenience
* Remove KM/gameunits conversion from Configuration.cs
* Remove 1 unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Refactor code, remove old code, improve maintainability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants