diff --git a/Content.Server/_CP14/Fishing/CP14FishingProcessSystem.cs b/Content.Server/_CP14/Fishing/CP14FishingProcessSystem.cs index 88f7d9e2d3..533e6d4e09 100644 --- a/Content.Server/_CP14/Fishing/CP14FishingProcessSystem.cs +++ b/Content.Server/_CP14/Fishing/CP14FishingProcessSystem.cs @@ -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(); - while (query.MoveNext(out var entityUid, out var processComponent)) - { - Update((entityUid, processComponent), frameTime * 2); - } - } - - public override void FishPreUpdate(Entity process, Fish fish, float frameTime) - { - base.FishPreUpdate(process, fish, frameTime); - - fish.UpdateSpeed(_random, _timing); - Dirty(process); - } - - public override void UpdateDirty(Entity process) - { - base.UpdateDirty(process); - - /* - if (_timing.CurTime < _dirtyDelayTime) - return; - - _dirtyDelayTime = _timing.CurTime + _dirtyDelay; - Dirty(process); - */ - } - public override void Finish(Entity 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; diff --git a/Content.Shared/_CP14/Fishing/Core/Behaviors/Behavior.cs b/Content.Shared/_CP14/Fishing/Core/Behaviors/Behavior.cs index 349f976b65..151a6a43e7 100644 --- a/Content.Shared/_CP14/Fishing/Core/Behaviors/Behavior.cs +++ b/Content.Shared/_CP14/Fishing/Core/Behaviors/Behavior.cs @@ -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)); + } } diff --git a/Content.Shared/_CP14/Fishing/Core/Fish.cs b/Content.Shared/_CP14/Fishing/Core/Fish.cs index 48e1c9379b..04e491418d 100644 --- a/Content.Shared/_CP14/Fishing/Core/Fish.cs +++ b/Content.Shared/_CP14/Fishing/Core/Fish.cs @@ -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]; } } diff --git a/Content.Shared/_CP14/Fishing/Systems/CP14SharedFishingProcessSystem.cs b/Content.Shared/_CP14/Fishing/Systems/CP14SharedFishingProcessSystem.cs index 00f2819694..577f767018 100644 --- a/Content.Shared/_CP14/Fishing/Systems/CP14SharedFishingProcessSystem.cs +++ b/Content.Shared/_CP14/Fishing/Systems/CP14SharedFishingProcessSystem.cs @@ -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 FishingRod; protected EntityQuery 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 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; diff --git a/Pow3r/Program.OpenGL.cs b/Pow3r/Program.OpenGL.cs index 1e4298e4bc..790165e96f 100644 --- a/Pow3r/Program.OpenGL.cs +++ b/Pow3r/Program.OpenGL.cs @@ -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 _);