コード例 #1
0
        public void TestSingleSystemSave()
        {
            _game = TestingUtilities.CreateTestUniverse(1);
            _smAuthToken = new AuthenticationToken(_game.SpaceMaster);

            StarSystemFactory starsysfac = new StarSystemFactory(_game);
            StarSystem sol  = starsysfac.CreateSol(_game);
            StaticDataManager.ExportStaticData(sol, "solsave.json");
        }
コード例 #2
0
        public void Stargen_Default_StarSystem_With_No_Name_Throws()
        {
            var ssf = new StarSystemFactory(true);

            var ss = ssf.Create("");

            Assert.IsNotNull(ss);
            Assert.AreEqual("", ss.Name);
            Assert.IsNotNull(ss.Stars);
            Assert.GreaterOrEqual(ss.Stars.Count, 1);


            PrintSummary(ss);
        }
コード例 #3
0
        public void PerformanceTest()
        {
            // use a stop watch to get more accurate time.
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

            const int numSystems = 1000;

            _game = new Game(new NewGameSettings {
                GameName = "Unit Test Game", StartDateTime = DateTime.Now, MaxSystems = 0
            });                                                                                                                  // reinit with empty game, so we can do a clean test.
            _smAuthToken = new AuthenticationToken(_game.SpaceMaster);
            var ssf = new StarSystemFactory(_game);

            GC.Collect();

            // lets get our memory before starting:
            long startMemory = GC.GetTotalMemory(true);

            timer.Start();

            for (int i = 0; i < numSystems; i++)
            {
                ssf.CreateSystem(_game, "Performance Test No " + i, i);
            }

            timer.Stop();
            double totalTime = timer.Elapsed.TotalSeconds;

            int totalEntities = 0;

            foreach (StarSystem system in _game.GetSystems(_smAuthToken))
            {
                List <Entity> entities = system.GetAllEntitiesWithDataBlob <OrbitDB>(_smAuthToken);
                totalEntities += entities.Count;
            }

            long   endMemory   = GC.GetTotalMemory(true);
            double totalMemory = (endMemory - startMemory) / 1024.0; // in KB

            // note that because we do 1000 systems total time taken as milliseconds is the time for a single system, on average.
            string output = $"Total run time: {totalTime.ToString("N4")}s, per system: {(totalTime / numSystems * 1000).ToString("N2")}ms.\ntotal memory used: {(totalMemory / 1024.0).ToString("N2")} MB, per system: {(totalMemory / numSystems).ToString("N2")} KB.\nTotal Entities: {totalEntities}, per system: {totalEntities / (float)numSystems}.\nMemory per entity: {(totalMemory / totalEntities).ToString("N2")}KB";

            Console.WriteLine(output);

            // print results:
            Assert.Pass(output);
        }
コード例 #4
0
        public void Stargen_Default_StarSystem_Without_Moons()
        {
            var        ssf = new StarSystemFactory(false);
            StarSystem ss  = null;

            for (int i = 0; i < 200; i++)
            {
                ss = ssf.Create("Proxima");

                Assert.IsNotNull(ss);
                Assert.AreEqual("Proxima", ss.Name);
                Assert.IsNotNull(ss.Stars);
                Assert.GreaterOrEqual(ss.Stars.Count, 1);
            }

            PrintSummary(ss);
        }
コード例 #5
0
ファイル: Discovery.cs プロジェクト: vind113/4X
        private static IList <StarSystem> DiscoverNewStarSystem(int discoveredSystemsCount)
        {
            IList <StarSystem> generatedSystems = new List <StarSystem>();

            int maxSystemsToGenerate = (int)(Math.Sqrt(discoveredSystemsCount));
            int systemsToGenerate    = HelperRandomFunctions.GetRandomInt(1, maxSystemsToGenerate + 1);

            for (int index = 0; index < systemsToGenerate; index++)
            {
                StarSystem generatedSystem =
                    StarSystemFactory.GetStarSystem($"System {discoveredSystemsCount + 1} #{index}");

                generatedSystems.Add(generatedSystem);
            }

            return(generatedSystems);
        }
コード例 #6
0
        public void Stargen_Default_StarSystem_With_Moons()
        {
            var        ssf = new StarSystemFactory(true);
            StarSystem ss  = null;

            for (int i = 0; i < 200; i++)
            {
                ss = ssf.Create("Proxima");
                GameState.Instance.StarSystemCurrentIndex++;

                Assert.IsNotNull(ss);
                Assert.AreEqual("Proxima", ss.Name);
                Assert.IsNotNull(ss.Stars);
                Assert.GreaterOrEqual(ss.Stars.Count, 1);
            }

            PrintSummary(ss);
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            Application.Init();

            XmlConfigurator.Configure();
            logger.Info("Program Started");

            var ssf = new StarSystemFactory(true);

            GameState.Instance.StarSystems.Add(ssf.Create("Test"));
            GameState.Instance.StarSystems.Add(ssf.Create("Foo"));
            GameState.Instance.StarSystems.Add(ssf.Create("Bar"));

            MainWindowGTK win = new MainWindowGTK();

            win.Show();
            Application.Run();
        }
コード例 #8
0
ファイル: TestingUtilities.cs プロジェクト: mqrause/Pulsar4x
        internal TestGame(int numSystems = 10)
        {
            GameSettings = new  NewGameSettings {
                GameName = "Unit Test Game", MaxSystems = numSystems, CreatePlayerFaction = false
            };

            Game = new Game(GameSettings);

            // add a faction:
            HumanFaction = FactionFactory.CreateFaction(Game, "New Terran Utopian Empire");

            // add a species:
            HumanSpecies = SpeciesFactory.CreateSpeciesHuman(HumanFaction, Game.GlobalManager);

            // add another faction:
            GreyAlienFaction = FactionFactory.CreateFaction(Game, "The Grey Empire");
            // Add another species:
            GreyAlienSpecies = SpeciesFactory.CreateSpeciesHuman(GreyAlienFaction, Game.GlobalManager);

            // Greys Name the Humans.
            HumanSpecies.GetDataBlob <NameDB>().SetName(GreyAlienFaction.Guid, "Stupid Terrans");
            // Humans name the Greys.
            GreyAlienSpecies.GetDataBlob <NameDB>().SetName(HumanFaction.Guid, "Space bugs");


            StarSystemFactory starfac = new StarSystemFactory(Game);

            Sol         = starfac.CreateSol(Game);
            Earth       = NameLookup.GetFirstEntityWithName(Sol, "Earth"); //Sol.Entities[3]; //should be fourth entity created
            EarthColony = ColonyFactory.CreateColony(HumanFaction, HumanSpecies, Earth);

            DefaultEngineDesign = DefaultStartFactory.DefaultThrusterDesign(Game, HumanFaction);
            DefaultWeaponDesign = DefaultStartFactory.DefaultSimpleLaser(Game, HumanFaction);
            DefaultShipDesign   = DefaultStartFactory.DefaultShipDesign(Game, HumanFaction);

            Vector3 position = Earth.GetDataBlob <PositionDB>().AbsolutePosition_AU;

            DefaultShip = ShipFactory.CreateShip(DefaultShipDesign, HumanFaction, position, Earth, Sol, "Serial Peacemaker");
            Sol.SetDataBlob(DefaultShip.ID, new TransitableDB());
        }
コード例 #9
0
        public void TestSetup()
        {
            _gameState             = GameState.Instance;
            _gameState.Name        = "Test Game";
            _gameState.Species     = new BindingList <Species>();
            _gameState.Factions    = new BindingList <Faction>();
            _gameState.StarSystems = new BindingList <StarSystem>();
            _gameState.Stars       = new BindingList <Star>();
            _gameState.Planets     = new BindingList <Planet>();

            var species = new Species {
                Id = Guid.NewGuid(), Name = "Test Humans"
            };

            _gameState.Species.Add(species);
            var theme = new FactionTheme {
                Id = Guid.NewGuid(), Name = "Test Theme"
            };

            _gameState.Factions.Add(new Faction(0)
            {
                Id = Guid.NewGuid(), Name = "Test Faction", Species = species, Title = "Mighty Humans", FactionTheme = theme
            });

            var ssf = new StarSystemFactory(true);
            var ss  = ssf.Create("Test Sol");

            GameState.Instance.StarSystemCurrentIndex++;
            ss.Stars.ToList().ForEach(x => _gameState.Stars.Add(x));
            ss.Stars.ToList().SelectMany(x => x.Planets).ToList().ForEach(p => _gameState.Planets.Add(p));

            UriBuilder uri = new UriBuilder(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

            _appPath    = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path));
            _saveFolder = Path.Combine(_appPath, "Test");

            _nameThemes = new List <CommanderNameTheme>();
            var ct1 = new CommanderNameTheme()
            {
                Id          = Guid.NewGuid(),
                Name        = "Test Theme 1",
                NameEntries =
                {
                    new NameEntry()
                    {
                        IsFemale = false, Name = "Bob", NamePosition = NamePosition.FirstName
                    },
                    new NameEntry()
                    {
                        IsFemale = false, Name = "Smith", NamePosition = NamePosition.LastName
                    }
                }
            };

            _nameThemes.Add(ct1);
            var ct2 = new CommanderNameTheme()
            {
                Id          = Guid.NewGuid(),
                Name        = "Test Theme 2",
                NameEntries =
                {
                    new NameEntry()
                    {
                        IsFemale = true, Name = "Sarah", NamePosition = NamePosition.FirstName
                    },
                    new NameEntry()
                    {
                        IsFemale = false, Name = "Connor", NamePosition = NamePosition.LastName
                    }
                }
            };

            _nameThemes.Add(ct2);
        }
コード例 #10
0
ファイル: StarSystem.cs プロジェクト: Corteza/Galaxy
 private void Start()
 {
     StarSystemFactory.Create(Seed);
 }