Shared subfloor system (#3590)

* Shared subfloor system

Will also cull the broadphase for server a lot.

* Nullable subfloor

* Snapgrid nullable

* Actually use ComponentDependency

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-03-13 14:46:22 +11:00
committed by GitHub
parent 67d79a13db
commit 2f8bd10b47
6 changed files with 31 additions and 32 deletions

View File

@@ -4,11 +4,12 @@ using System;
using Content.Client.GameObjects.Components; using Content.Client.GameObjects.Components;
using Content.Client.GameObjects.EntitySystems; using Content.Client.GameObjects.EntitySystems;
using Content.Client.Interfaces; using Content.Client.Interfaces;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Maths;
using DrawDepth = Content.Shared.GameObjects.DrawDepth; using DrawDepth = Content.Shared.GameObjects.DrawDepth;
namespace Content.Client.Commands namespace Content.Client.Commands
@@ -37,7 +38,7 @@ namespace Content.Client.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args) public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
EntitySystem.Get<SubFloorHideSystem>() EntitySystem.Get<SubFloorHideSystem>()
.EnableAll ^= true; .ShowAll ^= true;
} }
} }
@@ -51,7 +52,7 @@ namespace Content.Client.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args) public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
EntitySystem.Get<SubFloorHideSystem>() EntitySystem.Get<SubFloorHideSystem>()
.EnableAll = true; .ShowAll = true;
var components = IoCManager.Resolve<IEntityManager>().ComponentManager var components = IoCManager.Resolve<IEntityManager>().ComponentManager
.EntityQuery<SubFloorHideComponent>(true); .EntityQuery<SubFloorHideComponent>(true);

View File

@@ -1,4 +1,5 @@
using System; using System;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Disposal; using Content.Shared.GameObjects.Components.Disposal;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;

View File

@@ -1,6 +1,7 @@
using System; using System;
using Content.Client.GameObjects.EntitySystems; using Content.Client.GameObjects.EntitySystems;
using Content.Client.UserInterface; using Content.Client.UserInterface;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Input; using Content.Shared.Input;
using Content.Shared.Sandbox; using Content.Shared.Sandbox;
using Robust.Client.Console; using Robust.Client.Console;
@@ -73,7 +74,7 @@ namespace Content.Client.Sandbox
ToggleShadowsButton = new Button { Text = Loc.GetString("Toggle Shadows"), ToggleMode = true, Pressed = !IoCManager.Resolve<ILightManager>().DrawShadows }; ToggleShadowsButton = new Button { Text = Loc.GetString("Toggle Shadows"), ToggleMode = true, Pressed = !IoCManager.Resolve<ILightManager>().DrawShadows };
vBox.AddChild(ToggleShadowsButton); vBox.AddChild(ToggleShadowsButton);
ToggleSubfloorButton = new Button { Text = Loc.GetString("Toggle Subfloor"), ToggleMode = true, Pressed = EntitySystem.Get<SubFloorHideSystem>().EnableAll }; ToggleSubfloorButton = new Button { Text = Loc.GetString("Toggle Subfloor"), ToggleMode = true, Pressed = EntitySystem.Get<SubFloorHideSystem>().ShowAll };
vBox.AddChild(ToggleSubfloorButton); vBox.AddChild(ToggleSubfloorButton);
SuicideButton = new Button { Text = Loc.GetString("Suicide") }; SuicideButton = new Button { Text = Loc.GetString("Suicide") };

View File

@@ -6,7 +6,6 @@ namespace Content.Server
public static string[] List => new [] { public static string[] List => new [] {
"ConstructionGhost", "ConstructionGhost",
"IconSmooth", "IconSmooth",
"SubFloorHide",
"LowWall", "LowWall",
"ReinforcedWall", "ReinforcedWall",
"InteractionOutline", "InteractionOutline",

View File

@@ -1,9 +1,8 @@
using System.Diagnostics; #nullable enable
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Utility; using Robust.Shared.Log;
namespace Content.Client.GameObjects.Components namespace Content.Shared.GameObjects.Components
{ {
/// <summary> /// <summary>
/// Simple component that automatically hides the sibling /// Simple component that automatically hides the sibling
@@ -20,14 +19,6 @@ namespace Content.Client.GameObjects.Components
/// <inheritdoc /> /// <inheritdoc />
public override string Name => "SubFloorHide"; public override string Name => "SubFloorHide";
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
_snapGridComponent = Owner.GetComponent<SnapGridComponent>();
}
/// <inheritdoc /> /// <inheritdoc />
protected override void Startup() protected override void Startup()
{ {
@@ -54,8 +45,13 @@ namespace Content.Client.GameObjects.Components
private void OnAddSnapGrid() private void OnAddSnapGrid()
{ {
DebugTools.AssertNotNull(_snapGridComponent); if (_snapGridComponent == null)
_snapGridComponent!.OnPositionChanged += SnapGridOnPositionChanged; {
// Shouldn't happen but allows us to use nullables. OnPositionChanged needs to be componentbus anyway.
Logger.Error("Snapgrid was null for subfloor {Owner}");
return;
}
_snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged;
} }
private void SnapGridOnPositionChanged() private void SnapGridOnPositionChanged()

View File

@@ -1,31 +1,32 @@
using Content.Client.GameObjects.Components; #nullable enable
using Content.Shared.GameObjects.Components;
using Content.Shared.Maps; using Content.Shared.Maps;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.EntitySystems namespace Content.Shared.GameObjects.EntitySystems
{ {
/// <summary> /// <summary>
/// Entity system backing <see cref="SubFloorHideComponent"/>. /// Entity system backing <see cref="SubFloorHideComponent"/>.
/// </summary> /// </summary>
internal sealed class SubFloorHideSystem : EntitySystem public class SubFloorHideSystem : EntitySystem
{ {
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
private bool _enableAll; private bool _showAll;
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public bool EnableAll public bool ShowAll
{ {
get => _enableAll; get => _showAll;
set set
{ {
_enableAll = value; if (_showAll == value) return;
_showAll = value;
UpdateAll(); UpdateAll();
} }
@@ -90,16 +91,16 @@ namespace Content.Client.GameObjects.EntitySystems
continue; continue;
} }
var enabled = EnableAll || !subFloorComponent.Running || tileDef.IsSubFloor; // Show sprite
if (entity.TryGetComponent(out SharedSpriteComponent? spriteComponent))
if (entity.TryGetComponent(out ISpriteComponent? spriteComponent))
{ {
spriteComponent.Visible = enabled; spriteComponent.Visible = ShowAll || !subFloorComponent.Running || tileDef.IsSubFloor;
} }
// So for collision all we care about is that the component is running.
if (entity.TryGetComponent(out PhysicsComponent? physicsComponent)) if (entity.TryGetComponent(out PhysicsComponent? physicsComponent))
{ {
physicsComponent.CanCollide = enabled; physicsComponent.CanCollide = !subFloorComponent.Running;
} }
} }
} }