Skip to content

Commit

Permalink
port trackmania to inlinearrays as well
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Mar 14, 2024
1 parent 7c24c30 commit 413f36c
Show file tree
Hide file tree
Showing 18 changed files with 654 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TargetFramework>net8.0</TargetFramework>
<Platforms>x64</Platforms>
<EnableDynamicLoading>true</EnableDynamicLoading>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions src/Artemis.Plugins.Games.TrackMania/DataModels/CarHandicap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Artemis.Plugins.Games.TrackMania.DataModels;

[Flags]
public enum CarHandicap
{
None = 0,
EngineForcedOff = 1,
EngineForcedOn = 2,
NoBrakes = 4,
NoSteering = 8,
NoGrip = 16
}
20 changes: 20 additions & 0 deletions src/Artemis.Plugins.Games.TrackMania/DataModels/GameDataModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Artemis.Core.Modules;
using Artemis.Plugins.Games.TrackMania.Telemetry;

namespace Artemis.Plugins.Games.TrackMania.DataModels;

public class GameDataModel
{
public EGameState State { get; set; }
public string GameplayVariant { get; set; }
public string MapName { get; set; }
public string MapId { get; set; }

public void Apply(in STelemetry telemetry)
{
State = telemetry.Game.State;
GameplayVariant = telemetry.Game.GameplayVariant;
MapName = telemetry.Game.MapName;
MapId = telemetry.Game.MapId;
}
}
179 changes: 15 additions & 164 deletions src/Artemis.Plugins.Games.TrackMania/DataModels/PluginDataModel.cs
Original file line number Diff line number Diff line change
@@ -1,174 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Modules;
using Artemis.Core.Modules;
using Artemis.Plugins.Games.TrackMania.Telemetry;

