Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
16042ad
renamed PersistTo to Scope
kianzarrin Nov 28, 2022
fac1c21
instantiate options in lifecycle
kianzarrin Nov 29, 2022
99f6d94
fix option usage in patches
kianzarrin Nov 29, 2022
849403c
moved classes to their own file
kianzarrin Nov 29, 2022
0fbb4e1
Merge branch 'master' into OptionsInstance
kianzarrin Nov 29, 2022
1939f8e
fixed debug build
kianzarrin Nov 29, 2022
54fdc36
undid Ldarga_S, 2
kianzarrin Nov 30, 2022
ea04bf7
fixed setvalue
kianzarrin Nov 30, 2022
d68db26
cache SavedGameOptions.Instance property
kianzarrin Nov 30, 2022
84bbc3d
kianzarrin Dec 1, 2022
4d3bd80
xml options
kianzarrin Dec 2, 2022
18e47ec
typo
kianzarrin Dec 5, 2022
46df582
Merge branch 'master' into OptionsInstance
kianzarrin Dec 5, 2022
daa2562
Merge branch 'master' into OptionsInstance
kianzarrin Dec 8, 2022
e22ceb1
increment version
kianzarrin Dec 8, 2022
5256557
fixed deserialize string
kianzarrin Dec 8, 2022
abb6114
polish
kianzarrin Dec 8, 2022
38f46b9
revert Strings.csv
kianzarrin Dec 11, 2022
4e75c11
fix UI Values are not updated between loads
kianzarrin Dec 11, 2022
16d60cb
Merge branch 'OptionsInstance' into options-XML3
kianzarrin Dec 13, 2022
f7e0606
bugfix: update UI
kianzarrin Dec 13, 2022
a79a95a
save options instance.
kianzarrin Dec 13, 2022
92b0a59
save options as XML string
kianzarrin Dec 16, 2022
8053d31
Merge branch 'master' into options-XML3
kianzarrin Dec 16, 2022
226d875
bugfixes
kianzarrin Dec 16, 2022
ef1af28
merge
kianzarrin Dec 16, 2022
5327723
save options in TMPE_Options_XML
kianzarrin Dec 16, 2022
1ae4714
drop path find version
kianzarrin Dec 16, 2022
227a5b8
Merge branch 'master' into options-XML3
kianzarrin Jan 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions TLM/TLM/Custom/PathFinding/CustomPathFind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class CustomPathFind : PathFind {

private GlobalConfig globalConf_;

private SavedGameOptions savedGameOptions_;

private struct BufferItem {
public PathUnit.Position Position;
public float ComparisonValue;
Expand Down Expand Up @@ -252,7 +254,9 @@ private bool ExtCalculatePath(uint unit, bool skipQueue) {
}

private void PathFindImplementation(uint unit, ref PathUnit data) {

globalConf_ = GlobalConfig.Instance; // NON-STOCK CODE
savedGameOptions_ = SavedGameOptions.Instance;

NetManager netManager = Singleton<NetManager>.instance;

Expand Down Expand Up @@ -298,11 +302,11 @@ private void PathFindImplementation(uint unit, ref PathUnit data) {
(queueItem_.vehicleType & ExtVehicleType.RoadVehicle) != ExtVehicleType.None;

isLaneArrowObeyingEntity_ =
(!Options.relaxedBusses || queueItem_.vehicleType != ExtVehicleType.Bus) &&
(!savedGameOptions_.relaxedBusses || queueItem_.vehicleType != ExtVehicleType.Bus) &&
(vehicleTypes_ & LaneArrowManager.VEHICLE_TYPES) != VehicleInfo.VehicleType.None &&
(queueItem_.vehicleType & LaneArrowManager.EXT_VEHICLE_TYPES) != ExtVehicleType.None;
#if DEBUG
isLaneArrowObeyingEntity_ &= !Options.allRelaxed;
isLaneArrowObeyingEntity_ &= !savedGameOptions_.allRelaxed;
#endif
#endif

Expand Down Expand Up @@ -1263,7 +1267,7 @@ ref nextLaneId.ToLane(),

if (isPedZoneRoad &&
// NON-STOCK CODE START skip execution when driving-only path for passenger car
!(Options.parkingAI &&
!(savedGameOptions_.parkingAI &&
queueItem_.vehicleType == ExtVehicleType.PassengerCar &&
queueItem_.pathType == ExtPathType.DrivingOnly)
// NON-STOCK CODE END
Expand Down Expand Up @@ -1366,7 +1370,7 @@ ref nextSegmentId.ToSegment(),
bool parkingAllowed = true;

// Parking AI: Determine if parking is allowed
if (Options.parkingAI) {
if (savedGameOptions_.parkingAI) {
if (isLogEnabled) {
DebugLog(
unitId,
Expand Down Expand Up @@ -1528,7 +1532,7 @@ ref sameSegLaneId.ToLane(),
}
} else {
// pocket car spawning
if (Options.parkingAI) {
if (savedGameOptions_.parkingAI) {
if (isLogEnabled) {
DebugLog(
unitId,
Expand Down Expand Up @@ -1792,11 +1796,11 @@ ref nextSegmentId.ToSegment(),
unitId,
item,
"ProcessItemMain: vehicle -> vehicle: Custom routing\n" +
$"\tOptions.advancedAI={Options.advancedAI}\n" +
$"\tOptions.advancedAI={savedGameOptions_.advancedAI}\n" +
$"\tprevIsRouted={prevIsRouted}\n" +
$"\tm_isRoadVehicle={isRoadVehicle_}\n" +
$"\tprevIsCarLane={prevIsCarLane}\n" +
$"\tm_stablePath={Options.advancedAI}");
$"\tm_stablePath={savedGameOptions_.advancedAI}");
}

// NON-STOCK CODE START
Expand All @@ -1812,7 +1816,7 @@ ref nextSegmentId.ToSegment(),
* Calculate Advanced Vehicle AI cost factors
* =============================================================================
*/
if (Options.advancedAI
if (savedGameOptions_.advancedAI
&& prevIsRouted
&& isRoadVehicle_
&& prevIsCarLane )
Expand Down Expand Up @@ -2692,7 +2696,7 @@ private bool ProcessItemCosts(
globalConf_.PathFinding.PublicTransportTransitionMaxPenalty;

bool applyTransportTransferPenalty =
Options.realisticPublicTransport &&
savedGameOptions_.realisticPublicTransport &&
!stablePath_ &&
(allowedLaneTypes &
(NetInfo.LaneType.PublicTransport | NetInfo.LaneType.Pedestrian)) ==
Expand All @@ -2708,7 +2712,7 @@ private bool ProcessItemCosts(
nextSegmentId,
$"ProcessItemCosts: Shall apply transport transfer penalty?\n" +
$"\tapplyTransportTransferPenalty={applyTransportTransferPenalty}\n" +
$"\tOptions.realisticPublicTransport={Options.realisticPublicTransport}\n" +
$"\tOptions.realisticPublicTransport={savedGameOptions_.realisticPublicTransport}\n" +
$"\tallowedLaneTypes={allowedLaneTypes}\n" +
$"\tallowedVehicleTypes={allowedVehicleTypes}\n" +
$"\tconf.pf.PubTranspTransitionMinPenalty={pfPublicTransportTransitionMinPenalty}\n" +
Expand Down Expand Up @@ -3239,12 +3243,12 @@ private void ProcessItemPedBicycle(
// NON-STOCK CODE START
bool mayCross = true;
#if JUNCTIONRESTRICTIONS || CUSTOMTRAFFICLIGHTS
if (Options.junctionRestrictionsEnabled || Options.timedLightsEnabled) {
if (savedGameOptions_.junctionRestrictionsEnabled || savedGameOptions_.timedLightsEnabled) {
bool nextIsStartNode = nextNodeId == nextSegment.m_startNode;

if (nextIsStartNode || nextNodeId == nextSegment.m_endNode) {
#if JUNCTIONRESTRICTIONS
if (Options.junctionRestrictionsEnabled &&
if (savedGameOptions_.junctionRestrictionsEnabled &&
item.Position.m_segment == nextSegmentId) {
// check if pedestrians are not allowed to cross here
if (!junctionManager.IsPedestrianCrossingAllowed(
Expand All @@ -3265,7 +3269,7 @@ private void ProcessItemPedBicycle(
#endif

#if CUSTOMTRAFFICLIGHTS
if (Options.timedLightsEnabled) {
if (savedGameOptions_.timedLightsEnabled) {
// check if pedestrian light won't change to green
CustomSegmentLights lights = customTrafficLightsManager.GetSegmentLights(nextSegmentId, nextIsStartNode, false);

Expand Down Expand Up @@ -3606,7 +3610,7 @@ private bool ProcessItemRouted(
* =====================================================================================
*/
bool canUseLane = CanUseLane(prevSegmentId, prevSegmentInfo, prevLaneIndex, prevLaneInfo, item.LaneId);
if (!canUseLane && Options.vehicleRestrictionsAggression ==
if (!canUseLane && savedGameOptions_.vehicleRestrictionsAggression ==
VehicleRestrictionsAggression.Strict) {
// vehicle is strictly prohibited to use this lane
if (isLogEnabled) {
Expand Down Expand Up @@ -3654,7 +3658,7 @@ private bool ProcessItemRouted(
bool isStockUturnPoint = (nextNode.m_flags & (NetNode.Flags.End | NetNode.Flags.OneWayOut)) != NetNode.Flags.None;

#if JUNCTIONRESTRICTIONS
if (Options.junctionRestrictionsEnabled) {
if (savedGameOptions_.junctionRestrictionsEnabled) {
bool nextIsStartNode = nextNodeId == prevSegment.m_startNode;
bool prevIsOutgoingOneWay =
nextIsStartNode
Expand Down Expand Up @@ -3712,7 +3716,7 @@ private bool ProcessItemRouted(
if (!canUseLane) {
laneSelectionCost *=
VehicleRestrictionsManager.PATHFIND_PENALTIES[
(int)Options.vehicleRestrictionsAggression];
(int)savedGameOptions_.vehicleRestrictionsAggression];
if (isLogEnabled) {
DebugLog(
unitId,
Expand All @@ -3727,7 +3731,7 @@ private bool ProcessItemRouted(
* Apply costs for large vehicles using inner lanes on highways
* =======================================================================================================
*/
if (Options.preferOuterLane &&
if (savedGameOptions_.preferOuterLane &&
isHeavyVehicle_ &&
isRoadVehicle_ &&
prevIsCarLane &&
Expand All @@ -3745,7 +3749,7 @@ private bool ProcessItemRouted(
item,
"ProcessItemRouted: Heavy trucks prefer outer lanes on highways: Applied lane costs\n"
+ "\t" + $"laneSelectionCost={laneSelectionCost}\n"
+ "\t" + $"Options.preferOuterLane={Options.preferOuterLane}\n"
+ "\t" + $"savedGameOptions_.preferOuterLane={savedGameOptions_.preferOuterLane}\n"
+ "\t" + $"m_isHeavyVehicle={isHeavyVehicle_}\n"
+ "\t" + $"m_isRoadVehicle={isRoadVehicle_}\n"
+ "\t" + $"prevIsCarLane={prevIsCarLane}\n"
Expand Down Expand Up @@ -4073,7 +4077,7 @@ private bool CanUseLane(ushort segmentId,
int laneIndex,
NetInfo.Lane laneInfo,
uint laneId) {
if (!Options.vehicleRestrictionsEnabled ||
if (!savedGameOptions_.vehicleRestrictionsEnabled ||
queueItem_.vehicleType == ExtVehicleType.None ||
queueItem_.vehicleType == ExtVehicleType.Tram ||
queueItem_.vehicleType == ExtVehicleType.Trolleybus ||
Expand Down
10 changes: 6 additions & 4 deletions TLM/TLM/Custom/PathFinding/PathfinderUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static class PathfinderUpdates {
[SuppressMessage("Usage", "RAS0002:Readonly field for a non-readonly struct", Justification = "Not performance critical.")]
internal static readonly byte LatestPathfinderEdition = 1;

public static byte SavegamePathfinderEdition = LatestPathfinderEdition;

/// <summary>
/// Checks savegame pathfinder edition and, if necessary, despawns
/// any vehicles that might have invalid paths due to bugs in the
Expand All @@ -38,13 +40,13 @@ public static class PathfinderUpdates {
public static ExtVehicleType DespawnVehiclesIfNecessary() {
var filter = ExtVehicleType.None;

if (Options.SavegamePathfinderEdition == LatestPathfinderEdition) {
if (SavegamePathfinderEdition == LatestPathfinderEdition) {
return filter; // nothing to do, everything is fine
}

Log.Info($"Pathfinder update from {Options.SavegamePathfinderEdition} to {LatestPathfinderEdition}.");
Log.Info($"Pathfinder update from {SavegamePathfinderEdition} to {LatestPathfinderEdition}.");

if (Options.SavegamePathfinderEdition < 1) {
if (SavegamePathfinderEdition < 1) {
filter |= ExtVehicleType.Plane; // #1338
}

Expand All @@ -60,7 +62,7 @@ public static ExtVehicleType DespawnVehiclesIfNecessary() {
}

// this will be stored in savegame
Options.SavegamePathfinderEdition = LatestPathfinderEdition;
SavegamePathfinderEdition = LatestPathfinderEdition;

return filter;
}
Expand Down
6 changes: 5 additions & 1 deletion TLM/TLM/Lifecycle/SerializableDataExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace TrafficManager.Lifecycle {
using TrafficManager.Manager.Impl;
using TrafficManager.Manager.Impl.LaneConnection;
using TrafficManager.State;
using Util;
using TrafficManager.Util;
using TrafficManager.Custom.PathFinding;

[UsedImplicitly]
public class SerializableDataExtension
Expand Down Expand Up @@ -216,6 +217,9 @@ private static void LoadDataState(out bool error) {
return;
}

// load Path Find Update
PathfinderUpdates.SavegamePathfinderEdition = _configuration.SavegamePathfinderEdition;

// load ext. citizens
if (_configuration.ExtCitizens != null) {
if (!ExtCitizenManager.Instance.LoadData(_configuration.ExtCitizens)) {
Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Lifecycle/TMPELifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private static void CompatibilityCheck() {
}

internal void Preload() {
SavedGameOptions.Release();
Patcher.InstallPreload();
Asset2Data = new Dictionary<BuildingInfo, AssetData>();
Log.Info("Preloading Managers");
Expand Down Expand Up @@ -343,7 +344,7 @@ internal void Load() {

internal void Unload() {
try {
Options.Available = false;
SavedGameOptions.Release();

GeometryNotifierDisposable?.Dispose();
GeometryNotifierDisposable = null;
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Lifecycle/ThreadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void OnBeforeSimulationTick() {
public override void OnBeforeSimulationFrame() {
base.OnBeforeSimulationFrame();

if (Options.timedLightsEnabled) {
if (SavedGameOptions.Instance.timedLightsEnabled) {
TrafficLightSimulationManager.Instance.SimulationStep();
}
}
Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Lifecycle/TrafficManagerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void OnSettingsUI(UIHelper helper) {
// Note: This bugs out if done in OnEnabled(), hence doing it here instead.
LocaleManager.eventLocaleChanged -= Translation.HandleGameLocaleChange;
LocaleManager.eventLocaleChanged += Translation.HandleGameLocaleChange;
Options.MakeSettings(helper);
SavedGameOptions.Ensure();
TMPESettings.MakeSettings(helper);
}

public void OnCreated(ILoading loading) { }
Expand Down
10 changes: 5 additions & 5 deletions TLM/TLM/Manager/Impl/AdvancedParkingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2415,12 +2415,12 @@ bool LoopHandler(int i, int j) {
out _))
{
NetInfo.Lane laneInfo = segmentInfo.m_lanes[laneIndex];
if (!Options.parkingRestrictionsEnabled ||
if (!SavedGameOptions.Instance.parkingRestrictionsEnabled ||
ParkingRestrictionsManager.Instance.IsParkingAllowed(
segmentId,
laneInfo.m_finalDirection))
{
if (!Options.vehicleRestrictionsEnabled ||
if (!SavedGameOptions.Instance.vehicleRestrictionsEnabled ||
(VehicleRestrictionsManager.Instance.GetAllowedVehicleTypes(
segmentId,
segmentInfo,
Expand Down Expand Up @@ -2658,7 +2658,7 @@ public bool FindParkingSpacePropAtBuilding(VehicleInfo vehicleInfo,
var result = false;

if (buildingInfo.m_class.m_service == ItemClass.Service.Residential &&
buildingId != homeId && rng.Int32((uint)Options.getRecklessDriverModulo()) != 0) {
buildingId != homeId && rng.Int32((uint)SavedGameOptions.Instance.getRecklessDriverModulo()) != 0) {
// NON-STOCK CODE
return false;
}
Expand Down Expand Up @@ -2830,7 +2830,7 @@ public bool FindParkingSpaceRoadSideForVehiclePos(VehicleInfo vehicleInfo,
out laneIndex,
out parkOffset))
{
if (!Options.parkingRestrictionsEnabled ||
if (!SavedGameOptions.Instance.parkingRestrictionsEnabled ||
ParkingRestrictionsManager.Instance.IsParkingAllowed(
segmentId,
netSegment.Info.m_lanes[laneIndex].m_finalDirection))
Expand Down Expand Up @@ -2936,7 +2936,7 @@ public bool VanillaFindParkingSpaceWithoutRestrictions(bool isElectric,
}

// in vanilla parkOffset is always >= 0 for RoadSideParkingSpace
if (Options.parkingRestrictionsEnabled && parkOffset >= 0) {
if (SavedGameOptions.Instance.parkingRestrictionsEnabled && parkOffset >= 0) {
if (netSegment.GetClosestLanePosition(
refPos,
NetInfo.LaneType.Parking,
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Manager/Impl/ExtBuildingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private ExtBuildingManager() {

public void OnBeforeSimulationStep(ushort buildingId, ref Building data) {
// slowly decrease parking space demand / public transport demand if Parking AI is active
if (!Options.parkingAI) {
if (!SavedGameOptions.Instance.parkingAI) {
return;
}

Expand Down
Loading