im trying to change speed value from 0,002543535 to 0 but i dont know how to do it and where to put the code.
using AssettoCorsaSharedMemory;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AssettoCorsa ac = new AssettoCorsa();
ac.StaticInfoInterval = 500; // Get StaticInfo updates ever 5 seconds
ac.StaticInfoUpdated = ac_StaticInfoUpdated; // Add event listener for StaticInfo
ac.PhysicsInterval = 500;
ac.PhysicsUpdated = ac_PhysicsUpdated;
ac.Start(); // Connect to shared memory and start interval timers
Console.ReadKey();
}
static void ac_StaticInfoUpdated(object sender, StaticInfoEventArgs e)
{
// Print out some data from StaticInfo
// Console.WriteLine("StaticInfo");
// Console.WriteLine(" Car Model: " e.StaticInfo.CarModel);
// Console.WriteLine(" Track: " e.StaticInfo.Track);
// Console.WriteLine(" Max RPM: " e.StaticInfo.MaxRpm);
}
static void ac_PhysicsUpdated(object sender, PhysicsEventArgs e)
{
// Print out some data from StaticInfo
Console.WriteLine(" Speed: " e.Physics.SpeedKmh);
// Console.WriteLine(" Gear: " e.Physics.Gear);
// Console.WriteLine(" TC: " e.Physics.TC);
Console.WriteLine(" RPM: " e.Physics.Rpms);
}
}
}
and this is code where SpeedKmh is declared
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace AssettoCorsaSharedMemory
{
public class PhysicsEventArgs : EventArgs
{
public PhysicsEventArgs (Physics physics)
{
this.Physics = physics;
}
public Physics Physics { get; private set; }
}
[StructLayout (LayoutKind.Sequential)]
public struct Coordinates
{
public float X;
public float Y;
public float Z;
}
[StructLayout (LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Unicode)]
[Serializable]
public struct Physics
{
public int PacketId;
public float Gas;
public float Brake;
public float Fuel;
public int Gear;
public int Rpms;
public float SteerAngle;
public float SpeedKmh;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 3)]
public float[] Velocity;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 3)]
public float[] AccG;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] WheelSlip;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] WheelLoad;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] WheelsPressure;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] WheelAngularSpeed;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] TyreWear;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] TyreDirtyLevel;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] TyreCoreTemperature;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] CamberRad;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] SuspensionTravel;
public float Drs;
public float TC;
public float Heading;
public float Pitch;
public float Roll;
public float CgHeight;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 5)]
public float[] CarDamage;
public int NumberOfTyresOut;
public int PitLimiterOn;
public float Abs;
public float KersCharge;
public float KersInput;
public int AutoShifterOn;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 2)]
public float[] RideHeight;
// since 1.5
public float TurboBoost;
public float Ballast;
public float AirDensity;
// since 1.6
public float AirTemp;
public float RoadTemp;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 3)]
public float[] LocalAngularVelocity;
public float FinalFF;
// since 1.7
public float PerformanceMeter;
public int EngineBrake;
public int ErsRecoveryLevel;
public int ErsPowerLevel;
public int ErsHeatCharging;
public int ErsisCharging;
public float KersCurrentKJ;
public int DrsAvailable;
public int DrsEnabled;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] BrakeTemp;
// since 1.10
public float Clutch;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] TyreTempI;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] TyreTempM;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public float[] TyreTempO;
// since 1.10.2
public int IsAIControlled;
// since 1.11
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public Coordinates[] TyreContactPoint;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public Coordinates[] TyreContactNormal;
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 4)]
public Coordinates[] TyreContactHeading;
public float BrakeBias;
// since 1.12
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 3)]
public float[] LocalVelocity;
}
}
when my car is not moving im getting speed value like on the picture, anyone know how to change it to just 0? _______________________________________________________________________________________
CodePudding user response:
Probably here (didn't see anywhere else it is possible):
static void ac_PhysicsUpdated(object sender, PhysicsEventArgs e)
{
Console.WriteLine(" Speed: " e.Physics.SpeedKmh); // <---
// ...
}
You can use System.Math.Round
method to get nearest integer value or cast explicitly to int
type:
float speed = e.Physics.SpeedKmh; // <-- 0.002543535 (float type)
double dRoundedSpeed = Math.Round(speed); // <-- 0 (double type)
float fRoundedSpeed = (float)Math.Round(speed); // <-- 0 (float type)
int iRoundedSpeed = (int)speed; // <-- 0 (int type)