public void LoadWorld(GameLoadSave gls) { Debug.Log(gls.WorldKingdoms + " - " + gls.WorldSettlements); WorldKingdoms = gls.WorldKingdoms; //TODO - fix load save //WorldLocation = gls.WorldKingdoms }
private List <Thread> InternalSettlementSave(GameLoadSave gls) { List <Thread> setSaveThreads = new List <Thread>(); Settlement[] toSave = new Settlement[5]; int sCount = 0; foreach (KeyValuePair <int, Settlement> kvp in gls.WorldSettlements) { toSave[sCount] = kvp.Value; sCount++; if (sCount == 5) { sCount = 0; Thread setSave = new Thread(() => ThreadSaveSettlements(toSave)); setSave.Start(); setSaveThreads.Add(setSave); toSave = new Settlement[5]; } } //Save remaining Thread last = new Thread(() => ThreadSaveSettlements(toSave)); last.Start(); setSaveThreads.Add(last); return(setSaveThreads); }
private void ThreadLoadKingdoms(GameLoadSave gls, string path) { if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path, FileMode.Open); gls.WorldKingdoms = (Dictionary <int, Kingdom>)bf.Deserialize(file); } }
private void ThreadSaveKingdoms(GameLoadSave gls) { BinaryFormatter bf = new BinaryFormatter(); string kingdomFile = PersistentDataPath + "/" + SaveFile + "/WorldKingdoms.save"; FileStream king = File.Create(kingdomFile); bf.Serialize(king, gls.WorldKingdoms); king.Close(); }
private void ThreadSaveEntity(GameLoadSave gls) { BinaryFormatter bf = new BinaryFormatter(); string entityFile = PersistentDataPath + "/" + SaveFile + "/Entities1.save"; string entityFile2 = PersistentDataPath + "/" + SaveFile + "/Entities2.save"; FileStream ent1 = File.Create(entityFile); bf.Serialize(ent1, gls.GameEntities); ent1.Close(); FileStream ent2 = File.Create(entityFile2); bf.Serialize(ent2, gls.GameEntityChunks); ent2.Close(); }
public GameLoadSave Load() { string filePath = PersistentDataPath + "/" + SaveFile + "/World.save"; string kingdomFile = PersistentDataPath + "/" + SaveFile + "/WorldKingdoms.save"; string settlementFile = PersistentDataPath + "/" + SaveFile + "/WorldSettlements.save"; string entityFile = PersistentDataPath + "/" + SaveFile + "/Entities1.save"; string entityFile2 = PersistentDataPath + "/" + SaveFile + "/Entities2.save"; GameLoadSave gls = new GameLoadSave(null); BinaryFormatter bf = new BinaryFormatter(); //Thread kThread = new Thread(() => ThreadLoadKingdoms(gls, kingdomFile)); //kThread.Start(); UnityEngine.Profiling.Profiler.BeginSample("kingdom_deserialisation"); if (File.Exists(kingdomFile)) { FileStream file = File.Open(kingdomFile, FileMode.Open); gls.WorldKingdoms = (Dictionary <int, Kingdom>)bf.Deserialize(file); } UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("set_deserialisation"); if (File.Exists(settlementFile)) { FileStream file = File.Open(settlementFile, FileMode.Open); gls.WorldSettlements = (Dictionary <int, Settlement>)bf.Deserialize(file); } UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("entity_deseri"); if (File.Exists(entityFile)) { FileStream file = File.Open(entityFile, FileMode.Open); gls.GameEntities = (Dictionary <int, Entity>)bf.Deserialize(file); } if (File.Exists(entityFile2)) { FileStream file = File.Open(entityFile2, FileMode.Open); gls.GameEntityChunks = (Dictionary <Vec2i, List <int> >)bf.Deserialize(file); } UnityEngine.Profiling.Profiler.EndSample(); //kThread. return(gls); }
/// <summary> /// Starts the main part of the game. /// Checks if a game exists to load, and if so loads it. /// If not, we generate a game <see cref="GameManager.GenerateGame(int)"/> /// If we generate a game, at current we set the players location /// </summary> void Start() { Debug.BeginDeepProfile("game_start"); if (GameToLoad == null || GameToLoad == "none") { Stopwatch s = new Stopwatch(); s.Start(); //UnityEngine.Profiling.CustomSampler gen = UnityEngine.Profiling.CustomSampler.Create("GenSampler"); int seed = 0; Debug.Log("No game to load, generating with seed " + seed); GenerateGame(seed); PathFinder = new PathFinder(WorldManager.World); PathFinder.SetPlayerPosition(PlayerManager.Player.TilePos); System.GC.Collect(); s.Stop(); Debug.Log("Generation took total time: " + s.ElapsedMilliseconds / 1000f); DebugGUI.SetData("genTime", s.ElapsedMilliseconds / 1000f); } else { UnityEngine.Profiling.CustomSampler load = UnityEngine.Profiling.CustomSampler.Create("LoadSampler"); load.Begin(); GameLoadSave gls = LoadSave.Load(); World world = new World(); world.LoadWorld(gls); EntityManager.Load(gls); WorldManager.SetWorld(world); Player player = new Player(); TestSettle = WorldManager.World.GetSettlement(0); Vec2i set = TestSettle.Centre; //player.SetPosition(new Vector3(set.x * World.ChunkSize, 0, set.z * World.ChunkSize)); player.SetPosition(new Vector3(World.WorldSize / 2 * World.ChunkSize, 0, World.WorldSize / 2 * World.ChunkSize)); PlayerManager.SetPlayer(player); load.End(); } Debug.EndDeepProfile("game_start"); RNG = new GenerationRandom(System.DateTime.Now.Millisecond); }
public void Load(GameLoadSave gls) { AllEntities = gls.GameEntities; //FixedEntitiesByChunk = gls.GameEntityChunks; }
public void Save(GameLoadSave gls) { gls.GameEntities = AllEntities; // gls.GameEntityChunks = FixedEntitiesByChunk; }
public void Load(GameLoadSave gls) { FixedEntities_ = gls.GameEntities; FixedEntities = gls.GameEntityChunks; }
public void Save(GameLoadSave gls) { gls.GameEntities = FixedEntities_; gls.GameEntityChunks = FixedEntities; }
public void WorldSave(GameLoadSave gls) { gls.WorldKingdoms = WorldKingdoms; gls.WorldSettlements = WorldSettlements; }
public void LoadWorld(GameLoadSave gls) { Debug.Log(gls.WorldKingdoms + " - " + gls.WorldSettlements); WorldKingdoms = gls.WorldKingdoms; WorldSettlements = gls.WorldSettlements; }
public void WorldSave(GameLoadSave gls) { gls.WorldKingdoms = WorldKingdoms; //TODO - fix world save // gls.WorldSettlements = WorldSettlements; }
public void Save(GameLoadSave gls) { string file = PersistentDataPath + "/" + SaveFile + "/World.save"; string kingdomFile = PersistentDataPath + "/" + SaveFile + "/WorldKingdoms.save"; string settlementFile = PersistentDataPath + "/" + SaveFile + "/WorldSettlements.save"; string entityFile = PersistentDataPath + "/" + SaveFile + "/Entities1.save"; string entityFile2 = PersistentDataPath + "/" + SaveFile + "/Entities2.save"; string direction = PersistentDataPath + "/" + SaveFile + "/ChunkRegions"; string setDir = PersistentDataPath + "/" + SaveFile + "/WorldSettlements"; Directory.CreateDirectory(direction); Directory.CreateDirectory(setDir); foreach (ChunkRegion r in gls.ChunkRegions) { if (r != null) { SaveChunkRegion(r); } } gls.GatherData(); List <Thread> threads = new List <Thread>(); threads.AddRange(InternalSettlementSave(gls)); Thread kingThread = new Thread(() => ThreadSaveKingdoms(gls)); kingThread.Start(); threads.Add(kingThread); /* * BinaryFormatter bf = new BinaryFormatter(); * FileStream king = File.Create(kingdomFile); * bf.Serialize(king, gls.WorldKingdoms); * king.Close();*/ Thread setThread = new Thread(() => ThreadSaveEntity(gls)); setThread.Start(); threads.Add(setThread); bool isFin = false; while (!isFin) { isFin = true; foreach (Thread t in threads) { if (t.IsAlive) { isFin = false; } } } /* * FileStream set = File.Create(settlementFile); * bf.Serialize(set, gls.WorldSettlements); * set.Close(); * * FileStream ent1 = File.Create(entityFile); * bf.Serialize(ent1, gls.GameEntities); * ent1.Close(); * * FileStream ent2 = File.Create(entityFile2); * bf.Serialize(ent2, gls.GameEntityChunks); * ent2.Close(); * //FileStream fs = File.Create(file); * //bf.Serialize(fs, gls); * //fs.Close();*/ }