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

central default value #1702

Merged
merged 16 commits into from
Dec 16, 2022
Merged

central default value #1702

merged 16 commits into from
Dec 16, 2022

Conversation

kianzarrin
Copy link
Collaborator

@kianzarrin kianzarrin commented Nov 29, 2022

  • Divided Options class into 2 classes: SavedGameOptions (for the values) and TMPESettings (for the UI).
  • Moved default values to SavedGameOptions (before it was hard coded in the loading code).
  • Made SavedGameOptions and instant class so that I can reset default values by Instantiating SavedGameOptions.
    • Fixed all references to such option fields.
    • To do so I also fixed a patch that was using an option field.
      • moved the patch into a function for more readability (even though @krzychu124 prefers IL instructions!)
      • bonus fix: replaced 'Ldarg_2(copies vehicle struct) withLdarga_S, 2` (loads address to vehicle struct - notice extra 'a' that stands for address).
      • removed duplicate code in the patch
  • lifecycle: SavedGameOptions is Ensured (created if needed) in OnSettingsUI() and OnBeforeLoadData() and its released in Preload() and Unload().

Note: No functional change
Hint: you might want to review this commit separately . this is rename and has 90% of changes.
image

TMPE.zip

@kianzarrin kianzarrin added technical Tasks that need to be performed in order to improve quality and maintainability Settings Road config, mod options, config xml labels Nov 29, 2022
@kianzarrin kianzarrin self-assigned this Nov 29, 2022
@kianzarrin kianzarrin marked this pull request as ready for review November 29, 2022 16:54
@krzychu124
Copy link
Member

Doesn't work (loading user savegame)...

