Timeline works YAY
This commit is contained in:
1 parent
6114192055
commit
7098d938a7
84 files changed
+96509
-51755
No files matched your search
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
public class BattleTimeline
|
||||
{
|
||||
public const int TicksPerSecond = 60;
|
||||
public const float TickDelta = 1f / TicksPerSecond;
|
||||
|
||||
public int CurrentBattleFrame { get; private set; }
|
||||
|
||||
private List<EntityTimelineActor> _entities;
|
||||
|
||||
public async UniTask RunBattleLoopAsync(List<EntityTimelineActor> entities, CancellationToken ct)
|
||||
{
|
||||
_entities = entities;
|
||||
|
||||
CurrentBattleFrame = 0;
|
||||
|
||||
await DecideActions(_entities, ct);
|
||||
|
||||
while (!IsBattleOver() && !ct.IsCancellationRequested)
|
||||
{
|
||||
List<EntityTimelineActor> entitiesNeedOrders = await PlayTimelineUntilPause(ct);
|
||||
|
||||
await DecideActions(entitiesNeedOrders, ct);
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask DecideActions(List<EntityTimelineActor> entityActionMakers, CancellationToken ct)
|
||||
{
|
||||
foreach (var entity in entityActionMakers)
|
||||
{
|
||||
Debug.Log($"Deciding action for {entity.name}");
|
||||
await entity.DecideAction(ct);
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTask<List<EntityTimelineActor>> PlayTimelineUntilPause(CancellationToken ct)
|
||||
{
|
||||
float accumulator = 0f;
|
||||
var readyEntities = new List<EntityTimelineActor>();
|
||||
|
||||
while (readyEntities.Count == 0 && !ct.IsCancellationRequested)
|
||||
{
|
||||
await UniTask.Yield(PlayerLoopTiming.Update, ct);
|
||||
|
||||
accumulator += Time.unscaledDeltaTime;
|
||||
|
||||
while (accumulator >= TickDelta)
|
||||
{
|
||||
accumulator -= TickDelta;
|
||||
SimulateSingleFrame(readyEntities);
|
||||
|
||||
if (readyEntities.Count > 0) return readyEntities;
|
||||
}
|
||||
}
|
||||
|
||||
return readyEntities;
|
||||
}
|
||||
|
||||
private void SimulateSingleFrame(List<EntityTimelineActor> outReadyEntities)
|
||||
{
|
||||
CurrentBattleFrame++;
|
||||
Debug.Log($"Current frame: {CurrentBattleFrame}");
|
||||
foreach (var entity in _entities)
|
||||
{
|
||||
entity.CurrentAction.Tick(TickDelta);
|
||||
}
|
||||
|
||||
foreach (var entity in _entities)
|
||||
{
|
||||
entity.animator.Update(TickDelta);
|
||||
}
|
||||
|
||||
Physics.Simulate(TickDelta);
|
||||
Physics.SyncTransforms();
|
||||
|
||||
foreach (var entity in _entities)
|
||||
{
|
||||
if (entity.Finished)
|
||||
{
|
||||
outReadyEntities.Add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBattleOver() => false;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
-5
@@ -2,11 +2,6 @@ using UnityEngine;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
public class TimelineBattle
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public struct TimelineBattleAction
|
||||
{
|
||||
public int Frame;
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f275ffa891ca472d85cae21f4440d4ae
|
||||
timeCreated: 1792691865
|
||||
Reference in new issue
Block a user