namespace Artemis.Plugins.Games.TrackMania.DataModels
{
public class PluginDataModel : DataModel
{
public TrackManiaVersion TrackManiaVersion { get; set; }

[DataModelProperty(Description = "Information about the current state of the game")]
public GameDataModel Game { get; set; } = new();

[DataModelProperty(Description = "Information about the current state of the race")]
public RaceDataModel Race { get; set; } = new();

[DataModelProperty(Description = "Current information about the vehicle itself")]
public VehicleDataModel Vehicle { get; set; } = new();

public void Apply(STelemetry telemetry)
{
Game.Apply(telemetry);
Race.Apply(telemetry);
Vehicle.Apply(telemetry);
}
}

public class GameDataModel : DataModel
{
public STelemetry.EGameState State { get; set; }
public string GameplayVariant { get; set; }
public string MapName { get; set; }
public string MapId { get; set; }


public void Apply(STelemetry telemetry)
{
State = telemetry.Game.State;
GameplayVariant = telemetry.Game.GameplayVariant;
MapName = telemetry.Game.MapName;
MapId = telemetry.Game.MapId;
}
}

public class RaceDataModel : DataModel
{
public STelemetry.ERaceState State { get; set; }
public TimeSpan Time { get; set; }
public int Respawns { get; set; }
public int Checkpoints { get; set; }

public List<TimeSpan> CheckpointTimes { get; set; }
public int CheckpointsPerLap { get; set; }
public int Laps { get; set; }

public void Apply(STelemetry telemetry)
{
State = telemetry.Race.State;
Time = TimeSpan.FromMilliseconds(Math.Max(0, telemetry.Race.Time));
Respawns = (int) telemetry.Race.NbRespawns;
Checkpoints = (int) telemetry.Race.NbCheckpoints;

CheckpointTimes = telemetry.Race.CheckpointTimes.Select(t => TimeSpan.FromMilliseconds(Math.Max(0, t))).ToList();
CheckpointsPerLap = (int) telemetry.Race.NbCheckpointsPerLap;
Laps = (int) telemetry.Race.NbLaps;
}
}


public class VehicleDataModel : DataModel
{
public float InputSteer { get; set; }
public float InputGasPedal { get; set; }
public bool InputIsBraking { get; set; }
public bool InputIsHorn { get; set; }

public float EngineRpm { get; set; } // 1500 -> 10000
public int EngineCurGear { get; set; }
public float EngineTurboRatio { get; set; } // 1 turbo starting/full .... 0 -> finished
public bool EngineFreeWheeling { get; set; }

public WheelDataModel FrontLeftWheel { get; set; } = new();
public WheelDataModel FrontRightWheel { get; set; } = new();
public WheelDataModel BackLeftWheel { get; set; } = new();
public WheelDataModel BackRightWheel { get; set; } = new();

public float WheelsDamperRangeMin { get; set; }
public float WheelsDamperRangeMax { get; set; }

public float RumbleIntensity { get; set; }

public int MetricSpeed { get; set; }
public int ImperialSpeed { get; set; }
public bool IsInWater { get; set; }
public bool IsSparkling { get; set; }
public bool IsLightTrails { get; set; }
public bool IsLightsOn { get; set; }
public bool IsFlying { get; set; } // long time since touching ground.
public bool IsOnIce { get; set; }
public CarHandicap Handicap { get; set; }
public uint HandicapTest { get; set; }
public float BoostRatio { get; set; }

public void Apply(STelemetry telemetry)
{
InputSteer = telemetry.Vehicle.InputSteer;
InputGasPedal = telemetry.Vehicle.InputGasPedal;
InputIsBraking = telemetry.Vehicle.InputIsBraking;
InputIsHorn = telemetry.Vehicle.InputIsHorn;

EngineRpm = telemetry.Vehicle.EngineRpm;
EngineCurGear = (int) telemetry.Vehicle.EngineCurGear;
EngineTurboRatio = telemetry.Vehicle.EngineTurboRatio;
EngineFreeWheeling = telemetry.Vehicle.EngineFreeWheeling;

FrontLeftWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[0];
FrontLeftWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[0];
FrontLeftWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[0];
FrontRightWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[1];
FrontRightWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[1];
FrontRightWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[1];
BackLeftWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[2];
BackLeftWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[2];
BackLeftWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[2];
BackRightWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[3];
BackRightWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[3];
BackRightWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[3];
namespace Artemis.Plugins.Games.TrackMania.DataModels;

public class PluginDataModel : DataModel
{
public TrackManiaVersion TrackManiaVersion { get; set; }

WheelsDamperRangeMin = telemetry.Vehicle.WheelsDamperRangeMin;
WheelsDamperRangeMax = telemetry.Vehicle.WheelsDamperRangeMax;
RumbleIntensity = telemetry.Vehicle.RumbleIntensity;
[DataModelProperty(Description = "Information about the current state of the game")]
public GameDataModel Game { get; set; } = new();

MetricSpeed = (int) telemetry.Vehicle.SpeedMeter;
ImperialSpeed = (int) Math.Round(telemetry.Vehicle.SpeedMeter * 0.621, MidpointRounding.AwayFromZero);
IsInWater = telemetry.Vehicle.IsInWater;
IsSparkling = telemetry.Vehicle.IsSparkling;
IsLightTrails = telemetry.Vehicle.IsLightTrails;
IsLightsOn = telemetry.Vehicle.IsLightsOn;
IsFlying = telemetry.Vehicle.IsFlying;
IsOnIce = telemetry.Vehicle.IsOnIce;
Handicap = telemetry.Vehicle.Handicap;
BoostRatio = telemetry.Vehicle.BoostRatio;
}
[DataModelProperty(Description = "Information about the current state of the race")]
public RaceDataModel Race { get; set; } = new();

[DataModelProperty(Description = "Current information about the vehicle itself")]
public VehicleDataModel Vehicle { get; set; } = new();

}

public class WheelDataModel
{
public bool HasGroundContact { get; set; }
public bool IsSlipping { get; set; }
public float DamperLength { get; set; }
}

public enum TrackManiaVersion
{
ManiaPlanet
}


[Flags]
public enum CarHandicap
internal void Apply(in STelemetry telemetry)
{
None = 0,
EngineForcedOff = 1,
EngineForcedOn = 2,
NoBrakes = 4,
NoSteering = 8,
NoGrip = 16
Game.Apply(in telemetry);
Race.Apply(in telemetry);
Vehicle.Apply(in telemetry);
}
}
29 changes: 29 additions & 0 deletions src/Artemis.Plugins.Games.TrackMania/DataModels/RaceDataModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Artemis.Plugins.Games.TrackMania.Telemetry;

namespace Artemis.Plugins.Games.TrackMania.DataModels;

public class RaceDataModel
{
public ERaceState State { get; set; }
public TimeSpan Time { get; set; }
public int Respawns { get; set; }
public int Checkpoints { get; set; }

public TimeSpan[] CheckpointTimes { get; set; } = new TimeSpan[125];
public int CheckpointsPerLap { get; set; }
public int Laps { get; set; }

public void Apply(in STelemetry telemetry)
{
State = telemetry.Race.State;
Time = TimeSpan.FromMilliseconds(Math.Max(0, telemetry.Race.Time));
Respawns = (int) telemetry.Race.NbRespawns;
Checkpoints = (int) telemetry.Race.NbCheckpoints;
ReadOnlySpan<int> checkpointTimes = telemetry.Race.CheckpointTimes;
for (var i = 0; i < checkpointTimes.Length; i++)
CheckpointTimes[i] = TimeSpan.FromMilliseconds(Math.Max(0, checkpointTimes[i]));
CheckpointsPerLap = (int) telemetry.Race.NbCheckpointsPerLap;
Laps = (int) telemetry.Race.NbLaps;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Artemis.Plugins.Games.TrackMania.DataModels;

public enum TrackManiaVersion
{
ManiaPlanet
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using Artemis.Plugins.Games.TrackMania.Telemetry;

namespace Artemis.Plugins.Games.TrackMania.DataModels;

public class VehicleDataModel
{
public float InputSteer { get; set; }
public float InputGasPedal { get; set; }
public bool InputIsBraking { get; set; }
public bool InputIsHorn { get; set; }

public float EngineRpm { get; set; } // 1500 -> 10000
public int EngineCurGear { get; set; }
public float EngineTurboRatio { get; set; } // 1 turbo starting/full .... 0 -> finished
public bool EngineFreeWheeling { get; set; }

public WheelDataModel FrontLeftWheel { get; set; } = new();
public WheelDataModel FrontRightWheel { get; set; } = new();
public WheelDataModel BackLeftWheel { get; set; } = new();
public WheelDataModel BackRightWheel { get; set; } = new();

public float WheelsDamperRangeMin { get; set; }
public float WheelsDamperRangeMax { get; set; }

public float RumbleIntensity { get; set; }

public int MetricSpeed { get; set; }
public int ImperialSpeed { get; set; }
public bool IsInWater { get; set; }
public bool IsSparkling { get; set; }
public bool IsLightTrails { get; set; }
public bool IsLightsOn { get; set; }
public bool IsFlying { get; set; } // long time since touching ground.
public bool IsOnIce { get; set; }
public CarHandicap Handicap { get; set; }
public uint HandicapTest { get; set; }
public float BoostRatio { get; set; }

public void Apply(in STelemetry telemetry)
{
InputSteer = telemetry.Vehicle.InputSteer;
InputGasPedal = telemetry.Vehicle.InputGasPedal;
InputIsBraking = telemetry.Vehicle.InputIsBraking;
InputIsHorn = telemetry.Vehicle.InputIsHorn;

EngineRpm = telemetry.Vehicle.EngineRpm;
EngineCurGear = (int) telemetry.Vehicle.EngineCurGear;
EngineTurboRatio = telemetry.Vehicle.EngineTurboRatio;
EngineFreeWheeling = telemetry.Vehicle.EngineFreeWheeling;

FrontLeftWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[0];
FrontLeftWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[0];
FrontLeftWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[0];
FrontRightWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[1];
FrontRightWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[1];
FrontRightWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[1];
BackLeftWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[2];
BackLeftWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[2];
BackLeftWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[2];
BackRightWheel.HasGroundContact = telemetry.Vehicle.WheelsIsGroundContact[3];
BackRightWheel.IsSlipping = telemetry.Vehicle.WheelsIsSliping[3];
BackRightWheel.DamperLength = telemetry.Vehicle.WheelsDamperLen[3];


WheelsDamperRangeMin = telemetry.Vehicle.WheelsDamperRangeMin;
WheelsDamperRangeMax = telemetry.Vehicle.WheelsDamperRangeMax;
RumbleIntensity = telemetry.Vehicle.RumbleIntensity;

MetricSpeed = (int) telemetry.Vehicle.SpeedMeter;
ImperialSpeed = (int) Math.Round(telemetry.Vehicle.SpeedMeter * 0.621, MidpointRounding.AwayFromZero);
IsInWater = telemetry.Vehicle.IsInWater;
IsSparkling = telemetry.Vehicle.IsSparkling;
IsLightTrails = telemetry.Vehicle.IsLightTrails;
IsLightsOn = telemetry.Vehicle.IsLightsOn;
IsFlying = telemetry.Vehicle.IsFlying;
IsOnIce = telemetry.Vehicle.IsOnIce;
Handicap = telemetry.Vehicle.Handicap;
BoostRatio = telemetry.Vehicle.BoostRatio;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Artemis.Plugins.Games.TrackMania.DataModels;

public class WheelDataModel
{
public bool HasGroundContact { get; set; }
public bool IsSlipping { get; set; }
public float DamperLength { get; set; }
}
Loading

0 comments on commit 413f36c

Please sign in to comment.