本文整理汇总了C#中Single.Average方法的典型用法代码示例。如果您正苦于以下问题:C# Single.Average方法的具体用法?C# Single.Average怎么用?C# Single.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Single
的用法示例。
在下文中一共展示了Single.Average方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updateData
public void updateData()
{
// Check if the SDK is connected
if (sdk.IsConnected())
{
// telemetry
gear = (Int32)sdk.GetData("Gear");
rpm = (Int32)(Single)sdk.GetData("RPM");
speed = (Int32)((Single)sdk.GetData("Speed") * 3.6);
fuel = (Int32)((Single)sdk.GetData("FuelLevel"));
shiftindicator = (Single)sdk.GetData("ShiftIndicatorPct");
Int32 enwarn = (Int32)sdk.GetData("EngineWarnings");
if (((Int32)sdk.GetData("EngineWarnings") & 0x10) > 0)
pitlimiter = true;
else
pitlimiter = false;
lap = (Int32)sdk.GetData("Lap");
lapsrem = (Int32)sdk.GetData("SessionLapsRemain");
Double sessionTime = new Double();
Boolean curontrack = (Boolean)sdk.GetData("IsOnTrack");
if (curontrack == false && ontrack == true)
SaveBestLap();
ontrack = curontrack;
if (ontrack)
sessionTime = (Double)sdk.GetData("SessionTime");
else
sessionTime = (Double)sdk.GetData("ReplaySessionTime");
if (carIdx >= 0) // skip things that require caridx if we don't have it
{
Int32[] driverLaps = new Int32[64];
driverLaps = (Int32[])sdk.GetData("CarIdxLap");
Single[] driverTrkPos = new Single[64];
driverTrkPos = (Single[])sdk.GetData("CarIdxLapDistPct");
Int32 lapPointer = (Int32)Math.Floor((driverTrkPos[carIdx] % 1) * (trackLength / 10));
timedelta.Update(sessionTime, driverTrkPos);
if (driverTrkPos[carIdx] < 0.1 && lastTickTrackPos > 0.9)
{
Double distance = (1 - lastTickTrackPos) + driverTrkPos[carIdx];
Double time = sessionTime - lastTickTime;
Double tickCorrection = (1 - lastTickTrackPos) / distance;
// save lap time
if (lapTimeValid)
{
Double laptime = (sessionTime - (1 - tickCorrection) * time) - lapStartTime;
prevlap = new TimeSpan(0, 0, 0, (Int32)Math.Floor(laptime), (Int32)Math.Floor((laptime % 1) * 1000));
fuelcons[fuelconsPtr % fuelcons.Length] = (Single)sdk.GetData("FuelLevel");
// update fuel consumption after one full lap
if (fuelconsPtr > 0)
{
if (fuelconsPtr >= fuelcons.Length)
{
Single[] consrate = new Single[fuelcons.Length-1];
Int32 j = 0;
for (int i = fuelconsPtr; i < fuelconsPtr+consrate.Length; i++)
{
consrate[j++] = fuelcons[(i + 1) % fuelcons.Length] - fuelcons[(i + 2) % fuelcons.Length];
}
fuelneed = (Int32)(fuelcons[fuelconsPtr % fuelcons.Length] - (lapsrem * consrate.Average()));
fuelconsumption = consrate.Average();
}
else if (fuelconsPtr > 0)
{
fuelneed = (Int32)(fuelcons[fuelconsPtr % fuelcons.Length] - (lapsrem * fuelcons[(fuelconsPtr - 1) % fuelcons.Length]));
fuelconsumption = fuelcons[(fuelconsPtr - 1) % fuelcons.Length] - fuelcons[fuelconsPtr % fuelcons.Length];
}
}
fuelconsPtr++;
}
// start new lap
lapStartTime = sessionTime - (1 - tickCorrection) * time;
lapTimeValid = true;
}
else if(Math.Abs(driverTrkPos[carIdx] - lastTickTrackPos) > 0.1) {
// invalidate lap time if jumping too much
lapTimeValid = false;
}
// reset fuel consumption when in pits
TrackLocation[] trackSurface = (iRSDKSharp.TrackLocation[])sdk.GetData("CarIdxTrackSurface");
if (trackSurface[carIdx] == TrackLocation.irsdk_InPitStall)
{
fuelcons = new Single[fuelconslaps];
fuelconsPtr = 0;
}
//.........这里部分代码省略.........