You do some, you lose some
This commit is contained in:
1 parent
1d107924bf
commit
2ce0391c16
42 files changed
+331912
-5358
No files matched your search
@@ -22,6 +22,9 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
public const int TicksPerSecond = 60;
|
||||
public const float TickDelta = 1f / TicksPerSecond;
|
||||
public static bool IsSilentSimulation { get; private set; }
|
||||
|
||||
public static float PlaybackSpeed { get; set; } = 1f;
|
||||
|
||||
private readonly ReactiveProperty<int> _currentBattleFrame = new(0);
|
||||
public ReadOnlyReactiveProperty<int> CurrentBattleFrame => _currentBattleFrame;
|
||||
@@ -38,15 +41,18 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
private Dictionary<EntityId, BattleActionDecisionResult> _actionDecisionResults = new();
|
||||
|
||||
private SnapshotUtilityNonStatic _snapshotUtility = new();
|
||||
|
||||
|
||||
private BattleActionDecisionPanel _battleActionDecisionPanel;
|
||||
private CameraStateMachine _cameraStateMachine;
|
||||
|
||||
private SemaphoreSlim _preview = new(1,1);
|
||||
|
||||
|
||||
// Entity, damage
|
||||
private List<EntityAttackedData> _attackRequests = new();
|
||||
|
||||
private List<EntityAttackedData> _predictedAttackRequests = new();
|
||||
|
||||
|
||||
public BattleTimeline(
|
||||
BattleTimelinePanel timelinePanel,
|
||||
IEnumerable<BattleAction> battleActions,
|
||||
@@ -73,6 +79,14 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
public async UniTask RunBattleLoopAsync(List<EntityProperties> entities, CancellationToken ctx)
|
||||
{
|
||||
_entities = entities.ToDictionary(x => x.GetEntityId());
|
||||
|
||||
foreach (var (id, entity) in _entities)
|
||||
{
|
||||
_battleActionDatas[id] = new NoneBattleActionData() { Finished = true };
|
||||
_actionDecisionResults[id] = new AsIsBattleActionDeciderResult()
|
||||
{ ActionType = BattleActionType.None, ResultCode = BattleActionDecisionResultCode.Decided };
|
||||
}
|
||||
|
||||
_currentBattleFrame.Value = 0;
|
||||
|
||||
_battleSubscriptions = new DisposableBag();
|
||||
@@ -106,7 +120,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
await UniTask.Yield(PlayerLoopTiming.Update, ctx);
|
||||
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f);
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f) * PlaybackSpeed;
|
||||
|
||||
while (accumulator >= TickDelta)
|
||||
{
|
||||
@@ -141,6 +155,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
}
|
||||
|
||||
// TODO ЗАПУСКАТЬ ДВА ЦИКЛА ПОЛНЫЙ И ДО ПРЕРЫВАНИЯ
|
||||
|
||||
private async UniTask PreviewBattleLoopAsync(int frameCount,
|
||||
Dictionary<EntityId, EntityProperties> entities,
|
||||
CancellationToken ctx)
|
||||
@@ -183,6 +198,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
_preview.Release(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask PreviewBattleLoopAsync(EntityId entityId,
|
||||
Dictionary<EntityId, EntityProperties> entities,
|
||||
CancellationToken ctx)
|
||||
@@ -230,7 +246,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
bool isCanceled = await UniTask.Yield(PlayerLoopTiming.Update, ctx).SuppressCancellationThrow();
|
||||
if (isCanceled) break;
|
||||
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f);
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f) * PlaybackSpeed;
|
||||
|
||||
while (accumulator >= TickDelta && counter > 0 && !ctx.IsCancellationRequested)
|
||||
{
|
||||
@@ -261,6 +277,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask PlayTimelineUntilThatSpecific(EntityId specificEntityId, CancellationToken ctx)
|
||||
{
|
||||
float accumulator = 0f;
|
||||
@@ -270,7 +287,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
bool isCanceled = await UniTask.Yield(PlayerLoopTiming.Update, ctx).SuppressCancellationThrow();
|
||||
if (isCanceled) break;
|
||||
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f);
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f) * PlaybackSpeed;
|
||||
|
||||
while (accumulator >= TickDelta && !ctx.IsCancellationRequested)
|
||||
{
|
||||
@@ -300,6 +317,39 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
}
|
||||
}
|
||||
|
||||
public List<EntityAttackedData> PredictSilently(int lookaheadFrames)
|
||||
{
|
||||
// var snapshot = TakeFullBattleSnapshot();
|
||||
_snapshotUtility.GetSnapshots(
|
||||
_entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
|
||||
_predictedAttackRequests.Clear();
|
||||
IsSilentSimulation = true;
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < lookaheadFrames; i++)
|
||||
{
|
||||
var readyEntities = SimulateSingleFrame(_entities);
|
||||
if (readyEntities.Length > 0) break; // Останавливаемся, если чей-то ход закончился
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsSilentSimulation = false;
|
||||
|
||||
_snapshotUtility.RestoreFromSnapshots(
|
||||
_entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
// RestoreFullBattleSnapshot(snapshot);
|
||||
}
|
||||
|
||||
return _predictedAttackRequests;
|
||||
}
|
||||
|
||||
private EntityId[] SimulateSingleFrame(Dictionary<EntityId, EntityProperties> inEntities)
|
||||
{
|
||||
foreach (var (entityId, entity) in inEntities)
|
||||
@@ -446,6 +496,8 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
await _preview.WaitAsync(previewCancellationToken.Token);
|
||||
|
||||
PredictSilently(actionData.TotalFrames);
|
||||
|
||||
PreviewBattleLoopAsync(entityId, _entities, previewCancellationToken.Token)
|
||||
.Forget();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user