mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58560f589f | ||
|
|
6e931ac175 | ||
|
|
a7eb5e8115 | ||
|
|
712e4acc66 | ||
|
|
fdcfdffc0b | ||
|
|
74eb8e3e8d | ||
|
|
ae4c764e4f | ||
|
|
7ef2cec121 | ||
|
|
40bff81017 |
@@ -16,7 +16,7 @@ namespace Robust.Client.GameObjects.EntitySystems
|
||||
/// Handles interpolation of transform positions.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
internal sealed class TransformSystem : EntitySystem
|
||||
internal sealed class TransformSystem : SharedTransformSystem
|
||||
{
|
||||
// Max distance per tick how far an entity can move before it is considered teleporting.
|
||||
// TODO: Make these values somehow dependent on server TPS.
|
||||
|
||||
@@ -11,6 +11,22 @@ namespace Robust.Client.Graphics.Clyde
|
||||
{
|
||||
static Clyde()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
|
||||
RuntimeInformation.ProcessArchitecture == Architecture.X64)
|
||||
{
|
||||
try
|
||||
{
|
||||
// We force load nvapi64.dll so nvidia gives us the dedicated GPU on optimus laptops.
|
||||
// This is 100x easier than nvidia's documented approach of NvOptimusEnablement,
|
||||
// and works while developing.
|
||||
NativeLibrary.Load("nvapi64.dll");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// If this fails whatever.
|
||||
}
|
||||
}
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -38,13 +38,6 @@ namespace Robust.Server.ServerStatus
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OnStatusRequest == null)
|
||||
{
|
||||
_httpSawmill.Warning("OnStatusRequest is not set, responding with a 501.");
|
||||
response.Respond(method, "Not Implemented", HttpStatusCode.NotImplemented);
|
||||
return true;
|
||||
}
|
||||
|
||||
response.StatusCode = (int) HttpStatusCode.OK;
|
||||
response.ContentType = "application/json";
|
||||
|
||||
@@ -53,7 +46,13 @@ namespace Robust.Server.ServerStatus
|
||||
return true;
|
||||
}
|
||||
|
||||
var jObject = new JObject();
|
||||
var jObject = new JObject
|
||||
{
|
||||
// We need to send at LEAST name and player count to have the launcher work with us.
|
||||
// Content can override these if it wants (e.g. stealthmins).
|
||||
["name"] = _serverNameCache,
|
||||
["players"] = _playerManager.PlayerCount
|
||||
};
|
||||
|
||||
OnStatusRequest?.Invoke(jObject);
|
||||
|
||||
|
||||
@@ -7,8 +7,11 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Robust.Server.Interfaces;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Server.Interfaces.ServerStatus;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Interfaces.Log;
|
||||
@@ -28,6 +31,8 @@ namespace Robust.Server.ServerStatus
|
||||
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
[Dependency] private readonly IServerNetManager _netManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IBaseServer _baseServer = default!;
|
||||
|
||||
private static readonly JsonSerializer JsonSerializer = new();
|
||||
private readonly List<StatusHostHandler> _handlers = new();
|
||||
@@ -35,6 +40,8 @@ namespace Robust.Server.ServerStatus
|
||||
private TaskCompletionSource? _stopSource;
|
||||
private ISawmill _httpSawmill = default!;
|
||||
|
||||
private string? _serverNameCache;
|
||||
|
||||
public Task ProcessRequestAsync(HttpListenerContext context)
|
||||
{
|
||||
var response = context.Response;
|
||||
@@ -85,6 +92,10 @@ namespace Robust.Server.ServerStatus
|
||||
_httpSawmill = Logger.GetSawmill($"{Sawmill}.http");
|
||||
RegisterCVars();
|
||||
|
||||
// Cache this in a field to avoid thread safety shenanigans.
|
||||
// Writes/reads of references are atomic in C# so no further synchronization necessary.
|
||||
_configurationManager.OnValueChanged(CVars.GameHostName, n => _serverNameCache = n);
|
||||
|
||||
if (!_configurationManager.GetCVar(CVars.StatusEnabled))
|
||||
{
|
||||
return;
|
||||
@@ -146,15 +157,22 @@ namespace Robust.Server.ServerStatus
|
||||
var buildInfo = File.ReadAllText(PathHelpers.ExecutableRelativeFile("build.json"));
|
||||
var info = JsonConvert.DeserializeObject<BuildInfo>(buildInfo);
|
||||
|
||||
_configurationManager.SetCVar(CVars.BuildEngineVersion, info.EngineVersion);
|
||||
_configurationManager.SetCVar(CVars.BuildForkId, info.ForkId);
|
||||
_configurationManager.SetCVar(CVars.BuildVersion, info.Version);
|
||||
_configurationManager.SetCVar(CVars.BuildDownloadUrl, info.Download);
|
||||
_configurationManager.SetCVar(CVars.BuildHash, info.Hash ?? "");
|
||||
// Don't replace cvars with contents of build.json if overriden by --cvar or such.
|
||||
SetCVarIfUnmodified(CVars.BuildEngineVersion, info.EngineVersion);
|
||||
SetCVarIfUnmodified(CVars.BuildForkId, info.ForkId);
|
||||
SetCVarIfUnmodified(CVars.BuildVersion, info.Version);
|
||||
SetCVarIfUnmodified(CVars.BuildDownloadUrl, info.Download ?? "");
|
||||
SetCVarIfUnmodified(CVars.BuildHash, info.Hash ?? "");
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
}
|
||||
|
||||
void SetCVarIfUnmodified(CVarDef<string> cvar, string val)
|
||||
{
|
||||
if (_configurationManager.GetCVar(cvar) == "")
|
||||
_configurationManager.SetCVar(cvar, val);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -172,8 +190,8 @@ namespace Robust.Server.ServerStatus
|
||||
private sealed class BuildInfo
|
||||
{
|
||||
[JsonProperty("engine_version")] public string EngineVersion = default!;
|
||||
[JsonProperty("hashes")] public string? Hash;
|
||||
[JsonProperty("downloads")] public string Download = default!;
|
||||
[JsonProperty("hash")] public string? Hash;
|
||||
[JsonProperty("download")] public string? Download;
|
||||
[JsonProperty("fork_id")] public string ForkId = default!;
|
||||
[JsonProperty("version")] public string Version = default!;
|
||||
}
|
||||
|
||||
@@ -233,10 +233,10 @@ namespace Robust.Shared
|
||||
CVarDef.Create("display.height", 720, CVar.CLIENTONLY);
|
||||
|
||||
public static readonly CVarDef<int> DisplayLightMapDivider =
|
||||
CVarDef.Create("display.lightmapdivider", 2, CVar.CLIENTONLY);
|
||||
CVarDef.Create("display.lightmapdivider", 2, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
public static readonly CVarDef<bool> DisplaySoftShadows =
|
||||
CVarDef.Create("display.softshadows", true, CVar.CLIENTONLY);
|
||||
CVarDef.Create("display.softshadows", true, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
public static readonly CVarDef<float> DisplayUIScale =
|
||||
CVarDef.Create("display.uiScale", 0f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
@@ -261,7 +261,7 @@ namespace Robust.Shared
|
||||
CVarDef.Create("audio.device", string.Empty, CVar.CLIENTONLY);
|
||||
|
||||
public static readonly CVarDef<float> AudioMasterVolume =
|
||||
CVarDef.Create("audio.mastervolume", 1.0f, CVar.CLIENTONLY);
|
||||
CVarDef.Create("audio.mastervolume", 1.0f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||
|
||||
/*
|
||||
* PLAYER
|
||||
|
||||
@@ -845,6 +845,7 @@ Types:
|
||||
Func`15: { All: True }
|
||||
Func`16: { All: True }
|
||||
Func`17: { All: True }
|
||||
Guid: { All: True }
|
||||
HashCode: { All: True }
|
||||
IAsyncDisposable: { All: True }
|
||||
IAsyncResult: { }
|
||||
|
||||
@@ -5,6 +5,7 @@ using Robust.Shared.Animations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects.Components.Map;
|
||||
using Robust.Shared.GameObjects.EntitySystemMessages;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
@@ -722,8 +723,9 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
var oldPos = Coordinates;
|
||||
SetPosition(newState.LocalPosition);
|
||||
|
||||
Owner.EntityManager.EventBus.RaiseEvent(
|
||||
EventSource.Local, new MoveEvent(Owner, oldPos, Coordinates));
|
||||
var ev = new MoveEvent(Owner, oldPos, Coordinates);
|
||||
EntitySystem.Get<SharedTransformSystem>().DeferMoveEvent(ev);
|
||||
|
||||
rebuildMatrices = true;
|
||||
}
|
||||
|
||||
@@ -873,6 +875,7 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
public IEntity Sender { get; }
|
||||
public EntityCoordinates OldPosition { get; }
|
||||
public EntityCoordinates NewPosition { get; }
|
||||
public bool Handled { get; set; }
|
||||
}
|
||||
|
||||
public class RotateEvent : EntitySystemMessage
|
||||
|
||||
34
Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs
Normal file
34
Robust.Shared/GameObjects/Systems/SharedTransformSystem.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.GameObjects.Components.Map;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
|
||||
namespace Robust.Shared.GameObjects.Systems
|
||||
{
|
||||
internal class SharedTransformSystem : EntitySystem
|
||||
{
|
||||
private readonly List<MoveEvent> _deferredMoveEvents = new();
|
||||
|
||||
public void DeferMoveEvent(MoveEvent moveEvent)
|
||||
{
|
||||
_deferredMoveEvents.Add(moveEvent);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var events = _deferredMoveEvents
|
||||
.OrderBy(e => e.Sender.HasComponent<IMapGridComponent>())
|
||||
.ToArray();
|
||||
|
||||
foreach (var ev in events)
|
||||
{
|
||||
ev.Sender.EntityManager.EventBus.RaiseEvent(EventSource.Local, ev);
|
||||
ev.Handled = true;
|
||||
}
|
||||
|
||||
_deferredMoveEvents.RemoveAll(e => e.Handled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ namespace Robust.Shared.Reflection
|
||||
|
||||
private readonly Dictionary<(Type baseType, string typeName), Type?> _yamlTypeTagCache = new();
|
||||
|
||||
private readonly Dictionary<string, Type> _looseTypeCache = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<Type> GetAllChildren<T>(bool inclusive = false)
|
||||
{
|
||||
@@ -134,6 +136,9 @@ namespace Robust.Shared.Reflection
|
||||
|
||||
public bool TryLooseGetType(string name, [NotNullWhen(true)] out Type? type)
|
||||
{
|
||||
if (_looseTypeCache.TryGetValue(name, out type))
|
||||
return true;
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
foreach (var tryType in assembly.DefinedTypes)
|
||||
@@ -141,6 +146,7 @@ namespace Robust.Shared.Reflection
|
||||
if (tryType.FullName!.EndsWith(name))
|
||||
{
|
||||
type = tryType;
|
||||
_looseTypeCache[name] = type;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ namespace Robust.Shared.Serialization
|
||||
var hashStr = Convert.ToBase64String(MappedStringsHash);
|
||||
hashStr = ConvertToBase64Url(hashStr);
|
||||
|
||||
var fileName = CacheForHash(hashStr);
|
||||
var fileName = CacheForHash(hashStr)!;
|
||||
using var file = File.OpenWrite(fileName);
|
||||
stream.CopyTo(file);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.IO;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Robust.Client.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
@@ -35,6 +35,17 @@ namespace Robust.UnitTesting.Client.GameObjects.Components
|
||||
private MapId MapB;
|
||||
private IMapGrid GridB = default!;
|
||||
|
||||
protected override void OverrideIoC()
|
||||
{
|
||||
base.OverrideIoC();
|
||||
|
||||
var mock = new Mock<IEntitySystemManager>();
|
||||
var system = new SharedTransformSystem();
|
||||
mock.Setup(m => m.GetEntitySystem<SharedTransformSystem>()).Returns(system);
|
||||
|
||||
IoCManager.RegisterInstance<IEntitySystemManager>(mock.Object, true);
|
||||
}
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void Setup()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user