位置改变消息的条件为距离超过0.5和时间经过500ms改为位置有变化就通知,位置不变,时间再长也不通知,不过加入强制通知位置的机制

修改位置不变,如果没有500ms自动通知,颜色就不刷新的bug
更新虚拟飞行器状态的时间间隔由150改为50毫秒,飞机更平滑,不过i7只能飞500架左右,1000架的话还是需要改回150ms刷新一次
This commit is contained in:
xu 2020-04-22 01:14:16 +08:00
parent 717e77f6be
commit 9a9c25a1dd
3 changed files with 31 additions and 4 deletions

View File

@ -153,5 +153,9 @@ namespace Plane.Copters
Task DoCommandAckAsync(ushort command, byte result); Task DoCommandAckAsync(ushort command, byte result);
//强制刷新位置
void RefreashLoc();
} }
} }

View File

@ -723,7 +723,11 @@ namespace Plane.Copters
public string LEDColor public string LEDColor
{ {
get { return _LEDColor; } get { return _LEDColor; }
set { Set(nameof(LEDColor), ref _LEDColor, value); } set {
if (Set(nameof(LEDColor), ref _LEDColor, value))
//强制刷新颜色--在刷新位置时才刷新颜色
RefreashLoc();
}
} }
#if PRIVATE #if PRIVATE
@ -1131,14 +1135,33 @@ namespace Plane.Copters
protected void RaiseLocationChanged() => LocationChanged?.Invoke(this, EventArgs.Empty); protected void RaiseLocationChanged() => LocationChanged?.Invoke(this, EventArgs.Empty);
protected void RaiseLocationChangedIfNeeded() public void RefreashLoc()
{ {
if (_lastChangedLocation == null || this.CalcDistance(_lastChangedLocation) >= 0.5 || DateTime.Now.AddMilliseconds(-500) >= _lastRaiseLocationChangedTime) RaiseLocationChangedIfNeeded(true);
}
protected void RaiseLocationChangedIfNeeded(bool forcemk=false)
{
//强制刷新位置
if (forcemk)
{
RaiseLocationChanged();
return;
}
//减少计算量,在模拟飞机很多时花时间
bool EnRaise = true;
if (_lastChangedLocation != null)
EnRaise = (Altitude != _lastChangedLocation.Altitude) ||
(Latitude != _lastChangedLocation.Latitude) ||
(Longitude != _lastChangedLocation.Longitude);
//if (_lastChangedLocation == null || this.CalcDistance(_lastChangedLocation) >= 0.5 || DateTime.Now.AddMilliseconds(-500) >= _lastRaiseLocationChangedTime)
if (EnRaise)
{ {
RaiseLocationChanged(); RaiseLocationChanged();
_lastChangedLocation = new PLLocation(this); _lastChangedLocation = new PLLocation(this);
_lastRaiseLocationChangedTime = DateTime.Now; _lastRaiseLocationChangedTime = DateTime.Now;
} }
} }
protected void RaiseMissionItemReceived(MissionItemReceivedEventArgs e) protected void RaiseMissionItemReceived(MissionItemReceivedEventArgs e)

View File

@ -32,7 +32,7 @@ namespace Plane.Copters
/// <summary> /// <summary>
/// 更新虚拟飞行器状态的时间间隔,单位为毫秒。 /// 更新虚拟飞行器状态的时间间隔,单位为毫秒。
/// </summary> /// </summary>
private const int UPDATE_INTERVAL = 150; //150可以跑1000架 100可以跑500架 private const int UPDATE_INTERVAL = 50; //150可以跑1000架 100可以跑500架
/// <summary> /// <summary>
/// 对飞行器的模拟是否正在运行。 /// 对飞行器的模拟是否正在运行。