public void LoadEntities(string data) { { var keyvalues = KeyValuesParser.ParseAll(data); //For diagnostics: index of the entity in the entity data var index = 0; foreach (var block in keyvalues) { //Better error handling than the engine: if an entity couldn't be created, log it and keep going try { LoadEntity(block, index); } catch (ArgumentException e) { Log.Message($"A problem occurred while creating entity {index}:"); Log.Exception(e); } ++index; } } //At this point we'll have a lot of garbage, so clean up as much as possible GC.Collect(); }
private void LoadEntities(string entityData) { var keyvalues = KeyValuesParser.ParseAll(entityData); for (var index = 0; index < keyvalues.Count; ++index) { //Better error handling than the engine: if an entity couldn't be created, log it and keep going try { LoadEntity(keyvalues[index], index); } catch (EntityInstantiationException e) { _logger.Error(e, $"A problem occurred while creating entity {index}"); } } }
/// <summary> /// Extracts the WAD path keyvalue from the entities string /// </summary> /// <param name="entities"></param> /// <returns></returns> public static string ExtractWADPathKeyValue(string entities) { if (string.IsNullOrWhiteSpace(entities)) { throw new ArgumentException(nameof(entities)); } //Scan the worldspawn entity for the wad keyvalue var worldspawnData = KeyValuesParser.Parse(entities); var wadPathIndex = worldspawnData.FindIndex(kp => kp.Key == "wad"); if (wadPathIndex != -1) { return(worldspawnData[wadPathIndex].Value); } throw new InvalidOperationException("No wadpath keyvalue found"); }
/// <summary> /// Extracts the WAD path keyvalue from the entities string /// </summary> /// <param name="entities"></param> public static string ExtractWADPathKeyValue(string entities) { if (string.IsNullOrWhiteSpace(entities)) { throw new ArgumentException("Entities string must be valid", nameof(entities)); } //Scan the worldspawn entity for the wad keyvalue var worldspawnData = KeyValuesParser.Parse(entities); var wadPathIndex = worldspawnData.FindIndex(kp => kp.Key == "wad"); if (wadPathIndex != -1) { return(worldspawnData[wadPathIndex].Value); } //To match original engine behavior, return an empty string return(string.Empty); }
public void LoadEntities(string entityData) { var keyvalues = KeyValuesParser.ParseAll(entityData); for (var index = 0; index < keyvalues.Count; ++index) { //Better error handling than the engine: if an entity couldn't be created, log it and keep going try { LoadEntity(keyvalues[index], index); } catch (EntityInstantiationException e) { Logger.Error(e, $"A problem occurred while creating entity {index}"); } } //TODO: maybe verify that this is worldspawn? World = Entities[0].GetComponent <Collider>(); }