优化虚拟飞机计算过程,间隔改为150ms可以基本流程模拟1000架
This commit is contained in:
parent
d1a0283dad
commit
c72399d3b0
@ -32,7 +32,7 @@ namespace Plane.Copters
|
||||
/// <summary>
|
||||
/// 更新虚拟飞行器状态的时间间隔,单位为毫秒。
|
||||
/// </summary>
|
||||
private const int UPDATE_INTERVAL = 100;
|
||||
private const int UPDATE_INTERVAL = 150; //150可以跑1000架 100可以跑500架
|
||||
|
||||
/// <summary>
|
||||
/// 对飞行器的模拟是否正在运行。
|
||||
@ -139,14 +139,19 @@ namespace Plane.Copters
|
||||
this.Connection = connection ?? EmptyConnection.Instance;
|
||||
_isRunning = true;
|
||||
// 持续计算并更新虚拟飞行器的状态。
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// Task.Run(async () =>
|
||||
|
||||
Task.Factory.StartNew(async () =>
|
||||
|
||||
{
|
||||
while (_isRunning)
|
||||
{
|
||||
Update();
|
||||
await TaskUtils.Delay(UPDATE_INTERVAL).ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
, TaskCreationOptions.LongRunning
|
||||
);
|
||||
|
||||
|
||||
++HeartbeatCount;
|
||||
@ -682,10 +687,12 @@ namespace Plane.Copters
|
||||
// 更新高度。
|
||||
Altitude += altDelta;
|
||||
|
||||
|
||||
// 目标点相对于当前位置的方向。
|
||||
var direction = this.CalcDirection2D(lat, lng);
|
||||
|
||||
var direction = this.CalcDirection2D(lat, lng);
|
||||
/*
|
||||
// 更新姿态。
|
||||
|
||||
if (Mode == FlightMode.RTL)
|
||||
{
|
||||
// 林俊清, 20160126, 目前飞行器只在返航时会旋转机头,面对飞行方向。
|
||||
@ -701,6 +708,7 @@ namespace Plane.Copters
|
||||
// Roll = MAX_TILT_IN_FLIGHT * (float)Math.Sin(directionDelta);
|
||||
// Pitch = MAX_TILT_IN_FLIGHT * (float)Math.Cos(directionDelta);
|
||||
}
|
||||
*/
|
||||
|
||||
// 水平面上的移动距离。
|
||||
var moveInHorizontalPlane = Math.Sqrt(move * move - altDelta * altDelta);
|
||||
|
Loading…
Reference in New Issue
Block a user