public void DispatchEvent(string name, object data = null) { ValidateName(name); //The fast path here is the direct system being used all the time, and the queued system never seeing action //Only rarely will the event system be used while an event is being dispatched, so this should be pretty efficient //if we're already dispatching an event, queue this up for later if (_internalEventSystem == _queuedEventSystem) { _internalEventSystem.DispatchEvent(name, data); } else { //Swap to the queued system to avoid corrupting execution state _internalEventSystem = _queuedEventSystem; _directEventSystem.DispatchEvent(name, data); while (_queuedEventSystem.HasOperations) { _queuedEventSystem.ApplyTo(_directEventSystem); } //Reset this after applying operations to avoid edge cases where a queued up dispatch allows operations to go to the direct system _internalEventSystem = _directEventSystem; } }
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(); } }
public void Execute(IEventSystem eventSystem) { eventSystem.DispatchEvent(_name, _data); }