Phase 4: TimeScale加速仿真, 109测试5秒完成
This commit is contained in:
parent
0ec0b2c002
commit
eb347b3bb0
@ -29,6 +29,8 @@ namespace CounterDrone.Core.Simulation
|
||||
public SimulationState State { get; private set; } = SimulationState.Idle;
|
||||
public int FrameIndex { get; private set; }
|
||||
public float SimulationTime { get; private set; }
|
||||
/// <summary>时间倍速:>1 加速仿真(仅测试或快速推演用)</summary>
|
||||
public float TimeScale { get; set; } = 1f;
|
||||
private float _tickInterval;
|
||||
|
||||
private List<DroneEntity> _drones = new();
|
||||
@ -134,7 +136,8 @@ namespace CounterDrone.Core.Simulation
|
||||
if (State != SimulationState.Running)
|
||||
return new SimulationFrameResult { State = State, FrameIndex = FrameIndex, SimulationTime = SimulationTime };
|
||||
|
||||
SimulationTime += deltaTime;
|
||||
var scaledDt = deltaTime * TimeScale;
|
||||
SimulationTime += scaledDt;
|
||||
FrameIndex++;
|
||||
var frameEvents = new List<SimEvent>();
|
||||
|
||||
@ -167,7 +170,7 @@ namespace CounterDrone.Core.Simulation
|
||||
// 2. 弹药飞行 → 云团生成
|
||||
foreach (var m in _munitions.ToList())
|
||||
{
|
||||
m.Update(deltaTime);
|
||||
m.Update(scaledDt);
|
||||
if (m.HasArrived)
|
||||
{
|
||||
var disp = AlgorithmFactory.Create<ICloudDispersionModel>();
|
||||
@ -186,7 +189,7 @@ namespace CounterDrone.Core.Simulation
|
||||
// 3. 云团演化
|
||||
foreach (var c in _clouds.ToList())
|
||||
{
|
||||
c.Tick(deltaTime, (float)_scene.WindSpeed, (WindDirection)_scene.WindDirection);
|
||||
c.Tick(scaledDt, (float)_scene.WindSpeed, (WindDirection)_scene.WindDirection);
|
||||
if (c.IsDissipated) _clouds.Remove(c);
|
||||
}
|
||||
|
||||
@ -197,10 +200,10 @@ namespace CounterDrone.Core.Simulation
|
||||
{
|
||||
if (cloud.ContainsPoint(drone.PosX, drone.PosY, drone.PosZ))
|
||||
{
|
||||
drone.ExposureTime += deltaTime;
|
||||
drone.ExposureTime += scaledDt;
|
||||
var dmg = _damageModel.CalculateDamage(
|
||||
drone.TargetType, drone.PowerType, cloud.AerosolType,
|
||||
cloud.Dispersion.CoreDensity, drone.ExposureTime, deltaTime);
|
||||
cloud.Dispersion.CoreDensity, drone.ExposureTime, scaledDt);
|
||||
drone.ApplyDamage(dmg);
|
||||
if (drone.Status == DroneStatus.Destroyed)
|
||||
frameEvents.Add(new SimEvent
|
||||
@ -215,7 +218,7 @@ namespace CounterDrone.Core.Simulation
|
||||
// 5. 无人机移动
|
||||
foreach (var drone in _drones.Where(d => d.Status == DroneStatus.Flying))
|
||||
{
|
||||
drone.Update(deltaTime, (float)_scene.WindSpeed, (WindDirection)_scene.WindDirection);
|
||||
drone.Update(scaledDt, (float)_scene.WindSpeed, (WindDirection)_scene.WindDirection);
|
||||
if (drone.Status == DroneStatus.ReachedTarget)
|
||||
frameEvents.Add(new SimEvent
|
||||
{
|
||||
@ -225,7 +228,7 @@ namespace CounterDrone.Core.Simulation
|
||||
}
|
||||
|
||||
// 6. 平台冷却
|
||||
foreach (var p in _platforms) p.Update(deltaTime);
|
||||
foreach (var p in _platforms) p.Update(scaledDt);
|
||||
|
||||
// 7. 管控区域
|
||||
foreach (var drone in _drones.Where(d => d.Status == DroneStatus.Flying))
|
||||
|
||||
@ -82,6 +82,7 @@ namespace CounterDrone.Core.Tests
|
||||
}
|
||||
|
||||
engine.Initialize(_taskId);
|
||||
engine.TimeScale = 4f; // 4倍速加速
|
||||
for (int i = 0; i < maxTicks; i++)
|
||||
{
|
||||
var r = engine.Tick(tickDt);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user