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:
@@ -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);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Disposal;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
@@ -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") };
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Content.Server
|
||||
public static string[] List => new [] {
|
||||
"ConstructionGhost",
|
||||
"IconSmooth",
|
||||
"SubFloorHide",
|
||||
"LowWall",
|
||||
"ReinforcedWall",
|
||||
"InteractionOutline",
|
||||
|
||||
@@ -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()
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user