private void ImportExportSystem(StarSystem system) { //TODO: need to be able to export a system that will only save systemBodies. //for a generated one, just saving the seed should suffice. //for a created one we'll have to do more. //also need to be able to export a players view of a system. but that would likely be a different function altogether. SerializationManager.Export(_game, "testSystemExport", system); string jsonString = SerializationManager.Export(_game, system); int entityCount = system.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>(_smAuthToken).Count; _game = TestingUtilities.CreateTestUniverse(0); _smAuthToken = new AuthenticationToken(_game.SpaceMaster); StarSystem importedSystem = SerializationManager.ImportSystemJson(_game, jsonString); Assert.AreEqual(system.Guid, importedSystem.Guid); // See that the entities were imported. Assert.AreEqual(entityCount, importedSystem.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>(_smAuthToken).Count); // Ensure the system was added to the game's system list. List <StarSystem> systems = _game.GetSystems(_smAuthToken); Assert.AreEqual(1, systems.Count); // Ensure the returned value references the same system as the game's system list system = _game.GetSystem(_smAuthToken, system.Guid); Assert.AreEqual(importedSystem, system); }
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"); }
public void TestNewtonTrajectory() { Game game = new Game(); EntityManager mgr = new EntityManager(game, false); Entity parentEntity = TestingUtilities.BasicEarth(mgr); PositionDB pos1 = new PositionDB(mgr.ManagerGuid) { X = 0, Y = 8.52699302490434E-05, Z = 0 }; BaseDataBlob[] objBlobs1 = new BaseDataBlob[3]; objBlobs1[0] = pos1; objBlobs1[1] = new MassVolumeDB() { Mass = 10000 }; objBlobs1[2] = new NewtonMoveDB(parentEntity) { CurrentVector_kms = new Vector3(-10.0, 0, 0) }; Entity objEntity1 = new Entity(mgr, objBlobs1); PositionDB pos2 = new PositionDB(mgr.ManagerGuid) { X = 0, Y = 8.52699302490434E-05, Z = 0 }; BaseDataBlob[] objBlobs2 = new BaseDataBlob[3]; objBlobs2[0] = pos2; objBlobs2[1] = new MassVolumeDB() { Mass = 10000 }; objBlobs2[2] = new NewtonMoveDB(parentEntity) { CurrentVector_kms = new Vector3(-10.0, 0, 0) }; Entity objEntity2 = new Entity(mgr, objBlobs2); var seconds = 100; for (int i = 0; i < seconds; i++) { NewtonionMovementProcessor.NewtonMove(objEntity1, 1); } NewtonionMovementProcessor.NewtonMove(objEntity2, seconds); var distance1 = Distance.AuToKm(pos1.AbsolutePosition_AU.Length()); var distance2 = Distance.AuToKm(pos2.AbsolutePosition_AU.Length()); //this test is currently failing and I'm unsure why. right now the code is using a 1s timestep so it should come out exact... //it looks ok graphicaly though so I'm not *too* conserned about this one right now. Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta }
public void GameImportExport() { // Nubmer of systems to generate for this test. Configurable. const int numSystems = 10; const bool generateSol = false; int totalSystems = generateSol ? numSystems + 1 : numSystems; // lets create a bad save game: // Check default nulls throw: Assert.Catch <ArgumentNullException>(() => SerializationManager.Export(null, File)); Assert.Catch <ArgumentException>(() => SerializationManager.Export(_game, (string)null)); Assert.Catch <ArgumentException>(() => SerializationManager.Export(_game, string.Empty)); Assert.Catch <ArgumentException>(() => SerializationManager.ImportGame((string)null)); Assert.Catch <ArgumentException>(() => SerializationManager.ImportGame(string.Empty)); Assert.Catch <ArgumentNullException>(() => SerializationManager.ImportGame((Stream)null)); _game = TestingUtilities.CreateTestUniverse(numSystems, _testTime, generateSol); // lets create a good saveGame SerializationManager.Export(_game, File); Assert.IsTrue(System.IO.File.Exists(Path.Combine(SerializationManager.GetWorkingDirectory(), File))); Console.WriteLine(Path.Combine(SerializationManager.GetWorkingDirectory(), File)); // now lets give ourselves a clean game: _game = null; //and load the saved data: _game = SerializationManager.ImportGame(File); _smAuthToken = new AuthenticationToken(_game.SpaceMaster); Assert.AreEqual(totalSystems, _game.GetSystems(_smAuthToken).Count); Assert.AreEqual(_testTime, StaticRefLib.CurrentDateTime); List <Entity> entities = _game.GlobalManager.GetAllEntitiesWithDataBlob <FactionInfoDB>(_smAuthToken); Assert.AreEqual(3, entities.Count); entities = _game.GlobalManager.GetAllEntitiesWithDataBlob <SpeciesDB>(_smAuthToken); Assert.AreEqual(2, entities.Count); // lets check the the refs were hocked back up: Entity species = _game.GlobalManager.GetFirstEntityWithDataBlob <SpeciesDB>(_smAuthToken); NameDB speciesName = species.GetDataBlob <NameDB>(); Assert.AreSame(speciesName.OwningEntity, species); // <?TODO: Expand this out to cover many more DBs, entities, and cases. }
public void SaveGameConsistency() { const int maxTries = 10; for (int numTries = 0; numTries < maxTries; numTries++) { TestingUtilities.CreateTestUniverse(10); SerializationManager.Export(_game, File); _game = SerializationManager.ImportGame(File); SerializationManager.Export(_game, File2); var fs1 = new FileStream(Path.Combine(SerializationManager.GetWorkingDirectory(), File), FileMode.Open); var fs2 = new FileStream(Path.Combine(SerializationManager.GetWorkingDirectory(), File2), FileMode.Open); if (fs1.Length == fs2.Length) { // Read and compare a byte from each file until either a // non-matching set of bytes is found or until the end of // file1 is reached. int file1Byte; int file2Byte; do { // Read one byte from each file. file1Byte = fs1.ReadByte(); file2Byte = fs2.ReadByte(); } while ((file1Byte == file2Byte) && (file1Byte != -1)); // Close the files. fs1.Close(); fs2.Close(); // Return the success of the comparison. "file1byte" is // equal to "file2byte" at this point only if the files are // the same. if (file1Byte - file2Byte == 0) { Assert.Pass("Save Games consistent on try #" + (numTries + 1)); } } fs1.Close(); fs2.Close(); } Assert.Fail("SaveGameConsistency could not be verified. Please ensure saves are properly loading and saving."); }
public void Init() { _game = new Game(new NewGameSettings { GameName = "Unit Test Game", StartDateTime = DateTime.Now, MaxSystems = 1 }); _faction = FactionFactory.CreateFaction(_game, "Terran"); _faction.GetDataBlob <FactionTechDB>().ResearchedTechs.Add(new Guid("b8ef73c7-2ef0-445e-8461-1e0508958a0e"), 3); _faction.GetDataBlob <FactionTechDB>().ResearchedTechs.Add(new Guid("08fa4c4b-0ddb-4b3a-9190-724d715694de"), 3); _faction.GetDataBlob <FactionTechDB>().ResearchedTechs.Add(new Guid("8557acb9-c764-44e7-8ee4-db2c2cebf0bc"), 5); _faction.GetDataBlob <FactionTechDB>().ResearchedTechs.Add(new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c"), 1); _faction.GetDataBlob <FactionTechDB>().ResearchedTechs.Add(new Guid("c827d369-3f16-43ef-b112-7d5bcafb74c7"), 1); //Nuclear Thermal Engine Technology _faction.GetDataBlob <FactionTechDB>().ResearchedTechs.Add(new Guid("db6818f3-99e9-46c1-b903-f3af978c38b2"), 1); _starSystem = new StarSystem(_game, "Sol", -1); _sol = TestingUtilities.BasicSol(_starSystem); /////Ship Class///// }
public void EntityImportExport() { // Ensure we have a test universe. _game = TestingUtilities.CreateTestUniverse(10); _smAuthToken = new AuthenticationToken(_game.SpaceMaster); Assert.NotNull(_game); // Choose a random system. var rand = new Random(); List <StarSystem> systems = _game.GetSystems(_smAuthToken); int systemIndex = rand.Next(systems.Count - 1); StarSystem system = systems[systemIndex]; // Export/Reinport all system bodies in that system. foreach (Entity entity in system.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>(_smAuthToken)) { string jsonString = SerializationManager.Export(_game, entity); // Clone the entity for later comparison. ProtoEntity clone = entity.Clone(); // Destroy the entity. entity.Destroy(); // Ensure the entity was destroyed. Entity foundEntity; Assert.IsFalse(system.FindEntityByGuid(clone.Guid, out foundEntity)); // Import the entity back into the manager. Entity importedEntity = SerializationManager.ImportEntityJson(_game, jsonString, system); // Ensure the imported entity is valid Assert.IsTrue(importedEntity.IsValid); // Check to find the guid. Assert.IsTrue(system.FindEntityByGuid(clone.Guid, out foundEntity)); // Check the ID imported correctly. Assert.AreEqual(clone.Guid, importedEntity.Guid); // Check the datablobs imported correctly. Assert.AreEqual(clone.DataBlobs.Where(dataBlob => dataBlob != null).ToList().Count, importedEntity.DataBlobs.Count); // Check the manager is the same. Assert.AreEqual(system, importedEntity.Manager); } }
public void CompareLoadedGameWithOrigional() //TODO do this after a few game ticks and check the comparitiveTests again. { //create a new game Game newGame = TestingUtilities.CreateTestUniverse(10, _testTime, true); Entity ship = newGame.GlobalManager.GetFirstEntityWithDataBlob <TransitableDB>(); StarSystem firstSystem = newGame.Systems.First().Value; DateTime jumpTime = StaticRefLib.CurrentDateTime + TimeSpan.FromMinutes(1); //insert a jump so that we can compair timeloop dictionary InterSystemJumpProcessor.SetJump(newGame, jumpTime, firstSystem, jumpTime, ship); // lets create a good saveGame SerializationManager.Export(newGame, File); //then load it: Game loadedGame = SerializationManager.ImportGame(File); //run some tests ComparitiveTests(newGame, loadedGame); }
public void StarSystemImportExport() { _game = TestingUtilities.CreateTestUniverse(10); _smAuthToken = new AuthenticationToken(_game.SpaceMaster); Assert.NotNull(_game); // Choose a procedural system. List <StarSystem> systems = _game.GetSystems(_smAuthToken); var rand = new Random(); int systemIndex = rand.Next(systems.Count - 1); StarSystem system = systems[systemIndex]; ImportExportSystem(system); //Now do the same thing, but with Sol. DefaultStartFactory.DefaultHumans(_game, "Humans"); systems = _game.GetSystems(_smAuthToken); system = systems[systems.Count - 1]; ImportExportSystem(system); }
private void ImportExportSystem(StarSystem system) { string jsonString = SerializationManager.Export(_game, system); int entityCount = system.SystemManager.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>(_smAuthToken).Count; _game = TestingUtilities.CreateTestUniverse(0); _smAuthToken = new AuthenticationToken(_game.SpaceMaster); StarSystem importedSystem = SerializationManager.ImportSystemJson(_game, jsonString); Assert.AreEqual(system.Guid, importedSystem.Guid); // See that the entities were imported. Assert.AreEqual(entityCount, importedSystem.SystemManager.GetAllEntitiesWithDataBlob <SystemBodyInfoDB>(_smAuthToken).Count); // Ensure the system was added to the game's system list. List <StarSystem> systems = _game.GetSystems(_smAuthToken); Assert.AreEqual(1, systems.Count); // Ensure the returned value references the same system as the game's system list system = _game.GetSystem(_smAuthToken, system.Guid); Assert.AreEqual(importedSystem, system); }
public void TestNewtonTrajectory() { Game game = new Game(); EntityManager mgr = new EntityManager(game, false); Entity parentEntity = TestingUtilities.BasicEarth(mgr); PositionDB pos1 = new PositionDB(mgr.ManagerGuid, parentEntity) { X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0 }; var newt1 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0)) { DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0) }; BaseDataBlob[] objBlobs1 = new BaseDataBlob[4]; objBlobs1[0] = pos1; objBlobs1[1] = new MassVolumeDB() { MassDry = 10000 }; objBlobs1[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid); objBlobs1[3] = newt1; Entity objEntity1 = new Entity(mgr, objBlobs1); PositionDB pos2 = new PositionDB(mgr.ManagerGuid, parentEntity) { X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0 }; var newt2 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0)) { DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0) }; BaseDataBlob[] objBlobs2 = new BaseDataBlob[4]; objBlobs2[0] = pos2; objBlobs2[1] = new MassVolumeDB() { MassDry = 10000 }; objBlobs2[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid); objBlobs2[3] = newt2; Entity objEntity2 = new Entity(mgr, objBlobs2); var seconds = 100; for (int i = 0; i < seconds; i++) { NewtonionMovementProcessor.NewtonMove(objEntity1, 1); //this is a hacky way to allow us to increment each second, //since the above method looks at the manager datetime and we're not updating that. newt1.LastProcessDateTime -= TimeSpan.FromSeconds(1); } NewtonionMovementProcessor.NewtonMove(objEntity2, seconds); var distance1 = (pos1.RelativePosition_m.Length()); var distance2 = (pos2.RelativePosition_m.Length()); Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta }