public void TestGetWorldMatches()
        {
            var server = RobustServerSimulation.NewSimulation().InitializeInstance();

            var entManager = server.Resolve <IEntityManager>();
            var mapManager = server.Resolve <IMapManager>();

            var mapId = mapManager.CreateMap();

            var ent1 = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId));
            var ent2 = entManager.SpawnEntity(null, new MapCoordinates(new Vector2(100f, 0f), mapId));

            var xform1 = entManager.GetComponent <TransformComponent>(ent1);
            var xform2 = entManager.GetComponent <TransformComponent>(ent2);

            xform2.AttachParent(xform1);

            xform1.LocalRotation = MathF.PI;

            var(worldPos, worldRot, worldMatrix) = xform2.GetWorldPositionRotationMatrix();

            Assert.That(worldPos, Is.EqualTo(xform2.WorldPosition));
            Assert.That(worldRot, Is.EqualTo(xform2.WorldRotation));
            Assert.That(worldMatrix, Is.EqualTo(xform2.WorldMatrix));

            var(_, _, invWorldMatrix) = xform2.GetWorldPositionRotationInvMatrix();

            Assert.That(invWorldMatrix, Is.EqualTo(xform2.InvWorldMatrix));
        }
Beispiel #2
0
        public void SubscribeCompRefDirectedEvent()
        {
            // Arrange.
            var simulation = RobustServerSimulation
                             .NewSimulation()
                             .RegisterComponents(factory => factory.RegisterClass <DummyComponent>())
                             .RegisterEntitySystems(factory => factory.LoadExtraSystemType <SubscribeCompRefDirectedEventSystem>())
                             .InitializeInstance();

            var map = new MapId(1);

            simulation.AddMap(map);

            var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map));

            IoCManager.Resolve <IEntityManager>().AddComponent <DummyComponent>(entity);

            // Act.
            var testEvent = new TestStructEvent {
                TestNumber = 5
            };
            var eventBus = simulation.Resolve <IEntityManager>().EventBus;

            eventBus.RaiseLocalEvent(entity, ref testEvent);

            // Check that the entity system changed the value correctly
            Assert.That(testEvent.TestNumber, Is.EqualTo(10));
        }
Beispiel #3
0
        private static ISimulation SimulationFactory()
        {
            var sim = RobustServerSimulation
                      .NewSimulation()
                      .InitializeInstance();

            return(sim);
        }
Beispiel #4
0
    private static ISimulation SimulationFactory()
    {
        var sim = RobustServerSimulation
                  .NewSimulation()
                  .RegisterComponents(factory => factory.RegisterClass <IgnorePauseComponent>())
                  .InitializeInstance();

        return(sim);
    }
Beispiel #5
0
        public void SubscriptionNoMixedRefValueBroadcastEvent()
        {
            // Arrange.
            var simulation = RobustServerSimulation
                             .NewSimulation()
                             .RegisterEntitySystems(factory =>
                                                    factory.LoadExtraSystemType <SubscriptionNoMixedRefValueBroadcastEventSystem>());

            // Act. No mixed ref and value subscriptions are allowed.
            Assert.Throws(typeof(InvalidOperationException), () => simulation.InitializeInstance());
        }
        private static ISimulation SimulationFactory()
        {
            var sim = RobustServerSimulation
                      .NewSimulation()
                      .InitializeInstance();

            // Adds the map with id 1, and spawns entity 1 as the map entity.
            sim.AddMap(1);

            return(sim);
        }
        private static ISimulation SimulationFactory()
        {
            var sim = RobustServerSimulation
                      .NewSimulation()
                      .RegisterPrototypes(protoMan => protoMan.LoadString(Prototypes))
                      .InitializeInstance();

            // Adds the map with id 1, and spawns entity 1 as the map entity.
            sim.AddMap(1);

            return(sim);
        }
Beispiel #8
0
        private static ISimulation SimulationFactory()
        {
            var sim = RobustServerSimulation
                      .NewSimulation()
                      .RegisterComponents(factory => { factory.RegisterClass <ContainerManagerComponent>(); })
                      .RegisterPrototypes(protoMan => protoMan.LoadString(PROTOTYPES))
                      .InitializeInstance();

            // Adds the map with id 1, and spawns entity 1 as the map entity.
            sim.AddMap(1);

            return(sim);
        }
