You fix some, you brake some
This commit is contained in:
1 parent
d810ea00b6
commit
1a75cf8461
778 files changed
+203405
-86541
No files matched your search
@@ -107,7 +107,24 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
var readyEntities = SimulateSingleFrame(_entities);
|
||||
|
||||
if (readyEntities.Length > 0) return readyEntities;
|
||||
if (readyEntities.Length > 0)
|
||||
{
|
||||
foreach (var entityId in readyEntities)
|
||||
{
|
||||
Debug.Log($"Entity {entityId} is real ready");
|
||||
|
||||
_battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
_battleActionDatas[entityId],
|
||||
_actionDecisionResults[entityId]);
|
||||
|
||||
_battleActionDatas.Remove(entityId);
|
||||
_actionDecisionResults.Remove(entityId);
|
||||
}
|
||||
|
||||
return readyEntities;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +174,42 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
_preview.Release(1);
|
||||
}
|
||||
}
|
||||
private async UniTask PreviewBattleLoopAsync(EntityId entityId,
|
||||
Dictionary<EntityId, EntityProperties> entities,
|
||||
CancellationToken ctx)
|
||||
{
|
||||
_snapshotUtility.GetSnapshots(
|
||||
entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
|
||||
try
|
||||
{
|
||||
while (!ctx.IsCancellationRequested)
|
||||
{
|
||||
_snapshotUtility.RestoreFromSnapshots(
|
||||
entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
|
||||
await PlayTimelineUntilThatSpecific(entityId, ctx).AttachExternalCancellation(ctx);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_snapshotUtility.RestoreFromSnapshots(
|
||||
entities,
|
||||
_actionDecisionResults,
|
||||
_battleActionDatas);
|
||||
|
||||
foreach (var (_, entity) in entities)
|
||||
{
|
||||
entity.EntityPreviewVisuals.HidePreviewState();
|
||||
}
|
||||
|
||||
_preview.Release(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask PlayTimelineForCertainFrames(int frameCount, CancellationToken ctx)
|
||||
{
|
||||
@@ -182,22 +235,58 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
foreach (var entityId in readyEntities)
|
||||
{
|
||||
Debug.Log($"Entity {entityId} is ready");
|
||||
var battleActionType = _actionDecisionResults[entityId].ActionType;
|
||||
Debug.Log($"Entity {entityId} is preview ready {battleActionType}");
|
||||
|
||||
_battleActions[battleActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
_battleActionDatas[entityId],
|
||||
_actionDecisionResults[entityId]);
|
||||
|
||||
_battleActionDatas.Remove(entityId);
|
||||
_actionDecisionResults.Remove(entityId);
|
||||
|
||||
// _battleActionDatas[entityId] = new WaitBattleActionData {
|
||||
// TotalFrames = frameCount,
|
||||
// WaitFrames = frameCount
|
||||
// };
|
||||
// _actionDecisionResults[entityId] = new FrameBattleActionDeciderResult
|
||||
// {
|
||||
// ActionType = BattleActionType.Wait,
|
||||
// FrameCount = frameCount,
|
||||
// ResultCode = BattleActionDecisionResultCode.Decided
|
||||
// };
|
||||
}
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private async UniTask PlayTimelineUntilThatSpecific(EntityId specificEntityId, CancellationToken ctx)
|
||||
{
|
||||
float accumulator = 0f;
|
||||
|
||||
while (!ctx.IsCancellationRequested)
|
||||
{
|
||||
bool isCanceled = await UniTask.Yield(PlayerLoopTiming.Update, ctx).SuppressCancellationThrow();
|
||||
if (isCanceled) break;
|
||||
|
||||
accumulator += Mathf.Min(Time.unscaledDeltaTime, 0.1f);
|
||||
|
||||
while (accumulator >= TickDelta && !ctx.IsCancellationRequested)
|
||||
{
|
||||
// Debug.Log($"Simulating {counter}/{frameCount}");
|
||||
accumulator -= TickDelta;
|
||||
|
||||
var readyEntities = SimulateSingleFrame(_entities);
|
||||
|
||||
if (readyEntities.Length > 0)
|
||||
{
|
||||
foreach (var entityId in readyEntities)
|
||||
{
|
||||
var battleActionType = _actionDecisionResults[entityId].ActionType;
|
||||
Debug.Log($"Entity {entityId} is preview ready {battleActionType}");
|
||||
|
||||
_battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
_battleActionDatas[entityId],
|
||||
_actionDecisionResults[entityId]);
|
||||
|
||||
_battleActionDatas.Remove(entityId);
|
||||
_actionDecisionResults.Remove(entityId);
|
||||
}
|
||||
if(readyEntities.Contains(specificEntityId)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,7 +410,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
await _preview.WaitAsync(previewCancellationToken.Token);
|
||||
|
||||
PreviewBattleLoopAsync(actionData.TotalFrames, _entities, previewCancellationToken.Token)
|
||||
PreviewBattleLoopAsync(entityId, _entities, previewCancellationToken.Token)
|
||||
.Forget();
|
||||
}
|
||||
else if (decisionResult.ResultCode == BattleActionDecisionResultCode.CancelDecision)
|
||||
@@ -337,6 +426,9 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
_battleActionDeciders[deciderType].UnmountDecider();
|
||||
}
|
||||
|
||||
_battleActionDatas[entityId] = entityActionDataSnapshot;
|
||||
_actionDecisionResults[entityId] = entityResultSnapshot;
|
||||
|
||||
if (decisionResult == null || actionData == null) throw new ArgumentNullException(nameof(decisionResult));
|
||||
|
||||
return (decisionResult, actionData);
|
||||
@@ -347,6 +439,14 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
BattleActionData forcedBattleActionData,
|
||||
BattleActionDecisionResult forcedBattleActionDataResult)
|
||||
{
|
||||
if(_battleActionDatas.TryGetValue(entityId, out var battleActionData)
|
||||
&& _actionDecisionResults.TryGetValue(entityId, out var actionDecisionResult))
|
||||
_battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
battleActionData,
|
||||
actionDecisionResult);
|
||||
|
||||
_battleActionDatas[entityId] = forcedBattleActionData;
|
||||
_actionDecisionResults[entityId] = forcedBattleActionDataResult;
|
||||
|
||||
|
||||
Reference in new issue
Block a user