// After being deserialized we need to reset the world boundaries since they aren't serialized. // We also deserialize each organism public void CompleteOrganismDeserialization() { foreach (DictionaryEntry e in _orgMap) { var organism = ((OrganismWrapper)e.Value).Organism; OrganismWorldBoundary.SetWorldBoundary(organism, (string)e.Key); try { if (organism is Animal) { ((Animal)organism).DeserializeAnimal(organism.SerializedStream); } else { ((Plant)organism).DeserializePlant(organism.SerializedStream); } } catch (Exception exception) { ErrorLog.LogHandledException(exception); if (GameEngine.Current != null) { GameEngine.Current.OnEngineStateChanged( new EngineStateChangedEventArgs(EngineStateChangeType.Other, "Organism Deserialization Failure.", organism.GetType().Assembly.GetName().Name + "refuses to come out of Cryogenic Stasis until a cure is found for Terrarium Syndrome (aka Deserialization Failure)")); } } organism.SerializedStream = null; } }
// This is our last line of defense to deal with animals that try to hang the game (deadlock). // (the first line of defense is ThreadAborting the thread with our timer, see description in ActivateBug()). // Thus, it must have robust code that can always fail in some graceful way, and should blacklist // any animal that hangs. Because blacklisting an animal is very drastic, we go through great pains // to do it fairly, which means that we want to ensure that the animal is getting actual time to run // in the OS kernel, and the elapsed time isn't simply because the system is starving its thread // or something. If the animal got plenty of kernel time and didn't come back, we restart the game // and blacklist them permanently. If they aren't getting kernel time but it still taking way too long // we simply restart the game. // Add an organism to get timesliced. public void Add(Organism org, string id) { // We should only be adding organisms at the beginning Debug.Assert(_organismsActivated == 0); // Reconstruct its world boundary OrganismWorldBoundary.SetWorldBoundary(org, id); if (_organisms.ContainsKey(id)) { throw new OrganismAlreadyExistsException(); } _organisms.Add(new OrganismWrapper(org)); }