Info 487.6267004: OptionsManager.LoadData: 61 bytes
Error 487.6488223: System.Reflection.TargetException: Non-static field requires a target
  at System.Reflection.MonoField.SetValue (System.Object obj, System.Object val, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.FieldInfo.SetValue (System.Object obj, System.Object value) [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.Helpers.SerializableUIOptionBase`3[TrafficManager.API.Traffic.Enums.SimulationAccuracy,ColossalFramework.UI.UIDropDown,TrafficManager.UI.Helpers.DropDownOption`1[TrafficManager.API.Traffic.Enums.SimulationAccuracy]].set_Value (SimulationAccuracy value) [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.Helpers.DropDownOption`1[TrafficManager.API.Traffic.Enums.SimulationAccuracy].set_Value (SimulationAccuracy value) [0x00000] in <filename unknown>:0 
  at TrafficManager.UI.Helpers.DropDownOption`1[TrafficManager.API.Traffic.Enums.SimulationAccuracy].Load (Byte data) [0x00000] in <filename unknown>:0 
  at TrafficManager.Manager.Impl.OptionsManager.ToOption (System.Byte[] data, UInt32 idx, ILegacySerializableOption opt) [0x00000] in <filename unknown>:0 
  at TrafficManager.Manager.Impl.OptionsManager.LoadData (System.Byte[] data) [0x00000] in <filename unknown>:0 
	====================
   at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
   at CSUtil.Commons.Log.Error(System.String s)
   at TrafficManager.Util.Shortcuts.LogException(System.Exception ex, Boolean showInPanel)
   at TrafficManager.Manager.Impl.OptionsManager.LoadData(System.Byte[] data)
   at TrafficManager.Lifecycle.SerializableDataExtension.Load()
   at TrafficManager.Lifecycle.SerializableDataExtension.OnLoadData()
   at SerializableDataWrapper.OnLoadData()
   at SimulationManager.LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at SimulationManager.Managers_LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at LoadingManager+<LoadSimulationData>c__IteratorB.MoveNext()
   at AsyncTask.Execute()
   at SimulationManager.SimulationStep()
   at SimulationManager.SimulationThread()

TMPE.log

@kianzarrin kianzarrin marked this pull request as draft November 29, 2022 20:35
@kianzarrin kianzarrin marked this pull request as ready for review November 30, 2022 23:15
@kianzarrin kianzarrin added the Blocking Another issue depends on this issue. label Dec 2, 2022
@kianzarrin kianzarrin added this to the 11.7.3.0 milestone Dec 5, 2022
@krzychu124 krzychu124 self-requested a review December 8, 2022 17:28
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.

Does not work correctly, actually not a surprise for me since I mentioned about that.

Info 521.2699181: Initialization done. Loading mod data now.
Info 521.2834804: Loading VersionInfo Data! Length=424
Info 521.3043247: Reading VersionInfo from config
Info 521.3066605: Save game was created with TM:PE 11.7.2.32153 - Test
Info 521.3096925: Loading Data from New Load Routine! Length=8215
Info 521.3717997: Loading State from Config
Info 521.3738369: Loading 0 extended citizens
Info 521.3771330: Loading 0 extended citizen instances
Info 521.3785392: Priority segments data structure (old) undefined!
Info 521.3812201: Loading 0 priority segments (new method)
Info 521.3839069: Loading parking restrictions data. 0 elements
Info 521.3864258: Loading lane vehicle restriction data. 0 elements
Info 521.4002488: Loading 0 timed traffic lights (new method)
Info 521.4036183: Loading junction traffic light data (old method)
Info 521.4065993: Loading toggled traffic lights (new method)
Info 521.4076064: Lane arrow data structure (old) undefined!
Info 521.4103714: Loading lane arrow data (new method)
Info 521.4123714: Loading 0 lane connections
Info 521.4149324: Loading 0 lane connections
Info 521.4161229: Loading 0 lane connections
Info 521.4190053: Loading custom default speed limit data. 0 elements
Info 521.4218735: Loading lane speed limit data. 0 elements
Info 521.4249492: Loading junction restrictions. 0 elements
Info 521.4293720: OptionsManager.LoadData: 3497 bytes
Error 521.4362877: unrecognised value:60 for enum:SimulationAccuracy
   at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
   at CSUtil.Commons.Log.Error(System.String s)
   at TrafficManager.UI.Helpers.DropDownOption`1[[TrafficManager.API.Traffic.Enums.SimulationAccuracy, TMPE.API, Version=11.7.2.32152, Culture=neutral, PublicKeyToken=null]].set_Value(SimulationAccuracy value)
   at TrafficManager.UI.Helpers.DropDownOption`1[[TrafficManager.API.Traffic.Enums.SimulationAccuracy, TMPE.API, Version=11.7.2.32152, Culture=neutral, PublicKeyToken=null]].Load(Byte data)
   at TrafficManager.Manager.Impl.OptionsManager.ToOption(System.Byte[] data, UInt32 idx, ILegacySerializableOption opt)
   at TrafficManager.Manager.Impl.OptionsManager.LoadDataLegacy(System.Byte[] data)
   at TrafficManager.Manager.Impl.OptionsManager.LoadData(System.Byte[] data)
   at TrafficManager.Lifecycle.SerializableDataExtension.Load()
   at TrafficManager.Lifecycle.SerializableDataExtension.OnLoadData()
   at SerializableDataWrapper.OnLoadData()
   at SimulationManager.LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at SimulationManager.Managers_LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at LoadingManager+<LoadSimulationData>c__IteratorB.MoveNext()
   at AsyncTask.Execute()
   at SimulationManager.SimulationStep()
   at SimulationManager.SimulationThread()

Error 521.4419724: unrecognised value:120 for enum:RecklessDrivers
   at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
   at CSUtil.Commons.Log.Error(System.String s)
   at TrafficManager.UI.Helpers.DropDownOption`1[[TrafficManager.API.Traffic.Enums.RecklessDrivers, TMPE.API, Version=11.7.2.32152, Culture=neutral, PublicKeyToken=null]].set_Value(RecklessDrivers value)
   at TrafficManager.UI.Helpers.DropDownOption`1[[TrafficManager.API.Traffic.Enums.RecklessDrivers, TMPE.API, Version=11.7.2.32152, Culture=neutral, PublicKeyToken=null]].Load(Byte data)
   at TrafficManager.Manager.Impl.OptionsManager.ToOption(System.Byte[] data, UInt32 idx, ILegacySerializableOption opt)
   at TrafficManager.Manager.Impl.OptionsManager.LoadDataLegacy(System.Byte[] data)
   at TrafficManager.Manager.Impl.OptionsManager.LoadData(System.Byte[] data)
   at TrafficManager.Lifecycle.SerializableDataExtension.Load()
   at TrafficManager.Lifecycle.SerializableDataExtension.OnLoadData()
   at SerializableDataWrapper.OnLoadData()
   at SimulationManager.LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at SimulationManager.Managers_LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at LoadingManager+<LoadSimulationData>c__IteratorB.MoveNext()
   at AsyncTask.Execute()
   at SimulationManager.SimulationStep()
   at SimulationManager.SimulationThread()

Info 521.4852683: CheckboxOption.Value: `nodesOverlay` changed to True
Info 521.4874312: CheckboxOption.Value: `allowEnterBlockedJunctions` changed to True
Info 521.4885719: CheckboxOption.Value: `advancedAI` changed to True
Info 521.4895001: CheckboxOption.Value: `highwayRules` changed to True
Info 521.4939077: CheckboxOption.Value: `strongerRoadConditionEffects` changed to True
Info 521.4949835: CheckboxOption.Value: `allowUTurns` changed to True
Info 521.4964012: CheckboxOption.Value: `allowLaneChangesWhileGoingStraight` changed to True
Info 521.4979016: CheckboxOption.Value: `disableDespawning` changed to True
Info 521.4998670: CheckboxOption.Value: `parkingAI` changed to True
Info 521.5018157: CheckboxOption.Value: `preferOuterLane` changed to True
Info 521.5063603: CheckboxOption.Value: `evacBussesMayIgnoreRules` changed to True
Info 521.5078081: CheckboxOption.Value: `banRegularTrafficOnBusLanes` changed to True
Info 521.5100523: CheckboxOption.Value: `showPathFindStats` changed to True
Info 521.5141986: SliderOption.Value: `altLaneSelectionRatio` changed to 45
Error 521.5195614: unrecognised value:54 for enum:VehicleRestrictionsAggression
   at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
   at CSUtil.Commons.Log.Error(System.String s)
   at TrafficManager.UI.Helpers.DropDownOption`1[[TrafficManager.API.Traffic.Enums.VehicleRestrictionsAggression, TMPE.API, Version=11.7.2.32152, Culture=neutral, PublicKeyToken=null]].set_Value(VehicleRestrictionsAggression value)
   at TrafficManager.UI.Helpers.DropDownOption`1[[TrafficManager.API.Traffic.Enums.VehicleRestrictionsAggression, TMPE.API, Version=11.7.2.32152, Culture=neutral, PublicKeyToken=null]].Load(Byte data)
   at TrafficManager.Manager.Impl.OptionsManager.ToOption(System.Byte[] data, UInt32 idx, ILegacySerializableOption opt)
   at TrafficManager.Manager.Impl.OptionsManager.LoadDataLegacy(System.Byte[] data)
   at TrafficManager.Manager.Impl.OptionsManager.LoadData(System.Byte[] data)
   at TrafficManager.Lifecycle.SerializableDataExtension.Load()
   at TrafficManager.Lifecycle.SerializableDataExtension.OnLoadData()
   at SerializableDataWrapper.OnLoadData()
   at SimulationManager.LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at SimulationManager.Managers_LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
   at LoadingManager+<LoadSimulationData>c__IteratorB.MoveNext()
   at AsyncTask.Execute()
   at SimulationManager.SimulationStep()
   at SimulationManager.SimulationThread()

Info 521.5222948: CheckboxOption.Value: `trafficLightPriorityRules` changed to True
Info 521.5239486: CheckboxOption.Value: `realisticPublicTransport` changed to True
Info 521.5254218: CheckboxOption.Value: `allowNearTurnOnRed` changed to True
Info 521.5271850: CheckboxOption.Value: `allowFarTurnOnRed` changed to True
Info 521.5288149: CheckboxOption.Value: `RoundAboutQuickFix_NoCrossYieldR` changed to True
Info 521.5302995: CheckboxOption.Value: `PriorityRoad_CrossMainR` changed to True
Info 521.5326717: CheckboxOption.Value: `PriorityRoad_AllowLeftTurns` changed to True
Info 521.5342372: CheckboxOption.Value: `PriorityRoad_EnterBlockedYeild` changed to True
Info 521.5357333: CheckboxOption.Value: `PriorityRoad_StopAtEntry` changed to True
Info 521.5374737: CheckboxOption.Value: `RoundAboutQuickFix_RealisticSpeedLimits` changed to True
Info 521.5384945: CheckboxOption.Value: `RoundAboutQuickFix_ParkingBanYieldR` changed to True
Info 521.5399277: CheckboxOption.Value: `NoDoubleCrossings` changed to True
Info 521.5413940: CheckboxOption.Value: `DedicatedTurningLanes` changed to True
Info 521.5428891: CheckboxOption.Value: `showDefaultSpeedSubIcon` changed to True
Info 521.5443958: CheckboxOption.Value: `highwayMergingRules` changed to True
Info 521.5461050: OnLoadData completed successfully.

Seriously, looking at what values it tried to convert to enum something went horribly wrong and I have no idea what it actually saved in that xml...

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, UI remains synced when switching savegame 👍

@krzychu124 krzychu124 modified the milestones: 11.7.3.0, 11.7.4.0 Dec 13, 2022
@kianzarrin kianzarrin merged commit aadca33 into master Dec 16, 2022
@kianzarrin kianzarrin deleted the OptionsInstance branch December 16, 2022 16:14
@krzychu124 krzychu124 mentioned this pull request Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocking Another issue depends on this issue. Settings Road config, mod options, config xml technical Tasks that need to be performed in order to improve quality and maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants