Skip to content

Commit

Permalink
Оптимизация и обновление ночного виденья (#431)
Browse files Browse the repository at this point in the history
* optimize night vision shader

* upd

* nvd restyle

* upd

* я не знаю почему эта хуйня не работает, я уже здался

* fix

* upd

* fix
  • Loading branch information
Rinary1 authored Oct 3, 2024
1 parent 7ffd5ba commit 2fe0f92
Show file tree
Hide file tree
Showing 26 changed files with 201 additions and 35 deletions.
23 changes: 23 additions & 0 deletions Content.Client/_Sunrise/Eye/NightVision/NVGSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Shared._Sunrise.Eye.NightVision.Components;
using Content.Shared._Sunrise.Eye.NightVision.Systems;
using Robust.Client.GameObjects;

namespace Content.Client._Sunrise.Eye.NightVision;

public sealed class NVGSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<NVGComponent, AfterNVGUpdateVisualsEvent>(OnAfterNVGUpdateVisualsEvent);
}

private void OnAfterNVGUpdateVisualsEvent(EntityUid uid, NVGComponent component, AfterNVGUpdateVisualsEvent args)
{
var nvcomp = args.nvcomp;

if (TryComp<SpriteComponent>(component.Owner, out var sprite))
sprite.LayerSetVisible(NVGVisuals.Light, nvcomp.IsNightVision);
}
}
23 changes: 13 additions & 10 deletions Content.Client/_Sunrise/Eye/NightVision/NightVisionOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ protected override bool BeforeDraw(in OverlayDrawArgs args)
var playerEntity = _playerManager.LocalSession?.AttachedEntity;
if (playerEntity == null)
return false;

if (!_entityManager.TryGetComponent(playerEntity, out EyeComponent? eyeComp))
return false;

if (args.Viewport.Eye != eyeComp.Eye)
return false;

if (!_entityManager.TryGetComponent<NightVisionComponent>(playerEntity, out var nightvisionComp))
if (!_entityManager.TryGetComponent<NightVisionComponent>(playerEntity.Value, out var nightvisionComp))
return false;

_nightvisionComponent = nightvisionComp;

var nightvision = _nightvisionComponent.IsNightVision;

if (!nightvision && _nightvisionComponent.DrawShadows) // Disable our Night Vision
Expand Down Expand Up @@ -78,13 +78,16 @@ protected override void Draw(in OverlayDrawArgs args)
_nightvisionComponent.GraceFrame = false;
}

_greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);

var worldHandle = args.WorldHandle;
var viewport = args.WorldBounds;
worldHandle.UseShader(_greyscaleShader);
worldHandle.DrawRect(viewport, NightvisionColor);
worldHandle.UseShader(null);
if (_nightvisionComponent.IsNightVision)
{
_greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);

var worldHandle = args.WorldHandle;
var viewport = args.WorldBounds;
worldHandle.UseShader(_greyscaleShader);
worldHandle.DrawRect(viewport, NightvisionColor);
worldHandle.UseShader(null);
}
}
}
}
13 changes: 13 additions & 0 deletions Content.Shared/_Sunrise/Eye/NightVision/Components/NVGComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Content.Shared.Actions;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Shared._Sunrise.Eye.NightVision.Components;
Expand All @@ -11,4 +13,15 @@ public sealed partial class NVGComponent : Component
{
[DataField] public EntProtoId<InstantActionComponent> ActionProto = "NVToggleAction";
[DataField] public EntityUid? ActionContainer;

[DataField("playSounds")]
public bool PlaySounds = true;
public SoundSpecifier SoundOn = new SoundPathSpecifier("/Audio/_Sunrise/Items/night_vision_on.ogg");
public SoundSpecifier SoundOff = new SoundPathSpecifier("/Audio/_Sunrise/Items/night_vision_off.ogg");
}

[Serializable, NetSerializable]
public enum NVGVisuals : byte
{
Light
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public sealed partial class NightVisionComponent : Component

[Access(Other = AccessPermissions.ReadWriteExecute)]
public bool GraceFrame = false;

[DataField("playSoundOn")]
public bool PlaySoundOn = true;
public SoundSpecifier OnOffSound = new SoundPathSpecifier("/Audio/_Sunrise/Misc/night-vision-sound-effect_E_minor.ogg");
}

public sealed partial class NVInstantActionEvent : InstantActionEvent { }
44 changes: 41 additions & 3 deletions Content.Shared/_Sunrise/Eye/NightVision/Systems/NVGSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
using Content.Shared.Inventory.Events;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
using Robust.Shared.Log;
using JetBrains.Annotations;

namespace Content.Shared._Sunrise.Eye.NightVision.Systems;

public sealed class PNVSystem : EntitySystem
public sealed class NVGSystem : EntitySystem
{
[Dependency] private readonly NightVisionSystem _nightvisionableSystem = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly INetManager _net = default!;

private EntityUid? _equippedNVGItem;

public override void Initialize()
{
Expand All @@ -21,12 +25,34 @@ public override void Initialize()
SubscribeLocalEvent<NVGComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<NVGComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<NVGComponent, InventoryRelayedEvent<CanVisionAttemptEvent>>(OnPNVTrySee);
SubscribeLocalEvent<NVGComponent, NVGUpdateVisualsEvent>(OnNVGUpdateVisuals);
}

private void OnPNVTrySee(EntityUid uid, NVGComponent component, InventoryRelayedEvent<CanVisionAttemptEvent> args)
{
args.Args.Cancel();
}

private void OnNVGUpdateVisuals(EntityUid uid, NVGComponent component, NVGUpdateVisualsEvent args)
{
var nvcomp = args.nvcomp;

_actionsSystem.SetCooldown(component.ActionContainer, TimeSpan.FromSeconds(15));

if (nvcomp.IsNightVision)
{
if (_net.IsServer && component.PlaySounds)
_audioSystem.PlayPvs(component.SoundOn, uid);
}
else if (!nvcomp.IsNightVision)
{
if (_net.IsServer && component.PlaySounds)
_audioSystem.PlayPvs(component.SoundOff, uid);
}

var updVisEv = new AfterNVGUpdateVisualsEvent(nvcomp);
RaiseLocalEvent(component.Owner, ref updVisEv);
}

private void OnEquipped(EntityUid uid, NVGComponent component, GotEquippedEvent args)
{
Expand All @@ -37,16 +63,18 @@ private void OnEquipped(EntityUid uid, NVGComponent component, GotEquippedEvent
return;

var nvcomp = EnsureComp<NightVisionComponent>(args.Equipee);

_equippedNVGItem = args.Equipee;

_nightvisionableSystem.UpdateIsNightVision(args.Equipee, nvcomp);
if (component.ActionContainer == null)
_actionsSystem.AddAction(args.Equipee, ref component.ActionContainer, component.ActionProto);
_actionsSystem.SetCooldown(component.ActionContainer, TimeSpan.FromSeconds(1)); // GCD?

if (nvcomp.PlaySoundOn && nvcomp.IsNightVision)
if (component.PlaySounds && nvcomp.IsNightVision)
{
if (_net.IsServer)
_audioSystem.PlayPvs(nvcomp.OnOffSound, uid);
_audioSystem.PlayPvs(component.SoundOn, uid);
}

}
Expand All @@ -68,4 +96,14 @@ private void OnUnequipped(EntityUid uid, NVGComponent component, GotUnequippedEv

RemCompDeferred<NightVisionComponent>(args.Equipee);
}
}

[PublicAPI, ByRefEvent]
public sealed class AfterNVGUpdateVisualsEvent : EntityEventArgs {
public NightVisionComponent nvcomp;

public AfterNVGUpdateVisualsEvent(NightVisionComponent component)
{
nvcomp = component;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Content.Shared._Sunrise.Eye.NightVision.Systems;
public sealed class NightVisionSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly INetManager _net = default!;

Expand Down Expand Up @@ -38,11 +39,31 @@ private void OnActionToggle(EntityUid uid, NightVisionComponent component, NVIns
var changeEv = new NightVisionToggledEvent(component.IsNightVision);
RaiseLocalEvent(uid, ref changeEv);
Dirty(uid, component);
_actionsSystem.SetCooldown(component.ActionContainer, TimeSpan.FromSeconds(1));
if (component is { IsNightVision: true, PlaySoundOn: true })
_actionsSystem.SetCooldown(component.ActionContainer, TimeSpan.FromSeconds(15));


var updVisEv = new NVGUpdateVisualsEvent(component);

if (_inventory.TryGetSlotEntity(uid, "eyes", out var eyesEntity))
{
if (_net.IsServer)
_audioSystem.PlayPvs(component.OnOffSound, uid);
if (HasComp<NVGComponent>(eyesEntity))
{
RaiseLocalEvent(eyesEntity.Value, ref updVisEv);
}
}
else if (_inventory.TryGetSlotEntity(uid, "mask", out var maskEntity))
{
if (HasComp<NVGComponent>(maskEntity))
{
RaiseLocalEvent(maskEntity.Value, ref updVisEv);
}
}
else if (_inventory.TryGetSlotEntity(uid, "head", out var headEntity))
{
if (HasComp<NVGComponent>(headEntity))
{
RaiseLocalEvent(headEntity.Value, ref updVisEv);
}
}
}

Expand Down Expand Up @@ -71,6 +92,15 @@ public void UpdateIsNightVision(EntityUid uid, NightVisionComponent? component =
[ByRefEvent]
public record struct NightVisionToggledEvent(bool CanEnableNightVision);

[PublicAPI, ByRefEvent]
public sealed class NVGUpdateVisualsEvent : EntityEventArgs {
public NightVisionComponent nvcomp;

public NVGUpdateVisualsEvent(NightVisionComponent component)
{
nvcomp = component;
}
}

public sealed class CanVisionAttemptEvent : CancellableEntityEventArgs, IInventoryRelayEvent
{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
- type: EyeProtection
- type: IdentityBlocker
coverage: EYES
- type: NVG #Sunrise - night vision

- type: entity
parent: ClothingEyesBase
Expand Down
4 changes: 0 additions & 4 deletions Resources/Prototypes/Entities/Mobs/NPCs/animals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
- type: NightVision #Sunrise - Night vision
isToggle: true
color: "#808080"
playSoundOn: false

- type: entity
name: bee
Expand Down Expand Up @@ -1763,7 +1762,6 @@
- type: NightVision #Sunrise - Night vision
isToggle: true
color: "#808080"
playSoundOn: false

- type: entity
parent: MobMouse
Expand Down Expand Up @@ -2285,7 +2283,6 @@
- type: NightVision #Sunrise - Night vision
isToggle: true
color: "#808080"
playSoundOn: false

# Code unique spider prototypes or combine them all into one spider and get a
# random sprite state when you spawn it.
Expand Down Expand Up @@ -2925,7 +2922,6 @@
- type: NightVision #Sunrise - Night vision
isToggle: true
color: "#808080"
playSoundOn: false

- type: entity
name: calico cat
Expand Down
1 change: 0 additions & 1 deletion Resources/Prototypes/Entities/Mobs/NPCs/carp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
- type: NightVision
isToggle: true
color: "#808080"
playSoundOn: false
# Sunrise-End

- type: entity
Expand Down
1 change: 0 additions & 1 deletion Resources/Prototypes/Entities/Mobs/Player/dragon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
- type: NightVision
isToggle: true
color: "#808080"
playSoundOn: false
# Sunrise-End

- type: entity
Expand Down
33 changes: 26 additions & 7 deletions Resources/Prototypes/_Sunrise/Entities/Clothing/Eyes/nvg.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
- type: entity
name: NVD
id: ClothingEyesVision
id: ClothingEyesNVD
parent: BaseItem
description: Night vision device. Provides an image of the terrain in low-light conditions.
components:
- type: Item
- type: Sprite
sprite: Clothing/Eyes/Glasses/ninjavisor.rsi
state: icon
sprite: _Sunrise/Clothing/Eyes/Glasses/nvg.rsi
layers:
- state: icon
- state: icon-unshaded
shader: unshaded
- state: light-overlay
visible: false
shader: unshaded
map: [ "enum.NVGVisuals.Light" ]
- type: Clothing
sprite: Clothing/Eyes/Glasses/ninjavisor.rsi
sprite: _Sunrise/Clothing/Eyes/Glasses/nvg.rsi
quickEquip: true
clothingVisuals:
eyes:
- state: off-equipped-EYES
- state: equipped-EYES-unshaded
shader: unshaded
slots: [ Eyes ]
- type: UseDelay
delay: 4
- type: NVG
- type: PointLight
color: green
enabled: false
autoRot: true
radius: 0.5
energy: 0.5
- type: Appearance

- type: entity
parent: [ClothingEyesVision,ShowSecurityIcons]
id: ClothingEyesVisionNuki
suffix: nuke
parent: [ClothingEyesNVD,ShowSecurityIcons]
id: ClothingEyesNVDSyndicate
suffix: syndicate
components:
- type: ShowSyndicateIcons
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2fe0f92

Please sign in to comment.