Skip to content

Commit

Permalink
should work?
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidenkrz committed Dec 16, 2024
1 parent 0da467e commit 9679660
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Robust.Client.GameObjects;
using Robust.Client.Physics;
using Robust.Client.Player;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
Expand All @@ -19,22 +17,26 @@ namespace Content.Client._RMC14.Weapons.Ranged.Prediction;

public sealed class GunPredictionSystem : SharedGunPredictionSystem
{
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly SharedGunSystem _gun = default!;
[Dependency] private readonly PhysicsSystem _physics = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly ProjectileSystem _projectile = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

private EntityQuery<IgnorePredictionHideComponent> _ignorePredictionHideQuery;

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in Content.Client/_RMC14/Weapons/Ranged/Prediction/GunPredictionSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'IgnorePredictionHideComponent' could not be found (are you missing a using directive or an assembly reference?)
private EntityQuery<SpriteComponent> _spriteQuery;

public override void Initialize()
{
base.Initialize();

_ignorePredictionHideQuery = GetEntityQuery<IgnorePredictionHideComponent>();
_spriteQuery = GetEntityQuery<SpriteComponent>();

SubscribeLocalEvent<PhysicsUpdateBeforeSolveEvent>(OnBeforeSolve);
SubscribeLocalEvent<PhysicsUpdateAfterSolveEvent>(OnAfterSolve);
SubscribeLocalEvent<RequestShootEvent>(OnShootRequest);
SubscribeNetworkEvent<MaxLinearVelocityMsg>(OnLinearVelocityMsg);

SubscribeLocalEvent<PredictedProjectileClientComponent, UpdateIsPredictedEvent>(OnClientProjectileUpdateIsPredicted);
SubscribeLocalEvent<PredictedProjectileClientComponent, StartCollideEvent>(OnClientProjectileStartCollide);
Expand Down Expand Up @@ -76,11 +78,6 @@ private void OnShootRequest(RequestShootEvent ev, EntitySessionEventArgs args)
_gun.ShootRequested(ev.Gun, ev.Coordinates, ev.Target, null, args.SenderSession);
}

private void OnLinearVelocityMsg(MaxLinearVelocityMsg ev)
{
_config.SetCVar(CVars.MaxLinVelocity, ev.Velocity);
}

private void OnClientProjectileUpdateIsPredicted(Entity<PredictedProjectileClientComponent> ent, ref UpdateIsPredictedEvent args)
{
args.IsPredicted = true;
Expand Down Expand Up @@ -111,7 +108,13 @@ private void OnServerProjectileStartup(Entity<PredictedProjectileServerComponent
if (!GunPrediction)
return;

if (ent.Comp.ClientEnt == _player.LocalEntity && TryComp(ent, out SpriteComponent? sprite))
if (ent.Comp.ClientEnt != _player.LocalEntity)
return;

if (_ignorePredictionHideQuery.HasComp(ent))
return;

if (_spriteQuery.TryComp(ent, out var sprite))
sprite.Visible = false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
using Content.Server.GameTicking;
using Content.Server.Movement.Components;
using Content.Server.Movement.Systems;
using Content.Server.Movement.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared._RMC14.CCVar;
using Content.Shared._RMC14.Weapons.Ranged.Prediction;
using Content.Shared.Coordinates;
using Content.Shared.GameTicking;
using Content.Shared.Physics;
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged.Events;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
Expand All @@ -28,11 +20,8 @@ namespace Content.Server._RMC14.Weapons.Ranged.Prediction;
public sealed class GunPredictionSystem : SharedGunPredictionSystem
{
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly LagCompensationSystem _lagCompensation = default!;
[Dependency] private readonly GunSystem _gun = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly SharedProjectileSystem _projectile = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly TransformSystem _transform = default!;
Expand Down Expand Up @@ -66,33 +55,23 @@ public override void Initialize()
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestartCleanup);
SubscribeNetworkEvent<RequestShootEvent>(OnShootRequest);
SubscribeNetworkEvent<PredictedProjectileHitEvent>(OnPredictedProjectileHit);
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnSendLinearVelocityAll);

SubscribeLocalEvent<PredictedProjectileServerComponent, MapInitEvent>(OnPredictedMapInit);
SubscribeLocalEvent<PredictedProjectileServerComponent, ComponentRemove>(OnPredictedRemove);
SubscribeLocalEvent<PredictedProjectileServerComponent, EntityTerminatingEvent>(OnPredictedRemove);
SubscribeLocalEvent<PredictedProjectileServerComponent, PreventCollideEvent>(OnPredictedPreventCollide);

Subs.CVar(_config, CVars.MaxLinVelocity, OnSendLinearVelocityAll);
Subs.CVar(_config, RMCCVars.RMCGunPredictionPreventCollision, v => _preventCollision = v, true);
Subs.CVar(_config, RMCCVars.RMCGunPredictionLogHits, v => _logHits = v, true);
Subs.CVar(_config, RMCCVars.RMCGunPredictionCoordinateDeviation, v => _coordinateDeviation = v, true);
Subs.CVar(_config, RMCCVars.RMCGunPredictionLowestCoordinateDeviation, v => _lowestCoordinateDeviation = v, true);
Subs.CVar(_config, RMCCVars.RMCGunPredictionAabbEnlargement, v => _aabbEnlargement = v, true);

_player.PlayerStatusChanged += OnPlayerStatusChanged;
}

public override void Shutdown()
{
base.Shutdown();
_player.PlayerStatusChanged -= OnPlayerStatusChanged;
}

private void OnRoundRestartCleanup(RoundRestartCleanupEvent ev)
{
_predicted.Clear();
OnSendLinearVelocityAll(ev);
}

private void OnShootRequest(RequestShootEvent ev, EntitySessionEventArgs args)
Expand Down Expand Up @@ -124,16 +103,6 @@ private void OnPredictedProjectileHit(PredictedProjectileHitEvent ev, EntitySess
_predictedHits.Add((ev, args.SenderSession));
}

private void OnSendLinearVelocityAll<T>(T ev)
{
if (_net.IsClient)
return;

// TODO gun prediction remove this when we pull engine with a replicated physics maxlinvelocity
var msg = new MaxLinearVelocityMsg(_config.GetCVar(CVars.MaxLinVelocity));
RaiseNetworkEvent(msg);
}

private void OnPredictedPreventCollide(Entity<PredictedProjectileServerComponent> ent, ref PreventCollideEvent args)
{
if (!_preventCollision)
Expand Down Expand Up @@ -162,16 +131,6 @@ private void OnPredictedPreventCollide(Entity<PredictedProjectileServerComponent
}
}

private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
{
if (e.NewStatus != SessionStatus.Connected && e.NewStatus != SessionStatus.InGame)
return;

// TODO gun prediction remove this when we pull engine with a replicated physics maxlinvelocity
var msg = new MaxLinearVelocityMsg(_config.GetCVar(CVars.MaxLinVelocity));
RaiseNetworkEvent(msg, e.Session.Channel);
}

private bool Collides(
Entity<PredictedProjectileServerComponent, PhysicsComponent> projectile,
Entity<LagCompensationComponent, FixturesComponent, PhysicsComponent, TransformComponent> other,
Expand Down

This file was deleted.

0 comments on commit 9679660

Please sign in to comment.