Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
28f9f90
First version of extended sequences implemented
pnwparksfan Feb 7, 2025
5802045
Misc performance improvements
pnwparksfan Feb 7, 2025
b512ea6
fixed oops
pnwparksfan Feb 7, 2025
e8b8342
deconflict non-extended sequences
pnwparksfan Feb 7, 2025
d1f3364
Update version
pnwparksfan Feb 7, 2025
9cf940c
Added sequencer condition
pnwparksfan Feb 21, 2025
a61c045
Fixed and optimizations to better support sequence condition
pnwparksfan Feb 21, 2025
dcbd7cb
Fixed sequencers not processing on first beat
pnwparksfan Feb 27, 2025
268f0f9
Fixed lights not getting updated if not already enabled
pnwparksfan Feb 27, 2025
54f8f0e
Prevent deadlock if sequence is blank
pnwparksfan Mar 21, 2025
f795047
Fixed delta/start deg getting set incorrectly
pnwparksfan Mar 21, 2025
c4b6cd5
Adding caching of previously-active modes on control groups to resume…
pnwparksfan Mar 26, 2025
ff8b1f2
Add option (enabled by default) for control group condition to return…
pnwparksfan Mar 30, 2025
6b01dcc
Add DLS overall status to debug output
pnwparksfan Mar 30, 2025
a10723c
Improved handling of default modes when loading DLS or switching betw…
pnwparksfan Mar 30, 2025
2d48253
Increment minor version number
pnwparksfan Mar 30, 2025
5e268f6
Add condition for R* editor recording
pnwparksfan Mar 30, 2025
3befb0a
Fix group condition check
pnwparksfan Apr 17, 2025
9d34d71
Fixed sirens always being muted for AI vehicles and default siren sou…
pnwparksfan Apr 17, 2025
3e2b924
Increment version
pnwparksfan Apr 17, 2025
574c469
Added pause/console checks, fix race condition on siren sound disable
pnwparksfan Apr 21, 2025
18c97f8
Misc cleanup, version increment
pnwparksfan Apr 29, 2025
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
13 changes: 12 additions & 1 deletion DLSv2/Conditions/GlobalConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ private bool IsWeather(string weather)
NativeFunction.Natives.GET_CURR_WEATHER_STATE(out uint weather1, out uint weather2, out float pctWeather2);
return (weather1 == Game.GetHashKey(weather) && pctWeather2 <= 0.5f) || (weather2 == Game.GetHashKey(weather) && pctWeather2 >= 0.5f);
}
}
}

public class RecordingCondition : GlobalCondition
{
[XmlAttribute("active")]
public bool IsRecording { get; set; } = true;

protected override bool Evaluate()
{
return NativeFunction.Natives.IS_REPLAY_RECORDING<bool>() == IsRecording;
}
}
18 changes: 15 additions & 3 deletions DLSv2/Conditions/ModeConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DLSv2.Conditions;

using Core;
using System.Linq;

public class AudioControlGroupCondition : VehicleCondition
{
Expand Down Expand Up @@ -41,12 +42,23 @@ public class LightControlGroupCondition : VehicleCondition
public string ControlGroupName { get; set; }

[XmlAttribute("active")]
public bool GroupEnabled { get; set; }
public bool GroupEnabled { get; set; } = true;

[XmlAttribute("any_mode")]
public bool AnyModeInGroup { get; set; } = true;

protected override bool Evaluate(ManagedVehicle veh)
{
return veh.LightControlGroups.ContainsKey(ControlGroupName) &&
veh.LightControlGroups[ControlGroupName].Enabled == GroupEnabled;
if (!veh.LightControlGroups.ContainsKey(ControlGroupName))
return false;

var cg = veh.LightControlGroups[ControlGroupName];

if (!AnyModeInGroup)
return cg.Enabled == GroupEnabled;

// If allowed to check any mode in group
return cg.BaseControlGroup.Modes.Any(m => m.Modes.Any(m => veh.LightModes[m].Enabled)) == GroupEnabled;
}
}

Expand Down
31 changes: 31 additions & 0 deletions DLSv2/Conditions/SequenceConditions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Xml.Serialization;

namespace DLSv2.Conditions;

using Core;
using System.Linq;

public class SequenceBeatCondition : VehicleCondition
{
[XmlAttribute("sequence")]
public string Sequence
{
get => string.Concat(boolSequence.Select(x => x ? '1' : '0'));

set
{
boolSequence = value.Where(c => (c == '1' || c == '0')).Select(c => c == '1').ToArray();
}
}

internal bool[] boolSequence;

protected override bool Evaluate(ManagedVehicle veh)
{
return
boolSequence.Length > 0
&& veh.sirenInstance.TotalSirenBeats >= 0
&& boolSequence[veh.sirenInstance.TotalSirenBeats % boolSequence.Length];
}
}