Beispiel #9
0
        public void SubscribeCompRefBroadcastEvent()
        {
            // Arrange.
            var simulation = RobustServerSimulation
                             .NewSimulation()
                             .RegisterEntitySystems(factory => factory.LoadExtraSystemType <SubscribeCompRefBroadcastSystem>())
                             .InitializeInstance();

            var ev = new TestStructEvent()
            {
                TestNumber = 5
            };

            simulation.Resolve <IEntityManager>().EventBus.RaiseEvent(EventSource.Local, ref ev);
            Assert.That(ev.TestNumber, Is.EqualTo(15));
        }
        public void SortedDirectedRefEvents()
        {
            // Arrange.
            var simulation = RobustServerSimulation
                             .NewSimulation()
                             .RegisterComponents(factory =>
            {
                factory.RegisterClass <OrderComponentA>();
                factory.RegisterClass <OrderComponentB>();
                factory.RegisterClass <OrderComponentC>();
            })
                             .RegisterEntitySystems(factory =>
            {
                factory.LoadExtraSystemType <OrderASystem>();
                factory.LoadExtraSystemType <OrderBSystem>();
                factory.LoadExtraSystemType <OrderCSystem>();
            })
                             .InitializeInstance();

            var map = new MapId(1);

            simulation.AddMap(map);

            var entity = simulation.SpawnEntity(null, new MapCoordinates(0, 0, map));

            entity.AddComponent <OrderComponentA>();
            entity.AddComponent <OrderComponentB>();
            entity.AddComponent <OrderComponentC>();

            // Act.
            var testEvent = new TestStructEvent {
                TestNumber = 5
            };
            var eventBus = simulation.Resolve <IEntityManager>().EventBus;

            eventBus.RaiseLocalEvent(entity.Uid, ref testEvent);

            // Check that the entity systems changed the value correctly
            Assert.That(testEvent.TestNumber, Is.EqualTo(15));
        }
Beispiel #11
0
        public void TestAnchoring()
        {
            var sim = RobustServerSimulation.NewSimulation();
            // sim.RegisterEntitySystems(m => m.LoadExtraSystemType<EntityLookupSystem>());
            var server = sim.InitializeInstance();

            var lookup     = server.Resolve <IEntitySystemManager>().GetEntitySystem <EntityLookupSystem>();
            var entManager = server.Resolve <IEntityManager>();
            var mapManager = server.Resolve <IMapManager>();

            var mapId = mapManager.CreateMap();
            var grid  = mapManager.CreateGrid(mapId);

            var theMapSpotBeingUsed = new Box2(Vector2.Zero, Vector2.One);

            grid.SetTile(new Vector2i(), new Tile(1));

            Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed).ToList().Count, Is.EqualTo(0));

            // Setup and check it actually worked
            var dummy = entManager.SpawnEntity(null, new MapCoordinates(Vector2.Zero, mapId));

            Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed).ToList().Count, Is.EqualTo(1));

            var xform = entManager.GetComponent <TransformComponent>(dummy);

            // When anchoring it should still get returned.
            xform.Anchored = true;
            Assert.That(xform.Anchored);
            Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed).ToList().Count, Is.EqualTo(1));

            xform.Anchored = false;
            Assert.That(lookup.GetEntitiesIntersecting(mapId, theMapSpotBeingUsed).ToList().Count, Is.EqualTo(1));

            entManager.DeleteEntity(dummy);
            mapManager.DeleteGrid(grid.Index);
            mapManager.DeleteMap(mapId);
        }
Beispiel #12
0
        public void SortedBroadcastRefEvents()
        {
            // Arrange.
            var simulation = RobustServerSimulation
                             .NewSimulation()
                             .RegisterEntitySystems(factory =>
            {
                factory.LoadExtraSystemType <BroadcastOrderASystem>();
                factory.LoadExtraSystemType <BroadcastOrderBSystem>();
                factory.LoadExtraSystemType <BroadcastOrderCSystem>();
            })
                             .InitializeInstance();

            // Act.
            var testEvent = new TestStructEvent {
                TestNumber = 5
            };
            var eventBus = simulation.Resolve <IEntityManager>().EventBus;

            eventBus.RaiseEvent(EventSource.Local, ref testEvent);

            // Check that the entity systems changed the value correctly
            Assert.That(testEvent.TestNumber, Is.EqualTo(15));
        }