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 features, overlays, and junction option groups #1422

Merged
merged 15 commits into from
Mar 2, 2022

Conversation

originalfoo
Copy link
Member

@originalfoo originalfoo commented Feb 18, 2022

Compiled mod for testing: TMPE.zip

Part of ongoing work for #1356 phase 2 - #1356 (comment)

This started out as just a refactor of the Activated Features option group, but it was heavily entangled with Overlays and At Junctions option groups so they got refactored too. In the process noticed that there were some duplicate Set.. functions in MaintenanceTab and PoliciesTab, so they got chainsawed.

  • Split option groups in to separate classes/files
  • Convert to CheckboxOption
  • Chainsaw numerous Set.. and On..Changed functions
  • Move bunch of methods from Options.cs to OptionsManager.cs
  • De-spam multiple calls to external methods during option loading
  • Ensure 'activated features' defaults are set properly

Fixes: #1423
Updates: #62

They were all entangled hence somewhat larger than expected commit.
@originalfoo originalfoo added Usability Make mod easier to use technical Tasks that need to be performed in order to improve quality and maintainability UI User interface updates Settings Road config, mod options, config xml labels Feb 18, 2022
@originalfoo originalfoo added this to the 11.6.5.1 milestone Feb 18, 2022
@originalfoo originalfoo self-assigned this Feb 18, 2022
@originalfoo originalfoo marked this pull request as draft February 18, 2022 02:10
@originalfoo originalfoo added Dependent This issue is blocked by another issue. DO NOT MERGE YET Don't merge this PR, even if approved, until further notice labels Feb 18, 2022
Similar approach to CheckboxOption, but just a button.
- Move pathfind stats cb to overlays group
- Split maint buttons in to two groups...
- Tools group
- Config group
@originalfoo originalfoo added Dependent This issue is blocked by another issue. and removed Dependent This issue is blocked by another issue. labels Feb 21, 2022
@krzychu124
Copy link
Member

krzychu124 commented Feb 27, 2022

Do you have plans for Options checkbox that can use different class for storing/reading fields? I almost finished Allow despawn thingy but I'm thinking how to save/restore everything. Saving value for each vehicle type seems to be an overkill since we can read and store it as bitflags of ExtVehicleTypes.
Here is the list of available options, there are no overlapping so storing everything as single value will help with comparing.
image

! could use it like this instead of huge switch or chain of if...else

//MayDespawn if
|| Options.allowedDespawnVehicleTypes.IsFlagSet(extVehicle.vehicleType));

@originalfoo
Copy link
Member Author

originalfoo commented Feb 27, 2022

@krzychu124 We're limited to saving as byte currently = 8 bits.

EDIT: We could store it as a global option = much more flexible, eg. we could use int or whatever works best with xml.

@krzychu124
Copy link
Member

Yeah, global options might be a good idea to store this info

@krzychu124
Copy link
Member

We're limited to saving as byte currently = 8 bits.

Not if we get rid of ILegacySerializableOption interface from SerializableUIOptionBase and create another layer for byte options as a base for checkbox/slider options so I could create different type for GlobalConfig

On the other hand, we don't need load and save for globalconfig if we add event OnAfterValueSet or something like that (and set it to GlobalConfig.Save())

I'm not sure if you are going to change anything there but I can fix everything and create base for GlobalConfig options

@originalfoo
Copy link
Member Author

originalfoo commented Feb 28, 2022

The scope property has a Options.PersistTo.Global which I was planning to use (ie. when that's specified it will save to Main instance) but hand't got round to it yet.

Note that currently the checkboxes are defined as static fields on the group classes; I wasn't sure at what point global config gets loaded, and also what happens if it's reloaded or reset eg. in-game via the buttons on Maintenance tab? Like, how will that affect the instance reference?

@krzychu124
Copy link
Member

Note that currently the checkboxes are defined as static fields on the group classes; I wasn't sure at what point global config gets loaded, and also what happens if it's reloaded or reset eg. in-game via the buttons on Maintenance tab? Like, how will that affect the instance reference?

I already replaced static access with generic, reset/reload can be solver with observer. I'll experiment with that and try to add basic support for it. We can improve it later, since I already have working solution for "allow-despawn" feature but without persistence layer 😕

@originalfoo originalfoo removed DO NOT MERGE YET Don't merge this PR, even if approved, until further notice Dependent This issue is blocked by another issue. labels Feb 28, 2022
@originalfoo originalfoo marked this pull request as ready for review February 28, 2022 03:21
@originalfoo
Copy link
Member Author

ready for review

Copy link
Member

@krzychu124 krzychu124 left a comment

Choose a reason for hiding this comment

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

Looks ok 👍

Copy link
Collaborator

@kvakvs kvakvs left a comment

Choose a reason for hiding this comment

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

Looked through the changes, just minor naming

return SimulationAccuracy.MaxValue - value;
}
// See: OnAfterLoadData() and related methods
private static bool _needUpdateRoutingManager = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Confusing naming. Routing manager NEEDS update? We or someone else should update routing manager? Who will update?
Suggested naming: _updateRoutingManagerFlag | _routingManagerUpdateFlag, or _invalidateRoutingManager
Missing xmldoc. Don't send to read code instead of writing 1line explanation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a hunch it might not even be necessary (ie. it can probably be completely removed) but need to check first... brb

Copy link
Member Author

Choose a reason for hiding this comment

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

RoutingManager.OnAfterLoadData() invokes RecalculateAll() so I don't need the _needUpdateRoutingManager stuff (during deserialisation, I can just ignore requests because post-deserialisation the RoutingManager is going to do full recalc anyway).

However I noticed that RequestFullRecalculation() is doing different stuff to RecalculateAll() (nothing to do with this PR) so that might merit some investigation at future date.

Copy link
Member Author

Choose a reason for hiding this comment

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

@kianzarrin Can you verify my assumptions in the comment above - that during deserialisation I don't need to trigger RequestFullRecalculation() becuase routing manager will subseuqently do a RecalculateAll()?

@@ -262,11 +303,11 @@ public bool MayPublishSegmentChanges()
save[55] = OptionsMassEditTab.RoundAboutQuickFix_ParkingBanYieldR.Save();

save[56] = PoliciesTab.NoDoubleCrossings.Save();
save[57] = PoliciesTab.DedicatedTurningLanes.Save();
save[57] = PoliciesTab_AtJunctionsGroup.DedicatedTurningLanes.Save();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Naming. Save is an action to write something somewhere. What Save here doing is Serilalization, maybe Serialize? if that's not a reserved name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that naming is from the original CheckboxOption before I started altering it. As it's just converting bool to byte maybe ToByte() would be better name?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a task to #1356 to rename the methods.

@originalfoo originalfoo merged commit b4d19a6 into master Mar 2, 2022
@originalfoo originalfoo deleted the refactor-maintenance-features branch March 2, 2022 02:25
@kianzarrin
Copy link
Collaborator

kianzarrin commented Mar 2, 2022

@kianzarrin
Copy link
Collaborator

Actually it might be a commit before that but its in the PR

@kianzarrin
Copy link
Collaborator

image
red arrow is bad green arrow is good

@originalfoo
Copy link
Member Author

thanks for heads up - investgating...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Settings Road config, mod options, config xml technical Tasks that need to be performed in order to improve quality and maintainability UI User interface updates Usability Make mod easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing timed traffic lights and manual traffic lights buttons
4 participants