3 changes: 3 additions & 0 deletions DLSv2/Conditions/VehicleStatusConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace DLSv2.Conditions;

public class DriverCondition : VehicleCondition
{
protected override uint UpdateWait => 100;
[XmlAttribute("has_driver")]
public bool HasDriver { get; set; } = true;

Expand Down Expand Up @@ -143,6 +144,8 @@ public class VehicleOwnerCondition : VehicleCondition

public class AtTrafficLightCondition : VehicleCondition
{
protected override uint UpdateWait => 100;

[XmlAttribute("stopped_at_light")]
public bool IsAtTrafficLight { get; set; }

Expand Down
59 changes: 49 additions & 10 deletions DLSv2/Core/DLSModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace DLSv2.Core;

using Rage;
using Utils;

[XmlRoot("Model")]
Expand Down Expand Up @@ -110,7 +111,7 @@ public class LightMode : BaseMode
public List<PaintJob> PaintJobs = new();

[XmlElement("SirenSettings", IsNullable = true)]
public SirenSetting SirenSettings = new();
public SirenSetting SirenSettings;

[XmlArray("Sequences", IsNullable = true)]
[XmlArrayItem("Item")]
Expand All @@ -119,34 +120,41 @@ public SequenceItem[] Sequences
get => sequences;
set
{


foreach (SequenceItem item in value)
{
if (SirenSettings == null) SirenSettings = new SirenSetting();
// Convert ID string to individual siren IDs
var ids = item.IDs == "all" ? Enumerable.Range(1, EmergencyLighting.MaxLights).Select(x => x.ToString()) : item.IDs.Split(',');

// Parse siren ID into one or more integers
foreach (string id in item.IDs.Split(','))
foreach (string id in ids)
{
// If siren ID string is a head/tail light sequencer, set and continue to next item
switch (id)
{
case "leftHeadLight":
SirenSettings.LeftHeadLightSequencer = new SequencerWrapper(item.Sequence);
if (SirenSettings == null) SirenSettings = new SirenSetting();
SirenSettings.LeftHeadLightSequencer = new SequencerWrapper(item.StandardSequence);
continue;
case "rightHeadLight":
SirenSettings.RightHeadLightSequencer = new SequencerWrapper(item.Sequence);
if (SirenSettings == null) SirenSettings = new SirenSetting();
SirenSettings.RightHeadLightSequencer = new SequencerWrapper(item.StandardSequence);
continue;
case "leftTailLight":
SirenSettings.LeftTailLightSequencer = new SequencerWrapper(item.Sequence);
if (SirenSettings == null) SirenSettings = new SirenSetting();
SirenSettings.LeftTailLightSequencer = new SequencerWrapper(item.StandardSequence);
continue;
case "rightTailLight":
SirenSettings.RightTailLightSequencer = new SequencerWrapper(item.Sequence);
if (SirenSettings == null) SirenSettings = new SirenSetting();
SirenSettings.RightTailLightSequencer = new SequencerWrapper(item.StandardSequence);
continue;
}

if (int.TryParse(id.Trim(), out int ID))
{
SirenEntry siren = new SirenEntry(ID) { Flashiness = new LightDetailEntry { Sequence = new Sequencer(item.Sequence) } };
SirenSettings.SirenList.Add(siren);
if (item.IsExtended) ExtendedSequences.Add(ID, item.Sequence);
else StandardSequences.Add(ID, item.Sequence);
} else
{
$"Mode {Name} siren id {id} is invalid".ToLog(LogLevel.ERROR);
Expand All @@ -159,6 +167,13 @@ public SequenceItem[] Sequences
}
private SequenceItem[] sequences;

[XmlIgnore]
// key = siren ID, value = extended sequence string
internal Dictionary<int, string> ExtendedSequences = new();

[XmlIgnore]
internal Dictionary<int, string> StandardSequences = new();

public override string ToString() => Name;
}

Expand Down Expand Up @@ -239,7 +254,31 @@ public class SequenceItem
public string IDs;

[XmlAttribute("sequence")]
public string Sequence;
public string Sequence
{
get => sequence;
set
{
// If initial length is less than 32 bits, repeat the sequence until it's over the min length
string origSeq = value;
origSeq = string.Concat(origSeq.Where(x => x == '1' || x == '0'));
if (string.IsNullOrEmpty(origSeq)) origSeq = "0";

string seq = origSeq;

while(seq.Length < 32)
{
seq += origSeq;
}
sequence = seq;
}
}

private string sequence;

public bool IsExtended => Sequence.Length > 32;

public string StandardSequence => Sequence.Substring(0, 32);
}

public class LightControlGroup : BaseControlGroup<LightModeSelection>
Expand Down
Loading