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

View File

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

View File

@@ -1,6 +1,7 @@
using System;
using Content.Client.GameObjects.EntitySystems;
using Content.Client.UserInterface;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Input;
using Content.Shared.Sandbox;
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 };
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);
SuicideButton = new Button { Text = Loc.GetString("Suicide") };

View File

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

View File

@@ -1,9 +1,8 @@
using System.Diagnostics;
using Robust.Client.GameObjects;
#nullable enable
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;
using Robust.Shared.Log;
namespace Content.Client.GameObjects.Components
namespace Content.Shared.GameObjects.Components
{
/// <summary>
/// Simple component that automatically hides the sibling
@@ -20,14 +19,6 @@ namespace Content.Client.GameObjects.Components
/// <inheritdoc />
public override string Name => "SubFloorHide";
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
_snapGridComponent = Owner.GetComponent<SnapGridComponent>();
}
/// <inheritdoc />
protected override void Startup()
{
@@ -54,8 +45,13 @@ namespace Content.Client.GameObjects.Components
private void OnAddSnapGrid()
{
DebugTools.AssertNotNull(_snapGridComponent);
_snapGridComponent!.OnPositionChanged += SnapGridOnPositionChanged;
if (_snapGridComponent == null)
{
// 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()

View File

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