本文整理汇总了C#中System.Double.Average方法的典型用法代码示例。如果您正苦于以下问题:C# Double.Average方法的具体用法?C# Double.Average怎么用?C# Double.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Double
的用法示例。
在下文中一共展示了Double.Average方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updateData
//.........这里部分代码省略.........
maxrpm = shmem.ReadDouble(pos);
pos += sizeof(Double);
shmem.ReadArray<Double>(pos, driverTrkPos, 0, maxcars);
pos += maxcars * sizeof(Double);
Byte[] buf = new Byte[64];
shmem.ReadArray<Byte>(pos, buf, 0, 64);
pos += 64 * sizeof(Byte);
buf = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, buf);
carname = Encoding.UTF8.GetString(buf, 0, 64);
carname = carname.Substring(0, carname.IndexOf('\0'));
shmem.ReadArray<Byte>(pos, buf, 0, 64);
pos += 64 * sizeof(Byte);
buf = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, buf);
trackname = Encoding.UTF8.GetString(buf, 0, 64);
trackname = trackname.Substring(0, trackname.IndexOf('\0'));
// process
if (needReset && trackLength > 0)
{
reset();
LoadBestLap();
needReset = false;
}
if (prevstate != state)
{
if (state == 2) // entering driving mode
LoadBestLap();
else if (prevstate == 2) // exiting driving mode
SaveBestLap();
prevstate = state;
}
timedelta.Update(timestamp, driverTrkPos);
if (driverTrkPos[carid] < 0.1 && lastTickTrackPos > 0.9)
{
Double distance = (1 - lastTickTrackPos) + driverTrkPos[carid];
Double time = timestamp - lastTickTime;
Double tickCorrection = (1 - lastTickTrackPos) / distance;
// save lap time
if (lapTimeValid)
{
fuelcons[fuelconsPtr % fuelcons.Length] = fuel;
// update fuel consumption after one full lap
if (fuelconsPtr > 0)
{
if (fuelconsPtr >= fuelcons.Length)
{
Double[] consrate = new Double[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] - ((totallaps-lap) * consrate.Average()));
fuelconsumption = consrate.Average();
}
else if (fuelconsPtr > 0)
{
fuelneed = (Int32)(fuelcons[fuelconsPtr % fuelcons.Length] - ((totallaps - lap) * fuelcons[(fuelconsPtr - 1) % fuelcons.Length]));
fuelconsumption = fuelcons[(fuelconsPtr - 1) % fuelcons.Length] - fuelcons[fuelconsPtr % fuelcons.Length];
}
}
fuelconsPtr++;
}
// start new lap
lapStartTime = timestamp - (1 - tickCorrection) * time;
lapTimeValid = true;
// reset fuel consumption when in pits
if (driverTrkPos[carid] < 0)
{
fuelcons = new Double[fuelconslaps];
fuelconsPtr = 0;
}
}
else if (Math.Abs(driverTrkPos[carid] - lastTickTrackPos) > 0.1)
{
// invalidate lap time if jumping too much
lapTimeValid = false;
}
lastTickTrackPos = driverTrkPos[carid]; // save for next tick
lastTickTime = timestamp;
if (sessiontype >= 10) // if (race)
delta = timedelta.GetDelta(carid, carinfront);
else
delta = timedelta.GetBestLapDelta(driverTrkPos[carid] % 1);
}
}