public bool TryLoadMap(string mapName, ITime engineTime, ICommandContext commandContext) { //TODO: need to make sure the scene can be queried properly var models = new ModelManager(_modelCreator, Renderer.Scene); try { var mapFileName = BSPUtils.FormatMapFileName(mapName); IModel worldModel; try { worldModel = models.Load(mapFileName); } catch (Exception e) { //TODO: needs a rework if (e is InvalidOperationException || e is InvalidBSPVersionException || e is IOException) { worldModel = null; } else { throw; } } if (worldModel == null) { Logger.Information($"Couldn't spawn server {mapFileName}"); return(false); } _eventSystem.DispatchEvent(EngineEvents.ServerMapDataFinishLoad); if (!(worldModel is BSPModel bspWorldModel)) { Logger.Information($"Model {mapFileName} is not a map"); return(false); } _eventSystem.DispatchEvent(EngineEvents.ServerMapCRCComputed); MapInfo = new MapInfo(mapName, MapInfo?.Name, bspWorldModel); //Load the fallback model now to ensure that BSP indices are matched up models.LoadFallbackModel(Framework.FallbackModelName); Scene = new Entities.Scene(this, EntitySystemMetaData, models, engineTime, commandContext); models = null; EntitySystem.SetScene(Scene); return(true); } finally { models?.Dispose(); } }
/// <summary> /// Returns whether the given map name is valid /// </summary> /// <param name="mapName">The map name without directory or extension</param> public bool IsMapValid(string mapName) { return(_fileSystem.Exists(BSPUtils.FormatMapFileName(mapName))); }