Пример #1
0
 public SimulationConfiguration(List <NodeConfig> nodeConfiguration,
                                List <EdgeConfig> edgeConfiguration,
                                List <PlayerConfig> playerConfiguration,
                                List <Archetype> archetypes,
                                List <SystemConfiguration> systems,
                                LifeCycleConfiguration lifeCycleConfiguration)
     : base(archetypes, systems, lifeCycleConfiguration)
 {
     NodeConfiguration   = nodeConfiguration ?? new List <NodeConfig>();
     EdgeConfiguration   = edgeConfiguration ?? new List <EdgeConfig>();
     PlayerConfiguration = playerConfiguration ?? new List <PlayerConfig>();
 }
Пример #2
0
        public void TestMemoryResourceTransmission()
        {
            var nodeConfigs = new List <NodeConfig> {
                new NodeConfig()
                {
                    X         = 0,
                    Y         = 0,
                    Name      = "Node 0",
                    Archetype = SubsystemNode.Archetype,
                }
            };

            ConfigurationHelper.ProcessNodeConfigs(nodeConfigs);

            var systems = new List <SystemConfiguration>()
            {
                new SystemConfiguration <ItemStorageSystem>(),
                new SystemConfiguration <ResourcesSystem>()
                {
                    ExtensionConfiguration = new SystemExtensionConfiguration[]
                    {
                        new SystemExtensionConfiguration <ISubsystemResourceEffect>()
                        {
                            Implementations = new SystemExtensionImplementation[]
                            {
                                new SystemExtensionConfiguration <ISubsystemResourceEffect> .SystemExtensionImplementation <ResetMemoryEachTick>(),
                                new SystemExtensionConfiguration <ISubsystemResourceEffect> .SystemExtensionImplementation <ItemStorageConsumesMemoryEffect>(),
                            }
                        }
                    }
                },
            };

            var archetypes = new List <Archetype>()
            {
                SubsystemNode.Archetype,
                ScannerTool.Archetype,
            };

            var lifecycleConfig = new LifeCycleConfiguration();
            var configuration   = new SimulationConfiguration(nodeConfigs, null, null, archetypes, systems, lifecycleConfig);
            var scenarioA       = new SimulationScenario()
            {
                Configuration = configuration
            };
            var rootA = SimulationInstaller.CreateSimulationRoot(scenarioA);
            var ecsA  = rootA.ECS;

            MemoryResource memoryResourceA;

            TestEntityState(ecsA, SimulationConstants.SubsystemInitialMemory, out memoryResourceA);

            ecsA.Tick();

            var scenarioB = new SimulationScenario()
            {
                Configuration = configuration
            };
            var rootB = SimulationInstaller.CreateSimulationRoot(scenarioB);
            var ecsB  = rootB.ECS;

            MemoryResource memoryResourceB;

            TestEntityState(ecsB, SimulationConstants.SubsystemInitialMemory, out memoryResourceB);

            Assert.That(memoryResourceB, Is.Not.EqualTo(memoryResourceA));

            var json = rootA.GetEntityState();

            rootB.UpdateEntityState(json);

            MemoryResource memoryResourceC;

            TestEntityState(ecsB, SimulationConstants.ItemMemoryConsumption, out memoryResourceC);

            Assert.That(memoryResourceC, Is.EqualTo(memoryResourceB), "Memory Resource was recreated");
        }
Пример #3
0
        public void TestItemOwnerTransmission()
        {
            var testSystem = new Archetype("TestSystem")
                             .HasComponent(new ComponentBinding <Subsystem>())
                             .HasComponent(new ComponentBinding <Coordinate2DProperty>())
                             .HasComponent(new ComponentBinding <Name>())
                             .HasComponent(new ComponentBinding <ItemStorage>()
            {
                ComponentTemplate = new ItemStorage()
                {
                    Items = new ItemContainer[1],
                }
            });

            var testItem = new Archetype("TestItem")
                           .HasComponent(new ComponentBinding <Scanner>())
                           .HasComponent(new ComponentBinding <Owner>());

            var nodeConfigs = new List <NodeConfig> {
                new NodeConfig()
                {
                    X         = 0,
                    Y         = 0,
                    Name      = "Node 0",
                    Archetype = testSystem.Name
                },
            };

            ConfigurationHelper.ProcessNodeConfigs(nodeConfigs);

            var systems = new List <SystemConfiguration>()
            {
                new SystemConfiguration <ItemStorageSystem>(),
            };

            var archetypes = new List <Archetype>()
            {
                testSystem,
                testItem,
            };

            var lifecycleConfig = new LifeCycleConfiguration();
            var configuration   = new SimulationConfiguration(nodeConfigs, null, null, archetypes, systems, lifecycleConfig);
            var scenario        = new SimulationScenario()
            {
                Configuration = configuration
            };

            var rootA = SimulationInstaller.CreateSimulationRoot(scenario);
            var ecsA  = rootA.ECS;

            Owner ownerA;

            TestEntityState(ecsA, null, out ownerA);

            ecsA.Tick();

            var rootB = SimulationInstaller.CreateSimulationRoot(scenario);
            var ecsB  = rootB.ECS;

            Owner ownerB;

            TestEntityState(ecsB, null, out ownerB);

            Assert.That(ownerB, Is.Not.EqualTo(ownerA));

            const int owner = 3;

            ownerA.Value = 3;

            var json = rootA.GetEntityState();

            rootB.UpdateEntityState(json);

            Owner ownerC;

            TestEntityState(ecsB, owner, out ownerC);

            Assert.That(ownerC, Is.EqualTo(ownerB), "Owner was recreated");

            ownerA.Value = null;
            json         = rootA.GetEntityState();
            rootB.UpdateEntityState(json);

            Owner ownerD;

            TestEntityState(ecsB, null, out ownerD);

            Assert.That(ownerD, Is.EqualTo(ownerB), "Owner was recreated");
        }