Files
RobustToolbox/Robust.UnitTesting/Shared/GameObjects/EntityState_Tests.cs
T
AcruidandGitHub 6b9b56ca83 Grid Components Allocate Grids (#2597)
* Deleting a map is now routed through MapComponent deletion.

* Remove map and grid deletions from map networking, just delete the entity if you want to remove the map.

* Moved the chunkSize property of created grids from the networked MapData to the MapGridComponent state.

* Remove unused IMapManager.DefaultMap property.

* Removed MapCreationTick field from MapManager.MapCollection.

* Removed _maps hashset field from MapManager.

* Removed CreatedMaps array from network MapData.

* MapGrid.ParentMapId is now derived from the bound TransformComponent, and isn't required in the MapGrid ctor.
Removed MapGrid.CreatedTick, it can be found on MapGridComponent.CreationTick.

* Remove a bunch of ApplyGameStatePre code duplication.

* Completely refactored CreateGrid.

* Adds AddComponentUninitialized to the ECS system. This allows you to access a component before it is initialized in a using block.

* Use AddComponentUninitialized to allocate a grid after the component is allocated.

* MapLoader now creates the grids after creating the map entities.

* Chunksize and TileSize properties are now actually read out of the map yaml.
TileSize has a public Setter.

* Minor cleanup.

* Moved grid allocation onto the MapGridComponent.

* Final Cleanup.

* Merge Fail.

* Fixed test, grid was getting deleted because it was empty.

* Remove DeletedChunkDatum from grid networking.

* ApplyMapGridState moved from map manager to the MapGridComponent.
2022-03-13 18:28:59 -07:00

76 lines
2.8 KiB
C#

using System;
using System.IO;
using NUnit.Framework;
using Robust.Server.Reflection;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Reflection;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
namespace Robust.UnitTesting.Shared.GameObjects
{
[TestFixture, Serializable]
sealed class EntityState_Tests
{
/// <summary>
/// Used to measure the size of <see cref="object"/>s in bytes. This is not actually a test,
/// but a useful benchmark tool, so i'm leaving it here.
/// </summary>
[Test]
public void ComponentChangedSerialized()
{
var container = new DependencyCollection();
container.Register<ILogManager, LogManager>();
container.Register<IConfigurationManager, ConfigurationManager>();
container.Register<IConfigurationManagerInternal, ConfigurationManager>();
container.Register<INetManager, NetManager>();
container.Register<IReflectionManager, ServerReflectionManager>();
container.Register<IRobustSerializer, RobustSerializer>();
container.Register<IRobustMappedStringSerializer, RobustMappedStringSerializer>();
container.Register<IAuthManager, AuthManager>();
container.Register<IGameTiming, GameTiming>();
container.BuildGraph();
var cfg = container.Resolve<IConfigurationManagerInternal>();
cfg.Initialize(true);
cfg.LoadCVarsFromAssembly(typeof(IConfigurationManager).Assembly);
container.Resolve<IReflectionManager>().LoadAssemblies(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Shared"));
IoCManager.InitThread(container, replaceExisting: true);
cfg.LoadCVarsFromAssembly(typeof(IConfigurationManager).Assembly); // Robust.Shared
container.Resolve<INetManager>().Initialize(true);
var serializer = container.Resolve<IRobustSerializer>();
serializer.Initialize();
IoCManager.Resolve<IRobustMappedStringSerializer>().LockStrings();
byte[] array;
using(var stream = new MemoryStream())
{
var payload = new EntityState(
new EntityUid(512),
new []
{
new ComponentChange(0, true, false, new MapGridComponentState(new GridId(0), 16))
});
serializer.Serialize(stream, payload);
array = stream.ToArray();
}
IoCManager.Clear();
Assert.Pass($"Size in Bytes: {array.Length.ToString()}");
}
}
}