Try to predict
This commit is contained in:
@@ -16,43 +16,6 @@ public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
|
||||
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||
[Dependency] private readonly CP14FishingPoolSystem _pool = default!;
|
||||
|
||||
/*
|
||||
private readonly TimeSpan _dirtyDelay = TimeSpan.FromTicks(10000000000000);
|
||||
private TimeSpan _dirtyDelayTime;
|
||||
*/
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
// DON'T CALL BASE METHOD!!!
|
||||
|
||||
var query = EntityQueryEnumerator<CP14FishingProcessComponent>();
|
||||
while (query.MoveNext(out var entityUid, out var processComponent))
|
||||
{
|
||||
Update((entityUid, processComponent), frameTime * 2);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FishPreUpdate(Entity<CP14FishingProcessComponent> process, Fish fish, float frameTime)
|
||||
{
|
||||
base.FishPreUpdate(process, fish, frameTime);
|
||||
|
||||
fish.UpdateSpeed(_random, _timing);
|
||||
Dirty(process);
|
||||
}
|
||||
|
||||
public override void UpdateDirty(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
base.UpdateDirty(process);
|
||||
|
||||
/*
|
||||
if (_timing.CurTime < _dirtyDelayTime)
|
||||
return;
|
||||
|
||||
_dirtyDelayTime = _timing.CurTime + _dirtyDelay;
|
||||
Dirty(process);
|
||||
*/
|
||||
}
|
||||
|
||||
public override void Finish(Entity<CP14FishingProcessComponent> process, bool success)
|
||||
{
|
||||
base.Finish(process, success);
|
||||
@@ -101,6 +64,7 @@ public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
|
||||
|
||||
process.Comp.Player = new Player(fishingRod.Comp.Size);
|
||||
process.Comp.Fish = new Fish(new MixedBehavior(), _timing.CurTime + TimeSpan.FromSeconds(0.5f));
|
||||
process.Comp.Fish.Init(_random);
|
||||
|
||||
process.Comp.LootProtoId = loot;
|
||||
process.Comp.StyleSheet = style;
|
||||
|
||||
@@ -15,4 +15,9 @@ public abstract partial class Behavior
|
||||
public float Difficulty { get; set; } = 2f;
|
||||
|
||||
public abstract float CalculateSpeed(IRobustRandom random);
|
||||
|
||||
public virtual TimeSpan CalculateDelay(IRobustRandom random)
|
||||
{
|
||||
return TimeSpan.FromSeconds(random.NextFloat(1.5f - 1f / Difficulty, 2.5f - 1f / Difficulty));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,39 +11,74 @@ public sealed class Fish
|
||||
private const float MaxPosition = 1f;
|
||||
private const float MinPosition = 0f;
|
||||
|
||||
private const int SpeedLoopSize = 8;
|
||||
private const int DelayLoopSize = 12;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Position { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private readonly Behavior _behavior;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan _delay;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private float _speed;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan _updateSpeedTime;
|
||||
private float[] _speedLoop = new float[SpeedLoopSize];
|
||||
|
||||
public Fish(Behavior behavior, TimeSpan updateSpeedTime)
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan[] _delayLoop = new TimeSpan[DelayLoopSize];
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private int _speedIndex;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private int _delayIndex;
|
||||
|
||||
public Fish(Behavior behavior, TimeSpan delay)
|
||||
{
|
||||
_behavior = behavior;
|
||||
_updateSpeedTime = updateSpeedTime;
|
||||
_delay = delay;
|
||||
}
|
||||
|
||||
public void Init(IRobustRandom random)
|
||||
{
|
||||
for (var i = 0; i < SpeedLoopSize; i++)
|
||||
{
|
||||
_speedLoop[i] = _behavior.CalculateSpeed(random);
|
||||
}
|
||||
|
||||
for (var i = 0; i < DelayLoopSize; i++)
|
||||
{
|
||||
_delayLoop[i] = _behavior.CalculateDelay(random);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
// Update position
|
||||
Position += _speed * frameTime;
|
||||
|
||||
// Clamp position
|
||||
Position = Math.Clamp(Position, MinPosition, MaxPosition);
|
||||
}
|
||||
|
||||
public void UpdateSpeed(IRobustRandom random, IGameTiming timing)
|
||||
public void UpdateSpeed(IGameTiming timing)
|
||||
{
|
||||
if (_updateSpeedTime > timing.CurTime)
|
||||
if (_delay > timing.CurTime)
|
||||
return;
|
||||
|
||||
_speed = _behavior.CalculateSpeed(random);
|
||||
_updateSpeedTime = timing.CurTime + TimeSpan.FromSeconds(random.NextFloat(1.5f - 1f / _behavior.Difficulty, 2.5f - 1f / _behavior.Difficulty));
|
||||
_speed = GetNextSpeed();
|
||||
_delay = GetNextDelay(timing);
|
||||
}
|
||||
|
||||
private float GetNextSpeed()
|
||||
{
|
||||
return _speedLoop[_speedIndex++ % _speedLoop.Length];
|
||||
}
|
||||
|
||||
private TimeSpan GetNextDelay(IGameTiming timing)
|
||||
{
|
||||
return timing.CurTime + _delayLoop[_delayIndex++ % _delayLoop.Length];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Fishing.Core;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Systems;
|
||||
|
||||
public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
|
||||
protected EntityQuery<CP14FishingRodComponent> FishingRod;
|
||||
protected EntityQuery<CP14FishingPoolComponent> FishingPool;
|
||||
|
||||
private int _frames;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -29,6 +33,8 @@ public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
{
|
||||
Update((entityUid, processComponent), frameTime);
|
||||
}
|
||||
|
||||
Log.Debug($"Frame {_frames++} FrameTime: {frameTime}");
|
||||
}
|
||||
|
||||
private void UpdateReeling(Entity<CP14FishingProcessComponent> process,
|
||||
@@ -84,9 +90,9 @@ public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
|
||||
if (process.Comp.Fish is { } fish)
|
||||
{
|
||||
FishPreUpdate(process, fish, frameTime);
|
||||
|
||||
fish.Update(frameTime);
|
||||
fish.UpdateSpeed(_timing);
|
||||
|
||||
var collides = Collide(fish, player);
|
||||
|
||||
var progressAdditive = collides ? 0.1f : -0.2f;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Pow3r
|
||||
BlendingFactorSrc.One,
|
||||
BlendingFactorDest.OneMinusSrcAlpha);
|
||||
|
||||
|
||||
var io = ImGui.GetIO();
|
||||
|
||||
io.Fonts.GetTexDataAsRGBA32(out byte* pixels, out var width, out var height, out _);
|
||||
|
||||
Reference in New Issue
Block a user