mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
#if TOOLS
|
|
using System;
|
|
using JetBrains.Profiler.Api;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Robust.Server.Console.Commands;
|
|
|
|
public sealed partial class ProfileEntitySpawningCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private IEntityManager _entities = default!;
|
|
|
|
public string Command => "profileEntitySpawning";
|
|
public string Description => "Profiles entity spawning with n entities";
|
|
public string Help => $"Usage: {Command} | {Command} <amount> <prototype>";
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
var amount = 1000;
|
|
string? prototype = null;
|
|
|
|
switch (args.Length)
|
|
{
|
|
case 0:
|
|
break;
|
|
case 2:
|
|
if (!int.TryParse(args[0], out amount))
|
|
{
|
|
shell.WriteError($"First argument is not an integer: {args[0]}");
|
|
return;
|
|
}
|
|
|
|
prototype = args[1];
|
|
|
|
break;
|
|
default:
|
|
shell.WriteError(Help);
|
|
return;
|
|
}
|
|
|
|
GC.Collect();
|
|
|
|
Span<EntityUid> ents = stackalloc EntityUid[amount];
|
|
var stopwatch = new Stopwatch();
|
|
stopwatch.Start();
|
|
|
|
MeasureProfiler.StartCollectingData();
|
|
|
|
for (var i = 0; i < amount; i++)
|
|
{
|
|
ents[i] = _entities.SpawnEntity(prototype, MapCoordinates.Nullspace);
|
|
}
|
|
|
|
MeasureProfiler.SaveData();
|
|
|
|
shell.WriteLine($"Server: Profiled spawning {amount} entities in {stopwatch.Elapsed.TotalMilliseconds:N3} ms");
|
|
|
|
foreach (var ent in ents)
|
|
{
|
|
_entities.DeleteEntity(ent);
|
|
}
|
|
}
|
|
}
|
|
#endif
|